FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Parallel::FMTTask Class Reference

Task for parallel jobs. More...

#include <FMTTask.h>

Inheritance diagram for Parallel::FMTTask:
[legend]
Collaboration diagram for Parallel::FMTTask:
[legend]

Public Member Functions

 FMTTask ()
 Default constructor for FMTTask.
 
virtual ~FMTTask ()=default
 Default virtual destructor for FMTTask.
 
 FMTTask (const FMTTask &rhs)
 Default copy constructor for FMTTask.
 
FMTTaskoperator= (const FMTTask &rhs)
 Default copy assignment operator for FMTTask.
 
virtual std::unique_ptr< FMTTaskclone () const
 Clone function for FMTTask.
 
virtual std::vector< std::unique_ptr< FMTTask > > split (const unsigned int &numberoftasks) const
 Split the actual task into multiple tasks.
 
virtual std::unique_ptr< FMTTaskspawn ()
 Spawn a minimal task from the master task.
 
virtual void work ()
 Main job executed by the thread.
 
virtual void run ()
 Set up the crash handler and call work.
 
virtual void finalize ()
 Called right after the last task is done, when overridden.
 
virtual bool SupportsMultiThreading () const
 Check if the task support multithreading.
 
- Public Member Functions inherited from Core::FMTObject
 FMTObject ()
 Default constructor for FMTObject.
 
virtual ~FMTObject ()
 Default virtual destructor for FMTObject.
 
 FMTObject (const std::unique_ptr< Exception::FMTExceptionHandler > exhandler)
 Construct a FMTObject passing in the exception handler of another FMTObject.
 
 FMTObject (const FMTObject &rhs)
 Copy constructor for FMTObject.
 
FMTObjectoperator= (const FMTObject &rhs)
 Copy assignment operator for FMTObject.
 
virtual void passInLogger (const std::unique_ptr< Logging::FMTLogger > &logger)
 Pass in the logger of another FMTObject.
 
void passInExceptionHandler (const std::unique_ptr< Exception::FMTExceptionHandler > &exhandler)
 Pass in the exception handler of another FMTObject.
 
void redirectLogToFile (const std::string &location)
 Redirect the log to a specific file, appending to it.
 
virtual void setDefaultLogger ()
 Create and set a default logger to the FMTObject.
 
virtual void setQuietLogger ()
 Create and set a quiet logger to the FMTObject.
 
virtual void setTaskLogger ()
 Create and set a task logger to the FMTObject.
 
virtual void setDebugLogger ()
 Create and set a debug logger to the FMTObject.
 
void setDefaultExceptionHandler ()
 Create and set a default exception handler to the FMTObject.
 
void setQuietExceptionHandler ()
 Create and set a quiet exception handler to the FMTObject.
 
void setDebugExceptionHandler ()
 Create and set a debug exception handler to the FMTObject.
 
void setFreeExceptionHandler ()
 Create and set a free exception handler to the FMTObject.
 
void disableNestedExceptions ()
 Disable the nested exception throw of the exception handler.
 
void enableNestedExceptions ()
 Enable the nested exception throw of the exception handler.
 
void setErrorsToWarnings (const std::vector< Exception::FMTexc > &errors)
 Set a list of errors to be cast to warnings on the exception handler.
 
void setMaxWarningsBeforeSilenced (const size_t &maxwarningcount)
 Set the number of warnings raised before being silenced.
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Static Public Member Functions

static std::string getThreadId ()
 Return true if the job is all done.
 
static void setTotalThreads (const size_t &p_threads)
 Set the total amount of threads.
 
- Static Public Member Functions inherited from Core::FMTObject
static Logging::FMTLoggergetLogger ()
 get a pointer to the actual logger.
 
static Exception::FMTExceptionHandlergetExceptionHandler ()
 get a pointer to the actual exception handler.
 
static std::string getRuntimeLocation ()
 Return the location of the FMT shared library.
 
static unsigned long long getAvailableMemory ()
 Return the available memory in bytes.
 
static void setTerminateStack ()
 will write the stack in the log when terminate called and raise a function failed.
 
static void setAbortStack ()
 will write the stack in the log when abort called with SIGABRT and raise a function failed.
 

Public Attributes

bool done
 If the task is done true else false.
 

Protected Member Functions

std::vector< size_t > _splitWork (int numberoftasks, const int &totalworksize) const
 Change the status of the task.
 
void _decrementWorkingThread ()
 Decrement the number of working threads.
 
void _checkpoint ()
 Wait for the other threads to finish their jobs, then continue.
 
void _setCrashHandlers ()
 Set the terminate and abort handlers before running the global function in the thread, and set the se_translator on Windows.
 
- Protected Member Functions inherited from Core::FMTObject
template<class Archive >
void forceSave (Archive &ar, const unsigned int version) const
 Force the serialization to save useful information, which the default FMTObject serialization does not.
 
template<class Archive >
void forceLoad (Archive &ar, const unsigned int version)
 Force the serialization to load useful information, which the default FMTObject serialization does not.
 
void checkSignals () const
 Check if the user has sent a ctrl-c signal using boost::python to FMT.
 
void setCplHandler ()
 Pass the FMT exception handler to the GDAL exception handler (GDAL only).
 

Protected Attributes

std::unique_ptr< Logging::FMTLoggerm_tasklogger
 

Static Protected Attributes

static boost::recursive_mutex m_taskmutex
 Recursive mutex for the task.
 
- Static Protected Attributes inherited from Core::FMTObject
static std::unique_ptr< Exception::FMTExceptionHandler_exhandler
 A shared pointer to the exception handler.
 
