RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
policy.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef policy_openmp_HPP
21 #define policy_openmp_HPP
22 
23 #include <type_traits>
24 #include <omp.h>
25 
27 
28 // Rely on builtin_atomic when OpenMP can't do the job
30 
31 #if defined(RAJA_COMPILER_MSVC)
32 typedef enum omp_sched_t
33 {
34  // schedule kinds
35  omp_sched_static = 0x1,
36  omp_sched_dynamic = 0x2,
37  omp_sched_guided = 0x3,
38  omp_sched_auto = 0x4,
39 
40  // schedule modifier
41  omp_sched_monotonic = 0x80000000u
42 } omp_sched_t;
43 #endif
44 
45 namespace RAJA
46 {
47 namespace omp
48 {
49 
50 enum struct multi_reduce_algorithm : int
51 {
54 };
55 
56 template<multi_reduce_algorithm t_algorithm>
58 {
59  static constexpr multi_reduce_algorithm algorithm = t_algorithm;
60  static constexpr bool consistent =
62 };
63 
64 } // namespace omp
65 
66 namespace policy
67 {
68 namespace omp
69 {
70 
71 namespace internal
72 {
74 {};
75 
76 template<omp_sched_t Sched, int Chunk>
77 struct Schedule : public ScheduleTag
78 {
79  constexpr static omp_sched_t schedule = Sched;
80  constexpr static int chunk_size = Chunk;
81  constexpr static Policy policy = Policy::openmp;
82 };
83 } // namespace internal
84 
85 //
87 //
88 // Basic tag types
89 //
91 //
92 
93 struct Parallel
94 {};
95 
96 struct For
97 {};
98 
99 struct NoWait
100 {};
101 
102 static constexpr int default_chunk_size = -1;
103 
104 struct Auto : public internal::Schedule<omp_sched_auto, default_chunk_size>
105 {};
106 
107 template<int ChunkSize = default_chunk_size>
108 struct Static : public internal::Schedule<omp_sched_static, ChunkSize>
109 {};
110 
111 template<int ChunkSize = default_chunk_size>
113 
114 template<int ChunkSize = default_chunk_size>
116 
117 struct Runtime : private internal::Schedule<static_cast<omp_sched_t>(-1),
118  default_chunk_size>
119 {};
120 
121 //
123 //
124 // Execution policies
125 //
127 //
128 
133  : make_policy_pattern_launch_platform_t<Policy::openmp,
134  Pattern::region,
135  Launch::undefined,
136  Platform::host>
137 {};
138 
143  Pattern::region,
144  Launch::undefined,
145  Platform::host>
146 {};
147 
151 template<typename Sched>
153  : make_policy_pattern_launch_platform_t<Policy::openmp,
154  Pattern::forall,
155  Launch::undefined,
156  Platform::host,
157  omp::For,
158  omp::NoWait,
159  Sched>
160 {
161  static_assert(
162  std::is_base_of<::RAJA::policy::omp::internal::ScheduleTag, Sched>::value,
163  "Schedule type must be one of: Auto|Runtime|Static|Dynamic|Guided");
164 };
165 
169 template<typename Sched>
171  : make_policy_pattern_launch_platform_t<Policy::openmp,
172  Pattern::forall,
173  Launch::undefined,
174  Platform::host,
175  omp::For,
176  Sched>
177 {
178  static_assert(
179  std::is_base_of<::RAJA::policy::omp::internal::ScheduleTag, Sched>::value,
180  "Schedule type must be one of: Auto|Runtime|Static|Dynamic|Guided");
181 };
182 
188 
190 template<int ChunkSize = default_chunk_size>
192 
194 template<int ChunkSize = default_chunk_size>
196 
198 template<int ChunkSize = default_chunk_size>
200 
203 
204 
218 template<int ChunkSize = default_chunk_size>
221 
226 template<typename InnerPolicy>
231  Platform::host,
234 
240 
242 template<int ChunkSize = default_chunk_size>
245 
247 template<int ChunkSize = default_chunk_size>
250 
252 template<int ChunkSize = default_chunk_size>
255 
259 
260 
269 
272 
281  : make_policy_pattern_t<Policy::openmp, Pattern::taskgraph, omp::Parallel>
282 {};
283 
286  : make_policy_pattern_t<Policy::openmp, Pattern::taskgraph, omp::Parallel>
287 {};
288 
297  Pattern::workgroup_exec,
298  Launch::sync,
299  Platform::host>
300 {};
301 
309 struct omp_reduce : make_policy_pattern_t<Policy::openmp, Pattern::reduce>
310 {};
311 
314  : make_policy_pattern_t<Policy::openmp, Pattern::reduce, reduce::ordered>
315 {};
316 
318 template<typename tuning>
320  Policy::openmp,
321  Pattern::multi_reduce,
322  Launch::undefined,
323  Platform::host,
324  std::conditional_t<tuning::consistent,
325  reduce::ordered,
326  reduce::unordered>>
327 {};
328 
331  Pattern::synchronize,
332  Launch::sync>
333 {};
334 
335 #if defined(RAJA_COMPILER_MSVC)
336 
337 // For MS Visual C, just default to builtin_atomic for everything
338 using omp_atomic = builtin_atomic;
339 
340 #else // RAJA_COMPILER_MSVC not defined
341 
343 {};
344 
345 #endif
346 
348 {};
349 
350 template<RAJA::omp::multi_reduce_algorithm algorithm>
353 
354 // Policies for RAJA::MultiReduce* objects with specific behaviors.
355 // - combine_on_destruction policies combine new values into a single value for
356 // each object then each object combines its values into the parent object's
357 // values on destruction in a critical region.
360 // - combine_on_get policies combine new values into a single value for
361 // each thread then when get is called those values are combined.
364 
365 // Policy for RAJA::MultiReduce* objects that gives the
366 // same answer every time when used in the same way
368 
369 // Policy for RAJA::MultiReduce* objects that may not give the
370 // same answer every time when used in the same way
372 
374 
375 } // namespace omp
376 } // namespace policy
377 
385 
390 
395 
408 
415 
421 
427 
442 
456 
462 
473 
478 
481 
482 } // namespace RAJA
483 
484 #endif
Header file for basic RAJA policy mechanics.
RAJA header file defining automatic and builtin atomic operations.
multi_reduce_algorithm
Definition: policy.hpp:51
omp_multi_reduce_combine_on_destruction omp_multi_reduce_unordered
Definition: policy.hpp:371
omp_for_schedule_exec< Auto > omp_for_exec
Definition: policy.hpp:187
omp_multi_reduce_tuning< RAJA::omp::multi_reduce_algorithm::combine_on_get > omp_multi_reduce_combine_on_get
Definition: policy.hpp:363
omp_for_schedule_exec< omp::Runtime > omp_for_runtime_exec
Definition: policy.hpp:202
omp_parallel_exec< omp_for_schedule_exec< omp::Static< ChunkSize > >> omp_parallel_for_static_exec
Definition: policy.hpp:244
omp_for_schedule_exec< omp::Static< ChunkSize > > omp_for_static_exec
Definition: policy.hpp:191
omp_multi_reduce_tuning< RAJA::omp::multi_reduce_algorithm::combine_on_destruction > omp_multi_reduce_combine_on_destruction
Definition: policy.hpp:359
omp_multi_reduce_unordered omp_multi_reduce
Definition: policy.hpp:373
omp_parallel_for_exec omp_parallel_for_segit
Definition: policy.hpp:268
omp_for_schedule_exec< omp::Dynamic< ChunkSize > > omp_for_dynamic_exec
Definition: policy.hpp:195
omp_for_schedule_exec< omp::Guided< ChunkSize > > omp_for_guided_exec
Definition: policy.hpp:199
omp_parallel_for_segit omp_parallel_segit
Definition: policy.hpp:271
omp_for_nowait_schedule_exec< omp::Static< ChunkSize > > omp_for_nowait_static_exec
Definition: policy.hpp:220
omp_parallel_exec< omp_for_schedule_exec< omp::Runtime > > omp_parallel_for_runtime_exec
Definition: policy.hpp:258
omp_parallel_exec< omp_for_schedule_exec< omp::Dynamic< ChunkSize > >> omp_parallel_for_dynamic_exec
Definition: policy.hpp:249
omp_multi_reduce_combine_on_get omp_multi_reduce_ordered
Definition: policy.hpp:367
make_policy_pattern_launch_platform_t< Policy::openmp, Pattern::forall, Launch::undefined, Platform::host, omp::Parallel, wrapper< InnerPolicy > > omp_parallel_exec
Definition: policy.hpp:233
omp_parallel_exec< omp_for_exec > omp_parallel_for_exec
Definition: policy.hpp:239
omp_parallel_exec< omp_for_schedule_exec< omp::Guided< ChunkSize > >> omp_parallel_for_guided_exec
Definition: policy.hpp:254
Definition: AlignedRangeIndexSetBuilders.cpp:35
Policy
Definition: PolicyBase.hpp:32
Definition: PolicyBase.hpp:75
Atomic policy that uses the compilers builtin __atomic_XXX routines.
Definition: atomic_builtin.hpp:48
Definition: policy.hpp:58
static constexpr bool consistent
Definition: policy.hpp:60
static constexpr multi_reduce_algorithm algorithm
Definition: policy.hpp:59
Definition: policy.hpp:105
Definition: policy.hpp:97
Definition: policy.hpp:100
Definition: policy.hpp:94
Definition: policy.hpp:119
Definition: policy.hpp:109
Definition: policy.hpp:78
constexpr static Policy policy
Definition: policy.hpp:81
constexpr static int chunk_size
Definition: policy.hpp:80
constexpr static omp_sched_t schedule
Definition: policy.hpp:79
Definition: policy.hpp:343
Definition: policy.hpp:146
Definition: policy.hpp:137
Definition: policy.hpp:315
Definition: policy.hpp:310
Definition: policy.hpp:333
Definition: policy.hpp:282
Definition: policy.hpp:348
Definition: policy.hpp:300
Definition: PolicyBase.hpp:151