From: Bruno Turcksin Date: Tue, 12 Mar 2019 13:32:28 +0000 (-0400) Subject: Encapsulate the calls to tbb::parallel_for X-Git-Tag: v9.1.0-rc1~282^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f73b559112557765bb53f9b288158040cae697e;p=dealii.git Encapsulate the calls to tbb::parallel_for --- diff --git a/include/deal.II/base/parallel.h b/include/deal.II/base/parallel.h index 9f82c11750..d9db08f5ac 100644 --- a/include/deal.II/base/parallel.h +++ b/include/deal.II/base/parallel.h @@ -131,6 +131,7 @@ namespace parallel }; + /** * Take a function object and create a Body object from it. We do this in * this helper function since alternatively we would have to specify the @@ -143,6 +144,41 @@ namespace parallel { return Body(f); } + + + + /** + * Encapsulate tbb::parallel_for. + */ + template + void + parallel_for(Iterator x_begin, + Iterator x_end, + const Functor & functor, + const unsigned int grainsize) + { + tbb::parallel_for(tbb::blocked_range(x_begin, x_end, grainsize), + functor, + tbb::auto_partitioner()); + } + + + + /** + * Encapsulate tbb::parallel_for when an affinite_partitioner is provided. + */ + template + void + parallel_for(Iterator x_begin, + Iterator x_end, + const Functor & functor, + const unsigned int grainsize, + const std::shared_ptr &partitioner) + { + tbb::parallel_for(tbb::blocked_range(x_begin, x_end, grainsize), + functor, + *partitioner); + } } // namespace internal /** @@ -188,11 +224,10 @@ namespace parallel using SyncIterators = SynchronousIterators; Iterators x_begin(begin_in, out); Iterators x_end(end_in, OutputIterator()); - tbb::parallel_for(tbb::blocked_range(x_begin, - x_end, - grainsize), - internal::make_body(predicate), - tbb::auto_partitioner()); + internal::parallel_for(SyncIterators(x_begin), + SyncIterators(x_end), + internal::make_body(predicate), + grainsize); #endif } @@ -246,11 +281,10 @@ namespace parallel using SyncIterators = SynchronousIterators; Iterators x_begin(begin_in1, in2, out); Iterators x_end(end_in1, InputIterator2(), OutputIterator()); - tbb::parallel_for(tbb::blocked_range(x_begin, - x_end, - grainsize), - internal::make_body(predicate), - tbb::auto_partitioner()); + internal::parallel_for(SyncIterators(x_begin), + SyncIterators(x_end), + internal::make_body(predicate), + grainsize); #endif } @@ -309,11 +343,10 @@ namespace parallel InputIterator2(), InputIterator3(), OutputIterator()); - tbb::parallel_for(tbb::blocked_range(x_begin, - x_end, - grainsize), - internal::make_body(predicate), - tbb::auto_partitioner()); + internal::parallel_for(SyncIterators(x_begin), + SyncIterators(x_end), + internal::make_body(predicate), + grainsize); #endif } @@ -428,12 +461,13 @@ namespace parallel ff(begin, end); # endif #else - tbb::parallel_for( - tbb::blocked_range(begin, end, grainsize), + internal::parallel_for( + begin, + end, std::bind(&internal::apply_to_subranges, std::placeholders::_1, std::cref(f)), - tbb::auto_partitioner()); + grainsize); #endif } @@ -826,10 +860,7 @@ namespace parallel apply_to_subrange(begin, end); #else internal::ParallelForWrapper worker(*this); - tbb::parallel_for( - tbb::blocked_range(begin, end, minimum_parallel_grain_size), - worker, - tbb::auto_partitioner()); + internal::parallel_for(begin, end, worker, minimum_parallel_grain_size); #endif } diff --git a/include/deal.II/base/work_stream.h b/include/deal.II/base/work_stream.h index b09c2d1fdf..555c35c98d 100644 --- a/include/deal.II/base/work_stream.h +++ b/include/deal.II/base/work_stream.h @@ -1154,14 +1154,13 @@ namespace WorkStream sample_scratch_data, sample_copy_data); - tbb::parallel_for( - tbb::blocked_range(colored_iterators[color].begin(), - colored_iterators[color].end(), - /*grain_size=*/chunk_size), + parallel::internal::parallel_for( + colored_iterators[color].begin(), + colored_iterators[color].end(), std::bind(&WorkerAndCopier::operator(), std::ref(worker_and_copier), std::placeholders::_1), - tbb::auto_partitioner()); + chunk_size); } } # endif diff --git a/include/deal.II/lac/vector_operations_internal.h b/include/deal.II/lac/vector_operations_internal.h index 5d98e3f23a..bd13406faa 100644 --- a/include/deal.II/lac/vector_operations_internal.h +++ b/include/deal.II/lac/vector_operations_internal.h @@ -188,10 +188,8 @@ namespace internal partitioner->acquire_one_partitioner(); TBBForFunctor generic_functor(functor, start, end); - tbb::parallel_for( - tbb::blocked_range(0, generic_functor.n_chunks, 1), - generic_functor, - *tbb_partitioner); + parallel::internal::parallel_for( + 0U, generic_functor.n_chunks, generic_functor, 1, tbb_partitioner); partitioner->release_one_partitioner(tbb_partitioner); } else if (vec_size > 0) @@ -1389,10 +1387,8 @@ namespace internal TBBReduceFunctor generic_functor(op, start, end); - tbb::parallel_for( - tbb::blocked_range(0, generic_functor.n_chunks, 1), - generic_functor, - *tbb_partitioner); + parallel::internal::parallel_for( + 0U, generic_functor.n_chunks, generic_functor, 1, tbb_partitioner); partitioner->release_one_partitioner(tbb_partitioner); result = generic_functor.do_sum(); }