From: Timo Heister Date: Wed, 8 Jul 2020 20:02:15 +0000 (-0400) Subject: extract TBB colored WorkStream::run X-Git-Tag: v9.3.0-rc1~1286^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d7c9b0a3cf41a10c98ee0335075d0bc00df48bb;p=dealii.git extract TBB colored WorkStream::run --- diff --git a/include/deal.II/base/work_stream.h b/include/deal.II/base/work_stream.h index 5eddc7ed2f..7550a1acf5 100644 --- a/include/deal.II/base/work_stream.h +++ b/include/deal.II/base/work_stream.h @@ -1015,6 +1015,49 @@ namespace WorkStream const ScratchData &sample_scratch_data; const CopyData & sample_copy_data; }; + + /** + * The colored run function using TBB. + */ + template + void + run(const std::vector> &colored_iterators, + Worker worker, + Copier copier, + const ScratchData & sample_scratch_data, + const CopyData & sample_copy_data, + const unsigned int chunk_size) + { + // loop over the various colors of what we're given + for (unsigned int color = 0; color < colored_iterators.size(); ++color) + if (colored_iterators[color].size() > 0) + { + using WorkerAndCopier = internal::tbb_colored:: + WorkerAndCopier; + + using RangeType = typename std::vector::const_iterator; + + WorkerAndCopier worker_and_copier(worker, + copier, + sample_scratch_data, + sample_copy_data); + + parallel::internal::parallel_for( + colored_iterators[color].begin(), + colored_iterators[color].end(), + [&worker_and_copier]( + const tbb::blocked_range< + typename std::vector::const_iterator> &range) { + worker_and_copier(range); + }, + chunk_size); + } + } + } // namespace tbb_colored # endif // DEAL_II_WITH_TBB @@ -1308,30 +1351,12 @@ namespace WorkStream if (MultithreadInfo::n_threads() > 1) { # ifdef DEAL_II_WITH_TBB - // loop over the various colors of what we're given - for (unsigned int color = 0; color < colored_iterators.size(); ++color) - if (colored_iterators[color].size() > 0) - { - using WorkerAndCopier = internal::tbb_colored:: - WorkerAndCopier; - - using RangeType = typename std::vector::const_iterator; - - WorkerAndCopier worker_and_copier(worker, - copier, - sample_scratch_data, - sample_copy_data); - - parallel::internal::parallel_for( - colored_iterators[color].begin(), - colored_iterators[color].end(), - [&worker_and_copier]( - const tbb::blocked_range< - typename std::vector::const_iterator> &range) { - worker_and_copier(range); - }, - chunk_size); - } + internal::tbb_colored::run(colored_iterators, + worker, + copier, + sample_scratch_data, + sample_copy_data, + chunk_size); // exit this function to not run the sequential version below: return;