Parallel reduction computation.
More...
Parallel reduction computation.
template<typename RAI , typename ReturnType , typename ReductionFunction , typename TransformationFunction >
Performs a parallel reduction operation on a range of elements.
The range consists of the elements from first
to last
, excluding the last element. The type of the result (ReturnType
) is deduced from the neutral
element.
- Returns
reduction(transformation(*first), ..., transformation(*(last-1)))
where the reduction function is applied pairwise.
- Exceptions
-
- Concurrency
- Thread-safe if the elements in the range are not modified by another thread while the algorithm is executed.
- Note
- No guarantee is given on the order in which the functions
reduction
and transformation
are applied to the elements.
For all x
of type ReturnType
it must hold that reduction(x, neutral) == x
.
The reduction operation need not be commutative but must be associative, i.e., reduction(x, reduction(y, z)) == reduction(reduction(x, y), z))
for all x
, y
, z
of type ReturnType
.
For nested algorithms, the task limit may be exceeded. In that case, increase the task limit of the MTAPI node.
- See also
- embb::mtapi::ExecutionPolicy, ZipIterator, Identity
- Template Parameters
-
RAI | Random access iterator |
ReturnType | Type of result of reduction operation, deduced from neutral |
ReductionFunction | Binary reduction function object with signature ReturnType ReductionFunction(ReturnType, ReturnType) or an embb::mtapi::Job associated with an action function accepting a struct containing two ReturnType members as its argument buffer and a struct containing one ReturnType member as its result buffer. |
TransformationFunction | Unary transformation function object with signature ReturnType TransformationFunction(typename std::iterator_traits<RAI>::value_type) or an embb::mtapi::Job associated with an action function accepting a struct containing one InputType member as its argument buffer and a struct containing one ReturnType member as its result buffer. |
- Parameters
-
[in] | first | Random access iterator pointing to the first element of the range |
[in] | last | Random access iterator pointing to the last plus one element of the range |
[in] | neutral | Neutral element of the reduction operation. |
[in] | reduction | Reduction operation to be applied to the elements of the range |
[in] | transformation | Transforms the elements of the range before the reduction operation is applied |
[in] | policy | embb::mtapi::ExecutionPolicy for the reduction computation |
[in] | block_size | Lower bound for partitioning the range of elements into blocks that are treated in parallel. Partitioning of a block stops if its size is less than or equal to block_size . The default value 0 means that the minimum block size is determined automatically depending on the number of elements in the range divided by the number of available cores. |