Template Function concore::v1::conc_reduce(It, It, Value, const BinaryOp&, const ReductionOp&, task_group, partition_hints)

Function Documentation

template<typename It, typename Value, typename BinaryOp, typename ReductionOp>
Value concore::v1::conc_reduce(It first, It last, Value identity, const BinaryOp &op, const ReductionOp &reduction, task_group grp, partition_hints hints)

A concurrent reduce algorithm.

This implements a reduce operation (similar to

std::accumulate) but does it by exposing concurrent computations. In order for this to be well defined, the given operation and reduction functors must be able to properly run in parallel on different parts of the input collection.
Parameters
  • first: Iterator pointing to the first element in a collection

  • last: Iterator pointing to the last element in a collection (1 past the end)

  • identity: The identity value; the starting point of the reduce

  • op: Binary functor that is applied to the elements

  • reduction: Binary functor that reduces the values

  • grp: Group in which to execute the tasks

  • hints: Hints that may be passed to the

  • work: The work to be applied to be executed for the elements (when not using f)

Template Parameters
  • It: The type of the iterator to use

  • Value: The type of the value used for computation

  • BinaryOp: The type of function used by the operation that applies to elements

  • ReductionOp: The type of function used by the reduction operation

  • WorkType: The type of a work object to be used (when not using op and reduction)

The operation is called exactly once for each element. The reduction is called each time we need to combine the results of two computations.

This generates internal tasks by spawning and waiting for those tasks to complete. If the user spawns other tasks during the execution of an iteration, those tasks would also be waited on.

One can cancel the execution of the tasks by passing a task_group object in, and canceling that task_group.

One can also provide hints to the implementation to fine-tune the algorithms to better fit the data it operates on. Please note however that the implementation may completely ignore all the hints it was provided.

Warning

If the iterations are not completely independent, this results in undefined behavior.

See

partition_hints, partition_method, conc_for(), task_group