26 #ifndef SCHNEK_GRID_ITERATION_KOKKOSITERATION_HPP_ 27 #define SCHNEK_GRID_ITERATION_KOKKOSITERATION_HPP_ 29 #include "../../config.hpp" 30 #include "../array.hpp" 32 #ifdef SCHNEK_HAVE_KOKKOS 34 #include <Kokkos_Core.hpp> 40 typename executionSpace = Kokkos::DefaultExecutionSpace
42 struct RangeKokkosIterationPolicy
59 static void forEach(
const RangeType& range,
const Func &func);
67 template<
typename Func,
typename RangeType>
68 struct RangeKokkosIterationPolicyFunctor
72 template<
typename... Indices>
73 SCHNEK_INLINE
void operator()(Indices... ind)
const 75 func(
typename RangeType::LimitType{ind...});
81 template<
typename executionSpace>
82 struct RangeKokkosIterationPolicy<1, executionSpace>
88 static void forEach(
const RangeType& range,
const Func &func)
90 typedef typename RangeType::value_type T;
91 typedef Kokkos::RangePolicy<
96 ExecutionPolicy rangePolicy(range.getLo()[0], range.getHi()[0] + 1);
98 internal::RangeKokkosIterationPolicyFunctor<Func, RangeType> functor{func};
100 Kokkos::parallel_for(
"schnek:forEach", rangePolicy, functor);
106 typename executionSpace
112 inline void RangeKokkosIterationPolicy<rank, executionSpace>::forEach(
const RangeType& range,
const Func &func)
114 typedef typename RangeType::value_type T;
117 const typename RangeType::LimitType& loR = range.getLo();
118 const typename RangeType::LimitType& hiR = range.getHi();
120 for (
size_t i=0; i<rank; ++i)
126 Kokkos::MDRangePolicy<
127 Kokkos::IndexType<T>,
130 > rangePolicy(lo, hi);
132 internal::RangeKokkosIterationPolicyFunctor<Func, RangeType> functor{func};
134 Kokkos::parallel_for(
"schnek:forEach", rangePolicy, functor);
139 #endif // SCHNEK_HAVE_KOKKOS 140 #endif // SCHNEK_GRID_ITERATION_RANGEITERATION_HPP_