]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Be type correct -- the new TBB allows us to.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sun, 5 Dec 2021 22:42:36 +0000 (15:42 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 6 Dec 2021 03:34:03 +0000 (20:34 -0700)
include/deal.II/base/work_stream.h

index 3c2be4bd931c98c62d8debc690a8971c69014174..590ac54b77b44d9aec2ac37a97055b8e2c4ca91e 100644 (file)
@@ -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<Iterator,
+                                                            ScratchData,
+                                                            CopyData>::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 *&current_item) const
         {
-          // first unpack the current item
-          using ItemType =
-            typename IteratorRangeToItemStream<Iterator,
-                                               ScratchData,
-                                               CopyData>::ItemType;
-
-          ItemType *current_item = static_cast<ItemType *>(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<Iterator,
+                                                            ScratchData,
+                                                            CopyData>::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 *&current_item) const
         {
-          // first unpack the current item
-          using ItemType =
-            typename IteratorRangeToItemStream<Iterator,
-                                               ScratchData,
-                                               CopyData>::ItemType;
-
-          ItemType *current_item = static_cast<ItemType *>(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<Iterator,
+                                                            ScratchData,
+                                                            CopyData>::ItemType;
+
         // create the three stages of the pipeline
         IteratorRangeToItemStream<Iterator, ScratchData, CopyData>
              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<void, void *>(
-          tbb::filter::serial, [&](tbb::flow_control &fc) -> void * {
+        auto tbb_item_stream_filter = tbb::make_filter<void, ItemType *>(
+          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<Iterator, ScratchData, CopyData> worker_filter(worker);
         auto                                       tbb_worker_filter =
-          tbb::make_filter<void *, void *>(tbb::filter::parallel,
-                                           worker_filter);
+          tbb::make_filter<ItemType *, ItemType *>(tbb::filter::parallel,
+                                                   worker_filter);
 
         TBBCopier<Iterator, ScratchData, CopyData> copier_filter(copier);
         auto                                       tbb_copier_filter =
-          tbb::make_filter<void *, void>(tbb::filter::serial, copier_filter);
+          tbb::make_filter<ItemType *, void>(tbb::filter::serial,
+                                             copier_filter);
 
         // now create a pipeline from these stages
         tbb::parallel_pipeline(queue_length,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.