From: allmaras Date: Thu, 10 Nov 2011 17:03:34 +0000 (+0000) Subject: Use ThreadLocalStorage for scratch objects in WorkStream X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9acf5c59deec2c2d6cea2f0b9cf563d68d0502df;p=dealii-svn.git Use ThreadLocalStorage for scratch objects in WorkStream git-svn-id: https://svn.dealii.org/trunk@24741 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 9aeb6cb33e..db7cfb9624 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -73,6 +73,11 @@ enabled due to a missing include file in file

Specific improvements

    +
  1. Changed: WorkStream now allocates one scratch object per thread instead of +one scratch object per item. +
    +(Moritz Allmaras, 2011/11/10) +
  2. 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.
    (Jörg Frohne, 2011/11/01) -
    1. 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 diff --git a/deal.II/include/deal.II/base/work_stream.h b/deal.II/include/deal.II/base/work_stream.h index 12157b8e28..b6a2fc39a3 100644 --- a/deal.II/include/deal.II/base/work_stream.h +++ b/deal.II/include/deal.II/base/work_stream.h @@ -18,6 +18,7 @@ #include #include #include +#include #if DEAL_II_USE_MT == 1 # include @@ -155,7 +156,7 @@ namespace WorkStream */ typedef std_cxx1x::tuple, - ScratchData*, + Threads::ThreadLocalStorage*, std::vector, 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[i]); - } - /** * Create a item and return a * pointer to it. @@ -258,6 +250,12 @@ namespace WorkStream */ std::vector ring_buffer; + /** + * Scratch data object. Each thread will + * have its own local copy. + */ + Threads::ThreadLocalStorage 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(*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