16 #ifndef dealii_parallel_h 17 #define dealii_parallel_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/exceptions.h> 22 #include <deal.II/base/template_constraints.h> 23 #include <deal.II/base/synchronous_iterator.h> 24 #include <deal.II/base/thread_management.h> 31 #ifdef DEAL_II_WITH_THREADS 32 # include <tbb/parallel_for.h> 33 # include <tbb/parallel_reduce.h> 34 # include <tbb/partitioner.h> 35 # include <tbb/blocked_range.h> 41 DEAL_II_NAMESPACE_OPEN
51 template <
typename Number>
54 static const bool value =
true;
57 #ifdef __INTEL_COMPILER 65 static const bool value =
false;
86 template <
typename Range>
88 operator () (
const Range &range)
const 90 for (
typename Range::const_iterator p=range.begin();
91 p != range.end(); ++p)
104 template <
typename I1,
typename I2>
108 const std::tuple<I1,I2> &p)
110 *std::get<1>(p) =
f (*std::get<0>(p));
116 template <
typename I1,
typename I2,
typename I3>
120 const std::tuple<I1,I2,I3> &p)
122 *std::get<2>(p) =
f (*std::get<0>(p),
129 template <
typename I1,
typename I2,
130 typename I3,
typename I4>
134 const std::tuple<I1,I2,I3,I4> &p)
136 *std::get<3>(p) =
f (*std::get<0>(p),
149 template <
typename F>
179 template <
typename InputIterator,
180 typename OutputIterator,
183 const InputIterator &end_in,
185 Predicate &predicate,
186 const unsigned int grainsize)
188 #ifndef DEAL_II_WITH_THREADS 193 for (OutputIterator in = begin_in; in != end_in;)
194 *out++ = predicate (*in++);
196 typedef std::tuple<InputIterator,OutputIterator> Iterators;
198 Iterators x_begin (begin_in, out);
199 Iterators x_end (end_in, OutputIterator());
200 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
204 tbb::auto_partitioner());
233 template <
typename InputIterator1,
234 typename InputIterator2,
235 typename OutputIterator,
238 const InputIterator1 &end_in1,
241 Predicate &predicate,
242 const unsigned int grainsize)
244 #ifndef DEAL_II_WITH_THREADS 249 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
250 *out++ = predicate (*in1++, *in2++);
253 std::tuple<InputIterator1,InputIterator2,OutputIterator>
256 Iterators x_begin (begin_in1, in2, out);
257 Iterators x_end (end_in1, InputIterator2(), OutputIterator());
258 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
262 tbb::auto_partitioner());
291 template <
typename InputIterator1,
292 typename InputIterator2,
293 typename InputIterator3,
294 typename OutputIterator,
297 const InputIterator1 &end_in1,
301 Predicate &predicate,
302 const unsigned int grainsize)
304 #ifndef DEAL_II_WITH_THREADS 309 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
310 *out++ = predicate (*in1++, *in2++, *in3++);
313 std::tuple<InputIterator1,InputIterator2,InputIterator3,OutputIterator>
316 Iterators x_begin (begin_in1, in2, in3, out);
317 Iterators x_end (end_in1, InputIterator2(),
318 InputIterator3(), OutputIterator());
319 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
323 tbb::auto_partitioner());
330 #ifdef DEAL_II_WITH_THREADS 335 template <
typename RangeType,
typename Function>
339 f (range.begin(), range.end());
416 template <
typename RangeType,
typename Function>
418 const typename identity<RangeType>::type &end,
420 const unsigned int grainsize)
422 #ifndef DEAL_II_WITH_THREADS 427 # ifndef DEAL_II_BIND_NO_CONST_OP_PARENTHESES 436 tbb::parallel_for (tbb::blocked_range<RangeType>
437 (begin, end, grainsize),
438 std::bind (&internal::apply_to_subranges<RangeType,Function>,
439 std::placeholders::_1,
441 tbb::auto_partitioner());
491 const std::size_t end,
492 const std::size_t minimum_parallel_grain_size)
const;
501 const std::size_t)
const = 0;
508 #ifdef DEAL_II_WITH_THREADS 515 template <
typename ResultType,
533 template <
typename Reductor>
568 template <
typename RangeType>
572 f (range.begin(), range.end()));
592 const std::function<ResultType (ResultType, ResultType)>
reductor;
657 template <
typename ResultType,
typename RangeType,
typename Function>
659 const RangeType &begin,
660 const typename identity<RangeType>::type &end,
661 const unsigned int grainsize)
663 #ifndef DEAL_II_WITH_THREADS 668 # ifndef DEAL_II_BIND_NO_CONST_OP_PARENTHESES 669 return f (begin, end);
674 return ff (begin, end);
678 reductor (f, std::plus<ResultType>(), 0);
679 tbb::parallel_reduce (tbb::blocked_range<RangeType>(begin, end, grainsize),
681 tbb::auto_partitioner());
708 #ifdef DEAL_II_WITH_THREADS 721 std::shared_ptr<tbb::affinity_partitioner>
722 acquire_one_partitioner();
729 void release_one_partitioner(std::shared_ptr<tbb::affinity_partitioner> &p);
736 std::shared_ptr<tbb::affinity_partitioner> my_partitioner;
756 namespace VectorImplementation
772 extern unsigned int minimum_parallel_grain_size;
776 namespace SparseMatrixImplementation
782 extern unsigned int minimum_parallel_grain_size;
793 #ifdef DEAL_II_WITH_THREADS 808 void operator() (
const tbb::blocked_range<std::size_t> &range)
const 823 const std::size_t end,
824 const std::size_t minimum_parallel_grain_size)
const 826 #ifndef DEAL_II_WITH_THREADS 829 (void) minimum_parallel_grain_size;
834 tbb::parallel_for (tbb::blocked_range<std::size_t>
835 (begin, end, minimum_parallel_grain_size),
837 tbb::auto_partitioner());
843 DEAL_II_NAMESPACE_CLOSE
Body< F > make_body(const F &f)
const std::function< ResultType(ResultType, ResultType)> reductor
void join(const ReductionOnSubranges &r)
static void apply(const F &f, const std::tuple< I1, I2, I3 > &p)
void operator()(const tbb::blocked_range< RangeType > &range)
void apply_to_subranges(const RangeType &begin, const typename identity< RangeType >::type &end, const Function &f, const unsigned int grainsize)
ReductionOnSubranges(const Function &f, const Reductor &reductor, const ResultType neutral_element=ResultType())
static void apply(const F &f, const std::tuple< I1, I2, I3, I4 > &p)
void apply_to_subranges(const tbb::blocked_range< RangeType > &range, const Function &f)
ReductionOnSubranges(const ReductionOnSubranges &r, tbb::split)
static void apply(const F &f, const std::tuple< I1, I2 > &p)
ResultType accumulate_from_subranges(const Function &f, const RangeType &begin, const typename identity< RangeType >::type &end, const unsigned int grainsize)
const ResultType neutral_element
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, Predicate &predicate, const unsigned int grainsize)
void apply_parallel(const std::size_t begin, const std::size_t end, const std::size_t minimum_parallel_grain_size) const
virtual void apply_to_subrange(const std::size_t, const std::size_t) const =0
virtual ~ParallelForInteger()=default