[execpol] # 26 Algorithms library [[algorithms]](./#algorithms) ## 26.3 Parallel algorithms [[algorithms.parallel]](algorithms.parallel#execpol) ### 26.3.6 Execution policies [execpol] #### [26.3.6.1](#general) General [[execpol.general]](execpol.general) [1](#general-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L636) Subclause [execpol] describes classes that are [*execution policy*](#def:execution_policy "26.3.6.1 General [execpol.general]") types[.](#general-1.sentence-1) 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[.](#general-1.sentence-2) Execution policy types are declared in header [](execution.syn#header:%3cexecution%3e "33.4 Header synopsis [execution.syn]")[.](#general-1.sentence-3) [*Example [1](#general-example-1)*: using namespace std; vector 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 [1](#general-note-1)*: Implementations can provide additional execution policies to those described in this document as extensions to address parallel architectures that require idiosyncratic parameters for efficient execution[.](#general-1.sentence-4) — *end note*] #### [26.3.6.2](#type) Execution policy type trait [[execpol.type]](execpol.type) [🔗](#lib:is_execution_policy) `template struct is_execution_policy; ` [1](#type-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L675) is_execution_policy can be used to detect execution policies for the purpose of excluding function signatures from otherwise ambiguous overload resolution participation[.](#type-1.sentence-1) [2](#type-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L680) is_execution_policy is a *Cpp17UnaryTypeTrait* with a base characteristic of true_type if T is the type of a standard or implementation-defined execution policy, otherwise false_type[.](#type-2.sentence-1) [*Note [1](#type-note-1)*: This provision reserves the privilege of creating non-standard execution policies to the library implementation[.](#type-2.sentence-2) — *end note*] [3](#type-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L691) The behavior of a program that adds specializations foris_execution_policy is undefined[.](#type-3.sentence-1) #### [26.3.6.3](#seq) Sequenced execution policy [[execpol.seq]](execpol.seq) [🔗](#lib:execution::sequenced_policy) `class execution::sequenced_policy { unspecified }; ` [1](#seq-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L704) 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[.](#seq-1.sentence-1) [2](#seq-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L709) During the execution of a parallel algorithm with the execution​::​sequenced_policy policy, if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2 The std​::​terminate function"))[.](#seq-2.sentence-1) #### [26.3.6.4](#par) Parallel execution policy [[execpol.par]](execpol.par) [🔗](#lib:execution::parallel_policy) `class execution::parallel_policy { unspecified }; ` [1](#par-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L724) 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[.](#par-1.sentence-1) [2](#par-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L729) During the execution of a parallel algorithm with the execution​::​parallel_policy policy, if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2 The std​::​terminate function"))[.](#par-2.sentence-1) #### [26.3.6.5](#parunseq) Parallel and unsequenced execution policy [[execpol.parunseq]](execpol.parunseq) [🔗](#lib:execution::parallel_unsequenced_policy) `class execution::parallel_unsequenced_policy { unspecified }; ` [1](#parunseq-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L744) 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[.](#parunseq-1.sentence-1) [2](#parunseq-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L750) 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 exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2 The std​::​terminate function"))[.](#parunseq-2.sentence-1) #### [26.3.6.6](#unseq) Unsequenced execution policy [[execpol.unseq]](execpol.unseq) [🔗](#lib:execution::unsequenced_policy) `class execution::unsequenced_policy { unspecified }; ` [1](#unseq-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L765) The class 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 vectorized, e.g., executed on a single thread using instructions that operate on multiple data items[.](#unseq-1.sentence-1) [2](#unseq-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L772) During the execution of a parallel algorithm with the execution​::​unsequenced_policy policy, if the invocation of an element access function exits via an exception,terminate is invoked ([[except.terminate]](except.terminate "14.6.2 The std​::​terminate function"))[.](#unseq-2.sentence-1) #### [26.3.6.7](#objects) Execution policy objects [[execpol.objects]](execpol.objects) [🔗](#lib:seq) `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 }; inline constexpr execution::unsequenced_policy execution::unseq{ unspecified }; ` [1](#objects-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L795) The header [](execution.syn#header:%3cexecution%3e "33.4 Header synopsis [execution.syn]") declares global objects associated with each type of execution policy[.](#objects-1.sentence-1)