From 7685f1ed371f15b8e88726edfaed42d4207c8014 Mon Sep 17 00:00:00 2001 From: bangerth Date: Thu, 27 Jun 2013 23:16:41 +0000 Subject: [PATCH] Re-enable the functionality previously reverted in 24748. This didn't work back then, and it's likely not going to work now, but I need a baseline of tests that fail. git-svn-id: https://svn.dealii.org/trunk@29899 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/work_stream.h | 27 ++++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/deal.II/include/deal.II/base/work_stream.h b/deal.II/include/deal.II/base/work_stream.h index 3a98da2afa..8e2ade6d71 100644 --- a/deal.II/include/deal.II/base/work_stream.h +++ b/deal.II/include/deal.II/base/work_stream.h @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef DEAL_II_WITH_THREADS # include @@ -156,8 +157,8 @@ namespace WorkStream */ typedef std_cxx1x::tuple, - ScratchData *, - std::vector, + Threads::ThreadLocalStorage*, + std::vector, unsigned int> ItemType; @@ -180,6 +181,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) { @@ -194,20 +196,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. @@ -260,6 +252,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 * to chunk_size iterator elements. @@ -286,7 +284,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, @@ -295,7 +292,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); } @@ -354,7 +351,7 @@ namespace WorkStream try { 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]); } catch (const std::exception &exc) -- 2.39.5