23 General utilities library [utilities]

23.19 Execution policies [execpol]

23.19.1 In general [execpol.general]

This subclause describes classes that are execution policy types.
An object of an execution policy type indicates the kinds of parallelism allowed in the execution of an algorithm and expresses the consequent requirements on the element access functions.
[Example
:
using namespace std;
vector<int> v = /* ... */;

// standard sequential sort
sort(v.begin(), v.end());

// explicitly sequential sort
sort(execution::seq, v.begin(), v.end());

// permitting parallel execution
sort(execution::par, v.begin(), v.end());

// permitting vectorization as well
sort(execution::par_unseq, v.begin(), v.end());
end example
]
[Note
:
Because different parallel architectures may require idiosyncratic parameters for efficient execution, implementations may provide additional execution policies to those described in this standard as extensions.
end note
]

23.19.2 Header <execution> synopsis [execution.syn]

namespace std {
  // [execpol.type], execution policy type trait
  template<class T> struct is_execution_policy;
  template<class T> inline constexpr bool is_execution_policy_v = is_execution_policy<T>::value;
}

namespace std::execution {
  // [execpol.seq], sequenced execution policy
  class sequenced_policy;

  // [execpol.par], parallel execution policy
  class parallel_policy;

  // [execpol.parunseq], parallel and unsequenced execution policy
  class parallel_unsequenced_policy;

  // [execpol.objects], execution policy objects
  inline constexpr sequenced_policy            seq{ unspecified };
  inline constexpr parallel_policy             par{ unspecified };
  inline constexpr parallel_unsequenced_policy par_unseq{ unspecified };
}

23.19.3 Execution policy type trait [execpol.type]

template<class T> struct is_execution_policy { see below };
is_­execution_­policy can be used to detect execution policies for the purpose of excluding function signatures from otherwise ambiguous overload resolution participation.
is_­execution_­policy<T> shall be a UnaryTypeTrait with a base characteristic of true_­type if T is the type of a standard or implementation-defined execution policy, otherwise false_­type.
[Note
:
This provision reserves the privilege of creating non-standard execution policies to the library implementation.
end note
]
The behavior of a program that adds specializations for is_­execution_­policy is undefined.

23.19.4 Sequenced execution policy [execpol.seq]

class execution​::​sequenced_­policy { unspecified };
The class execution​::​sequenced_­policy is an execution policy type used as a unique type to disambiguate parallel algorithm overloading and require that a parallel algorithm's execution may not be parallelized.
During the execution of a parallel algorithm with the execution​::​sequenced_­policy policy, if the invocation of an element access function exits via an uncaught exception, terminate() shall be called.

23.19.5 Parallel execution policy [execpol.par]

class execution​::​parallel_­policy { unspecified };
The class execution​::​parallel_­policy is an execution policy type used as a unique type to disambiguate parallel algorithm overloading and indicate that a parallel algorithm's execution may be parallelized.
During the execution of a parallel algorithm with the execution​::​parallel_­policy policy, if the invocation of an element access function exits via an uncaught exception, terminate() shall be called.

23.19.6 Parallel and unsequenced execution policy [execpol.parunseq]

class execution​::​parallel_­unsequenced_­policy { unspecified };
The class execution​::​parallel_­unsequenced_­policy is an execution policy type used as a unique type to disambiguate parallel algorithm overloading and indicate that a parallel algorithm's execution may be parallelized and vectorized.
During the execution of a parallel algorithm with the execution​::​parallel_­unsequenced_­policy policy, if the invocation of an element access function exits via an uncaught exception, terminate() shall be called.

23.19.7 Execution policy objects [execpol.objects]

inline constexpr execution::sequenced_policy execution::seq{ unspecified }; inline constexpr execution::parallel_policy execution::par{ unspecified }; inline constexpr execution::parallel_unsequenced_policy execution::par_unseq{ unspecified };
The header <execution> declares global objects associated with each type of execution policy.