Parallel STL

As of C++17, the STL library has been extended with parallel versions of most, but not all, algorithms. Changing your algorithms to execute in parallel is only a matter of adding a parameter that tells the algorithm which parallel execution policy to use.

As stressed earlier in this book, if your code base is based upon STL algorithms, or at least if you have the habit of writing C++ by using algorithms, you get an instant performance boost almost for free by adding an execution policy where suitable.

auto roller_coasters = std::vector<std::string>{ 
  "woody", "steely", "loopy", "upside_down" 
}; 

Sequential version

Parallel version

auto loopy_coaster = *std::find(  roller_coasters.begin(),  roller_coasters.end(),  "loopy" ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.