17 #ifndef __deal2__parallel_h
18 #define __deal2__parallel_h
21 #include <deal.II/base/config.h>
23 #include <deal.II/base/template_constraints.h>
24 #include <deal.II/base/synchronous_iterator.h>
26 #include <deal.II/base/std_cxx1x/tuple.h>
27 #include <deal.II/base/std_cxx1x/bind.h>
28 #include <deal.II/base/std_cxx1x/function.h>
32 #ifdef DEAL_II_WITH_THREADS
33 # include <tbb/parallel_for.h>
34 # include <tbb/parallel_reduce.h>
35 # include <tbb/partitioner.h>
36 # include <tbb/blocked_range.h>
66 template <
typename Range>
68 operator () (
const Range &range)
const
70 for (
typename Range::const_iterator p=range.begin();
71 p != range.end(); ++p)
85 template <
typename I1,
typename I2>
89 const std_cxx1x::tuple<I1,I2> &p)
91 *std_cxx1x::get<1>(p) = f (*std_cxx1x::get<0>(p));
98 template <
typename I1,
typename I2,
typename I3>
102 const std_cxx1x::tuple<I1,I2,I3> &p)
104 *std_cxx1x::get<2>(p) = f (*std_cxx1x::get<0>(p),
105 *std_cxx1x::get<1>(p));
112 template <
typename I1,
typename I2,
113 typename I3,
typename I4>
117 const std_cxx1x::tuple<I1,I2,I3,I4> &p)
119 *std_cxx1x::get<3>(p) = f (*std_cxx1x::get<0>(p),
120 *std_cxx1x::get<1>(p),
121 *std_cxx1x::get<2>(p));
135 template <
typename F>
136 Body<F> make_body(
const F &f)
175 template <
typename InputIterator,
176 typename OutputIterator,
179 const InputIterator &end_in,
181 Predicate &predicate,
182 const unsigned int grainsize)
184 #ifndef DEAL_II_WITH_THREADS
189 for (OutputIterator in = begin_in; in != end_in;)
190 *out++ = predicate (*in++);
192 typedef std_cxx1x::tuple<InputIterator,OutputIterator> Iterators;
194 Iterators x_begin (begin_in, out);
195 Iterators x_end (end_in, OutputIterator());
196 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
199 internal::make_body (predicate),
200 tbb::auto_partitioner());
241 template <
typename InputIterator1,
242 typename InputIterator2,
243 typename OutputIterator,
246 const InputIterator1 &end_in1,
249 Predicate &predicate,
250 const unsigned int grainsize)
252 #ifndef DEAL_II_WITH_THREADS
257 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
258 *out++ = predicate (*in1++, *in2++);
261 std_cxx1x::tuple<InputIterator1,InputIterator2,OutputIterator>
264 Iterators x_begin (begin_in1, in2, out);
265 Iterators x_end (end_in1, InputIterator2(), OutputIterator());
266 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
269 internal::make_body (predicate),
270 tbb::auto_partitioner());
309 template <
typename InputIterator1,
310 typename InputIterator2,
311 typename InputIterator3,
312 typename OutputIterator,
315 const InputIterator1 &end_in1,
319 Predicate &predicate,
320 const unsigned int grainsize)
322 #ifndef DEAL_II_WITH_THREADS
327 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
328 *out++ = predicate (*in1++, *in2++, *in3++);
331 std_cxx1x::tuple<InputIterator1,InputIterator2,InputIterator3,OutputIterator>
334 Iterators x_begin (begin_in1, in2, in3, out);
335 Iterators x_end (end_in1, InputIterator2(),
336 InputIterator3(), OutputIterator());
337 tbb::parallel_for (tbb::blocked_range<SyncIterators>(x_begin,
340 internal::make_body (predicate),
341 tbb::auto_partitioner());
348 #ifdef DEAL_II_WITH_THREADS
353 template <
typename RangeType,
typename Function>
357 f (range.begin(), range.end());
463 template <
typename RangeType,
typename Function>
465 const typename identity<RangeType>::type &end,
467 const unsigned int grainsize)
469 #ifndef DEAL_II_WITH_THREADS
476 tbb::parallel_for (tbb::blocked_range<RangeType>
477 (begin, end, grainsize),
478 std_cxx1x::bind (&internal::apply_to_subranges<RangeType,Function>,
481 tbb::auto_partitioner());
534 const std::size_t end,
535 const std::size_t minimum_parallel_grain_size)
const;
547 const std::size_t)
const = 0;
554 #ifdef DEAL_II_WITH_THREADS
565 template <
typename ResultType,
590 template <
typename Reductor>
611 reductor (r.reductor)
628 template <
typename RangeType>
632 f (range.begin(), range.end()));
657 const std_cxx1x::function<ResultType (ResultType, ResultType)>
reductor;
743 template <
typename ResultType,
typename RangeType,
typename Function>
745 const RangeType &begin,
746 const typename identity<RangeType>::type &end,
747 const unsigned int grainsize)
749 #ifndef DEAL_II_WITH_THREADS
757 reductor (f, std::plus<ResultType>(), 0);
758 tbb::parallel_reduce (tbb::blocked_range<RangeType>(begin, end, grainsize),
760 tbb::auto_partitioner());
797 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
void apply_parallel(const std::size_t begin, const std::size_t end, const std::size_t minimum_parallel_grain_size) const
void join(const ReductionOnSubranges &r)
static void apply(const F &f, const std_cxx1x::tuple< I1, I2 > &p)
static void apply(const F &f, const std_cxx1x::tuple< I1, I2, I3 > &p)
void operator()(const tbb::blocked_range< RangeType > &range)
const std_cxx1x::function< ResultType(ResultType, ResultType)> reductor
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())
virtual ~ParallelForInteger()
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)
virtual void apply_to_subrange(const std::size_t, const std::size_t) const =0
static void apply(const F &f, const std_cxx1x::tuple< I1, I2, I3, I4 > &p)