From: Wolfgang Bangerth Date: Sun, 5 Dec 2021 22:51:43 +0000 (-0700) Subject: Remove the TBBCopier class and just inline its only function as a lambda. X-Git-Tag: v9.3.3~5^2~13 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdabda85b641f099a44084932825c899c5177953;p=dealii.git Remove the TBBCopier class and just inline its only function as a lambda. --- diff --git a/include/deal.II/base/work_stream.h b/include/deal.II/base/work_stream.h index 9c9efe30e1..1349f60115 100644 --- a/include/deal.II/base/work_stream.h +++ b/include/deal.II/base/work_stream.h @@ -608,73 +608,6 @@ namespace WorkStream - /** - * A class that manages calling the copier function. Note that it is, in - * the TBB notation, a filter that runs sequentially, ensuring that all - * items are copied in the same order in which they are created. - */ - template - class TBBCopier - { - public: - using ItemType = typename IteratorRangeToItemStream::ItemType; - - /** - * Constructor. Takes a reference to the object on which we will - * operate as well as a pointer to the function that will do the - * copying from the additional data object to the global matrix or - * similar. - */ - TBBCopier(const std::function &copier) - : copier(copier) - {} - - - /** - * Work on a single item. - */ - ItemType * - operator()(ItemType *¤t_item) const - { - // initiate copying data. for the same reasons as in the worker class - // above, catch exceptions rather than letting it propagate into - // unknown territories - for (unsigned int i = 0; i < current_item->n_items; ++i) - { - try - { - if (copier) - copier(current_item->copy_datas[i]); - } - catch (const std::exception &exc) - { - Threads::internal::handle_std_exception(exc); - } - catch (...) - { - Threads::internal::handle_unknown_exception(); - } - } - - // mark current item as usable again - current_item->currently_in_use = false; - - - // Return an invalid item since we are at the end of the - // pipeline - return nullptr; - } - - - private: - /** - * Pointer to the function that does the copying of data. - */ - const std::function copier; - }; - template (tbb::filter::parallel, worker_filter); - TBBCopier copier_filter(copier); - auto tbb_copier_filter = - tbb::make_filter(tbb::filter::serial, - copier_filter); + auto tbb_copier_filter = tbb::make_filter( + tbb::filter::serial, + [copier = std::function(copier)]( + ItemType *¤t_item) { + // Initiate copying data. For the same reasons as in the worker + // class above, catch exceptions rather than letting them propagate + // into unknown territories: + for (unsigned int i = 0; i < current_item->n_items; ++i) + { + try + { + if (copier) + copier(current_item->copy_datas[i]); + } + catch (const std::exception &exc) + { + Threads::internal::handle_std_exception(exc); + } + catch (...) + { + Threads::internal::handle_unknown_exception(); + } + } + + // mark current item as usable again + current_item->currently_in_use = false; + }); - // now create a pipeline from these stages + // Now create a pipeline from these stages and execute it: tbb::parallel_pipeline(queue_length, tbb_item_stream_filter & tbb_worker_filter & tbb_copier_filter);