forked from cplusplus/parallelism-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execution_policies.html
300 lines (245 loc) · 10.2 KB
/
execution_policies.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<cxx-clause id="parallel.execpol">
<h1>Execution policies</h1>
<cxx-section id="parallel.execpol.general">
<h1>In general</h1>
<p>This subclause describes classes that represent <dfn>execution policies</dfn>. An
<dfn>execution policy</dfn> is an object that expresses the requirements on the ordering
of functions invoked as a consequence of the invocation of a standard
algorithm. Execution policies afford standard algorithms the discretion to
execute in parallel.</p>
<cxx-example>
<pre>std::vector<int> v = ...
// standard sequential sort
<del>std::sort(vec.begin(), vec.end());</del>
<insdel>std::sort(std::begin(vec), std::end(vec));</insdel>
<ins2>std::sort(vec.begin(), vec.end());</ins2>
using namespace std::experimental::parallel<ins2>_v1</ins2>;
// explicitly sequential sort
<del>sort(seq, v.begin(), v.end());</del>
<insdel>sort(seq, std::begin(v), std::end(v));</insdel>
<ins2>sort(seq, v.begin(), v.end());</ins2>
// permitting parallel execution
<del>sort(par, v.begin(), v.end());</del>
<insdel>sort(par, std::begin(v), std::end(v));</insdel>
<ins2>sort(par, v.begin(), v.end());</ins2>
// permitting vectorization as well
<del>sort(vec, v.begin(), v.end());</del>
<insdel>sort(vec, std::begin(v), std::end(v));</insdel>
<ins2>sort(par_vec, v.begin(), v.end());</ins2>
// sort with dynamically-selected execution
size_t threshold = ...
execution_policy exec = seq;
if(v.size() > threshold)
{
exec = par;
}
<del>sort(exec, v.begin(), v.end());</del>
<insdel>sort(exec, std::begin(v), std::end(v));</insdel>
<ins2>sort(exec, v.begin(), v.end());</ins2>
</pre>
</cxx-example><pre>
</pre>
<cxx-note>
Because different parallel architectures may require idiosyncratic
parameters for efficient execution, implementations of the Standard Library
<del2>should</del2><ins2>may</ins2> provide additional execution policies to those described in this
Technical Specification as extensions.
</cxx-note>
</cxx-section>
<cxx-section id="parallel.execpol.synop">
<h1>Header <code><experimental/execution_policy></code> synopsis</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
<cxx-ref insynopsis="" to="parallel.execpol.type"></cxx-ref>
template<class T> struct is_execution_policy;
<cxx-ref insynopsis="" to="parallel.execpol.seq"></cxx-ref>
class sequential_execution_policy;
<cxx-ref insynopsis="" to="parallel.execpol.par"></cxx-ref>
class parallel_execution_policy;
<cxx-ref insynopsis="" to="parallel.execpol.vec"></cxx-ref>
class <del2>vector_execution_policy</del2><ins2>parallel_vector_execution_policy</ins2>;
<cxx-ref insynopsis="" to="parallel.execpol.dynamic"></cxx-ref>
class execution_policy;
}
}
}
</pre>
</cxx-section>
<cxx-section id="parallel.execpol.type">
<h1>Execution policy type trait</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
template<class T> struct is_execution_policy
: integral_constant<bool, <em>see below</em>> { };
}
}
}
</pre>
<p><code>is_execution_policy</code> can be used to detect parallel execution policies for the purpose of excluding function signatures from otherwise ambiguous overload resolution participation.</p>
<p>If <code>T</code> is the type of a standard or implementation-defined execution policy, <code>is_execution_policy<T></code> shall be publicly derived from <code>integral_constant<bool,true></code>,
otherwise from <code>integral_constant<bool,false></code>.</p>
<p>The behavior of a program that adds specializations for <code>is_execution_policy</code> is undefined.</p>
</cxx-section>
<cxx-section id="parallel.execpol.seq">
<h1>Sequential execution policy</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
class sequential_execution_policy{ <ins2><i>unspecified</i></ins2> };
}
}
}
</pre>
<p>The class <code>sequential_execution_policy</code> 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.</p>
</cxx-section>
<cxx-section id="parallel.execpol.par">
<h1>Parallel execution policy</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
class parallel_execution_policy{ <ins2><i>unspecified</i></ins2> };
}
}
}
</pre>
<p>The class <code>parallel_execution_policy</code> 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.</p>
</cxx-section>
<cxx-section id="parallel.execpol.vec">
<h1><ins2>Parallel+</ins2>Vector execution policy</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
class <del2>vector_execution_policy</del2><ins2>parallel_vector_execution_policy</ins2>{ <ins2><i>unspecified</i></ins2> };
}
}
}
</pre>
<p>The class <code>class <del2>vector_execution_policy</del2><ins2>parallel_vector_execution_policy</ins2></code> 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.</p>
</cxx-section>
<cxx-section id="parallel.execpol.dynamic">
<h1>Dynamic execution policy</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
class execution_policy
{
public:
<cxx-ref insynopsis="" to="parallel.execpol.con"></cxx-ref>
template<class T> execution_policy(const T& exec);
template<class T> execution_policy& operator=(const T& exec);
<cxx-ref insynopsis="" to="parallel.execpol.access"></cxx-ref>
template<class T> T* get() noexcept;
template<class T> const T* get() const noexcept;
};
}
}
}
</pre>
<p>The class <code>execution_policy</code> is a dynamic container for execution policy objects.
<code>execution_policy</code> allows dynamic control over standard algorithm execution.</p>
<cxx-example>
<pre>std::vector<float> sort_me = ...
<ins>using namespace std::experimental::parallel<ins2>_v1</ins2>;</ins>
<del><code>std::</code></del>execution_policy exec = <del><code>std::</code></del>seq;
if(sort_me.size() > threshold)
{
exec = std::par;
}
<del>std::sort(exec, sort_me.begin(), sort_me.end());</del>
<ins>std::sort(exec, std::begin(sort_me), std::end(sort_me));</ins></pre>
</cxx-example>
<p>Objects of type <code>execution_policy</code> shall be constructible and assignable from objects of
type <code>T</code> for which <code>is_execution_policy<T>::value</code> is <code>true</code>.</p>
<cxx-section id="parallel.execpol.con">
<h1><code>execution_policy</code> construct/assign</h1>
<cxx-function>
<cxx-signature>template<class T> execution_policy(const T& exec);</cxx-signature>
<cxx-effects>Constructs an <code>execution_policy</code> object with a copy of <code>exec</code>'s state.</cxx-effects>
<del>
<cxx-requires>
<code>is_execution_policy<T>::value</code> is <code>true</code>.
</cxx-requires>
</del>
<ins>
<cxx-remarks>
This constructor shall not participate in overload resolution unless
<code>is_execution_policy<T>::value</code> is <code>true</code>.
</cxx-remarks>
</ins>
</cxx-function>
<cxx-function>
<cxx-signature>template<class T> execution_policy& operator=(const T& exec);</cxx-signature>
<cxx-effects>Assigns a copy of <code>exec</code>'s state to <code>*this</code>.</cxx-effects>
<cxx-returns><code>*this</code>.
<del>
<cxx-requires>
<code>is_execution_policy<T>::value</code> is <code>true</code>.
</cxx-requires>
</del>
<insdel>
<cxx-remarks>
This operator shall not partipate in overload resolution unless
<code>is_execution_policy<T>::value</code> is <code>true</code>.
</cxx-remarks>
</insdel>
</cxx-function>
</cxx-section>
<cxx-section id="parallel.execpol.access">
<h1><code>execution_policy</code> object access</h1>
<cxx-function>
<cxx-signature>
const type_info& type() const noexcept;
</cxx-signature>
<cxx-returns><code>typeid(T)</code>, such that <code>T</code> is the type of the execution policy object contained by <code>*this</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>
template<class T> T* get() noexcept;
template<class T> const T* get() <ins2>const</ins2> noexcept;
</cxx-signature>
<cxx-returns>If <code>target_type() == typeid(T)</code>, a pointer to the stored execution policy object; otherwise a null pointer.</cxx-returns>
<ins2>
<cxx-requires>
<code>is_execution_policy<T>::value</code> is <code>true</code>.
</cxx-requires>
</ins2>
<insdel>
<cxx-remarks>
This function shall not participate in overload resolution unless
<code>is_execution_policy<T></code> is <code>true</code>.
</cxx-remarks>
</insdel>
</cxx-function>
</cxx-section>
</cxx-section>
<cxx-section id="parallel.execpol.objects">
<h1>Execution policy objects</h1>
<pre>
namespace std {
namespace experimental {
namespace parallel<ins2>_v1</ins2> {
<del2>
constexpr sequential_execution_policy seq = sequential_execution_policy();
constexpr parallel_execution_policy par = parallel_execution_policy();
constexpr vector_execution_policy vec = vector_execution_policy();
</del2>
<ins2>
constexpr sequential_execution_policy seq = {};
constexpr parallel_execution_policy par = {};
constexpr parallel_vector_execution_policy par_vec = {};
</ins2>
}
}
}
</pre>
<p>The header <code><<ins2>experimental/</ins2>execution_policy></code> declares a global object associated with each type of execution policy defined by this Technical Specification.</p>
</cxx-section>
</cxx-clause>