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

Basic Executor implementation that runs all tasks sequentially, directly on the caller's thread. More...

#include <GREM/execution/Executor.hpp>

Inheritance diagram for grem::execution::SequentialExecutor:

Public Member Functions

void executeTaskGraph (Span< const Task > tasks, void *context, Task::SharedMemorySize requiredSharedMemorySize, CStringView name, Statistics *statistics) override
 Execute a pre-built task graph using this executor.
void executeParallelTasks (void *subTaskContext, Task::ParallelCount subTaskCount, ParallelTask subTask, Task::SharedMemorySize taskRequiredSharedMemorySize, Statistics *statistics) override
 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.
Task::ParallelCount getMaxParallelism () const noexcept override
 Get the maximum number of parallel threads of execution that this executor can run tasks on simultaneously.
Public Member Functions inherited from grem::execution::Executor
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.

Public Attributes

Allocation< byte > sharedMemory {}
 Allocated shared memory available for reuse in subsequent executions.

Additional Inherited Members

Static Protected Member Functions inherited from grem::execution::Executor
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

Basic Executor implementation that runs all tasks sequentially, directly on the caller's thread.

See also
DynamicExecutor

Member Function Documentation

◆ executeTaskGraph()

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

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.

Implements grem::execution::Executor.

◆ executeParallelTasks()

void grem::execution::SequentialExecutor::executeParallelTasks ( void * subTaskContext,
Task::ParallelCount subTaskCount,
ParallelTask subTask,
Task::SharedMemorySize taskRequiredSharedMemorySize,
Statistics * statistics )
inlineoverridevirtual

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.

Implements grem::execution::Executor.

◆ getMaxParallelism()

Task::ParallelCount grem::execution::SequentialExecutor::getMaxParallelism ( ) const
inlinenodiscardoverridevirtualnoexcept

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

Returns
the maximum task parallelism.

Implements grem::execution::Executor.

Member Data Documentation

◆ sharedMemory

Allocation<byte> grem::execution::SequentialExecutor::sharedMemory {}

Allocated shared memory available for reuse in subsequent executions.

This may be resized and overwritten whenever tasks are executed on this executor.


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