GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::execution::Executor Class Referenceabstract

Interface to a pool of execution resources (e.g. threads) for executing ad-hoc parallel tasks and pre-built task graphs defined through a Scheduler. More...

#include <GREM/execution/Executor.hpp>

Inheritance diagram for grem::execution::Executor:

Public Member Functions

virtual ~Executor ()=default
 Virtual destructor.
template<typename EntReg, typename ResReg>
void executeSchedule (const Schedule< EntReg, ResReg > &schedule, EntReg &entities, ResReg &resources, Statistics *statistics=nullptr)
 Execute a pre-built task Schedule using this executor.
template<typename Range, typename UnaryProcedure>
void executeOperation (Range &&range, UnaryProcedure operation)
 Execute an operation on each element in a given range, sequentially.
template<typename Range, typename UnaryProcedure>
void executeParallelOperation (Range &&range, UnaryProcedure operation)
 Execute an operation on each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.
template<typename IndexRange, typename Range, typename UnaryProcedure>
void executeSparseOperation (const IndexRange &indices, Range &&range, UnaryProcedure operation)
 Execute an operation on each indexed element specified by a given range of indices, sequentially.
template<typename IndexRange, typename Range, typename UnaryProcedure>
void executeParallelSparseOperation (const IndexRange &indices, Range &&range, UnaryProcedure operation)
 Execute an operation on each indexed element specified by a given range of indices, in up to getMaxParallelism() parallel chunks using this executor.
template<typename IndexedProcedure>
void executeIndexedOperation (size_t begin, size_t end, IndexedProcedure operation)
 Execute an operation for each index in a given interval, sequentially.
template<typename IndexedProcedure>
void executeParallelIndexedOperation (size_t begin, size_t end, IndexedProcedure operation)
 Execute an operation for each index in a given interval, in up to getMaxParallelism() parallel chunks using this executor.
template<typename Procedure, typename FirstRange, typename... OtherRanges>
void executeApplication (Procedure operation, FirstRange &&range, OtherRanges &&... ranges)
 Execute an operation for each row of elements in a given set of equally sized column ranges, sequentially.
template<typename Procedure, typename FirstRange, typename... OtherRanges>
void executeParallelApplication (Procedure operation, FirstRange &&range, OtherRanges &&... ranges)
 Execute an operation for each row of elements in a given set of equally sized column ranges, in up to getMaxParallelism() parallel chunks using this executor.
template<typename IndexRange, typename Procedure, typename FirstRange, typename... OtherRanges>
void executeSparseApplication (const IndexRange &indices, Procedure operation, FirstRange &&range, OtherRanges &&... ranges)
 Execute an operation for each indexed row of elements specified by a given range of indices in a given set of equally sized column ranges, sequentially.
template<typename IndexRange, typename Procedure, typename FirstRange, typename... OtherRanges>
void executeParallelSparseApplication (const IndexRange &indices, Procedure operation, FirstRange &&range, OtherRanges &&... ranges)
 Execute an operation for each indexed row of elements specified by a given range of indices in a given set of equally sized column ranges, in up to getMaxParallelism() parallel chunks using this executor.
template<typename Range, typename RandomAccessIterator, typename UnaryMapping>
void executeTransformation (const Range &range, RandomAccessIterator output, UnaryMapping transformationFunction)
 Transform each element in a given range, sequentially.
template<typename Range, typename RandomAccessIterator, typename UnaryMapping>
void executeParallelTransformation (const Range &range, RandomAccessIterator output, UnaryMapping transformationFunction)
 Transform each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.
template<typename IndexRange, typename Range, typename RandomAccessIterator, typename UnaryMapping>
void executeSparseTransformation (const IndexRange &indices, const Range &range, RandomAccessIterator output, UnaryMapping transformationFunction)
 Transform each indexed element specified by a given range of indices, sequentially.
