23 #ifndef RAJA_forall_openmp_HPP
24 #define RAJA_forall_openmp_HPP
26 #include "RAJA/config.hpp"
28 #if defined(RAJA_ENABLE_OPENMP)
31 #include <type_traits>
59 template<
typename Iterable,
63 RAJA_INLINE concepts::enable_if_t<
64 resources::EventProxy<resources::Host>,
68 const omp_parallel_exec<InnerPolicy>&,
74 camp::decay<Func>>::value)
76 RAJA::region<RAJA::omp_parallel_region>([&]() {
81 return resources::EventProxy<resources::Host>(host_res);
87 #if defined(RAJA_COMPILER_MSVC)
88 static_assert(
false,
"MSVC does not support an OpenMP reduction through "
89 "the RAJA::kernel abstraction");
91 auto reducers_tuple = loop_body.data.param_tuple;
93 using EXEC_POL = camp::decay<InnerPolicy>;
94 RAJA::expt::detail::init_params<EXEC_POL>(reducers_tuple);
99 RAJA_OMP_DECLARE_TUPLE_REDUCTION_COMBINE;
104 #pragma omp for reduction(combine : reducers_tuple)
105 for (decltype(distance_it) i = 0; i < distance_it; ++i)
107 body.get_priv()(begin_it[i]);
115 reducers_tuple =
body.get_priv().data.param_tuple;
118 RAJA::expt::detail::resolve_params<EXEC_POL>(reducers_tuple);
121 return resources::EventProxy<resources::Host>(host_res);
136 template<
typename Iterable,
typename Func>
137 RAJA_INLINE
void forall_impl(const ::RAJA::policy::omp::Auto&,
143 for (decltype(distance_it) i = 0; i < distance_it; ++i)
145 loop_body(begin_it[i]);
152 template<
typename Iterable,
typename Func,
int ChunkSize>
153 RAJA_INLINE
void forall_impl(const ::RAJA::policy::omp::Static<ChunkSize>&,
158 if constexpr (ChunkSize > 0)
160 #pragma omp for schedule(static, ChunkSize)
161 for (decltype(distance_it) i = 0; i < distance_it; ++i)
163 loop_body(begin_it[i]);
168 #pragma omp for schedule(static)
169 for (decltype(distance_it) i = 0; i < distance_it; ++i)
171 loop_body(begin_it[i]);
179 template<
typename Iterable,
typename Func,
int ChunkSize>
180 RAJA_INLINE
void forall_impl(const ::RAJA::policy::omp::Dynamic<ChunkSize>&,
185 if constexpr (ChunkSize > 0)
187 #pragma omp for schedule(dynamic, ChunkSize)
188 for (decltype(distance_it) i = 0; i < distance_it; ++i)
190 loop_body(begin_it[i]);
195 #pragma omp for schedule(dynamic)
196 for (decltype(distance_it) i = 0; i < distance_it; ++i)
198 loop_body(begin_it[i]);
206 template<
typename Iterable,
typename Func,
int ChunkSize>
207 RAJA_INLINE
void forall_impl(const ::RAJA::policy::omp::Guided<ChunkSize>&,
212 if constexpr (ChunkSize > 0)
214 #pragma omp for schedule(guided, ChunkSize)
215 for (decltype(distance_it) i = 0; i < distance_it; ++i)
217 loop_body(begin_it[i]);
222 #pragma omp for schedule(guided)
223 for (decltype(distance_it) i = 0; i < distance_it; ++i)
225 loop_body(begin_it[i]);
233 template<
typename Iterable,
typename Func>
234 RAJA_INLINE
void forall_impl(const ::RAJA::policy::omp::Runtime&,
239 #pragma omp for schedule(runtime)
240 for (decltype(distance_it) i = 0; i < distance_it; ++i)
242 loop_body(begin_it[i]);
247 #if !defined(RAJA_COMPILER_MSVC)
249 template<
typename Policy,
typename Iterable,
typename Func>
252 omp_sched_t prev_sched;
254 omp_get_schedule(&prev_sched, &prev_chunk);
255 omp_set_schedule(Policy::schedule, Policy::chunk_size);
257 std::forward<Func>(loop_body));
258 omp_set_schedule(prev_sched, prev_chunk);
268 template<
typename Iterable,
typename Func>
274 #pragma omp for nowait
275 for (decltype(distance_it) i = 0; i < distance_it; ++i)
277 loop_body(begin_it[i]);
284 template<
typename Iterable,
typename Func,
int ChunkSize>
286 const ::RAJA::policy::omp::Static<ChunkSize>&,
291 if constexpr (ChunkSize > 0)
293 #pragma omp for schedule(static, ChunkSize) nowait
294 for (decltype(distance_it) i = 0; i < distance_it; ++i)
296 loop_body(begin_it[i]);
301 #pragma omp for schedule(static) nowait
302 for (decltype(distance_it) i = 0; i < distance_it; ++i)
304 loop_body(begin_it[i]);
310 #if !defined(RAJA_COMPILER_MSVC)
312 template<
typename Policy,
typename Iterable,
typename Func>
317 omp_sched_t prev_sched;
319 omp_get_schedule(&prev_sched, &prev_chunk);
320 omp_set_schedule(Policy::schedule, Policy::chunk_size);
322 std::forward<Iterable>(
iter),
323 std::forward<Func>(loop_body));
324 omp_set_schedule(prev_sched, prev_chunk);
330 template<
typename Schedule,
333 typename ForallParam>
334 RAJA_INLINE concepts::enable_if_t<
335 resources::EventProxy<resources::Host>,
339 const omp_for_schedule_exec<Schedule>&,
345 std::forward<Func>(loop_body));
346 return resources::EventProxy<resources::Host>(host_res);
349 template<
typename Schedule,
352 typename ForallParam>
353 RAJA_INLINE concepts::enable_if_t<
354 resources::EventProxy<resources::Host>,
358 const omp_for_nowait_schedule_exec<Schedule>&,
364 std::forward<Func>(loop_body));
365 return resources::EventProxy<resources::Host>(host_res);
RAJA header file defining index set classes.
Header file containing definition of RAJA list segment class.
Header file containing definitions of RAJA range segment classes.
Header file containing type traits needed by kernel implementation.
RAJA_HOST_DEVICE RAJA_INLINE void RAJA_UNUSED_VAR(T &&...) noexcept
Definition: macros.hpp:120
value_type::device_call &[i_loop] iter
Definition: WorkRunner.hpp:216
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
RAJA_INLINE void forall_impl_nowait(const ::RAJA::policy::omp::Static< ChunkSize > &p, Iterable &&iter, Func &&loop_body, ForallParam &&f_params)
Definition: forall.hpp:257
RAJA_INLINE concepts::enable_if_t< resources::EventProxy< resources::Host >, RAJA::expt::type_traits::is_ForallParamPack< ForallParam >, concepts::negate< RAJA::expt::type_traits::is_ForallParamPack_empty< ForallParam > > > forall_impl(resources::Host host_res, const omp_parallel_exec< InnerPolicy > &, Iterable &&iter, Func &&loop_body, ForallParam f_params)
Definition: forall.hpp:325
RAJA_INLINE concepts::enable_if_t< resources::EventProxy< resources::Host >, expt::type_traits::is_ForallParamPack< ForallParam >, expt::type_traits::is_ForallParamPack_empty< ForallParam > > forall_impl(resources::Host host_res, const simd_exec &, Iterable &&iter, Func &&body, ForallParam)
Definition: forall.hpp:81
Definition: AlignedRangeIndexSetBuilders.cpp:35
Policy
Definition: PolicyBase.hpp:32
auto & body
Definition: launch.hpp:177
Header file containing RAJA OpenMP policy definitions.
#define RAJA_EXTRACT_BED_IT(CONTAINER)
Definition: forall.hpp:32
Header file containing RAJA index set and segment iteration template methods that take an execution p...
Header file containing the RAJA Region API call.
Definition: TypeTraits.hpp:67
Definition: TypeTraits.hpp:59
Definition: TypeTraits.hpp:49
Definition: policy.hpp:119
Header file for RAJA type definitions.