ParallelExecutor Class Reference

#include <ParallelExecutor.h>

Inheritance diagram for ParallelExecutor:

PIMPLHandle

List of all members.


Detailed Description

This class is used for performing multithreaded computations.

To use it, define a subclass of ParallelExecutor::Task that performs some computation. Then create a ParallelExecutor object and ask it to execute the task:

 ParallelExecutor executor;
 executor.execute(myTask, times);
 

The Task's execute() method will be called the specified number of times, with each invocation being given a different index value from 0 to times-1. The invocations are done in parallel on multiple threads, so you cannot make any assumptions about what order they will occur in or which ones will happen at the same time.

The threads are created in the ParallelExecutor's constructor and remain active until it is deleted. This means that creating a ParallelExecutor is a somewhat expensive operation, but it may then be used repeatedly for executing various calculations. By default, the number of threads is chosen to be equal to the number of available processor cores. You can optionally specify a different number of threads to create. For example, using more threads than processors can sometimes lead to better processor utilitization. Alternatively, if the Task will only be executed four times, you might specify max(4, ParallelExecutor::getNumProcessors()) to avoid creating extra threads that will never have any work to do.

Public Member Functions

 ParallelExecutor (int numThreads=getNumProcessors())
 Construct a ParallelExecutor.
void execute (Task &task, int times)
 Execute a parallel task.

Static Public Member Functions

static int getNumProcessors ()
 Get the number of available processor cores.
static bool isWorkerThread ()
 Determine whether the thread invoking this method is a worker thread created by ParallelExecutor.

Classes

class  Task
 Concrete subclasses of this abstract class represent tasks that can be executed by a ParallelExecutor. More...


Constructor & Destructor Documentation

ParallelExecutor ( int  numThreads = getNumProcessors()  ) 

Construct a ParallelExecutor.

Parameters:
numThreads the number of threads to create. By default, this is set equal to the number of processors.


Member Function Documentation

void execute ( Task task,
int  times 
)

Execute a parallel task.

Parameters:
task the Task to execute
times the number of times the Task should be executed

static int getNumProcessors (  )  [static]

Get the number of available processor cores.

static bool isWorkerThread (  )  [static]

Determine whether the thread invoking this method is a worker thread created by ParallelExecutor.


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

Generated on Fri Sep 26 07:44:29 2008 for SimTKcore by  doxygen 1.5.6