6#ifndef IPPL_PARALLEL_DISPATCH_H
7#define IPPL_PARALLEL_DISPATCH_H
9#include <Kokkos_Core.hpp>
23 template <
unsigned Dim,
class... PolicyArgs>
26 using policy_type = Kokkos::MDRangePolicy<PolicyArgs..., Kokkos::Rank<Dim>>;
28 using index_type =
typename policy_type::array_index_type;
36 template <
class... PolicyArgs>
54 template <
class... PolicyArgs,
typename View>
55 typename RangePolicy<View::rank,
typename View::execution_space, PolicyArgs...>::policy_type
57 constexpr unsigned Dim = View::rank;
58 using exec_space =
typename View::execution_space;
59 using policy_type =
typename RangePolicy<
Dim, exec_space, PolicyArgs...>::policy_type;
60 if constexpr (
Dim == 1) {
61 return policy_type(shift, view.size() - shift);
63 using index_type =
typename RangePolicy<
Dim, exec_space, PolicyArgs...>::index_type;
64 Kokkos::Array<index_type, Dim> begin, end;
65 for (
unsigned int d = 0; d <
Dim; d++) {
67 end[d] = view.extent(d) - shift;
69 return policy_type(begin, end);
72 throw IpplException(
"detail::getRangePolicy",
"Unreachable state");
87 template <
size_t Dim,
class... PolicyArgs>
91 using policy_type =
typename RangePolicy<
Dim, PolicyArgs...>::policy_type;
92 if constexpr (
Dim == 1) {
93 return policy_type(begin[0], end[0]);
95 return policy_type(begin, end);
98 throw IpplException(
"detail::createRangePolicy",
"Unreachable state");
108 template <
unsigned Dim,
typename T =
size_t>
117 template <
typename T>
128 template <
e_functor_type,
typename,
typename,
typename,
typename...>
140 template <
typename Functor,
typename Policy,
typename...
T,
typename... Acc>
151 KOKKOS_INLINE_FUNCTION
void operator()(
T... x, Acc&... res)
const {
152 using index_type =
typename Policy::index_type;
153 typename Policy::index_array_type args = {
static_cast<index_type
>(x)...};
158 template <
typename Functor,
typename Policy,
typename...
T>
163 using index_type =
typename Policy::index_type;
164 typename Policy::index_array_type args = {
static_cast<index_type
>(x)...};
173 template <
typename...
T>
177 template <
typename...
T>
181 template <
typename T>
183 {
typename T::value_type() };
185 template <
typename T>
189 template <HasMemberValueType T>
191 using type =
typename T::value_type;
202 template <
e_functor_type Type,
typename Policy,
typename... Acc,
typename Functor>
206 using index_type =
typename PolicyProperties::index_type;
214 template <
class ExecPolicy,
class FunctorType>
216 const FunctorType& functor) {
220 template <
class ExecPolicy,
class FunctorType,
class... ReducerArgument>
222 const FunctorType& functor, ReducerArgument&&... reducer) {
223 Kokkos::parallel_reduce(
228 std::forward<ReducerArgument>(reducer)...);
RangePolicy< Dim, PolicyArgs... >::policy_type createRangePolicy(const Kokkos::Array< typename RangePolicy< Dim, PolicyArgs... >::index_type, Dim > &begin, const Kokkos::Array< typename RangePolicy< Dim, PolicyArgs... >::index_type, Dim > &end)
RangePolicy< View::rank, typenameView::execution_space, PolicyArgs... >::policy_type getRangePolicy(const View &view, int shift=0)
void parallel_for(const std::string &name, const ExecPolicy &policy, const FunctorType &functor)
void parallel_reduce(const std::string &name, const ExecPolicy &policy, const FunctorType &functor, ReducerArgument &&... reducer)
auto functorize(const Functor &f)
::ippl::Vector< index_type, Dim > index_array_type
Kokkos::MDRangePolicy< PolicyArgs..., Kokkos::Rank< Dim > > policy_type
typename policy_type::array_index_type index_type
::ippl::Vector< index_type, 1 > index_array_type
typename policy_type::index_type index_type
Kokkos::RangePolicy< PolicyArgs... > policy_type
decltype(std::tuple_cat(std::declval< typename Coords< 1, T >::type >(), std::declval< typename Coords< Dim - 1, T >::type >())) type
KOKKOS_INLINE_FUNCTION void operator()(T... x, Acc &... res) const
KOKKOS_INLINE_FUNCTION void operator()(T... x) const
static constexpr int rank
static constexpr int rank
typename T::value_type type