12#include <Kokkos_Core.hpp>
14#include "ddc_to_kokkos_execution_policy.hpp"
15#include "discrete_element.hpp"
21template <
class F,
class Support,
class IndexSequence>
22class ForEachKokkosLambdaAdapter;
24template <
class F,
class Support, std::size_t... Idx>
25class ForEachKokkosLambdaAdapter<F, Support, std::index_sequence<Idx...>>
27 template <std::size_t I>
28 using index_type = DiscreteElementType;
35 explicit ForEachKokkosLambdaAdapter(F
const& f, Support
const& support)
41 template <std::size_t N =
sizeof...(Idx), std::enable_if_t<(N == 0),
bool> =
true>
42 KOKKOS_FUNCTION
void operator()([[maybe_unused]] index_type<0> unused_id)
const
44 m_f(DiscreteElement
<>());
47 template <std::size_t N =
sizeof...(Idx), std::enable_if_t<(N > 0),
bool> =
true>
48 KOKKOS_FUNCTION
void operator()(index_type<Idx>... ids)
const
50 m_f(m_support(
typename Support::discrete_vector_type(ids...)));
54template <
class ExecSpace,
class Support,
class Functor>
56 std::string
const& label,
57 ExecSpace
const& execution_space,
58 Support
const& domain,
59 Functor
const& f)
noexcept
63 ddc_to_kokkos_execution_policy(execution_space, domain),
64 ForEachKokkosLambdaAdapter<
67 std::make_index_sequence<Support::rank()>>(f, domain));
73
74
75
76
77
78template <
class ExecSpace,
class Support,
class Functor>
80 std::string
const& label,
81 ExecSpace
const& execution_space,
82 Support
const& domain,
85 detail::for_each_kokkos(label, execution_space, domain, std::forward<Functor>(f));
89
90
91
92
93template <
class ExecSpace,
class Support,
class Functor>
95 ExecSpace
const& execution_space,
96 Support
const& domain,
99 detail::for_each_kokkos(
100 "ddc_for_each_default",
103 std::forward<Functor>(f));
107
108
109
110
111template <
class Support,
class Functor>
112void parallel_for_each(std::string
const& label, Support
const& domain, Functor&& f)
noexcept
114 parallel_for_each(label, Kokkos::DefaultExecutionSpace(), domain, std::forward<Functor>(f));
118
119
120
121template <
class Support,
class Functor>
125 "ddc_for_each_default",
126 Kokkos::DefaultExecutionSpace(),
128 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