template<typename IndexRange, typename Range, typename RandomAccessIterator, typename UnaryMapping>
void executeParallelSparseTransformation (const IndexRange &indices, const Range &range, RandomAccessIterator output, UnaryMapping transformationFunction)
 Transform each indexed element specified by a given range of indices, in up to getMaxParallelism() parallel chunks using this executor.
template<typename Range, typename InitialValue, typename AssociativeBinaryFunction>
InitialValue executeReduction (const Range &range, const InitialValue &initialValue, AssociativeBinaryFunction reductionFunction)
 Perform a reduction over each element in a given range, sequentially.
template<typename Range, typename InitialValue, typename AssociativeBinaryFunction>
InitialValue executeParallelReduction (const Range &range, const InitialValue &initialValue, AssociativeBinaryFunction reductionFunction)
 Perform a reduction over each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.
virtual void executeTaskGraph (Span< const Task > tasks, void *context, Task::SharedMemorySize requiredSharedMemorySize, CStringView name, Statistics *statistics)=0
 Execute a pre-built task graph using this executor.
virtual void executeParallelTasks (void *subTaskContext, Task::ParallelCount subTaskCount, ParallelTask subTask, Task::SharedMemorySize taskRequiredSharedMemorySize, Statistics *statistics)=0
 Execute a set parallel sub-tasks through a ParallelTask function that performs a specific chunk of work based on the index of each sub-task (and the total number of them), using this executor.
virtual Task::ParallelCount getMaxParallelism () const noexcept=0
 Get the maximum number of parallel threads of execution that this executor can run tasks on simultaneously.

Static Protected Member Functions

static void executeTaskGraphSequentially (Span< const Task > tasks, void *context, byte *sharedMemory, CStringView name, Statistics *statistics)
 Basic implementation of executeTaskGraph() that executes the tasks sequentially, directly on the calling thread.
static void executeParallelTasksSequentially (void *subTaskContext, Task::ParallelCount subTaskCount, ParallelTask subTask, byte *taskSharedMemory, Statistics *statistics)
 Basic implementation of executeParallelTasks() that executes the sub-tasks sequentially, directly on the calling thread.

Detailed Description

Interface to a pool of execution resources (e.g. threads) for executing ad-hoc parallel tasks and pre-built task graphs defined through a Scheduler.

Constructor & Destructor Documentation

◆ ~Executor()

virtual grem::execution::Executor::~Executor ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ executeSchedule()

template<typename EntReg, typename ResReg>
void grem::execution::Executor::executeSchedule ( const Schedule< EntReg, ResReg > & schedule,
EntReg & entities,
ResReg & resources,
Statistics * statistics = nullptr )
inline

Execute a pre-built task Schedule using this executor.

Parameters
scheduleschedule of tasks to execute.
entitiesregistry containing the entity ranges and component pools to provide to tasks in the schedule.
resourcesregistry containing the resources to provide to tasks in the schedule.
statisticspointer to a set of statistics to fill out with the statistics resulting from executing the task graph, or nullptr to ignore.
Exceptions
execution::Errorwith a std::nested_exception of any exception thrown by the scheduled tasks. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeOperation()

template<typename Range, typename UnaryProcedure>
void grem::execution::Executor::executeOperation ( Range && range,
UnaryProcedure operation )
inline

Execute an operation on each element in a given range, sequentially.

Parameters
rangecontiguous, sized random-access range of elements to execute the operation on.
operationfunction object that takes a reference to each element and performs some in-place operation on it, returning void.
Exceptions
anyexception thrown by the operation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelOperation() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop or forEach().
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelOperation()

template<typename Range, typename UnaryProcedure>
void grem::execution::Executor::executeParallelOperation ( Range && range,
UnaryProcedure operation )
inline

Execute an operation on each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
rangecontiguous, sized random-access range of elements to execute the operation on.
operationfunction object that takes a reference to each element and performs some in-place operation on it, returning void.
Exceptions
anyexception thrown by the operation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeSparseOperation()

