#include <parallelfor.h>
This class contains of several methods that implement a for loop which is distributing the work load on multiple threads. You can choose between static or dynamic distribution and optionally specify objects to initialize and finalize per worker thread data.
Classes | |
class | BaseContext |
struct | BreakCondition |
class | BreakContext |
class | Dummy |
struct | DynamicContext |
class | DynamicJob |
struct | ForAlignedContext |
struct | ForAlignedContext< FORCONTEXT, INDEXTYPE, Dummy, Dummy > |
struct | ForState |
class | InvokeSelector |
class | NoBreakContext |
class | NoContext |
class | NoContextSelector |
class | NoContextWithResult |
class | NoContextWithResultSelector |
class | ParallelForJob |
class | SingleThreadedFinalize |
class | SingleThreadedFinalize< WORKER, false > |
struct | StaticContext |
class | StaticJob |
Static Public Member Functions | |
template<typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static auto | Dynamic (FROMTYPE from, INDEXTYPE to, const LOOP &obj, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) -> decltype(obj(to)) |
template<typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static Result< void > | Dynamic (FROMTYPE from, INDEXTYPE to, const LOOP &obj, JobStatusInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static Result< void > | Dynamic (FROMTYPE from, INDEXTYPE to, const LOOP &obj, JobInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static MAXON_ATTRIBUTE_NO_INLINE CONTEXT::ResultValueType | Dynamic (FROMTYPE from, INDEXTYPE to, const LOOP &obj, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static MAXON_ATTRIBUTE_NO_INLINE Result< void > | Dynamic (FROMTYPE from, INDEXTYPE to, const LOOP &obj, JobStatusInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static std::enable_if<!STD_IS_REPLACEMENT(convertible, typename std::remove_reference< LOOP >::type, maxon::Int), typename CONTEXT::ResultValueType >::type | Dynamic (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , PARALLELFORFLAGS FLAGS, typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static MAXON_ATTRIBUTE_NO_INLINE CONTEXT::ResultValueType | Dynamic (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , PARALLELFORFLAGS FLAGS, typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static MAXON_ATTRIBUTE_NO_INLINE Result< void > | Dynamic (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, JobStatusInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static MAXON_ATTRIBUTE_NO_INLINE Result< void > | Dynamic (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, JobStatusInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static MAXON_ATTRIBUTE_NO_INLINE Result< void > | Dynamic (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, JobInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int granularity=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static auto | Static (FROMTYPE from, INDEXTYPE to, const LOOP &obj, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) -> decltype(obj(to)) |
template<typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static Result< void > | Static (FROMTYPE from, INDEXTYPE to, const LOOP &obj, JobStatusInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static Result< void > | Static (FROMTYPE from, INDEXTYPE to, const LOOP &obj, JobInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static MAXON_ATTRIBUTE_NO_INLINE CONTEXT::ResultValueType | Static (FROMTYPE from, INDEXTYPE to, const LOOP &obj, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP > | |
static MAXON_ATTRIBUTE_NO_INLINE Result< void > | Static (FROMTYPE from, INDEXTYPE to, const LOOP &obj, JobStatusInterface *observeForCancellation, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static std::enable_if<!STD_IS_REPLACEMENT(convertible, typename std::remove_reference< LOOP >::type, maxon::Int), typename CONTEXT::ResultValueType >::type | Static (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
template<typename CONTEXT , PARALLELFORFLAGS FLAGS, typename FROMTYPE , typename INDEXTYPE , typename LOOP , typename INIT , typename FINALIZE > | |
static MAXON_ATTRIBUTE_NO_INLINE CONTEXT::ResultValueType | Static (FROMTYPE from, INDEXTYPE to, const INIT &init, const LOOP &obj, const FINALIZE &finalize, Int threadCnt=PARALLELFOR_USEMAXIMUMTHREADS, const Int minChunkSize=PARALLELFOR_DEFAULTGRANULARITY, JobQueueInterface *queue=JOBQUEUE_CURRENT) |
Static Private Member Functions | |
template<typename INDEXTYPE > | |
static INDEXTYPE | CalculateStaticChunkSize (UInt cnt, Int &threadCnt, Int minChunkSize) |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using dynamic distribution.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | granularity | The number of iterations after which a thread shares work with idle threads (1 means best distribution at the cost of higher synchronization, PARALLELFOR_DEFAULTGRANULARITY is the default). |
[in] | queue | Optional queue that the parallel for is executed within. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE) used for the loop. |
|
static |
|
static |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using dynamic distribution.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | granularity | The number of iterations after which a thread shares work with idle threads (1 means best distribution at the cost of higher synchronization, PARALLELFOR_DEFAULTGRANULARITY is the default). |
[in] | queue | Optional queue that the parallel for is executed within. |
CONTEXT | A class derived from ParallelFor::BaseContext. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE, CONTEXT&) used for the loop. |
|
static |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using dynamic distribution. The init method is called concurrently per worker thread whereas the finalize method is called synchronously (no concurrency) after the loop has finished.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | init | Lambda being called before the loop starts (threaded) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | finalize | Lambda being called after the loop has finished (synchronous) |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | granularity | The number of iterations after which a thread shares work with idle threads (1 means best distribution at the cost of higher synchronization, PARALLELFOR_DEFAULTGRANULARITY is the default). |
[in] | queue | Optional queue that the parallel for is executed within. |
CONTEXT | A class derived from ParallelFor::BaseContext for thread local data storage. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE, CONTEXT&) used for the loop. |
INIT | A class containing an operator ()(CONTEXT&) for per-thread initialization before the loop. |
FINALIZE | A class containing an operator ()(CONTEXT&) for per-thread cleanup after the loop. |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using dynamic distribution. The FLAGS template parameter can be used to specify if the init or finalize closure are called serialized or threaded.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | init | Lambda being called before the loop starts (threaded by default) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | finalize | Lambda being called after the loop has finished (synchronous by default) |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | granularity | The number of iterations after which a thread shares work with idle threads (1 means best distribution at the cost of higher synchronization, PARALLELFOR_DEFAULTGRANULARITY is the default). |
[in] | queue | Optional queue that the parallel for is executed within. |
CONTEXT | A class derived from ParallelFor::BaseContext for thread local data storage. |
FLAGS | Flags that specify whether init or finalize will be called threaded or synchronously. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE, CONTEXT&) used for the loop. |
INIT | A class containing an operator ()(CONTEXT&) for per-thread initialization before the loop. |
FINALIZE | A class containing an operator ()(CONTEXT&) for per-thread cleanup after the loop. |
|
static |
CONTEXT | A class derived from ParallelFor::BreakContext for thread local data storage. |
|
static |
|
static |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using static distribution.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | minChunkSize | Minimum number of loops that one thread should handle (default is PARALLELFOR_DEFAULTGRANULARITY) |
[in] | queue | Optional queue that the parallel for is executed within. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE) used for the loop. |
|
static |
|
static |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using static distribution.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | minChunkSize | Minimum number of loops that one thread should handle (default is PARALLELFOR_DEFAULTGRANULARITY) |
[in] | queue | Optional queue that the parallel for is executed within. |
CONTEXT | A class derived from ParallelFor::BaseContext. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE) used for the loop. |
|
static |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using static distribution. The init method is called concurrently per worker thread whereas the finalize method is called synchronously (no concurrency) after the loop has finished.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | init | Lambda being called before the loop starts (threaded) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | finalize | Lambda being called after the loop has finished (synchronously) |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | minChunkSize | Minimum number of loops that one thread should handle (default is PARALLELFOR_DEFAULTGRANULARITY) |
[in] | queue | Optional queue that the parallel for is executed within. |
CONTEXT | A class derived from ParallelFor::BaseContext for thread local data storage. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE, CONTEXT&) used for the loop. |
INIT | A class containing an operator ()(CONTEXT&) for per-thread initialization before the loop. |
FINALIZE | A class containing an operator ()(CONTEXT&) for per-thread cleanup after the loop. |
|
static |
Runs a parallelized for (i = from; i < to; i++) loop using static distribution. The FLAGS template parameter can be used to specify if the init or finalize closure are called serialized or threaded.
[in] | from | Start index. |
[in] | to | End index (excluded) |
[in] | init | Lambda being called before the loop starts (threaded by default) |
[in] | obj | Lambda or object with operator (), object will be referenced. |
[in] | finalize | Lambda being called after the loop has finished (synchronously by default) |
[in] | threadCnt | PARALLELFOR_USEMAXIMUMTHREADS for default handling (uses the maximum number of threads available), otherwise maximum number of threads to be used. A value of 1 will disable parallelization. |
[in] | minChunkSize | Minimum number of loops that one thread should handle (default is PARALLELFOR_DEFAULTGRANULARITY) |
[in] | queue | Optional queue that the parallel for is executed within. |
CONTEXT | A class derived from ParallelFor::BaseContext for thread local data storage. |
FLAGS | Flags that specify whether init or finalize will be called threaded or synchronously. |
FROMTYPE | An integral type used for the from variable, might be different than INDEXTYPE but is not allowed to have a bigger range. |
INDEXTYPE | An integral type used for the index of the loop. |
LOOP | A class containing an operator ()(INDEXTYPE, CONTEXT&) used for the loop. |
INIT | A class containing an operator ()(CONTEXT&) for per-thread initialization before the loop. |
FINALIZE | A class containing an operator ()(CONTEXT&) for per-thread cleanup after the loop. |
|
staticprivate |
Computes chunk size for static distribution. If only one thread is used, the index is signed and the range of the loop requires an unsigned counter the return value will overflow, but the loops that assign the chunks to the jobs take care of this.
[in] | cnt | Number of iterations. |
[in,out] | threadCnt | Number of threads to use. |
[in] | minChunkSize | Minimum chunk size. |
INDEXTYPE | An integral type used for the index of the loop. |