16#ifndef dealii_parallel_h
17#define dealii_parallel_h
32#ifdef DEAL_II_WITH_TBB
34# include <tbb/blocked_range.h>
35# include <tbb/parallel_for.h>
36# include <tbb/parallel_reduce.h>
37# include <tbb/partitioner.h>
55 template <
typename Number>
61#ifdef __INTEL_COMPILER
69 static const bool value =
false;
74#ifdef DEAL_II_WITH_TBB
78 template <
typename Iterator,
typename Functor>
82 const Functor & functor,
83 const unsigned int grainsize)
85 tbb::parallel_for(tbb::blocked_range<Iterator>(x_begin, x_end, grainsize),
87 tbb::auto_partitioner());
95 template <
typename Iterator,
typename Functor>
99 const Functor & functor,
100 const unsigned int grainsize,
101 const std::shared_ptr<tbb::affinity_partitioner> &partitioner)
103 tbb::parallel_for(tbb::blocked_range<Iterator>(x_begin, x_end, grainsize),
133 template <
typename InputIterator,
typename OutputIterator,
typename Predicate>
136 const InputIterator &end_in,
138 const Predicate & predicate,
139 const unsigned int grainsize)
141#ifndef DEAL_II_WITH_TBB
146 for (OutputIterator in = begin_in; in != end_in;)
147 *out++ = predicate(*in++);
149 using Iterators = std::tuple<InputIterator, OutputIterator>;
151 Iterators x_begin(begin_in, out);
152 Iterators x_end(end_in, OutputIterator());
154 SyncIterators(x_begin),
155 SyncIterators(x_end),
156 [predicate](
const auto &range) {
157 for (
const auto &p : range)
158 *std::get<1>(p) = predicate(*std::get<0>(p));
189 template <
typename InputIterator1,
190 typename InputIterator2,
191 typename OutputIterator,
195 const InputIterator1 &end_in1,
198 const Predicate & predicate,
199 const unsigned int grainsize)
201#ifndef DEAL_II_WITH_TBB
206 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
207 *out++ = predicate(*in1++, *in2++);
210 std::tuple<InputIterator1, InputIterator2, OutputIterator>;
212 Iterators x_begin(begin_in1, in2, out);
213 Iterators x_end(end_in1, InputIterator2(), OutputIterator());
215 SyncIterators(x_begin),
216 SyncIterators(x_end),
217 [predicate](
const auto &range) {
218 for (
const auto &p : range)
219 *std::get<2>(p) = predicate(*std::get<0>(p), *std::get<1>(p));
250 template <
typename InputIterator1,
251 typename InputIterator2,
252 typename InputIterator3,
253 typename OutputIterator,
257 const InputIterator1 &end_in1,
261 const Predicate & predicate,
262 const unsigned int grainsize)
264#ifndef DEAL_II_WITH_TBB
269 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
270 *out++ = predicate(*in1++, *in2++, *in3++);
272 using Iterators = std::
273 tuple<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
275 Iterators x_begin(begin_in1, in2, in3, out);
276 Iterators x_end(end_in1,
281 SyncIterators(x_begin),
282 SyncIterators(x_end),
283 [predicate](
const auto &range) {
284 for (
const auto &p : range)
286 predicate(*std::get<0>(p), *std::get<1>(p), *std::get<2>(p));
295#ifdef DEAL_II_WITH_TBB
300 template <
typename RangeType,
typename Function>
305 f(range.begin(), range.end());
380 template <
typename RangeType,
typename Function>
385 const unsigned int grainsize)
387#ifndef DEAL_II_WITH_TBB
397 [&f](
const tbb::blocked_range<RangeType> &range) {
398 internal::apply_to_subranges<RangeType, Function>(range, f);
451 const std::size_t end,
452 const std::size_t minimum_parallel_grain_size)
const;
526 template <
typename ResultType,
typename RangeType,
typename Function>
529 const RangeType & begin,
531 const unsigned int grainsize)
533#ifndef DEAL_II_WITH_TBB
538 return f(begin, end);
540 return tbb::parallel_reduce(
541 tbb::blocked_range<RangeType>(begin, end, grainsize),
543 [f](
const auto &range,
const ResultType &starting_value) {
544 ResultType value = starting_value;
545 value += f(range.begin(), range.end());
548 std::plus<ResultType>(),
549 tbb::auto_partitioner());
575#ifdef DEAL_II_WITH_TBB
588 std::shared_ptr<tbb::affinity_partitioner>
624 namespace VectorImplementation
644 namespace SparseMatrixImplementation
663 const std::size_t begin,
664 const std::size_t end,
665 const std::size_t minimum_parallel_grain_size)
const
667#ifndef DEAL_II_WITH_TBB
670 (void)minimum_parallel_grain_size;
677 [
this](
const tbb::blocked_range<std::size_t> &range) {
680 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_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
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< RangeType > &range, const Function &f)
ResultType accumulate_from_subranges(const Function &f, const RangeType &begin, const typename identity< RangeType >::type &end, const unsigned int grainsize)
void apply_to_subranges(const RangeType &begin, const typename identity< RangeType >::type &end, const Function &f, const unsigned int grainsize)
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Predicate &predicate, 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