15#ifndef dealii_parallel_h
16#define dealii_parallel_h
31#ifdef DEAL_II_WITH_TBB
32# include <tbb/blocked_range.h>
33# include <tbb/parallel_for.h>
34# include <tbb/parallel_reduce.h>
35# include <tbb/partitioner.h>
37# include <boost/range/iterator_range.hpp>
40#ifdef DEAL_II_HAVE_CXX20
58 template <
typename Number>
64#ifdef __INTEL_COMPILER
72 static const bool value =
false;
77#ifdef DEAL_II_WITH_TBB
81 template <
typename Iterator,
typename Functor>
85 const Functor &functor,
86 const unsigned int grainsize)
88 tbb::parallel_for(tbb::blocked_range<Iterator>(x_begin, x_end, grainsize),
90 tbb::auto_partitioner());
98 template <
typename Iterator,
typename Functor>
102 const Functor &functor,
103 const unsigned int grainsize,
104 const std::shared_ptr<tbb::affinity_partitioner> &partitioner)
106 tbb::parallel_for(tbb::blocked_range<Iterator>(x_begin, x_end, grainsize),
116 template <
typename Iterator,
typename Functor>
120 const Functor &functor,
123 functor(boost::iterator_range<Iterator>(x_begin, x_end));
158 template <
typename InputIterator,
typename OutputIterator,
typename Function>
160 (std::invocable<
Function,
decltype(*std::declval<InputIterator>())> &&
161 std::assignable_from<
162 decltype(*std::declval<OutputIterator>()),
164 decltype(*std::declval<InputIterator>())>>))
166 const InputIterator &end_in,
169 const
unsigned int grainsize)
171#ifndef DEAL_II_WITH_TBB
176 for (OutputIterator in = begin_in; in != end_in;)
177 *out++ = function(*in++);
179 using Iterators = std::tuple<InputIterator, OutputIterator>;
181 Iterators x_begin(begin_in, out);
182 Iterators x_end(end_in, OutputIterator());
184 SyncIterators(x_begin),
185 SyncIterators(x_end),
186 [function](
const auto &range) {
187 for (
const auto &p : range)
188 *std::get<1>(p) = function(*std::get<0>(p));
227 template <
typename InputIterator1,
228 typename InputIterator2,
229 typename OutputIterator,
233 decltype(*std::declval<InputIterator1>()),
234 decltype(*std::declval<InputIterator2>())> &&
235 std::assignable_from<
236 decltype(*std::declval<OutputIterator>()),
238 decltype(*std::declval<InputIterator1>()),
239 decltype(*std::declval<InputIterator2>())>>))
241 const InputIterator1 &end_in1,
245 const
unsigned int grainsize)
247#ifndef DEAL_II_WITH_TBB
252 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
253 *out++ = function(*in1++, *in2++);
256 std::tuple<InputIterator1, InputIterator2, OutputIterator>;
258 Iterators x_begin(begin_in1, in2, out);
259 Iterators x_end(end_in1, InputIterator2(), OutputIterator());
261 SyncIterators(x_begin),
262 SyncIterators(x_end),
263 [function](
const auto &range) {
264 for (
const auto &p : range)
265 *std::get<2>(p) = function(*std::get<0>(p), *std::get<1>(p));
306 template <
typename InputIterator1,
307 typename InputIterator2,
308 typename InputIterator3,
309 typename OutputIterator,
313 decltype(*std::declval<InputIterator1>()),
314 decltype(*std::declval<InputIterator2>()),
315 decltype(*std::declval<InputIterator3>())> &&
316 std::assignable_from<
317 decltype(*std::declval<OutputIterator>()),
319 decltype(*std::declval<InputIterator1>()),
320 decltype(*std::declval<InputIterator2>()),
321 decltype(*std::declval<InputIterator3>())>>))
323 const InputIterator1 &end_in1,
328 const
unsigned int grainsize)
330#ifndef DEAL_II_WITH_TBB
335 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
336 *out++ = function(*in1++, *in2++, *in3++);
338 using Iterators = std::
339 tuple<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
341 Iterators x_begin(begin_in1, in2, in3, out);
342 Iterators x_end(end_in1,
347 SyncIterators(x_begin),
348 SyncIterators(x_end),
349 [function](
const auto &range) {
350 for (
const auto &p : range)
352 function(*std::get<0>(p), *std::get<1>(p), *std::get<2>(p));
361#ifdef DEAL_II_WITH_TBB
368 template <
typename Iterator,
typename Function>
373 f(range.begin(), range.end());
450 template <
typename Iterator,
typename Function>
453 const
std_cxx20::type_identity_t<Iterator> &end,
455 const
unsigned int grainsize)
457#ifndef DEAL_II_WITH_TBB
467 [&f](
const tbb::blocked_range<Iterator> &range) {
521 const std::size_t end,
522 const std::size_t minimum_parallel_grain_size)
const;
602 template <
typename ResultType,
typename Iterator,
typename Function>
604 (std::invocable<Function, Iterator, Iterator> &&
605 std::convertible_to<std::invoke_result_t<Function, Iterator, Iterator>,
609 const Iterator &begin,
610 const
std_cxx20::type_identity_t<Iterator> &end,
611 const
unsigned int grainsize)
613#ifndef DEAL_II_WITH_TBB
618 return f(begin, end);
620 return tbb::parallel_reduce(
621 tbb::blocked_range<Iterator>(begin, end, grainsize),
623 [f](
const auto &range,
const ResultType &starting_value) {
624 ResultType value = starting_value;
625 value += f(range.begin(), range.end());
628 std::plus<ResultType>(),
629 tbb::auto_partitioner());
655#ifdef DEAL_II_WITH_TBB
668 std::shared_ptr<tbb::affinity_partitioner>
678 const std::shared_ptr<tbb::affinity_partitioner> &p);
705 namespace VectorImplementation
725 namespace SparseMatrixImplementation
744 const std::size_t begin,
745 const std::size_t end,
746 const std::size_t minimum_parallel_grain_size)
const
748#ifndef DEAL_II_WITH_TBB
751 (void)minimum_parallel_grain_size;
758 [
this](
const tbb::blocked_range<std::size_t> &range) {
761 minimum_parallel_grain_size);
std::shared_ptr< tbb::affinity_partitioner > acquire_one_partitioner()
void release_one_partitioner(const std::shared_ptr< tbb::affinity_partitioner > &p)
std::shared_ptr< tbb::affinity_partitioner > my_partitioner
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_CXX20_REQUIRES(condition)
#define DEAL_II_NAMESPACE_CLOSE
unsigned int minimum_parallel_grain_size
unsigned int minimum_parallel_grain_size
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize)
void apply_to_subranges(const tbb::blocked_range< Iterator > &range, const Function &f)
void apply_to_subranges(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const Function &f, const unsigned int grainsize)
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Function &function, const unsigned int grainsize)
ResultType accumulate_from_subranges(const Function &f, const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const unsigned int grainsize)
virtual ~ParallelForInteger()=default
virtual void apply_to_subrange(const std::size_t, const std::size_t) const =0
void apply_parallel(const std::size_t begin, const std::size_t end, const std::size_t minimum_parallel_grain_size) const