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>
38 # include <boost/range/iterator_range.hpp>
41 #ifdef DEAL_II_HAVE_CXX20
59 template <
typename Number>
65 #ifdef __INTEL_COMPILER
73 static const bool value =
false;
78 #ifdef DEAL_II_WITH_TBB
82 template <
typename Iterator,
typename Functor>
86 const Functor &functor,
87 const unsigned int grainsize)
91 tbb::auto_partitioner());
99 template <
typename Iterator,
typename Functor>
103 const Functor &functor,
104 const unsigned int grainsize,
105 const std::shared_ptr<tbb::affinity_partitioner> &partitioner)
117 template <
typename Iterator,
typename Functor>
121 const Functor &functor,
124 functor(boost::iterator_range<Iterator>(x_begin, x_end));
159 template <
typename InputIterator,
typename OutputIterator,
typename Function>
161 (std::invocable<
Function, decltype(*std::declval<InputIterator>())> &&
162 std::assignable_from<
163 decltype(*std::declval<OutputIterator>()),
165 decltype(*std::declval<InputIterator>())>>))
167 const InputIterator &end_in,
170 const
unsigned int grainsize)
172 #ifndef DEAL_II_WITH_TBB
177 for (OutputIterator in = begin_in; in != end_in;)
178 *out++ =
function(*in++);
180 using Iterators = std::tuple<InputIterator, OutputIterator>;
182 Iterators x_begin(begin_in, out);
183 Iterators x_end(end_in, OutputIterator());
185 SyncIterators(x_begin),
186 SyncIterators(x_end),
187 [
function](
const auto &range) {
188 for (
const auto &p : range)
189 *std::get<1>(p) =
function(*std::get<0>(p));
228 template <
typename InputIterator1,
229 typename InputIterator2,
230 typename OutputIterator,
234 decltype(*std::declval<InputIterator1>()),
235 decltype(*std::declval<InputIterator2>())> &&
236 std::assignable_from<
237 decltype(*std::declval<OutputIterator>()),
239 decltype(*std::declval<InputIterator1>()),
240 decltype(*std::declval<InputIterator2>())>>))
242 const InputIterator1 &end_in1,
246 const
unsigned int grainsize)
248 #ifndef DEAL_II_WITH_TBB
253 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
254 *out++ =
function(*in1++, *in2++);
257 std::tuple<InputIterator1, InputIterator2, OutputIterator>;
259 Iterators x_begin(begin_in1, in2, out);
260 Iterators x_end(end_in1, InputIterator2(), OutputIterator());
262 SyncIterators(x_begin),
263 SyncIterators(x_end),
264 [
function](
const auto &range) {
265 for (
const auto &p : range)
266 *std::get<2>(p) =
function(*std::get<0>(p), *std::get<1>(p));
307 template <
typename InputIterator1,
308 typename InputIterator2,
309 typename InputIterator3,
310 typename OutputIterator,
314 decltype(*std::declval<InputIterator1>()),
315 decltype(*std::declval<InputIterator2>()),
316 decltype(*std::declval<InputIterator3>())> &&
317 std::assignable_from<
318 decltype(*std::declval<OutputIterator>()),
320 decltype(*std::declval<InputIterator1>()),
321 decltype(*std::declval<InputIterator2>()),
322 decltype(*std::declval<InputIterator3>())>>))
324 const InputIterator1 &end_in1,
329 const
unsigned int grainsize)
331 #ifndef DEAL_II_WITH_TBB
336 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
337 *out++ =
function(*in1++, *in2++, *in3++);
339 using Iterators = std::
340 tuple<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
342 Iterators x_begin(begin_in1, in2, in3, out);
343 Iterators x_end(end_in1,
348 SyncIterators(x_begin),
349 SyncIterators(x_end),
350 [
function](
const auto &range) {
351 for (
const auto &p : range)
353 function(*std::get<0>(p), *std::get<1>(p), *std::get<2>(p));
362 #ifdef DEAL_II_WITH_TBB
369 template <
typename Iterator,
typename Function>
374 f(range.begin(), range.end());
451 template <
typename Iterator,
typename Function>
456 const
unsigned int grainsize)
458 #ifndef DEAL_II_WITH_TBB
468 [&f](
const tbb::blocked_range<Iterator> &range) {
469 internal::apply_to_subranges<Iterator, Function>(range, f);
522 const std::size_t
end,
603 template <
typename ResultType,
typename Iterator,
typename Function>
605 (std::invocable<Function, Iterator, Iterator> &&
606 std::convertible_to<std::invoke_result_t<Function, Iterator, Iterator>,
610 const Iterator &
begin,
612 const
unsigned int grainsize)
614 #ifndef DEAL_II_WITH_TBB
622 tbb::blocked_range<Iterator>(
begin,
end, grainsize),
624 [f](
const auto &range,
const ResultType &starting_value) {
625 ResultType value = starting_value;
626 value += f(range.begin(), range.end());
629 std::plus<ResultType>(),
630 tbb::auto_partitioner());
656 #ifdef DEAL_II_WITH_TBB
669 std::shared_ptr<tbb::affinity_partitioner>
705 namespace VectorImplementation
725 namespace SparseMatrixImplementation
744 const std::size_t
begin,
745 const std::size_t
end,
748 #ifndef DEAL_II_WITH_TBB
758 [
this](
const tbb::blocked_range<std::size_t> &range) {
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
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(VectorType &V)
unsigned int minimum_parallel_grain_size
unsigned int minimum_parallel_grain_size
void parallel_reduce(const Operation &op, const size_type start, const size_type end, ResultType &result, const std::shared_ptr<::parallel::internal::TBBPartitioner > &partitioner)
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize)
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize, const std::shared_ptr< tbb::affinity_partitioner > &partitioner)
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)
typename type_identity< T >::type type_identity_t
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