template<typename IndexRange, typename Range, typename UnaryProcedure>
void grem::execution::Executor::executeSparseOperation ( const IndexRange & indices,
Range && range,
UnaryProcedure operation )
inline

Execute an operation on each indexed element specified by a given range of indices, sequentially.

Parameters
indicescontiguous, sized random-access range of indices to the elements in range to execute the operation on. Each value must be implicitly convertible to a size_t that is less than std::size(range).
rangecontiguous, sized random-access range of elements, indexed by indices, to execute the operation on. May contain unused elements, which are ignored.
operationfunction object that takes a reference to each indexed element and performs some in-place operation on it, returning void.
Exceptions
anyexception thrown by the operation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelSparseOperation() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelSparseOperation()

template<typename IndexRange, typename Range, typename UnaryProcedure>
void grem::execution::Executor::executeParallelSparseOperation ( const IndexRange & indices,
Range && range,
UnaryProcedure operation )
inline

Execute an operation on each indexed element specified by a given range of indices, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
indicescontiguous, sized random-access range of indices to the elements in range to execute the operation on. Each value must be implicitly convertible to a size_t that is less than std::size(range).
rangecontiguous, sized random-access range of elements, indexed by indices, to execute the operation on. May contain unused elements, which are ignored.
operationfunction object that takes a reference to each indexed element and performs some in-place operation on it, returning void.
Exceptions
anyexception thrown by the operation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeIndexedOperation()

template<typename IndexedProcedure>
void grem::execution::Executor::executeIndexedOperation ( size_t begin,
size_t end,
IndexedProcedure operation )
inline

Execute an operation for each index in a given interval, sequentially.

Parameters
beginfirst index in the interval. Must be less than or equal to end.
endone past the last index in the interval. Must be greater than or equal to begin.
operationfunction object that takes each integer in the interval [begin, end) as a size_t and performs some operation using it, returning void.
Exceptions
anyexception thrown by the operation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelIndexedOperation() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelIndexedOperation()

template<typename IndexedProcedure>
void grem::execution::Executor::executeParallelIndexedOperation ( size_t begin,
size_t end,
IndexedProcedure operation )
inline

Execute an operation for each index in a given interval, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
beginfirst index in the interval. Must be less than or equal to end.
endone past the last index in the interval. Must be greater than or equal to begin.
operationfunction object that takes each integer in the interval [begin, end) as a size_t and performs some operation using it, returning void.
Exceptions
anyexception thrown by the operation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeApplication()

template<typename Procedure, typename FirstRange, typename... OtherRanges>
void grem::execution::Executor::executeApplication ( Procedure operation,
FirstRange && range,
OtherRanges &&... ranges )
inline

Execute an operation for each row of elements in a given set of equally sized column ranges, sequentially.

Parameters
operationfunction object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void.
rangefirst contiguous, sized random-access range in the set of column ranges.
rangesother contiguous, sized random-access ranges in the set of column ranges. Each must have the same size as the first range.
Exceptions
anyexception thrown by the operation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelApplication() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelApplication()

template<typename Procedure, typename FirstRange, typename... OtherRanges>
void grem::execution::Executor::executeParallelApplication ( Procedure operation,
FirstRange && range,
OtherRanges &&... ranges )
inline

Execute an operation for each row of elements in a given set of equally sized column ranges, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
operationfunction object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void.
rangefirst contiguous, sized random-access range in the set of column ranges.
rangesother contiguous, sized random-access ranges in the set of column ranges. Each must have the same size as the first range.
Exceptions
anyexception thrown by the operation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeSparseApplication()

template<typename IndexRange, typename Procedure, typename FirstRange, typename... OtherRanges>
void grem::execution::Executor::executeSparseApplication ( const IndexRange & indices,
Procedure operation,
FirstRange && range,
OtherRanges &&... ranges )
inline

Execute an operation for each indexed row of elements specified by a given range of indices in a given set of equally sized column ranges, sequentially.

