5#include <Kokkos_Core.hpp>
15template<
typename ValueType>
20template<
typename Kernel>
24 } -> std::same_as<void>;
27template<
typename Executor, parallelForKernel Kernel>
29 [[maybe_unused]]
const Executor& exec,
30 std::pair<localIdx, localIdx> range,
32 std::string
name =
"parallelFor"
35 auto [start, end] = range;
36 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
38 for (
localIdx i = start; i < end; i++)
45 using runOn =
typename Executor::exec;
48 Kokkos::RangePolicy<runOn>(start, end),
49 KOKKOS_LAMBDA(
const localIdx i) { kernel(i); }
55template<parallelForKernel Kernel>
58 std::pair<localIdx, localIdx> range,
60 std::string
name =
"parallelFor"
63 std::visit([&](
const auto& e) {
parallelFor(e, range, kernel,
name); }, exec);
67template<
typename Kernel,
typename ValueType>
71 } -> std::same_as<ValueType>;
81 [[maybe_unused]]
const Executor& exec,
82 ContType<ValueType>& container,
84 std::string
name =
"parallelFor"
87 auto view = container.view();
88 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
90 for (
localIdx i = 0; i < view.size(); i++)
97 using runOn =
typename Executor::exec;
100 Kokkos::RangePolicy<runOn>(0, view.size()),
101 KOKKOS_LAMBDA(
const localIdx i) { view[i] = kernel(i); }
110 parallelForContainerKernel<ValueType> Kernel>
111void parallelFor(ContType<ValueType>& cont, Kernel kernel, std::string
name =
"parallelFor")
113 std::visit([&](
const auto& e) {
parallelFor(e, cont, kernel,
name); }, cont.exec());
116template<
typename Executor,
typename Kernel,
typename T>
118 [[maybe_unused]]
const Executor& exec,
119 std::pair<localIdx, localIdx> range,
124 auto [start, end] = range;
125 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
127 for (
localIdx i = start; i < end; i++)
129 if constexpr (Kokkos::is_reducer<T>::value)
131 kernel(i, value.reference());
141 using runOn =
typename Executor::exec;
142 Kokkos::parallel_reduce(
143 "parallelReduce", Kokkos::RangePolicy<runOn>(start, end), kernel, value
148template<
typename Kernel,
typename T>
150 const NeoN::Executor& exec, std::pair<localIdx, localIdx> range, Kernel kernel, T& value
153 std::visit([&](
const auto& e) {
parallelReduce(e, range, kernel, value); }, exec);
157template<
typename Executor,
typename ValueType,
typename Kernel,
typename T>
162 if constexpr (std::is_same<std::remove_reference_t<Executor>,
SerialExecutor>::value)
165 for (
localIdx i = 0; i < fieldSize; i++)
167 if constexpr (Kokkos::is_reducer<T>::value)
169 kernel(i, value.reference());
179 using runOn =
typename Executor::exec;
180 Kokkos::parallel_reduce(
181 "parallelReduce", Kokkos::RangePolicy<runOn>(0, field.
size()), kernel, value
186template<
typename ValueType,
typename Kernel,
typename T>
189 std::visit([&](
const auto& e) {
parallelReduce(e, field, kernel, value); }, field.
exec());
192template<
typename Executor,
typename Kernel>
194 [[maybe_unused]]
const Executor& exec, std::pair<localIdx, localIdx> range, Kernel kernel
197 auto [start, end] = range;
198 using runOn =
typename Executor::exec;
199 Kokkos::parallel_scan(
"parallelScan", Kokkos::RangePolicy<runOn>(start, end), kernel);
202template<
typename Kernel>
205 std::visit([&](
const auto& e) {
parallelScan(e, range, kernel); }, exec);
208template<
typename Executor,
typename Kernel,
typename ReturnType>
210 [[maybe_unused]]
const Executor& exec,
211 std::pair<localIdx, localIdx> range,
213 ReturnType& returnValue
216 auto [start, end] = range;
217 using runOn =
typename Executor::exec;
218 Kokkos::parallel_scan(
219 "parallelScan", Kokkos::RangePolicy<runOn>(start, end), kernel, returnValue
223template<
typename Kernel,
typename ReturnType>
226 std::pair<localIdx, localIdx> range,
228 ReturnType& returnValue
231 std::visit([&](
const auto& e) {
parallelScan(e, range, kernel, returnValue); }, exec);
Reference executor for serial CPU execution.
A class to contain the data and executors for a field and define some basic operations.
localIdx size() const
Gets the size of the field.
const Executor & exec() const
Gets the executor associated with the field.
void parallelFor(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, std::string name="parallelFor")
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
void parallelReduce(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel, T &value)
const std::string & name(const NeoN::Document &doc)
Retrieves the name of a Document.
void parallelScan(const Executor &exec, std::pair< localIdx, localIdx > range, Kernel kernel)