20 #ifndef RAJA_pattern_launch_openmp_HPP
21 #define RAJA_pattern_launch_openmp_HPP
33 template<
typename ReduceParams,
typename BODY>
34 static concepts::enable_if_t<
35 resources::EventProxy<resources::Resource>,
37 exec(RAJA::resources::Resource res,
40 ReduceParams& f_params)
43 constexpr
bool has_reducers =
52 auto parallel_section = [&](ReduceParams& f_params,
auto func) {
56 static_assert(std::is_invocable<decltype(func), ReduceParams&, BodyType&,
58 "Internal RAJA error: Check the parallel kernel passed to "
59 "OpenMP Parallel section in openmp/launch.hpp");
63 func(f_params, loop_body,
ctx);
65 free(
ctx.shared_mem_ptr);
66 ctx.shared_mem_ptr =
nullptr;
73 if constexpr (has_reducers)
75 RAJA_OMP_DECLARE_REDUCTION_COMBINE;
76 #pragma omp parallel reduction(combine : f_params)
81 auto parallel_kernel = [&](ReduceParams& f_params, BodyType&
body,
85 parallel_section(f_params, parallel_kernel);
90 RAJA::region<RAJA::omp_parallel_region>([&]() {
91 auto parallel_kernel = [&](ReduceParams&, BodyType&
body,
95 parallel_section(f_params, parallel_kernel);
101 return resources::EventProxy<resources::Resource>(res);
105 template<
typename SEGMENT>
109 template<
typename LaunchContextPolicy,
typename BODY>
112 SEGMENT
const& segment,
116 int len = segment.end() - segment.begin();
117 RAJA::region<RAJA::omp_parallel_region>([&]() {
121 for (
int i = 0; i < len; i++)
124 loop_body.get_priv()(*(segment.begin() + i));
129 template<
typename LaunchContextPolicy,
typename BODY>
132 SEGMENT
const& segment0,
133 SEGMENT
const& segment1,
137 const int len1 = segment1.end() - segment1.begin();
138 const int len0 = segment0.end() - segment0.begin();
140 RAJA::region<RAJA::omp_parallel_region>([&]() {
145 for (
int j = 0; j < len1; j++)
147 for (
int i = 0; i < len0; i++)
150 loop_body.get_priv()(*(segment0.begin() + i),
151 *(segment1.begin() + j));
157 template<
typename LaunchContextPolicy,
typename BODY>
160 SEGMENT
const& segment0,
161 SEGMENT
const& segment1,
162 SEGMENT
const& segment2,
166 const int len2 = segment2.end() - segment2.begin();
167 const int len1 = segment1.end() - segment1.begin();
168 const int len0 = segment0.end() - segment0.begin();
170 RAJA::region<RAJA::omp_parallel_region>([&]() {
175 for (
int k = 0; k < len2; k++)
177 for (
int j = 0; j < len1; j++)
179 for (
int i = 0; i < len0; i++)
181 loop_body.get_priv()(*(segment0.begin() + i),
182 *(segment1.begin() + j),
183 *(segment2.begin() + k));
191 template<
typename SEGMENT>
195 template<
typename LaunchContextPolicy,
typename BODY>
198 SEGMENT
const& segment,
202 int len = segment.end() - segment.begin();
204 for (
int i = 0; i < len; i++)
207 body(*(segment.begin() + i));
211 template<
typename LaunchContextPolicy,
typename BODY>
214 SEGMENT
const& segment0,
215 SEGMENT
const& segment1,
219 const int len1 = segment1.end() - segment1.begin();
220 const int len0 = segment0.end() - segment0.begin();
223 for (
int j = 0; j < len1; j++)
225 for (
int i = 0; i < len0; i++)
228 body(*(segment0.begin() + i), *(segment1.begin() + j));
233 template<
typename LaunchContextPolicy,
typename BODY>
236 SEGMENT
const& segment0,
237 SEGMENT
const& segment1,
238 SEGMENT
const& segment2,
242 const int len2 = segment2.end() - segment2.begin();
243 const int len1 = segment1.end() - segment1.begin();
244 const int len0 = segment0.end() - segment0.begin();
247 for (
int k = 0; k < len2; k++)
249 for (
int j = 0; j < len1; j++)
251 for (
int i = 0; i < len0; i++)
253 body(*(segment0.begin() + i), *(segment1.begin() + j),
254 *(segment2.begin() + k));
264 template<
typename SEGMENT>
268 template<
typename LaunchContextPolicy,
typename BODY>
271 SEGMENT
const& segment,
275 int len = segment.end() - segment.begin();
278 for (
int i = 0; i < len; i++)
280 body(*(segment.begin() + i), i);
284 template<
typename LaunchContextPolicy,
typename BODY>
287 SEGMENT
const& segment0,
288 SEGMENT
const& segment1,
292 const int len1 = segment1.end() - segment1.begin();
293 const int len0 = segment0.end() - segment0.begin();
296 for (
int j = 0; j < len1; j++)
298 for (
int i = 0; i < len0; i++)
301 body(*(segment0.begin() + i), *(segment1.begin() + j), i, j);
306 template<
typename LaunchContextPolicy,
typename BODY>
309 SEGMENT
const& segment0,
310 SEGMENT
const& segment1,
311 SEGMENT
const& segment2,
315 const int len2 = segment2.end() - segment2.begin();
316 const int len1 = segment1.end() - segment1.begin();
317 const int len0 = segment0.end() - segment0.begin();
320 for (
int k = 0; k < len2; k++)
322 for (
int j = 0; j < len1; j++)
324 for (
int i = 0; i < len0; i++)
326 body(*(segment0.begin() + i), *(segment1.begin() + j),
327 *(segment2.begin() + k), i, j, k);
335 struct omp_parallel_nested_for_exec;
337 template<
typename SEGMENT>
341 template<
typename LaunchContextPolicy,
typename BODY>
344 SEGMENT
const& segment0,
345 SEGMENT
const& segment1,
349 const int len1 = segment1.end() - segment1.begin();
350 const int len0 = segment0.end() - segment0.begin();
352 RAJA::region<RAJA::omp_parallel_region>([&]() {
356 #pragma omp for RAJA_COLLAPSE(2)
357 for (
int j = 0; j < len1; j++)
359 for (
int i = 0; i < len0; i++)
362 loop_body.get_priv()(*(segment0.begin() + i),
363 *(segment1.begin() + j));
369 template<
typename LaunchContextPolicy,
typename BODY>
372 SEGMENT
const& segment0,
373 SEGMENT
const& segment1,
374 SEGMENT
const& segment2,
378 const int len2 = segment2.end() - segment2.begin();
379 const int len1 = segment1.end() - segment1.begin();
380 const int len0 = segment0.end() - segment0.begin();
382 RAJA::region<RAJA::omp_parallel_region>([&]() {
386 #pragma omp for RAJA_COLLAPSE(3)
387 for (
int k = 0; k < len2; k++)
389 for (
int j = 0; j < len1; j++)
391 for (
int i = 0; i < len0; i++)
393 loop_body.get_priv()(*(segment0.begin() + i),
394 *(segment1.begin() + j),
395 *(segment2.begin() + k));
404 template<
typename SEGMENT>
408 template<
typename LaunchContextPolicy,
typename BODY>
411 SEGMENT
const& segment0,
412 SEGMENT
const& segment1,
416 const int len1 = segment1.end() - segment1.begin();
417 const int len0 = segment0.end() - segment0.begin();
419 RAJA::region<RAJA::omp_parallel_region>([&]() {
423 #pragma omp for RAJA_COLLAPSE(2)
424 for (
int j = 0; j < len1; j++)
426 for (
int i = 0; i < len0; i++)
429 loop_body.get_priv()(*(segment0.begin() + i), *(segment1.begin() + j),
436 template<
typename LaunchContextPolicy,
typename BODY>
439 SEGMENT
const& segment0,
440 SEGMENT
const& segment1,
441 SEGMENT
const& segment2,
445 const int len2 = segment2.end() - segment2.begin();
446 const int len1 = segment1.end() - segment1.begin();
447 const int len0 = segment0.end() - segment0.begin();
449 RAJA::region<RAJA::omp_parallel_region>([&]() {
453 #pragma omp for RAJA_COLLAPSE(3)
454 for (
int k = 0; k < len2; k++)
456 for (
int j = 0; j < len1; j++)
458 for (
int i = 0; i < len0; i++)
460 loop_body.get_priv()(*(segment0.begin() + i),
461 *(segment1.begin() + j),
462 *(segment2.begin() + k), i, j, k);
470 template<
typename SEGMENT>
474 template<
typename LaunchContextPolicy,
typename BODY,
typename TILE_T>
478 SEGMENT
const& segment,
482 int len = segment.end() - segment.begin();
484 RAJA::region<RAJA::omp_parallel_region>([&]() {
489 for (
int i = 0; i < len; i += tile_size)
491 loop_body.get_priv()(segment.slice(i, tile_size));
497 template<
typename SEGMENT>
501 template<
typename LaunchContextPolicy,
typename BODY,
typename TILE_T>
505 SEGMENT
const& segment,
509 const int len = segment.end() - segment.begin();
510 const int numTiles = (len - 1) / tile_size + 1;
512 RAJA::region<RAJA::omp_parallel_region>([&]() {
516 #pragma omp parallel for
517 for (
int i = 0; i < numTiles; i++)
519 const int i_tile_size = i * tile_size;
520 loop_body.get_priv()(segment.slice(i_tile_size, tile_size), i);
526 template<
typename SEGMENT>
530 template<
typename LaunchContextPolicy,
typename BODY,
typename TILE_T>
534 SEGMENT
const& segment,
538 int len = segment.end() - segment.begin();
540 for (
int i = 0; i < len; i += tile_size)
542 body(segment.slice(i, tile_size));
547 template<
typename SEGMENT>
551 template<
typename LaunchContextPolicy,
typename BODY,
typename TILE_T>
555 SEGMENT
const& segment,
559 const int len = segment.end() - segment.begin();
560 const int numTiles = (len - 1) / tile_size + 1;
563 for (
int i = 0; i < numTiles; i++)
565 const int i_tile_size = i * tile_size;
566 body(segment.slice(i_tile_size, tile_size), i);
Definition: launch_core.hpp:246
Definition: launch_context_policy.hpp:30
RAJA header file containing the core components of RAJA::launch.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_UNUSED_ARG(x)
Definition: macros.hpp:97
constexpr RAJA_HOST_DEVICE auto invoke_body(Params &¶ms, Fn &&f, Ts &&... extra)
Definition: forall.hpp:598
RAJA_HOST_DEVICE auto thread_privatize(const T &item) -> Privatizer< T >
Create a private copy of the argument to be stored on the current thread's stack in a class of the Pr...
Definition: privatizer.hpp:88
omp_for_schedule_exec< Auto > omp_for_exec
Definition: policy.hpp:187
omp_parallel_exec< omp_for_exec > omp_parallel_for_exec
Definition: policy.hpp:239
Definition: AlignedRangeIndexSetBuilders.cpp:35
LaunchContextType ctx
Definition: launch.hpp:185
auto & body
Definition: launch.hpp:177
typename RAJA::detail::launch_context_type< BODY >::type LaunchContextType
Definition: launch.hpp:183
Header file containing RAJA OpenMP policy definitions.
static concepts::enable_if_t< resources::EventProxy< resources::Resource >, RAJA::expt::type_traits::is_ForallParamPack< ReduceParams > > exec(RAJA::resources::Resource res, LaunchParams const &launch_params, BODY const &body, ReduceParams &f_params)
Definition: launch.hpp:37
Definition: launch_core.hpp:263
Definition: launch_core.hpp:163
size_t shared_mem_size
Definition: launch_core.hpp:167
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:212
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:234
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:196
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:110
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:158
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:130
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:370
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:342
Definition: launch_core.hpp:480
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:285
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:269
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:307
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:437
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:409
Definition: launch_core.hpp:483
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:531
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:475
Definition: launch_core.hpp:579
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:552
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:502
Definition: launch_core.hpp:582
static constexpr void parampack_resolve(EXEC_POL const &pol, ForallParamPack< Params... > &f_params, Args &&... args)
Definition: forall.hpp:304
static constexpr void parampack_init(EXEC_POL const &pol, ForallParamPack< Params... > &f_params, Args &&... args)
Definition: forall.hpp:269
Definition: TypeTraits.hpp:67
Definition: TypeTraits.hpp:59
Definition: policy.hpp:146