ParallelTaskManager Class Reference

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

#include <quickmp.h>

Collaboration diagram for ParallelTaskManager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Static Public Member Functions

static ParallelTaskManagerinstance ()
 Provides access to the singleton instance.

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 (  )  [inline, static]

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 
) [inline]

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

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 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:
Generated on Fri Oct 30 16:29:04 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7