FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTTask.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7#ifndef FMTTASK_Hm_included
8#define FMTTASK_Hm_included
9#include <memory>
10#include "FMTObject.h"
11#include <boost/thread/recursive_mutex.hpp>
12#include <boost/thread/condition_variable.hpp>
13#if defined _MSC_VER
15#endif
16
17
19namespace Parallel
20{
21 // DocString: FMTTask
27 {
28 public:
29 // DocString: FMTTask::FMTTask()
34 // DocString: ~FMTTask()
38 virtual ~FMTTask() = default;
39 // DocString: FMTTask::FMTTask(const FMTTask&)
44 FMTTask(const FMTTask& rhs);
45 // DocString: FMTTask::operator=(const FMTTask&)
51 FMTTask& operator = (const FMTTask& rhs);
52 // DocString: FMTTask::clone()
57 virtual std::unique_ptr<FMTTask>clone() const;
58 // DocString: FMTTask::split()
64 virtual std::vector<std::unique_ptr<FMTTask>>split(const unsigned int& numberoftasks) const;
65 // DocString: FMTTask::spawn()
70 virtual std::unique_ptr<FMTTask>spawn();
71 // DocString: FMTTask::work
75 virtual void work();
76 // DocString: FMTTask::run
80 virtual void run();
81 // DocString: FMTTask::finalize
85 virtual void finalize();
86 // DocString: FMTTask::isDone()
91 //bool isDone() const;
92 // DocString: FMTTask::getThreadId()
97 static std::string getThreadId();
98 // DocString: FMTTask::setTotalThreads()
103 static void setTotalThreads(const size_t& p_threads);
104 // DocString: FMTTask::SupportsMultiThreading()
109 virtual bool SupportsMultiThreading() const;
110 // DocString: FMTTaskHandler::done
112 bool done;
113 protected:
114 // DocString: FMTTask::mutex
116 static boost::recursive_mutex m_taskmutex;
117 // DocString: FMTTask::m_tasklogger
120 std::unique_ptr<Logging::FMTLogger>m_tasklogger;
121 // DocString: FMTTask::setStatus()
125 //void setStatus(bool status);
126 // DocString: FMTTask::_splitWork
133 std::vector<size_t>_splitWork(int numberoftasks,const int& totalworksize) const;
134 // DocString: FMTTask::_decrementWorkingThread()
139 // DocString: FMTTask::_checkpoint()
144 // DocString: FMTTask::_setCrashHandlers
149 private:
150 // DocString: FMTTask::m_workingThreads
152 static size_t m_workingThreads;
153 // DocString: FMTTask::m_allThreads
155 static size_t m_allThreads;
156 // DocString: FMTTask::m_checkpoint
158 static boost::condition_variable m_checkpoint;
159 // DocString: FMTTask::m_checkpointMutex
161 static boost::mutex m_checkpointMutex;
162 #if defined _MSC_VER
163 // DocString: FMTTask::m_SeTranslator
166 #endif
167
168
169 };
170
171}
172
173#endif
#define FMTEXPORT
Definition: FMTutility.h:125
Base class of multiple FMT classes holding a shared exception handler pointer and logger.
Definition: FMTObject.h:49
RAII helper that installs a structured exception translator for its scope on MSVC.
Definition: FMTScopedSeTranslator.h:26
Task for parallel jobs.
Definition: FMTTask.h:27
std::unique_ptr< Logging::FMTLogger > m_tasklogger
Definition: FMTTask.h:120
virtual std::unique_ptr< FMTTask > spawn()
Spawn a minimal task from the master task.
void _decrementWorkingThread()
Decrement the number of working threads.
bool done
If the task is done true else false.
Definition: FMTTask.h:112
FMTTask()
Default constructor for FMTTask.
virtual bool SupportsMultiThreading() const
Check if the task support multithreading.
void _setCrashHandlers()
Set the terminate and abort handlers before running the global function in the thread,...
static std::string getThreadId()
Return true if the job is all done.
virtual ~FMTTask()=default
Default virtual destructor for FMTTask.
virtual std::unique_ptr< FMTTask > clone() const
Clone function for FMTTask.
static void setTotalThreads(const size_t &p_threads)
Set the total amount of threads.
void _checkpoint()
Wait for the other threads to finish their jobs, then continue.
virtual void finalize()
Called right after the last task is done, when overridden.
static boost::recursive_mutex m_taskmutex
Recursive mutex for the task.
Definition: FMTTask.h:116
virtual void work()
Main job executed by the thread.
virtual void run()
Set up the crash handler and call work.
virtual std::vector< std::unique_ptr< FMTTask > > split(const unsigned int &numberoftasks) const
Split the actual task into multiple tasks.
FMTTask(const FMTTask &rhs)
Default copy constructor for FMTTask.
std::vector< size_t > _splitWork(int numberoftasks, const int &totalworksize) const
Change the status of the task.
Namespace for parallel tasking may include multithreading / multiprocessing.
Definition: FMTOpAreaSchedulerTask.h:40