#include <parallelfor.h>
Basic context for ParallelFor loops. Each worker thread has its own local context.
Public Types | |
using | ResultValueType = void |
Public Member Functions | |
BaseContext () | |
template<typename INDEXTYPE > | |
void | PrivateInit (INDEXTYPE from, INDEXTYPE to, Int threadIndex, BreakCondition *breakCondition) |
template<typename FN , typename CONTEXT , typename INDEXTYPE > | |
void | Invoke (FN &obj, INDEXTYPE i) |
Bool | IsCancelled () const |
Int | GetWorkerThreadIndex () const |
void | UpdateWorkerThreadIndex (Int threadIndex=JobRef::GetCurrentWorkerThreadIndex()) |
Int | GetLocalThreadIndex () const |
void | Break (Result< void > result=OK) |
Static Public Member Functions | |
static ResultValueType | Return (Result< void > &&r) |
Public Attributes | |
Int | _from |
Int | _to |
Int | _workerThreadIndex |
Int | _localContextIndex |
Result< void > | _result |
BreakCondition * | _breakCondition |
Private Member Functions | |
MAXON_DISALLOW_COPY_AND_ASSIGN (BaseContext) | |
using ResultValueType = void |
BaseContext | ( | ) |
void PrivateInit | ( | INDEXTYPE | from, |
INDEXTYPE | to, | ||
Int | threadIndex, | ||
BreakCondition * | breakCondition | ||
) |
Intializes the custom user data for a complex loop.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | threadIndex | Initial thread index. |
[in] | breakCondition | Pointer to a BreakCondition or nullptr (break not supported by context). |
void Invoke | ( | FN & | obj, |
INDEXTYPE | i | ||
) |
Invokes the loop body object.
[in] | obj | Reference to loop body object. |
[in] | i | Index. |
FN | A class containing an operator ()(INDEXTYPE) used for the loop. |
CONTEXT | Type of context super class. |
INDEXTYPE | An integral type used for the index of the loop. |
Bool IsCancelled | ( | ) | const |
Returns true if the loop should be quit.
Int GetWorkerThreadIndex | ( | ) | const |
Returns the index of the worker thread. This is the same value as returned by JobRef::GetCurrentWorkerThreadIndex() (but with less overhead) and is guaranteed to be identical for nested ParallelFors on the same worker thread. The worker thread index might be greater than the number of threads you specified because your code will be scheduled to run on the first available thread of the queue.
void UpdateWorkerThreadIndex | ( | Int | threadIndex = JobRef::GetCurrentWorkerThreadIndex() | ) |
Updates the worker thread index once a loop is a started on a job.
Int GetLocalThreadIndex | ( | ) | const |
Returns a local thread index between 0 and the the number of threads requested - 1. The value is different from GetWorkerThreadIndex()/GetCurrentWorkerThreadIndex() and for nested ParallelFors it can be different on the same worker thread.
Does nothing (use BreakContext).
[in] | result | Used to return an optional error. |
|
static |
Ignores the result of the StaticJobGroup because it cannot fail (and the loop body returns void).
|
private |
Int _from |
Int _to |
Int _workerThreadIndex |
Int _localContextIndex |
Result<void> _result |
BreakCondition* _breakCondition |