16 #ifndef dealii_parallel_h 17 #define dealii_parallel_h 32 #ifdef DEAL_II_WITH_THREADS 33 # include <tbb/blocked_range.h> 34 # include <tbb/parallel_for.h> 35 # include <tbb/parallel_reduce.h> 36 # include <tbb/partitioner.h> 53 template <
typename Number>
59 #ifdef __INTEL_COMPILER 67 static const bool value =
false;
87 template <
typename Range>
91 for (
typename Range::const_iterator p = range.begin(); p != range.end();
105 template <
typename I1,
typename I2>
107 apply(
const F &f,
const std::tuple<I1, I2> &p)
109 *std::get<1>(p) = f(*std::get<0>(p));
115 template <
typename I1,
typename I2,
typename I3>
117 apply(
const F &f,
const std::tuple<I1, I2, I3> &p)
119 *std::get<2>(p) = f(*std::get<0>(p), *std::get<1>(p));
125 template <
typename I1,
typename I2,
typename I3,
typename I4>
127 apply(
const F &f,
const std::tuple<I1, I2, I3, I4> &p)
129 *std::get<3>(p) = f(*std::get<0>(p), *std::get<1>(p), *std::get<2>(p));
141 template <
typename F>
150 #ifdef DEAL_II_WITH_THREADS 154 template <
typename Iterator,
typename Functor>
158 const Functor & functor,
159 const unsigned int grainsize)
163 tbb::auto_partitioner());
171 template <
typename Iterator,
typename Functor>
175 const Functor & functor,
176 const unsigned int grainsize,
177 const std::shared_ptr<tbb::affinity_partitioner> &partitioner)
209 template <
typename InputIterator,
typename OutputIterator,
typename Predicate>
212 const InputIterator &end_in,
214 const Predicate & predicate,
215 const unsigned int grainsize)
217 #ifndef DEAL_II_WITH_THREADS 222 for (OutputIterator in = begin_in; in != end_in;)
223 *out++ = predicate(*in++);
225 using Iterators = std::tuple<InputIterator, OutputIterator>;
227 Iterators x_begin(begin_in, out);
228 Iterators x_end(end_in, OutputIterator());
230 SyncIterators(x_end),
261 template <
typename InputIterator1,
262 typename InputIterator2,
263 typename OutputIterator,
267 const InputIterator1 &end_in1,
270 const Predicate & predicate,
271 const unsigned int grainsize)
273 #ifndef DEAL_II_WITH_THREADS 278 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
279 *out++ = predicate(*in1++, *in2++);
282 std::tuple<InputIterator1, InputIterator2, OutputIterator>;
284 Iterators x_begin(begin_in1, in2, out);
285 Iterators x_end(end_in1, InputIterator2(), OutputIterator());
287 SyncIterators(x_end),
318 template <
typename InputIterator1,
319 typename InputIterator2,
320 typename InputIterator3,
321 typename OutputIterator,
325 const InputIterator1 &end_in1,
329 const Predicate & predicate,
330 const unsigned int grainsize)
332 #ifndef DEAL_II_WITH_THREADS 337 for (OutputIterator in1 = begin_in1; in1 != end_in1;)
338 *out++ = predicate(*in1++, *in2++, *in3++);
340 using Iterators = std::
341 tuple<InputIterator1, InputIterator2, InputIterator3, OutputIterator>;
343 Iterators x_begin(begin_in1, in2, in3, out);
344 Iterators x_end(end_in1,
349 SyncIterators(x_end),
358 #ifdef DEAL_II_WITH_THREADS 363 template <
typename RangeType,
typename Function>
368 f(range.begin(), range.end());
443 template <
typename RangeType,
typename Function>
448 const unsigned int grainsize)
450 #ifndef DEAL_II_WITH_THREADS 455 # ifndef DEAL_II_BIND_NO_CONST_OP_PARENTHESES 466 [&f](
const tbb::blocked_range<RangeType> &range) {
467 internal::apply_to_subranges<RangeType, Function>(
520 apply_parallel(
const std::size_t
begin,
521 const std::size_t
end,
531 apply_to_subrange(
const std::size_t,
const std::size_t)
const = 0;
538 #ifdef DEAL_II_WITH_THREADS 545 template <
typename ResultType,
typename Function>
562 template <
typename Reductor>
564 const Reductor & reductor,
565 const ResultType neutral_element = ResultType())
566 : result(neutral_element)
568 , neutral_element(neutral_element)
576 : result(r.neutral_element)
578 , neutral_element(r.neutral_element)
579 , reductor(r.reductor)
589 result = reductor(result, r.
result);
595 template <
typename RangeType>
599 result = reductor(result, f(range.begin(), range.end()));
619 const std::function<ResultType(ResultType, ResultType)>
reductor;
685 template <
typename ResultType,
typename RangeType,
typename Function>
688 const RangeType &
begin,
690 const unsigned int grainsize)
692 #ifndef DEAL_II_WITH_THREADS 697 # ifndef DEAL_II_BIND_NO_CONST_OP_PARENTHESES 698 return f(begin, end);
703 return ff(begin, end);
707 f, std::plus<ResultType>(), 0);
710 tbb::auto_partitioner());
737 #ifdef DEAL_II_WITH_THREADS 750 std::shared_ptr<tbb::affinity_partitioner>
751 acquire_one_partitioner();
759 release_one_partitioner(std::shared_ptr<tbb::affinity_partitioner> &p);
786 namespace VectorImplementation
806 namespace SparseMatrixImplementation
823 #ifdef DEAL_II_WITH_THREADS 838 operator()(
const tbb::blocked_range<std::size_t> &range)
const 840 worker_.apply_to_subrange(range.begin(), range.end());
852 const std::size_t
begin,
853 const std::size_t
end,
856 #ifndef DEAL_II_WITH_THREADS 859 (void)minimum_parallel_grain_size;
861 apply_to_subrange(begin, end);
Body< F > make_body(const F &f)
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Predicate &predicate, const unsigned int grainsize)
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize)
void join(const ReductionOnSubranges &r)
static void apply(const F &f, const std::tuple< I1, I2, I3 > &p)
std::shared_ptr< tbb::affinity_partitioner > my_partitioner
void operator()(const tbb::blocked_range< RangeType > &range)
Tensor< 2, dim, Number > F(const Tensor< 2, dim, Number > &Grad_u)
unsigned int minimum_parallel_grain_size
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)
#define DEAL_II_NAMESPACE_CLOSE
auto apply(F &&fn, Tuple &&t) -> decltype(apply_impl(std::forward< F >(fn), std::forward< Tuple >(t), std_cxx14::make_index_sequence< std::tuple_size< typename std::remove_reference< Tuple >::type >::value >()))
VectorType::value_type * end(VectorType &V)
ReductionOnSubranges(const ReductionOnSubranges &r, tbb::split)
void parallel_reduce(const Operation &op, const size_type start, const size_type end, ResultType &result, const std::shared_ptr<::parallel::internal::TBBPartitioner > &partitioner)
const std::function< ResultType(ResultType, ResultType)> reductor
static void apply(const F &f, const std::tuple< I1, I2 > &p)
void parallel_for(Iterator x_begin, Iterator x_end, const Functor &functor, const unsigned int grainsize, const std::shared_ptr< tbb::affinity_partitioner > &partitioner)
ResultType accumulate_from_subranges(const Function &f, const RangeType &begin, const typename identity< RangeType >::type &end, const unsigned int grainsize)
std::vector< value_type > split(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
const ResultType neutral_element
void operator()(const Range &range) const
MatrixTableIterators::Iterator< TransposeTable< T >, Constness, MatrixTableIterators::Storage::column_major > Iterator
void apply_parallel(const std::size_t begin, const std::size_t end, const std::size_t minimum_parallel_grain_size) const
#define DEAL_II_NAMESPACE_OPEN
VectorType::value_type * begin(VectorType &V)
void operator()(const tbb::blocked_range< std::size_t > &range) const
const parallel::ParallelForInteger & worker_
ParallelForWrapper(const parallel::ParallelForInteger &worker)