Parameters
indicescontiguous, sized random-access range of indices to the rows in the given column ranges to execute the operation on. Each value must be implicitly convertible to a size_t that is less than the size of each of the column ranges.
operationfunction object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void.
rangefirst contiguous, sized random-access range in the set of column ranges, indexed by indices. May contain unused elements, which are ignored.
rangesother contiguous, sized random-access ranges in the set of column ranges, indexed by indices. May contain unused elements, which are ignored. Each must have the same size as the first range.
Exceptions
anyexception thrown by the operation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelSparseApplication() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelSparseApplication()

template<typename IndexRange, typename Procedure, typename FirstRange, typename... OtherRanges>
void grem::execution::Executor::executeParallelSparseApplication ( const IndexRange & indices,
Procedure operation,
FirstRange && range,
OtherRanges &&... ranges )
inline

Execute an operation for each indexed row of elements specified by a given range of indices in a given set of equally sized column ranges, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
indicescontiguous, sized random-access range of indices to the rows in the given column ranges to execute the operation on. Each value must be implicitly convertible to a size_t that is less than the size of each of the column ranges.
operationfunction object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void.
rangefirst contiguous, sized random-access range in the set of column ranges, indexed by indices. May contain unused elements, which are ignored.
rangesother contiguous, sized random-access ranges in the set of column ranges, indexed by indices. May contain unused elements, which are ignored. Each must have the same size as the first range.
Exceptions
anyexception thrown by the operation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeTransformation()

template<typename Range, typename RandomAccessIterator, typename UnaryMapping>
void grem::execution::Executor::executeTransformation ( const Range & range,
RandomAccessIterator output,
UnaryMapping transformationFunction )
inline

Transform each element in a given range, sequentially.

Parameters
rangecontiguous, sized random-access range of elements to transform.
outputrandom access iterator to write the transformed outputs to. The range [output, output + std::size(range)) must form a valid writable range.
transformationFunctionfunction object that takes a read-only reference to each element and performs some transformation on it, returning the result.
Exceptions
anyexception thrown by the transformation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelTransformation() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop or transform().
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelTransformation()

template<typename Range, typename RandomAccessIterator, typename UnaryMapping>
void grem::execution::Executor::executeParallelTransformation ( const Range & range,
RandomAccessIterator output,
UnaryMapping transformationFunction )
inline

Transform each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
rangecontiguous, sized random-access range of elements to transform.
outputrandom access iterator to write the transformed outputs to. The range [output, output + std::size(range)) must form a valid writable range.
transformationFunctionfunction object that takes a read-only reference to each element and performs some transformation on it, returning the result.
Exceptions
anyexception thrown by the transformation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeSparseTransformation()

template<typename IndexRange, typename Range, typename RandomAccessIterator, typename UnaryMapping>
void grem::execution::Executor::executeSparseTransformation ( const IndexRange & indices,
const Range & range,
RandomAccessIterator output,
UnaryMapping transformationFunction )
inline

Transform each indexed element specified by a given range of indices, sequentially.

Parameters
indicescontiguous, sized random-access range of indices to the elements in range to transform. Each value must be implicitly convertible to a size_t that is less than std::size(range).
rangecontiguous, sized random-access range of elements to transform, indexed by indices. May contain unused elements, which are ignored.
outputrandom access iterator to write the transformed outputs to. The range [output, output + std::size(indices)) must form a valid writable range.
transformationFunctionfunction object that takes a read-only reference to each element and performs some transformation on it, returning the result.
Exceptions
anyexception thrown by the transformation.
Note
This function is provided to make it easier to transition parallel code based on executeParallelSparseTransformation() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelSparseTransformation()

template<typename IndexRange, typename Range, typename RandomAccessIterator, typename UnaryMapping>
void grem::execution::Executor::executeParallelSparseTransformation ( const IndexRange & indices,
const Range & range,
RandomAccessIterator output,
UnaryMapping transformationFunction )
inline

