From 8564779f1cfc556f277f0663300165be0d8638c9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 5 Dec 2021 15:42:36 -0700 Subject: [PATCH] Be type correct -- the new TBB allows us to. --- include/deal.II/base/work_stream.h | 57 ++++++++++++++---------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/include/deal.II/base/work_stream.h b/include/deal.II/base/work_stream.h index 3c2be4bd93..590ac54b77 100644 --- a/include/deal.II/base/work_stream.h +++ b/include/deal.II/base/work_stream.h @@ -347,7 +347,7 @@ namespace WorkStream /** * Create an item and return a pointer to it. */ - void * + ItemType * operator()() { // find first unused item. we know that there must be one @@ -470,6 +470,10 @@ namespace WorkStream class TBBWorker { 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 @@ -487,17 +491,9 @@ namespace WorkStream /** * Work on an item. */ - void * - operator()(void *&item) const + ItemType * + operator()(ItemType *¤t_item) const { - // first unpack the current item - using ItemType = - typename IteratorRangeToItemStream::ItemType; - - ItemType *current_item = static_cast(item); - // we need to find an unused scratch data object in the list that // corresponds to the current thread and then mark it as used. if // we can't find one, create one @@ -585,9 +581,9 @@ namespace WorkStream current_item->currently_in_use = false; - // then return the original pointer - // to the now modified object - return item; + // Then return the original pointer + // to the now modified object. The copier will work on it next. + return current_item; } @@ -617,6 +613,10 @@ namespace WorkStream 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 @@ -631,17 +631,9 @@ namespace WorkStream /** * Work on a single item. */ - void * - operator()(void *&item) const + ItemType * + operator()(ItemType *¤t_item) const { - // first unpack the current item - using ItemType = - typename IteratorRangeToItemStream::ItemType; - - ItemType *current_item = static_cast(item); - // initiate copying data. for the same reasons as in the worker class // above, catch exceptions rather than letting it propagate into // unknown territories @@ -666,7 +658,7 @@ namespace WorkStream current_item->currently_in_use = false; - // return an invalid item since we are at the end of the + // Return an invalid item since we are at the end of the // pipeline return nullptr; } @@ -694,6 +686,10 @@ namespace WorkStream const unsigned int queue_length, const unsigned int chunk_size) { + using ItemType = typename IteratorRangeToItemStream::ItemType; + // create the three stages of the pipeline IteratorRangeToItemStream iterator_range_to_item_stream(begin, @@ -702,8 +698,8 @@ namespace WorkStream chunk_size, sample_scratch_data, sample_copy_data); - auto tbb_item_stream_filter = tbb::make_filter( - tbb::filter::serial, [&](tbb::flow_control &fc) -> void * { + auto tbb_item_stream_filter = tbb::make_filter( + tbb::filter::serial, [&](tbb::flow_control &fc) -> ItemType * { if (const auto item = iterator_range_to_item_stream()) return item; else @@ -715,12 +711,13 @@ namespace WorkStream TBBWorker worker_filter(worker); auto tbb_worker_filter = - tbb::make_filter(tbb::filter::parallel, - worker_filter); + tbb::make_filter(tbb::filter::parallel, + worker_filter); TBBCopier copier_filter(copier); auto tbb_copier_filter = - tbb::make_filter(tbb::filter::serial, copier_filter); + tbb::make_filter(tbb::filter::serial, + copier_filter); // now create a pipeline from these stages tbb::parallel_pipeline(queue_length, -- 2.39.5