|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
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>

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. | |
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.
|
virtualdefault |
Virtual destructor.
|
inline |
Execute a pre-built task Schedule using this executor.
| schedule | schedule of tasks to execute. |
| entities | registry containing the entity ranges and component pools to provide to tasks in the schedule. |
| resources | registry containing the resources to provide to tasks in the schedule. |
| statistics | pointer to a set of statistics to fill out with the statistics resulting from executing the task graph, or nullptr to ignore. |
| execution::Error | with 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Execute an operation on each element in a given range, sequentially.
| range | contiguous, sized random-access range of elements to execute the operation on. |
| operation | function object that takes a reference to each element and performs some in-place operation on it, returning void. |
| any | exception thrown by the operation. |
|
inline |
Execute an operation on each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.
| range | contiguous, sized random-access range of elements to execute the operation on. |
| operation | function object that takes a reference to each element and performs some in-place operation on it, returning void. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Execute an operation on each indexed element specified by a given range of indices, sequentially.
| indices | contiguous, 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). |
| range | contiguous, sized random-access range of elements, indexed by indices, to execute the operation on. May contain unused elements, which are ignored. |
| operation | function object that takes a reference to each indexed element and performs some in-place operation on it, returning void. |
| any | exception thrown by the 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.
| indices | contiguous, 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). |
| range | contiguous, sized random-access range of elements, indexed by indices, to execute the operation on. May contain unused elements, which are ignored. |
| operation | function object that takes a reference to each indexed element and performs some in-place operation on it, returning void. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Execute an operation for each index in a given interval, sequentially.
| begin | first index in the interval. Must be less than or equal to end. |
| end | one past the last index in the interval. Must be greater than or equal to begin. |
| operation | function object that takes each integer in the interval [begin, end) as a size_t and performs some operation using it, returning void. |
| any | exception thrown by the operation. |
|
inline |
Execute an operation for each index in a given interval, in up to getMaxParallelism() parallel chunks using this executor.
| begin | first index in the interval. Must be less than or equal to end. |
| end | one past the last index in the interval. Must be greater than or equal to begin. |
| operation | function object that takes each integer in the interval [begin, end) as a size_t and performs some operation using it, returning void. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Execute an operation for each row of elements in a given set of equally sized column ranges, sequentially.
| operation | function object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void. |
| range | first contiguous, sized random-access range in the set of column ranges. |
| ranges | other contiguous, sized random-access ranges in the set of column ranges. Each must have the same size as the first range. |
| any | exception thrown by the operation. |
|
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.
| operation | function object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void. |
| range | first contiguous, sized random-access range in the set of column ranges. |
| ranges | other contiguous, sized random-access ranges in the set of column ranges. Each must have the same size as the first range. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
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.
| indices | contiguous, 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. |
| operation | function object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void. |
| range | first contiguous, sized random-access range in the set of column ranges, indexed by indices. May contain unused elements, which are ignored. |
| ranges | other 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. |
| any | exception thrown by the operation. |
|
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.
| indices | contiguous, 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. |
| operation | function object that takes references to the elements in each row of the given ranges and performs some in-place operation on them, returning void. |
| range | first contiguous, sized random-access range in the set of column ranges, indexed by indices. May contain unused elements, which are ignored. |
| ranges | other 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. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Transform each element in a given range, sequentially.
| range | contiguous, sized random-access range of elements to transform. |
| output | random access iterator to write the transformed outputs to. The range [output, output + std::size(range)) must form a valid writable range. |
| transformationFunction | function object that takes a read-only reference to each element and performs some transformation on it, returning the result. |
| any | exception thrown by the transformation. |
|
inline |
Transform each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.
| range | contiguous, sized random-access range of elements to transform. |
| output | random access iterator to write the transformed outputs to. The range [output, output + std::size(range)) must form a valid writable range. |
| transformationFunction | function object that takes a read-only reference to each element and performs some transformation on it, returning the result. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Transform each indexed element specified by a given range of indices, sequentially.
| indices | contiguous, 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). |
| range | contiguous, sized random-access range of elements to transform, indexed by indices. May contain unused elements, which are ignored. |
| output | random access iterator to write the transformed outputs to. The range [output, output + std::size(indices)) must form a valid writable range. |
| transformationFunction | function object that takes a read-only reference to each element and performs some transformation on it, returning the result. |
| any | exception thrown by the transformation. |
|
inline |
Transform each indexed element specified by a given range of indices, in up to getMaxParallelism() parallel chunks using this executor.
| indices | contiguous, 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). |
| range | contiguous, sized random-access range of elements to transform, indexed by indices. May contain unused elements, which are ignored. |
| output | random access iterator to write the transformed outputs to. The range [output, output + std::size(indices)) must form a valid writable range. |
| transformationFunction | function object that takes a read-only reference to each element and performs some transformation on it, returning the result. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Perform a reduction over each element in a given range, sequentially.
| range | contiguous, sized random-access range of elements to perform the reduction over. |
| initialValue | initial value of the reduction. |
| reductionFunction | function object that takes a reduction value and a read-only reference to each element and returns the new combined reduction value. |
| any | exception thrown by the reduction function. |
|
inlinenodiscard |
Perform a reduction over each element in a given range, in up to getMaxParallelism() parallel chunks using this executor.
| range | contiguous, sized random-access range of elements to perform the reduction over. |
| initialValue | initial value of the reduction. |
| reductionFunction | function object that takes a reduction value and a read-only reference to each element and returns the new combined reduction value. |
| any | exception 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
pure virtual |
Execute a pre-built task graph using this executor.
| tasks | topologically 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. |
| context | user-defined context pointer to provide to each task. |
| requiredSharedMemorySize | total 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). |
| name | UTF-8-encoded human-readable name of the task graph, which may be used in error messages. |
| statistics | pointer to a set of statistics to fill out with the statistics resulting from executing the task graph, or nullptr to ignore. |
| execution::Error | with 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
Implemented in grem::execution::DynamicExecutor, and grem::execution::SequentialExecutor.
|
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.
| subTaskContext | user-defined context pointer to provide to each sub-task. |
| subTaskCount | number of parallel sub-tasks to execute. |
| subTask | parallel task function to execute for each sub-task. |
| taskRequiredSharedMemorySize | amount 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). |
| statistics | pointer to a set of statistics to fill out with the statistics resulting from executing the sub-tasks, or nullptr to ignore. |
| execution::Error | with 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_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
Implemented in grem::execution::DynamicExecutor, and grem::execution::SequentialExecutor.
|
nodiscardpure virtualnoexcept |
Get the maximum number of parallel threads of execution that this executor can run tasks on simultaneously.
Implemented in grem::execution::DynamicExecutor, and grem::execution::SequentialExecutor.
|
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.
| tasks | topologically 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. |
| context | user-defined context pointer to provide to each task. |
| sharedMemory | non-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. |
| name | UTF-8-encoded human-readable name of the task graph, which may be used in error messages. |
| statistics | pointer to a set of statistics to fill out with the statistics resulting from executing the task graph, or nullptr to ignore. |
| execution::Error | with a std::nested_exception of any exception thrown by the tasks. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
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.
| subTaskContext | user-defined context pointer to provide to each sub-task. |
| subTaskCount | number of parallel sub-tasks to execute. |
| subTask | parallel task function to execute for each sub-task. |
| taskSharedMemory | non-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. |
| statistics | pointer to a set of statistics to fill out with the statistics resulting from executing the sub-tasks, or nullptr to ignore. |
| execution::Error | with a std::nested_exception of any exception thrown by the tasks. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |