16#ifndef dealii_parallel_h
17#define dealii_parallel_h
32#ifdef DEAL_II_WITH_TBB
33# include <tbb/blocked_range.h>
34# include <tbb/parallel_for.h>
35# include <tbb/parallel_reduce.h>
36# include <tbb/partitioner.h>
39#ifdef DEAL_II_HAVE_CXX20
57 template <
typename Number>
63#ifdef __INTEL_COMPILER
71 static const bool value =
false;
76#ifdef DEAL_II_WITH_TBB
80 template <
typename Iterator,
typename Functor>
84 const Functor & functor,
85 const unsigned int grainsize)
87 tbb::parallel_for(tbb::blocked_range<Iterator>(x_begin, x_end, grainsize),
89 tbb::auto_partitioner());
97 template <
typename Iterator,
typename Functor>
101 const Functor & functor,
102 const unsigned int grainsize,
103 const std::shared_ptr<tbb::affinity_partitioner> &partitioner)
105 tbb::parallel_for(tbb::blocked_range<Iterator>(x_begin, x_end, grainsize),
141 template <
typename InputIterator,
typename OutputIterator,
typename Function>
143 (std::invocable<
Function,
decltype(*std::declval<InputIterator>())> &&
144 std::assignable_from<
145 decltype(*std::declval<OutputIterator>()),
147 decltype(*std::declval<InputIterator>())>>))
149 const InputIterator &end_in,
152 const
unsigned int grainsize)
154#ifndef DEAL_II_WITH_TBB
159 for (OutputIterator in = begin_in; in != end_in;)
160 *out++ = function(*in++);
162 using Iterators = std::tuple<InputIterator, OutputIterator>;
164 Iterators x_begin(begin_in, out);
165 Iterators x_end(end_in, OutputIterator());
167 SyncIterators(x_begin),
168 SyncIterators(x_end),
169 [function](
const auto &range) {
170 for (
const auto &p : range)
171 *std::get<1>(p) = function(*std::get<0>(p));
210 template <
typename InputIterator1,
211 typename InputIterator2,
212 typename OutputIterator,
216 decltype(*std::declval<InputIterator1>()),
217 decltype(*std::declval<InputIterator2>())> &&
218 std::assignable_from<
219 decltype(*std::declval<OutputIterator>()),
221 decltype(*std::declval<InputIterator1>()),
222 decltype(*std::declval<InputIterator2>())>>))
224 const InputIterator1 &end_in1,
228 const
unsigned int grainsize)
230#ifndef DEAL_II_WITH_TBB
235 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
236 *out++ = function(*in1++, *in2++);
239 std::tuple<InputIterator1, InputIterator2, OutputIterator>;
241 Iterators x_begin(begin_in1, in2, out);
242 Iterators x_end(end_in1, InputIterator2(), OutputIterator());
244 SyncIterators(x_begin),
245 SyncIterators(x_end),
246 [function](
const auto &range) {
247 for (
const auto &p : range)
248 *std::get<2>(p) = function(*std::get<0>(p), *std::get<1>(p));
289 template <
typename InputIterator1,
290 typename InputIterator2,
291 typename InputIterator3,
292 typename OutputIterator,
296 decltype(*std::declval<InputIterator1>()),
297 decltype(*std::declval<InputIterator2>()),
298 decltype(*std::declval<InputIterator3>())> &&
299 std::assignable_from<
300 decltype(*std::declval<OutputIterator>()),
302 decltype(*std::declval<InputIterator1>()),
303 decltype(*std::declval<InputIterator2>()),
304 decltype(*std::declval<InputIterator3>())>>))
306 const InputIterator1 &end_in1,
311 const
unsigned int grainsize)
313#ifndef DEAL_II_WITH_TBB
318 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
319 *out++ = function(*in1++, *in2++, *in3++);
321 using Iterators = std::
322 tuple<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
324 Iterators x_begin(begin_in1, in2, in3, out);
325 Iterators x_end(end_in1,
330 SyncIterators(x_begin),
331 SyncIterators(x_end),
332 [function](
const auto &range) {
333 for (
const auto &p : range)
335 function(*std::get<0>(p), *std::get<1>(p), *std::get<2>(p));
344#ifdef DEAL_II_WITH_TBB
351 template <
typename Iterator,
typename Function>
356 f(range.begin(), range.end());
433 template <
typename Iterator,
typename Function>
436 const
std_cxx20::type_identity_t<Iterator> &end,
438 const
unsigned int grainsize)
440#ifndef DEAL_II_WITH_TBB
450 [&f](
const tbb::blocked_range<Iterator> &range) {
451 internal::apply_to_subranges<Iterator, Function>(range, f);
504 const std::size_t end,
505 const std::size_t minimum_parallel_grain_size)
const;
583 template <
typename ResultType,
typename Iterator,
typename Function>
585 (std::invocable<Function, Iterator, Iterator> &&
586 std::convertible_to<std::invoke_result_t<Function, Iterator, Iterator>,
590 const Iterator & begin,
591 const
std_cxx20::type_identity_t<Iterator> &end,
592 const
unsigned int grainsize)
594#ifndef DEAL_II_WITH_TBB
599 return f(begin, end);
601 return tbb::parallel_reduce(
602 tbb::blocked_range<Iterator>(begin, end, grainsize),
604 [f](
const auto &range,
const ResultType &starting_value) {
605 ResultType value = starting_value;
606 value += f(range.begin(), range.end());
609 std::plus<ResultType>(),
610 tbb::auto_partitioner());
636#ifdef DEAL_II_WITH_TBB
649 std::shared_ptr<tbb::affinity_partitioner>
685 namespace VectorImplementation
705 namespace SparseMatrixImplementation
724 const std::size_t begin,
725 const std::size_t end,
726 const std::size_t minimum_parallel_grain_size)
const
728#ifndef DEAL_II_WITH_TBB
731 (void)minimum_parallel_grain_size;
738 [
this](
const tbb::blocked_range<std::size_t> &range) {
741 minimum_parallel_grain_size);
std::shared_ptr< tbb::affinity_partitioner > acquire_one_partitioner()
std::shared_ptr< tbb::affinity_partitioner > my_partitioner
void release_one_partitioner(std::shared_ptr< tbb::affinity_partitioner > &p)
#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