Additions and Changes to Parallel Algorithms
Learn how to use std::reduce() and std::transform_reduce() as additions to the standard library for unordered parallel algorithms.
We'll cover the following
Most algorithms in the standard library are available as parallel versions
straight out the box. However, there are some noteworthy exceptions, including std::accumulate()
and std::for_each()
, as their original specifications required in-order execution.
std::accumulate()
and std::reduce()
The std::accumulate()
algorithm cannot be parallelized as it must be executed in the order of the elements, which is not possible to parallelize. Instead, a new algorithm called std::reduce()
has been added, which works just like std::accumulate()
with the exception that it is executed unordered.
With commutative operations, their results are the same, as the order of accumulation doesn’t matter. In other words, given a range of integers:
Get hands-on with 1400+ tech skills courses.