liveBook · Manning

Std::execution::par

As explained in C++ Concurrency in Action, Second Edition

The C++ standard-library execution policy object for parallel execution.

std::execution::par is an execution-policy object passed as the first argument to parallel overloads of standard algorithms. It permits an implementation to use multiple threads, but does not require it; how work is divided is also implementation-dependent. Parallel overloads usually have less restrictive complexity requirements than their serial counterparts. section 10.1

std::for_each(std::execution::par,v.begin(),v.end(),do_stuff);

Use the policy with an algorithm such as std::for_each to apply an operation across a range; independent work on each element is a straightforward parallel case. section 10.3.1

The operation must still be suitable for the policy. For example, an operation that uses a mutex for synchronization can be used with std::execution::par, but not with std::execution::par_unseq, whose requirements are tighter. The policy also supports larger tasks such as parallel visit counting with std::transform_reduce. section 10.3.1 section 10.3.2

How C++ Concurrency in Action, Second Edition covers it

How deep it goes
Explains policy selection, implementation discretion, and relaxed complexity requirements, but does not specify thread scheduling or guarantee parallel execution.
Examples
Uses independent per-element work with std::for_each and website-log visit counting with std::transform_reduce.
What you can do after
Apply std::execution::par to standard algorithm overloads while recognizing that parallel execution is permitted, not guaranteed.
How it connects
Links execution policies with parallel algorithms, std::for_each, std::transform_reduce, and std::execution::par_unseq.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of C++ Concurrency in Action, Second Edition. The section links point to the parts of the book it draws on.