List of all members.
Detailed Description
Generalization of a task that can be run in parallel. Any task that has a fixed number of computations that are independent (i.e. they don't need to be done in a certain order) can inherit ParallelTask and be executed in parallel by calling the ParallelTask::execute().
Example of usage:
float result[N];
for ( int idx=0; idx<N; idx++ )
result[idx] = input1[idx]* function( idx, other, variables );
could be made parallel by adding the class:
class CalcClass : public ParallelTask
{
public:
od_int64 nrIterations() const { return N; }
int doWork( od_int64 start, od_int64 stop, int threadid )
{
for ( int idx=start; idx<=stop && shouldContinue(); idx++ )
{
result[idx] = input1[idx] *
function( idx, other, variables );
addToNrDone( 1 );
}
return true;
}
};
and in use that instead of the for-loop:
CalcClass myclass( N, my, parameters );
myclass.exectute();
Constructor & Destructor Documentation
| virtual ParallelTask::~ParallelTask |
( |
|
) |
[virtual] |
| ParallelTask::ParallelTask |
( |
const char * |
nm = 0 |
) |
[protected] |
Member Function Documentation
| void ParallelTask::addToNrDone |
( |
int |
increment |
) |
[protected] |
Call this from within your thread to say that you have done something.
| int64_t ParallelTask::calculateThreadSize |
( |
int64_t |
totalnr, |
|
|
int |
nrthreads, |
|
|
int |
thread | |
|
) |
| | const [protected] |
| virtual bool ParallelTask::doFinish |
( |
bool |
success |
) |
[inline, private, virtual] |
Called after all doWork have finished.
- Parameters:
-
| success | indicates whether all doWork returned true. |
| virtual bool ParallelTask::doPrepare |
( |
int |
nrthreads |
) |
[inline, private, virtual] |
| virtual bool ParallelTask::doWork |
( |
int64_t |
start, |
|
|
int64_t |
stop, |
|
|
int |
threadid | |
|
) |
| | [private, pure virtual] |
| void ParallelTask::enableNrDoneCounting |
( |
bool |
yn |
) |
[virtual] |
| virtual bool ParallelTask::execute |
( |
bool |
parallel |
) |
[virtual] |
Runs the process the desired number of times.
- Note:
- that the function has static threads (normally the same number as there are processors on the machine), and these static threads will be shared by all instances of ParallelTask::execute.
| bool ParallelTask::execute |
( |
|
) |
[inline, virtual] |
Runs the process the desired number of times.
- Note:
- that the function has static threads (normally the same number as there are processors on the machine), and these static threads will be shared by all instances of ParallelTask::execute.
Implements Task.
| virtual int ParallelTask::maxNrThreads |
( |
|
) |
const [inline, protected, virtual] |
| virtual int ParallelTask::minThreadSize |
( |
|
) |
const [inline, protected, virtual] |
- Returns:
- the minimum number of computations that effectively can be run in a separate thread. A small number will give a large overhead for when each step is quick and nrIterations is small.
Reimplemented in MemSetter< T >, and MemCopier< T >.
| int64_t ParallelTask::nrDone |
( |
|
) |
const [virtual] |
May be -1, i.e. class does not report nrdone.
Reimplemented from Task.
| virtual int64_t ParallelTask::nrIterations |
( |
|
) |
const [protected, pure virtual] |
| void ParallelTask::reportNrDone |
( |
int |
nrdone |
) |
[protected] |
| void ParallelTask::setProgressMeter |
( |
ProgressMeter * |
|
) |
[virtual] |
| virtual bool ParallelTask::stopAllOnFailure |
( |
|
) |
const [inline, protected, virtual] |
If one thread fails, should an attempt be made to stop the others? If true, enableWorkControl will be enabled, and threads should call shouldContinue() regularly.
| int64_t ParallelTask::totalNr |
( |
|
) |
const [inline, virtual] |
Friends And Related Function Documentation
friend class ParallelTaskRunner [friend] |
Member Data Documentation