12#include <Kokkos_Core.hpp>
14#include "ddc/ddc_to_kokkos_execution_policy.hpp"
15#include "ddc/detail/kokkos.hpp"
16#include "ddc/discrete_domain.hpp"
17#include "ddc/discrete_element.hpp"
23template <
class F,
class... DDims>
24class ForEachKokkosLambdaAdapter
27 using index_type = DiscreteElementType;
32 explicit ForEachKokkosLambdaAdapter(F
const& f) : m_f(f) {}
34 template <std::size_t N =
sizeof...(DDims), std::enable_if_t<(N == 0),
bool> =
true>
35 void operator()([[maybe_unused]] index_type<
void> unused_id)
const
37 m_f(DiscreteElement
<>());
40 template <std::size_t N =
sizeof...(DDims), std::enable_if_t<(N == 0),
bool> =
true>
41 KOKKOS_FUNCTION
void operator()(
42 use_annotated_operator,
43 [[maybe_unused]] index_type<
void> unused_id)
const
45 m_f(DiscreteElement
<>());
48 template <std::size_t N =
sizeof...(DDims), std::enable_if_t<(N > 0),
bool> =
true>
49 void operator()(index_type<DDims>... ids)
const
51 m_f(DiscreteElement<DDims...>(ids...));
54 template <std::size_t N =
sizeof...(DDims), std::enable_if_t<(N > 0),
bool> =
true>
55 KOKKOS_FUNCTION
void operator()(use_annotated_operator, index_type<DDims>... ids)
const
57 m_f(DiscreteElement<DDims...>(ids...));
61template <
class ExecSpace,
class Functor,
class... DDims>
63 std::string
const& label,
64 ExecSpace
const& execution_space,
66 Functor
const& f)
noexcept
70 ddc_to_kokkos_execution_policy(execution_space, domain),
71 ForEachKokkosLambdaAdapter<Functor, DDims...>(f));
77
78
79
80
81
82template <
class ExecSpace,
class... DDims,
class Functor>
84 std::string
const& label,
85 ExecSpace
const& execution_space,
89 detail::for_each_kokkos(label, execution_space, domain, std::forward<Functor>(f));
93
94
95
96
97template <
class ExecSpace,
class... DDims,
class Functor>
99 ExecSpace
const& execution_space,
101 Functor&& f)
noexcept
103 detail::for_each_kokkos(
104 "ddc_for_each_default",
107 std::forward<Functor>(f));
111
112
113
114
115template <
class... DDims,
class Functor>
117 std::string
const& label,
119 Functor&& f)
noexcept
121 parallel_for_each(label, Kokkos::DefaultExecutionSpace(), domain, std::forward<Functor>(f));
125
126
127
128template <
class... DDims,
class Functor>
132 "ddc_for_each_default",
133 Kokkos::DefaultExecutionSpace(),
135 std::forward<Functor>(f));
friend class DiscreteDomain
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
The top-level namespace of DDC.
std::enable_if_t< Kokkos::is_execution_space_v< ExecSpace > > parallel_for_each(ExecSpace const &execution_space, DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
void parallel_for_each(std::string const &label, DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using the Kokkos default execution space
void parallel_for_each(std::string const &label, ExecSpace const &execution_space, DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
void parallel_for_each(DiscreteDomain< DDims... > const &domain, Functor &&f) noexcept
iterates over a nD domain using the Kokkos default execution space