Implementing parallel map and fold with standard parallel algorithms
In the previous two recipes, we implemented parallel versions of the map and fold functions (which are called
std::accumulate() in the standard library) using threads and tasks. However, these implementations required manual handling of parallelization details, such as splitting data into chunks to be processed in parallel and creating threads or tasks, synchronizing their execution, and merging the results.
In C++17, many of the standard generic algorithms have been parallelized. In fact, the same algorithm can execute sequentially or in parallel, depending on a provided execution policy. In this recipe, we will learn how to implement
fold in parallel with standard algorithms.
Before you continue with this recipe, it is recommended that you read the previous two to make sure you understand the differences between various parallel implementations.