static std::unique_ptr< Logging::FMTLogger_logger
 A shared pointer to the logger.
 

Additional Inherited Members

- Static Protected Member Functions inherited from Core::FMTObject
static std::chrono::time_point< std::chrono::high_resolution_clock > getClock ()
 Return a clock of the current time.
 
template<class chrono >
static double getDuration (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock as a double.
 
static std::string getDurationInSeconds (const std::chrono::time_point< std::chrono::high_resolution_clock > &startclock)
 Return the time elapsed since a start clock in seconds as a string.
 
static void _logStack ()
 Log the stack trace...
 
static void _terminate ()
 Raise an error with the boost stacktrace.
 
static void _abort (int p_signal)
 Raise an error with the boost stacktrace on abort.
 

Detailed Description

Task for parallel jobs.

Implement the clone, work and split functions of your task to use it in the FMTTaskHandler.

Constructor & Destructor Documentation

◆ FMTTask() [1/2]

Parallel::FMTTask::FMTTask ( )

Default constructor for FMTTask.

◆ ~FMTTask()

virtual Parallel::FMTTask::~FMTTask ( )
virtualdefault

Default virtual destructor for FMTTask.

◆ FMTTask() [2/2]

Parallel::FMTTask::FMTTask ( const FMTTask rhs)

Default copy constructor for FMTTask.

Parameters
[in]rhsthe FMTTask to copy.

Member Function Documentation

◆ _checkpoint()

void Parallel::FMTTask::_checkpoint ( )
protected

Wait for the other threads to finish their jobs, then continue.

◆ _decrementWorkingThread()

void Parallel::FMTTask::_decrementWorkingThread ( )
protected

Decrement the number of working threads.

◆ _setCrashHandlers()

void Parallel::FMTTask::_setCrashHandlers ( )
protected

Set the terminate and abort handlers before running the global function in the thread, and set the se_translator on Windows.

◆ _splitWork()

std::vector< size_t > Parallel::FMTTask::_splitWork ( int  numberoftasks,
const int &  totalworksize 
) const
protected

Change the status of the task.

Split the total work size into buckets that are as equal as possible.

Parameters
[in]numberoftasksthe number of tasks.
[in]totalworksizethe total work size.
Returns
the work size of each bucket.

◆ clone()

virtual std::unique_ptr< FMTTask > Parallel::FMTTask::clone ( ) const
virtual

Clone function for FMTTask.

Returns
a unique pointer to the cloned task.

Reimplemented in Parallel::FMTOpAreaSchedulerTask, Parallel::FMTPlanningTask, and Parallel::FMTReplanningTask.

◆ finalize()

virtual void Parallel::FMTTask::finalize ( )
virtual

Called right after the last task is done, when overridden.

Reimplemented in Parallel::FMTOpAreaSchedulerTask, Parallel::FMTPlanningTask, and Parallel::FMTReplanningTask.

◆ getThreadId()

static std::string Parallel::FMTTask::getThreadId ( )
static

Return true if the job is all done.

Returns
true if the job is done else false.

Get the thread id of the task.

Returns
the thread id.

◆ operator=()

FMTTask & Parallel::FMTTask::operator= ( const FMTTask rhs)

Default copy assignment operator for FMTTask.

Parameters
[in]rhsthe FMTTask to copy.
Returns
a reference to this FMTTask.

◆ run()

virtual void Parallel::FMTTask::run ( )
virtual

Set up the crash handler and call work.

◆ setTotalThreads()

static void Parallel::FMTTask::setTotalThreads ( const size_t &  p_threads)
static

Set the total amount of threads.

Parameters
[in]p_threadsthe number of threads.

◆ spawn()

virtual std::unique_ptr< FMTTask > Parallel::FMTTask::spawn ( )
virtual

Spawn a minimal task from the master task.

Returns
a unique pointer to the spawned task.

Reimplemented in Parallel::FMTOpAreaSchedulerTask, Parallel::FMTPlanningTask, and Parallel::FMTReplanningTask.

◆ split()

virtual std::vector< std::unique_ptr< FMTTask > > Parallel::FMTTask::split ( const unsigned int &  numberoftasks) const
virtual

Split the actual task into multiple tasks.

Parameters
[in]numberoftasksthe number of tasks.
Returns
the split tasks.

Reimplemented in Parallel::FMTOpAreaSchedulerTask, Parallel::FMTPlanningTask, and Parallel::FMTReplanningTask.

◆ SupportsMultiThreading()

virtual bool Parallel::FMTTask::SupportsMultiThreading ( ) const
virtual

Check if the task support multithreading.

Returns
true if it support

Reimplemented in Parallel::FMTOpAreaSchedulerTask, Parallel::FMTPlanningTask, and Parallel::FMTReplanningTask.

◆ work()

virtual void Parallel::FMTTask::work ( )
virtual

Main job executed by the thread.

Reimplemented in Parallel::FMTOpAreaSchedulerTask, Parallel::FMTPlanningTask, and Parallel::FMTReplanningTask.

Member Data Documentation

◆ done

bool Parallel::FMTTask::done

If the task is done true else false.

◆ m_tasklogger

std::unique_ptr<Logging::FMTLogger> Parallel::FMTTask::m_tasklogger
protected

Logger for solver in parallel...coinmessagehandler does not support concurency. This logger wont print anything so dont use it in parallel.

◆ m_taskmutex

boost::recursive_mutex Parallel::FMTTask::m_taskmutex
staticprotected

Recursive mutex for the task.


The documentation for this class was generated from the following file: