January 2018
Intermediate to advanced
374 pages
9h 53m
English
The std::accumulate algorithm cannot be parallelized as it requires to be executed in 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 un-ordered.
With commutative operations their result is the same, as the order of accumulation doesn't matter.
In other words, given a range of integers:
auto c = std::vector<int>{1, 2, 3, 4, 5};
Accumulating them by addition or multiplication:
auto sum = std::accumulate(c.begin(), c.end(), 0, [](int a, int b) { return a + b; }
); auto product = std::accumulate(c.begin(), c.end(), 1, [](int a, int b) { return a * b; } );
Would ...
Read now
Unlock full access