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 KOKKOS_FUNCTION
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()(index_type<DDims>... ids)
const
43 m_f(DiscreteElement<DDims...>(ids...));
47template <
class ExecSpace,
class Functor,
class... DDims>
49 std::string
const& label,
50 ExecSpace
const& execution_space,
52 Functor
const& f)
noexcept
56 ddc_to_kokkos_execution_policy(execution_space, domain),
57 ForEachKokkosLambdaAdapter<Functor, DDims...>(f));
63
64
65
66
67
68template <
class ExecSpace,
class... DDims,
class Functor>
70 std::string
const& label,
71 ExecSpace
const& execution_space,
75 detail::for_each_kokkos(label, execution_space, domain, std::forward<Functor>(f));
79
80
81
82
83template <
class ExecSpace,
class... DDims,
class Functor>
85 ExecSpace
const& execution_space,
89 detail::for_each_kokkos(
90 "ddc_for_each_default",
93 std::forward<Functor>(f));
97
98
99
100
101template <
class... DDims,
class Functor>
103 std::string
const& label,
105 Functor&& f)
noexcept
107 parallel_for_each(label, Kokkos::DefaultExecutionSpace(), domain, std::forward<Functor>(f));
111
112
113
114template <
class... DDims,
class Functor>
118 "ddc_for_each_default",
119 Kokkos::DefaultExecutionSpace(),
121 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