26#ifndef DUMUX_PARALLEL_PARALLEL_FOR_HH
27#define DUMUX_PARALLEL_PARALLEL_FOR_HH
31#if HAVE_CPP_PARALLEL_ALGORITHMS
34#include <dune/common/rangeutilities.hh>
38#include <tbb/parallel_for.h>
42#include <Kokkos_Core.hpp>
51template<
class FunctorType,
class ExecutionBackend>
56template<
class FunctorType>
57class ParallelFor<FunctorType, Multithreading::ExecutionBackends::Serial>
60 ParallelFor(
const std::size_t count,
const FunctorType& functor)
61 : functor_(functor), count_(count) {}
65 for (std::size_t i = 0; i < count_; ++i)
74#if HAVE_CPP_PARALLEL_ALGORITHMS
76template<
class FunctorType>
77class ParallelFor<FunctorType, Multithreading::ExecutionBackends::Cpp>
80 ParallelFor(
const std::size_t count,
const FunctorType& functor)
81 : functor_(functor), range_(count) {}
85 std::for_each(std::execution::par_unseq, range_.begin(), range_.end(), functor_);
90 Dune::IntegralRange<std::size_t> range_;
97template<
class FunctorType>
98class ParallelFor<FunctorType, Multithreading::ExecutionBackends::TBB>
101 ParallelFor(
const std::size_t count,
const FunctorType& functor)
102 : functor_(functor), count_(count) {}
106 tbb::parallel_for(std::size_t{0}, count_, [&](
const std::size_t i){ functor_(i); });
110 FunctorType functor_;
117template<
class FunctorType>
118class ParallelFor<FunctorType, Multithreading::ExecutionBackends::Kokkos>
121 ParallelFor(
const std::size_t count,
const FunctorType& functor)
122 : functor_(functor), count_(count) {}
126 Kokkos::parallel_for(count_, [&](
const std::size_t i){ functor_(i); });
130 FunctorType functor_;
138template<
class FunctorType>
139class ParallelFor<FunctorType, Multithreading::ExecutionBackends::OpenMP>
142 ParallelFor(
const std::size_t count,
const FunctorType& functor)
143 : functor_(functor), count_(count) {}
147 #pragma omp parallel for
148 for (std::size_t i = 0; i < count_; ++i)
153 FunctorType functor_;
172template<
class FunctorType>
173inline void parallelFor(
const std::size_t count,
const FunctorType& functor)
176 Detail::ParallelFor<FunctorType, ExecutionBackend> action(count, functor);
void parallelFor(const std::size_t count, const FunctorType &functor)
Definition: parallel_for.hh:173
Distance implementation details.
Definition: fclocalassembler.hh:42
ExecutionBackends::DUMUX_MULTITHREADING_BACKEND ExecutionBackend
Definition: multithreading.hh:47