From 98357b103018936236c7eff2cd7c8366b7867ca9 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Wed, 8 Jul 2020 10:15:03 -0400 Subject: [PATCH] fix colored sequential code --- include/deal.II/base/work_stream.h | 58 +++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/include/deal.II/base/work_stream.h b/include/deal.II/base/work_stream.h index e83099da19..5eddc7ed2f 100644 --- a/include/deal.II/base/work_stream.h +++ b/include/deal.II/base/work_stream.h @@ -772,6 +772,50 @@ namespace WorkStream copier(copy_data); } } + + + + /** + * Sequential version with colors + */ + template + void + run(const std::vector> &colored_iterators, + Worker worker, + Copier copier, + const ScratchData & sample_scratch_data, + const CopyData & sample_copy_data) + { + // need to copy the sample since it is marked const + ScratchData scratch_data = sample_scratch_data; + CopyData copy_data = sample_copy_data; // NOLINT + + // Optimization: Check if the functions are not the zero function. To + // check zero-ness, create a C++ function out of it: + const bool have_worker = + (static_cast &>(worker)) != + nullptr; + const bool have_copier = + (static_cast &>( + copier)) != nullptr; + + // Finally loop over all items and perform the necessary work: + for (unsigned int color = 0; color < colored_iterators.size(); ++color) + if (colored_iterators[color].size() > 0) + for (auto &it : colored_iterators[color]) + { + if (have_worker) + worker(it, scratch_data, copy_data); + if (have_copier) + copier(copy_data); + } + } + } // namespace sequential @@ -1296,15 +1340,11 @@ namespace WorkStream // run all colors sequentially: { - for (unsigned int color = 0; color < colored_iterators.size(); ++color) - { - internal::sequential::run(*colored_iterators[color].begin(), - *colored_iterators[color].end(), - worker, - copier, - sample_scratch_data, - sample_copy_data); - } + internal::sequential::run(colored_iterators, + worker, + copier, + sample_scratch_data, + sample_copy_data); } } -- 2.39.5