ParallelFor::BaseContext Class Reference

#include <parallelfor.h>

Inheritance diagram for ParallelFor::BaseContext:

Detailed Description

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)
 

Member Typedef Documentation

◆ ResultValueType

using ResultValueType = void

Constructor & Destructor Documentation

◆ BaseContext()

Member Function Documentation

◆ PrivateInit()

void PrivateInit ( INDEXTYPE  from,
INDEXTYPE  to,
Int  threadIndex,
BreakCondition breakCondition 
)

Intializes the custom user data for a complex loop.

Parameters
[in]fromStart index.
[in]toEnd index (excluded)
[in]threadIndexInitial thread index.
[in]breakConditionPointer to a BreakCondition or nullptr (break not supported by context).

◆ Invoke()

void Invoke ( FN &  obj,
INDEXTYPE  i 
)

Invokes the loop body object.

Parameters
[in]objReference to loop body object.
[in]iIndex.
Template Parameters
FNA class containing an operator ()(INDEXTYPE) used for the loop.
CONTEXTType of context super class.
INDEXTYPEAn integral type used for the index of the loop.

◆ IsCancelled()

Bool IsCancelled ( ) const

Returns true if the loop should be quit.

Returns
Always return false so that the compiler can remove unnecessary compares and jumps.

◆ GetWorkerThreadIndex()

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.

Returns
Worker thread index (between 0 and number of worker threads for the queue - 1).

◆ UpdateWorkerThreadIndex()

void UpdateWorkerThreadIndex ( Int  threadIndex = JobRef::GetCurrentWorkerThreadIndex())

Updates the worker thread index once a loop is a started on a job.

◆ GetLocalThreadIndex()

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.

Returns
Local thread index (between 0 and number of requested threads - 1).

◆ Break()

void Break ( Result< void >  result = OK)

Does nothing (use BreakContext).

Parameters
[in]resultUsed to return an optional error.

◆ Return()

static ResultValueType Return ( Result< void > &&  r)
static

Ignores the result of the StaticJobGroup because it cannot fail (and the loop body returns void).

◆ MAXON_DISALLOW_COPY_AND_ASSIGN()

MAXON_DISALLOW_COPY_AND_ASSIGN ( BaseContext  )
private

Member Data Documentation

◆ _from

Int _from

◆ _to

Int _to

◆ _workerThreadIndex

Int _workerThreadIndex

◆ _localContextIndex

Int _localContextIndex

◆ _result

Result<void> _result

◆ _breakCondition

BreakCondition* _breakCondition