Transform each indexed element specified by a given range of indices, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
indicescontiguous, sized random-access range of indices to the elements in range to transform. Each value must be implicitly convertible to a size_t that is less than std::size(range).
rangecontiguous, sized random-access range of elements to transform, indexed by indices. May contain unused elements, which are ignored.
outputrandom access iterator to write the transformed outputs to. The range [output, output + std::size(indices)) must form a valid writable range.
transformationFunctionfunction object that takes a read-only reference to each element and performs some transformation on it, returning the result.
Exceptions
anyexception thrown by the transformation. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeReduction()

template<typename Range, typename InitialValue, typename AssociativeBinaryFunction>
InitialValue grem::execution::Executor::executeReduction ( const Range & range,
const InitialValue & initialValue,
AssociativeBinaryFunction reductionFunction )
inlinenodiscard

Perform a reduction over each element in a given range, sequentially.

Parameters
rangecontiguous, sized random-access range of elements to perform the reduction over.
initialValueinitial value of the reduction.
reductionFunctionfunction object that takes a reduction value and a read-only reference to each element and returns the new combined reduction value.
Exceptions
anyexception thrown by the reduction function.
Note
This function is provided to make it easier to transition parallel code based on executeParallelReduction() to running sequentially, and vice versa. There is no other direct benefit compared to a basic for-loop or reduce().
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeParallelReduction()

template<typename Range, typename InitialValue, typename AssociativeBinaryFunction>
InitialValue grem::execution::Executor::executeParallelReduction ( const Range & range,
const InitialValue & initialValue,
AssociativeBinaryFunction reductionFunction )
inlinenodiscard

Perform a reduction over each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.

Parameters
rangecontiguous, sized random-access range of elements to perform the reduction over.
initialValueinitial value of the reduction.
reductionFunctionfunction object that takes a reduction value and a read-only reference to each element and returns the new combined reduction value.
Exceptions
anyexception thrown by the reduction function. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

◆ executeTaskGraph()

virtual void grem::execution::Executor::executeTaskGraph ( Span< const Task > tasks,
void * context,
Task::SharedMemorySize requiredSharedMemorySize,
CStringView name,
Statistics * statistics )
pure virtual

Execute a pre-built task graph using this executor.

Parameters
taskstopologically ordered list of tasks to execute. The tasks must not depend on the results of tasks that appear later in the list. Dependencies between tasks must be specified through Task::getDependencyIndices(), all of which must be less than the index of the dependent task.
contextuser-defined context pointer to provide to each task.
requiredSharedMemorySizetotal amount of contiguous memory, in bytes, to pre-allocate for all of the tasks to use as shared memory between their sub-tasks during execution. Each task is provided a non-owning pointer to the first byte in its slice of the allocated memory, based on task.getSharedMemoryOffset(), which it can use freely as long as the access does not overlap between sub-tasks or other tasks, or if the overlapping access is properly synchronized (e.g. through AtomicRef).
nameUTF-8-encoded human-readable name of the task graph, which may be used in error messages.
statisticspointer to a set of statistics to fill out with the statistics resulting from executing the task graph, or nullptr to ignore.
Exceptions
execution::Errorwith a std::nested_exception of any exception thrown by the scheduled tasks. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

Implemented in grem::execution::DynamicExecutor, and grem::execution::SequentialExecutor.

◆ executeParallelTasks()

virtual void grem::execution::Executor::executeParallelTasks ( void * subTaskContext,
Task::ParallelCount subTaskCount,
ParallelTask subTask,
Task::SharedMemorySize taskRequiredSharedMemorySize,
Statistics * statistics )
pure virtual

Execute a set parallel sub-tasks through a ParallelTask function that performs a specific chunk of work based on the index of each sub-task (and the total number of them), using this executor.

