14#ifndef DUMUX_PARALLEL_PARALLEL_FOR_HH
15#define DUMUX_PARALLEL_PARALLEL_FOR_HH
19#if DUMUX_HAVE_CPP_PARALLEL_ALGORITHMS
22#include <dune/common/rangeutilities.hh>
26#include <tbb/parallel_for.h>
30#include <Kokkos_Core.hpp>
39template<
class FunctorType,
class ExecutionBackend>
44template<
class FunctorType>
45class ParallelFor<FunctorType, Multithreading::ExecutionBackends::Serial>
48 ParallelFor(
const std::size_t count,
const FunctorType& functor)
49 : functor_(functor), count_(count) {}
53 for (std::size_t i = 0; i < count_; ++i)
62#if DUMUX_HAVE_CPP_PARALLEL_ALGORITHMS
64template<
class FunctorType>
65class ParallelFor<FunctorType, Multithreading::ExecutionBackends::Cpp>
68 ParallelFor(
const std::size_t count,
const FunctorType& functor)
69 : functor_(functor), range_(count) {}
73 std::for_each(std::execution::par_unseq, range_.begin(), range_.end(), functor_);
78 Dune::IntegralRange<std::size_t> range_;
85template<
class FunctorType>
86class ParallelFor<FunctorType, Multithreading::ExecutionBackends::TBB>
89 ParallelFor(
const std::size_t count,
const FunctorType& functor)
90 : functor_(functor), count_(count) {}
94 tbb::parallel_for(std::size_t{0}, count_, [&](
const std::size_t i){ functor_(i); });
105template<
class FunctorType>
106class ParallelFor<FunctorType, Multithreading::ExecutionBackends::Kokkos>
109 ParallelFor(
const std::size_t count,
const FunctorType& functor)
110 : functor_(functor), count_(count) {}
114 Kokkos::parallel_for(count_, [&](
const std::size_t i){ functor_(i); });
118 FunctorType functor_;
126template<
class FunctorType>
127class ParallelFor<FunctorType, Multithreading::ExecutionBackends::OpenMP>
130 ParallelFor(
const std::size_t count,
const FunctorType& functor)
131 : functor_(functor), count_(count) {}
135 #pragma omp parallel for
136 for (std::size_t i = 0; i < count_; ++i)
141 FunctorType functor_;
159template<
class FunctorType>
160inline void parallelFor(
const std::size_t count,
const FunctorType& functor)
163 Detail::ParallelFor<FunctorType, ExecutionBackend> action(count, functor);
void parallelFor(const std::size_t count, const FunctorType &functor)
A parallel for loop (multithreading)
Definition: parallel_for.hh:160
ExecutionBackends::DUMUX_MULTITHREADING_BACKEND ExecutionBackend
Definition: multithreading.hh:35
Distance implementation details.
Definition: cvfelocalresidual.hh:25