Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParallelTaskManager Class Reference

A singleton class to manage parallel code tasks. More...

#include <quickmp.h>

Public Member Functions

void setNumThreads (unsigned int numThreads=0)
 Specifies the number of threads to use in subsequent parallel for loops. More...
 
unsigned int getNumThreads () const
 Returns the number of threads currently being used. More...
 
unsigned int getMaxThreads () const
 Returns the total number of threads allocated for use in all parallel for loops. More...
 
unsigned int getNumProcessors () const
 Returns the number of processors in the current machine at runtime. More...
 
bool inParallel () const
 Returns true if called within a parallel for loop and false otherwise. More...
 
void setLoopIndices (int loopFirstIndex, unsigned int numIterations, quickmp::ScheduleHint scheduleHint)
 Defines the range of the loop index. More...
 
void setLoopIndices (int loopFirstIndex, unsigned int numIterations)
 Separate version which is used when no schedule hint is supplied. More...
 
void process (ParallelTask *task)
 Unleashes the threads on the new task/loop. More...
 
void processSubset (unsigned int threadIndex)
 Called by individual threads to process a subset of the loop iterations. More...
 
void criticalSectionBegin (unsigned int id)
 Defines the beginning of a critical section used for synchronization. More...
 
void criticalSectionEnd (unsigned int id)
 Defines the end of a critical section used for synchronization. More...
 
void barrier ()
 Defines a barrier routine used to synchronize threads. More...
 
PlatformThreadObjectsgetPlatformThreadObjects ()
 Provides access to the internal platform-specific data, like thread handles and synchronization objects. More...
 
bool shouldWorkerThreadsExit () const
 Returns true if the main thread has requested the worker threads to exit. More...
 

Static Public Member Functions

static ParallelTaskManagerinstance ()
 Provides access to the singleton instance. More...
 

Detailed Description

A singleton class to manage parallel code tasks.

This enables automatic init on first use and destroy on exit.

Member Function Documentation

void barrier ( )
inline

Defines a barrier routine used to synchronize threads.

Each thread blocks at the barrier until all threads have reached it.

void criticalSectionBegin ( unsigned int  id)
inline

Defines the beginning of a critical section used for synchronization.

This is necessary to protect shared variables which are read and written by multiple threads. The given id should be unique for each critical section within a parallel for loop. Keep the ids low to avoid allocating too many internal critical sections.

void criticalSectionEnd ( unsigned int  id)
inline

Defines the end of a critical section used for synchronization.

The given id must match the id given at the beginning of the critical section. Keep the ids low to avoid allocating too many internal critical sections.

unsigned int getMaxThreads ( ) const
inline

Returns the total number of threads allocated for use in all parallel for loops.

unsigned int getNumProcessors ( ) const
inline

Returns the number of processors in the current machine at runtime.

unsigned int getNumThreads ( ) const
inline

Returns the number of threads currently being used.

In sequential code sections this returns 1; in parallel for loops this returns the total number of threads allocated for use in parallel for loops.

PlatformThreadObjects * getPlatformThreadObjects ( )
inline

Provides access to the internal platform-specific data, like thread handles and synchronization objects.

This gives access to these things to the thread function.

bool inParallel ( ) const
inline

Returns true if called within a parallel for loop and false otherwise.

ParallelTaskManager & instance ( )
inlinestatic

Provides access to the singleton instance.

void process ( ParallelTask task)
inline

Unleashes the threads on the new task/loop.

void processSubset ( unsigned int  threadIndex)
inline

Called by individual threads to process a subset of the loop iterations.

void setLoopIndices ( int  loopFirstIndex,
unsigned int  numIterations,
quickmp::ScheduleHint  scheduleHint 
)
inline

Defines the range of the loop index.

Assumes the index begins at the first index and counts up. Internally, this sets the loop indices to be used by each thread.

void setLoopIndices ( int  loopFirstIndex,
unsigned int  numIterations 
)
inline

Separate version which is used when no schedule hint is supplied.

void setNumThreads ( unsigned int  numThreads = 0)
inline

Specifies the number of threads to use in subsequent parallel for loops.

If not called explicitly by the user, this will be called with the default value (zero), which uses one thread per processor. Can be called multiple times.

bool shouldWorkerThreadsExit ( ) const
inline

Returns true if the main thread has requested the worker threads to exit.


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