12#include <Kokkos_Core.hpp>
14#include "detail/kokkos.hpp"
16#include "ddc_to_kokkos_execution_policy.hpp"
17#include "discrete_domain.hpp"
18#include "discrete_element.hpp"
24template <
class F,
class Support,
class IndexSequence>
25class ForEachKokkosLambdaAdapter;
27template <
class F,
class Support, std::size_t... Idx>
28class ForEachKokkosLambdaAdapter<F, Support, std::index_sequence<Idx...>>
30 template <std::size_t I>
31 using index_type = DiscreteElementType;
38 explicit ForEachKokkosLambdaAdapter(F
const& f, Support
const& support)
44 template <std::size_t N =
sizeof...(Idx), std::enable_if_t<(N == 0),
bool> =
true>
45 KOKKOS_FUNCTION
void operator()([[maybe_unused]] index_type<0> unused_id)
const
47 m_f(DiscreteElement
<>());
50 template <std::size_t N =
sizeof...(Idx), std::enable_if_t<(N > 0),
bool> =
true>
51 KOKKOS_FUNCTION
void operator()(index_type<Idx>... ids)
const
53 m_f(m_support(
typename Support::discrete_vector_type(ids...)));
57template <
class ExecSpace,
class Support,
class Functor>
59 std::string
const& label,
60 ExecSpace
const& execution_space,
61 Support
const& domain,
62 Functor
const& f)
noexcept
66 ddc_to_kokkos_execution_policy(execution_space, domain),
67 ForEachKokkosLambdaAdapter<
70 std::make_index_sequence<Support::rank()>>(f, domain));
76
77
78
79
80
81template <
class ExecSpace,
class Support,
class Functor>
83 std::string
const& label,
84 ExecSpace
const& execution_space,
85 Support
const& domain,
88 detail::for_each_kokkos(label, execution_space, domain, std::forward<Functor>(f));
92
93
94
95
96template <
class ExecSpace,
class Support,
class Functor>
98 ExecSpace
const& execution_space,
99 Support
const& domain,
100 Functor&& f)
noexcept
102 detail::for_each_kokkos(
103 "ddc_for_each_default",
106 std::forward<Functor>(f));
110
111
112
113
114template <
class Support,
class Functor>
115void parallel_for_each(std::string
const& label, Support
const& domain, Functor&& f)
noexcept
117 parallel_for_each(label, Kokkos::DefaultExecutionSpace(), domain, std::forward<Functor>(f));
121
122
123
124template <
class Support,
class Functor>
128 "ddc_for_each_default",
129 Kokkos::DefaultExecutionSpace(),
131 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