Parameters
subTaskContextuser-defined context pointer to provide to each sub-task.
subTaskCountnumber of parallel sub-tasks to execute.
subTaskparallel task function to execute for each sub-task.
taskRequiredSharedMemorySizeamount of contiguous memory, in bytes, to pre-allocate for use as shared memory between the sub-tasks during execution. Each sub-task is provided a non-owning pointer to the first byte of the allocated memory, which it can use freely as long as the access does not overlap between sub-tasks, or if the overlapping access is properly synchronized (e.g. through AtomicRef).
statisticspointer to a set of statistics to fill out with the statistics resulting from executing the sub-tasks, or nullptr to ignore.
Exceptions
execution::Errorwith a std::nested_exception of any exception thrown by the parallel tasks. If multiple parallel tasks throw an exception while running in parallel, one of the tasks' exceptions will get propagated, but it is unspecified which one. The other parallel tasks' exceptions are discarded, but may print a warning message to stderr first.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
Warning
Tasks must not dynamically execute nested tasks on the executor that is running them.

Implemented in grem::execution::DynamicExecutor, and grem::execution::SequentialExecutor.

◆ getMaxParallelism()

virtual Task::ParallelCount grem::execution::Executor::getMaxParallelism ( ) const
nodiscardpure virtualnoexcept

Get the maximum number of parallel threads of execution that this executor can run tasks on simultaneously.

Returns
the maximum task parallelism.

Implemented in grem::execution::DynamicExecutor, and grem::execution::SequentialExecutor.

◆ executeTaskGraphSequentially()

void grem::execution::Executor::executeTaskGraphSequentially ( Span< const Task > tasks,
void * context,
byte * sharedMemory,
CStringView name,
Statistics * statistics )
staticprotected

Basic implementation of executeTaskGraph() that executes the tasks sequentially, directly on the calling thread.

This may be used as a fallback implementation for executors with a maximum task parallelism of 1. For example, it is used in the implementation of SequentialExecutor.

Parameters
taskstopologically ordered list of tasks to execute. The tasks must not depend on the results of tasks that appear later in the list. Dependencies between tasks must be specified through Task::getDependencyIndices(), all of which must be less than the index of the dependent task.
contextuser-defined context pointer to provide to each task.
sharedMemorynon-owning pointer to the shared memory to provide to the tasks. Each task is provided a non-owning pointer to the first byte in its slice of the shared memory, based on task.getSharedMemoryOffset(), which it can use freely as long as the access does not overlap between sub-tasks or other tasks, or if the overlapping access is properly synchronized (e.g. through AtomicRef). The amount of memory accessible through this pointer must be greater than or equal to the total amount required by the tasks. If the tasks use no shared memory, it may be nullptr.
nameUTF-8-encoded human-readable name of the task graph, which may be used in error messages.
statisticspointer to a set of statistics to fill out with the statistics resulting from executing the task graph, or nullptr to ignore.
Exceptions
execution::Errorwith a std::nested_exception of any exception thrown by the tasks.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ executeParallelTasksSequentially()

void grem::execution::Executor::executeParallelTasksSequentially ( void * subTaskContext,
Task::ParallelCount subTaskCount,
ParallelTask subTask,
byte * taskSharedMemory,
Statistics * statistics )
staticprotected

Basic implementation of executeParallelTasks() that executes the sub-tasks sequentially, directly on the calling thread.

This may be used as a fallback implementation for executors with a maximum task parallelism of 1. For example, it is used in the implementation of SequentialExecutor.

Parameters
subTaskContextuser-defined context pointer to provide to each sub-task.
subTaskCountnumber of parallel sub-tasks to execute.
subTaskparallel task function to execute for each sub-task.
taskSharedMemorynon-owning pointer to the shared memory to provide to the sub-tasks. Each sub-task is provided this pointer, which it can use freely as long as the access does not overlap between sub-tasks, or if the overlapping access is properly synchronized (e.g. through AtomicRef). The amount of memory accessible through this pointer must be greater than or equal to the total amount required by the sub-tasks. If the sub-tasks use no shared memory, it may be nullptr.
statisticspointer to a set of statistics to fill out with the statistics resulting from executing the sub-tasks, or nullptr to ignore.
Exceptions
execution::Errorwith a std::nested_exception of any exception thrown by the tasks.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

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