Par/Seq Policy Usage
Let's compare different situations to see where parallel execution works better.
We'll cover the following
Why do you need the sequential policy?
Most of the time you’ll be probably interested in using parallel policy or parallel unsequenced one. But for debugging it might be easier to use std::execution::seq
. The parameter is also quite convenient as you might easily switch between the execution model using a template parameter. For some algorithms, the sequential policy might also give better performance than the C++14 counterpart.
Read more in the Benchmark section.
Limitations and Unsafe Instructions
The whole point of execution policies is to parallelize standard algorithms in a declarative way effortlessly. Nevertheless, there are some limitations you need to be aware of​.
For example with std::par
if you want to modify a shared resource you need to use some synchronization mechanism to prevent data races and deadlocks [^readaccess]:
[^readaccess]: When you only want to read a shared resource, then there’s no need to synchronise.
Get hands-on with 1400+ tech skills courses.