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 Support,
class IndexSequence>
24class ForEachKokkosLambdaAdapter;
26template <
class F,
class Support, std::size_t... Idx>
27class ForEachKokkosLambdaAdapter<F, Support, std::index_sequence<Idx...>>
29 template <std::size_t I>
30 using index_type = DiscreteElementType;
37 explicit ForEachKokkosLambdaAdapter(F
const& f, Support
const& support)
43 template <std::size_t N =
sizeof...(Idx), std::enable_if_t<(N == 0),
bool> =
true>
44 KOKKOS_FUNCTION
void operator()([[maybe_unused]] index_type<0> unused_id)
const
46 m_f(DiscreteElement
<>());
49 template <std::size_t N =
sizeof...(Idx), std::enable_if_t<(N > 0),
bool> =
true>
50 KOKKOS_FUNCTION
void operator()(index_type<Idx>... ids)
const
52 m_f(m_support(
typename Support::discrete_vector_type(ids...)));
56template <
class ExecSpace,
class Support,
class Functor>
58 std::string
const& label,
59 ExecSpace
const& execution_space,
60 Support
const& domain,
61 Functor
const& f)
noexcept
65 ddc_to_kokkos_execution_policy(execution_space, domain),
66 ForEachKokkosLambdaAdapter<
69 std::make_index_sequence<Support::rank()>>(f, domain));
75
76
77
78
79
80template <
class ExecSpace,
class Support,
class Functor>
82 std::string
const& label,
83 ExecSpace
const& execution_space,
84 Support
const& domain,
87 detail::for_each_kokkos(label, execution_space, domain, std::forward<Functor>(f));
91
92
93
94
95template <
class ExecSpace,
class Support,
class Functor>
97 ExecSpace
const& execution_space,
98 Support
const& domain,
101 detail::for_each_kokkos(
102 "ddc_for_each_default",
105 std::forward<Functor>(f));
109
110
111
112
113template <
class Support,
class Functor>
114void parallel_for_each(std::string
const& label, Support
const& domain, Functor&& f)
noexcept
116 parallel_for_each(label, Kokkos::DefaultExecutionSpace(), domain, std::forward<Functor>(f));
120
121
122
123template <
class Support,
class Functor>
127 "ddc_for_each_default",
128 Kokkos::DefaultExecutionSpace(),
130 std::forward<Functor>(f));
KOKKOS_DEFAULTED_FUNCTION constexpr DiscreteElement()=default
The top-level namespace of DDC.
void parallel_for_each(std::string const &label, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using the Kokkos default execution space
void parallel_for_each(Support const &domain, Functor &&f) noexcept
iterates over a nD domain using the Kokkos default execution space
std::enable_if_t< Kokkos::is_execution_space_v< ExecSpace > > parallel_for_each(ExecSpace const &execution_space, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space
void parallel_for_each(std::string const &label, ExecSpace const &execution_space, Support const &domain, Functor &&f) noexcept
iterates over a nD domain using a given Kokkos execution space