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> 26 #include <deal.II/base/std_cxx11/tuple.h> 27 #include <deal.II/base/std_cxx11/bind.h> 28 #include <deal.II/base/std_cxx11/function.h> 29 #include <deal.II/base/std_cxx11/shared_ptr.h> 33 #ifdef DEAL_II_WITH_THREADS 34 # include <tbb/parallel_for.h> 35 # include <tbb/parallel_reduce.h> 36 # include <tbb/partitioner.h> 37 # include <tbb/blocked_range.h> 43 DEAL_II_NAMESPACE_OPEN
53 template <
typename Number>
56 static const bool value =
true;
59 #ifdef __INTEL_COMPILER 67 static const bool value =
false;
88 template <
typename Range>
90 operator () (
const Range &range)
const 92 for (
typename Range::const_iterator p=range.begin();
93 p != range.end(); ++p)
106 template <
typename I1,
typename I2>
110 const std_cxx11::tuple<I1,I2> &p)
112 *std_cxx11::get<1>(p) =
f (*std_cxx11::get<0>(p));
118 template <
typename I1,
typename I2,
typename I3>
122 const std_cxx11::tuple<I1,I2,I3> &p)
124 *std_cxx11::get<2>(p) =
f (*std_cxx11::get<0>(p),
125 *std_cxx11::get<1>(p));
131 template <
typename I1,
typename I2,
132 typename I3,
typename I4>
136 const std_cxx11::tuple<I1,I2,I3,I4> &p)
138 *std_cxx11::get<3>(p) =
f (*std_cxx11::get<0>(p),
139 *std_cxx11::get<1>(p),
140 *std_cxx11::get<2>(p));
151 template <
typename F>
181 template <
typename InputIterator,
182 typename OutputIterator,
185 const InputIterator &end_in,
187 Predicate &predicate,
188 const unsigned int grainsize)
190 #ifndef DEAL_II_WITH_THREADS 195 for (OutputIterator in = begin_in; in != end_in;)
196 *out++ = predicate (*in++);
198 typedef std_cxx11::tuple<InputIterator,OutputIterator> Iterators;
200 Iterators x_begin (begin_in, out);
201 Iterators x_end (end_in, OutputIterator());
202 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
206 tbb::auto_partitioner());
235 template <
typename InputIterator1,
236 typename InputIterator2,
237 typename OutputIterator,
240 const InputIterator1 &end_in1,
243 Predicate &predicate,
244 const unsigned int grainsize)
246 #ifndef DEAL_II_WITH_THREADS 251 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
252 *out++ = predicate (*in1++, *in2++);
255 std_cxx11::tuple<InputIterator1,InputIterator2,OutputIterator>
258 Iterators x_begin (begin_in1, in2, out);
259 Iterators x_end (end_in1, InputIterator2(), OutputIterator());
260 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
264 tbb::auto_partitioner());
293 template <
typename InputIterator1,
294 typename InputIterator2,
295 typename InputIterator3,
296 typename OutputIterator,
299 const InputIterator1 &end_in1,
303 Predicate &predicate,
304 const unsigned int grainsize)
306 #ifndef DEAL_II_WITH_THREADS 311 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
312 *out++ = predicate (*in1++, *in2++, *in3++);
315 std_cxx11::tuple<InputIterator1,InputIterator2,InputIterator3,OutputIterator>
318 Iterators x_begin (begin_in1, in2, in3, out);
319 Iterators x_end (end_in1, InputIterator2(),
320 InputIterator3(), OutputIterator());
321 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
325 tbb::auto_partitioner());
332 #ifdef DEAL_II_WITH_THREADS 337 template <
typename RangeType,
typename Function>
341 f (range.begin(), range.end());
418 template <
typename RangeType,
typename Function>
420 const typename identity<RangeType>::type &end,
422 const unsigned int grainsize)
424 #ifndef DEAL_II_WITH_THREADS 429 # ifndef DEAL_II_BIND_NO_CONST_OP_PARENTHESES 438 tbb::parallel_for (tbb::blocked_range<RangeType>
439 (begin, end, grainsize),
440 std_cxx11::bind (&internal::apply_to_subranges<RangeType,Function>,
443 tbb::auto_partitioner());
493 const std::size_t end,
494 const std::size_t minimum_parallel_grain_size)
const;
503 const std::size_t)
const = 0;
510 #ifdef DEAL_II_WITH_THREADS 517 template <
typename ResultType,
535 template <
typename Reductor>
570 template <
typename RangeType>
574 f (range.begin(), range.end()));
594 const std_cxx11::function<ResultType (ResultType, ResultType)>
reductor;
659 template <
typename ResultType,
typename RangeType,
typename Function>
661 const RangeType &begin,
662 const typename identity<RangeType>::type &end,
663 const unsigned int grainsize)
665 #ifndef DEAL_II_WITH_THREADS 670 # ifndef DEAL_II_BIND_NO_CONST_OP_PARENTHESES 671 return f (begin, end);
676 return ff (begin, end);
680 reductor (f, std::plus<ResultType>(), 0);
681 tbb::parallel_reduce (tbb::blocked_range<RangeType>(begin, end, grainsize),
683 tbb::auto_partitioner());
709 #ifdef DEAL_II_WITH_THREADS 711 my_partitioner(
new tbb::affinity_partitioner()),
716 #ifdef DEAL_II_WITH_THREADS 725 "it appears to be still in use."));
734 std_cxx11::shared_ptr<tbb::affinity_partitioner>
735 acquire_one_partitioner()
739 return std_cxx11::shared_ptr<tbb::affinity_partitioner>(
new tbb::affinity_partitioner());
742 return my_partitioner;
750 void release_one_partitioner(std_cxx11::shared_ptr<tbb::affinity_partitioner> &p)
752 if (p.get() == my_partitioner.get())
764 std_cxx11::shared_ptr<tbb::affinity_partitioner> my_partitioner;
800 extern unsigned int minimum_parallel_grain_size;
810 extern unsigned int minimum_parallel_grain_size;
821 #ifdef DEAL_II_WITH_THREADS 836 void operator() (
const tbb::blocked_range<std::size_t> &range)
const 856 const std::size_t end,
857 const std::size_t minimum_parallel_grain_size)
const 859 #ifndef DEAL_II_WITH_THREADS 862 (void) minimum_parallel_grain_size;
867 tbb::parallel_for (tbb::blocked_range<std::size_t>
868 (begin, end, minimum_parallel_grain_size),
870 tbb::auto_partitioner());
876 DEAL_II_NAMESPACE_CLOSE
Body< F > make_body(const F &f)
void join(const ReductionOnSubranges &r)
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_cxx11::tuple< I1, I2 > &p)
virtual ~ParallelForInteger()
#define Assert(cond, exc)
void apply_to_subranges(const tbb::blocked_range< RangeType > &range, const Function &f)
ReductionOnSubranges(const ReductionOnSubranges &r, tbb::split)
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
const std_cxx11::function< ResultType(ResultType, ResultType)> reductor
static void apply(const F &f, const std_cxx11::tuple< I1, I2, I3 > &p)
static void apply(const F &f, const std_cxx11::tuple< I1, I2, I3, I4 > &p)
static ::ExceptionBase & ExcInternalError()