]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Use ThreadLocalStorage for scratch objects in WorkStream
authorallmaras <allmaras@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 10 Nov 2011 17:03:34 +0000 (17:03 +0000)
committerallmaras <allmaras@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 10 Nov 2011 17:03:34 +0000 (17:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@24741 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/work_stream.h

index 9aeb6cb33e5968998fdc9b480d256a02b8058308..db7cfb962406962a326f3fb7b4e1c39226db96af 100644 (file)
@@ -73,6 +73,11 @@ enabled due to a missing include file in file
 <h3>Specific improvements</h3>
 
 <ol>
+<li> Changed: WorkStream now allocates one scratch object per thread instead of
+one scratch object per item.
+<br>
+(Moritz Allmaras, 2011/11/10)
+
 <li> New: Implementation of an alternative handling of
 inhomogeneous constraints in ConstraintMatrix. This is controlled with
 a new parameter use_inhomogeneities_for_rhs in
@@ -82,7 +87,6 @@ kept in the linear system during the solution process.
 <br>
 (Jörg Frohne, 2011/11/01)
 
-<ol>
 <li> Fixed: SparseMatrix::mmult and SpareMatrix::Tmmult had a number of
 issues that are now fixed: (i) rebuilding the sparsity pattern was allowed
 even if several of the matrices involved in these operations shared a
index 12157b8e285c95c837dc3d429f3f305b5f5bd562..b6a2fc39a3e64827c02e439c6cb50cb9aa4e9e2a 100644 (file)
@@ -18,6 +18,7 @@
 #include <deal.II/base/template_constraints.h>
 #include <deal.II/base/std_cxx1x/function.h>
 #include <deal.II/base/std_cxx1x/bind.h>
+#include <deal.II/base/thread_local_storage.h>
 
 #if DEAL_II_USE_MT == 1
 #  include <deal.II/base/thread_management.h>
@@ -155,7 +156,7 @@ namespace WorkStream
                                          */
        typedef
        std_cxx1x::tuple<std::vector<Iterator>,
-                        ScratchData*,
+                        Threads::ThreadLocalStorage<ScratchData>*,
                         std::vector<CopyData>,
                         unsigned int>
        ItemType;
@@ -179,6 +180,7 @@ namespace WorkStream
                        tbb::filter (/*is_serial=*/true),
                        remaining_iterator_range (begin, end),
                        ring_buffer (buffer_size),
+                       thread_local_scratch(sample_scratch_data),
                        n_emitted_items (0),
                        chunk_size (chunk_size)
          {
@@ -193,20 +195,10 @@ namespace WorkStream
              tasks += Threads::new_task (&IteratorRangeToItemStream::init_buffer_elements,
                                          *this,
                                          i,
-                                         std_cxx1x::cref(sample_scratch_data),
                                          std_cxx1x::cref(sample_copy_data));
            tasks.join_all ();
          }
 
-                                        /**
-                                         * Destructor.
-                                         */
-       ~IteratorRangeToItemStream ()
-         {
-           for (unsigned int i=0; i<ring_buffer.size(); ++i)
-             delete std_cxx1x::get<1>(ring_buffer[i]);
-         }
-      
                                         /**
                                          * Create a item and return a
                                          * pointer to it.
@@ -258,6 +250,12 @@ namespace WorkStream
                                          */
        std::vector<ItemType>        ring_buffer;
 
+                                        /**
+                                         * Scratch data object. Each thread will 
+                                         * have its own local copy. 
+                                         */
+       Threads::ThreadLocalStorage<ScratchData> thread_local_scratch;
+
                                         /**
                                          * Counter for the number of emitted
                                          * items. Each item may consist of up
@@ -285,7 +283,6 @@ namespace WorkStream
                                          * the ring buffer.
                                          */
        void init_buffer_elements (const unsigned int element,
-                                  const ScratchData &sample_scratch_data,
                                   const CopyData    &sample_copy_data)
          {
            Assert (std_cxx1x::get<1>(ring_buffer[element]) == 0,
@@ -294,7 +291,7 @@ namespace WorkStream
            std_cxx1x::get<0>(ring_buffer[element])
              .resize (chunk_size, remaining_iterator_range.second);
            std_cxx1x::get<1>(ring_buffer[element])
-             = new ScratchData(sample_scratch_data);
+               = &thread_local_scratch;
            std_cxx1x::get<2>(ring_buffer[element])
              .resize (chunk_size, sample_copy_data);
          }
@@ -349,7 +346,7 @@ namespace WorkStream
                                             // were given
            for (unsigned int i=0; i<std_cxx1x::get<3>(*current_item); ++i)
              worker (std_cxx1x::get<0>(*current_item)[i],
-                     *std_cxx1x::get<1>(*current_item),
+                     std_cxx1x::get<1>(*current_item)->get(),
                      std_cxx1x::get<2>(*current_item)[i]);
            
                                             // then return the original pointer

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.