Sequential, parallel, or parallel execution with vectorisation

We will now learn how to execute our algorithm according to a certain execution policy.

By using an execution policy in C++17, you can specify whether the algorithm should run sequentially, in parallel, or in parallel with vectorization.

Execution Policies

The policy tag specifies whether an algorithm should run sequentially, in parallel, or in parallel with vectorization.

  • std::execution::seq: runs the algorithm sequentially

  • std::execution::par: runs the algorithm in parallel on multiple threads

  • std::execution::par_unseq: runs the algorithm in parallel on multiple threads and allows the interleaving of individual loops; permits a vectorised version with SIMD (Single Instruction Multiple Data) extensions.

The following code snippet shows all execution policies.

Get hands-on with 1200+ tech skills courses.