Search⌘ K
AI Features

Additions and Changes to Parallel Algorithms

Explore the key additions and changes to C++17 parallel algorithms, including std::reduce and std::transform_reduce. Understand how these algorithms differ from traditional ones like std::accumulate and std::for_each, especially regarding parallel execution, commutativity, and performance implications. Gain insight into how floating-point operations affect determinism and learn about the adjusted behavior of std::for_each in parallel contexts.

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 ...