Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Classes | Public Member Functions | Private Attributes | List of all members
WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData > Class Template Reference

#include <deal.II/base/work_stream.h>

Inheritance diagram for WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >:
[legend]

Classes

struct  ItemType
 

Public Member Functions

 IteratorRangeToItemStream (const Iterator &begin, const Iterator &end, const unsigned int buffer_size, const unsigned int chunk_size, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data)
 
virtual void * operator() (void *) override
 

Private Attributes

std::pair< Iterator, Iterator > remaining_iterator_range
 
std::vector< ItemTypeitem_buffer
 
Threads::ThreadLocalStorage< typename ItemType::ScratchDataListthread_local_scratch
 
const ScratchData & sample_scratch_data
 
const unsigned int chunk_size
 

Detailed Description

template<typename Iterator, typename ScratchData, typename CopyData>
class WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >

A class that creates a sequence of items from a range of iterators.

Definition at line 181 of file work_stream.h.

Constructor & Destructor Documentation

◆ IteratorRangeToItemStream()

template<typename Iterator , typename ScratchData , typename CopyData >
WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::IteratorRangeToItemStream ( const Iterator &  begin,
const Iterator &  end,
const unsigned int  buffer_size,
const unsigned int  chunk_size,
const ScratchData &  sample_scratch_data,
const CopyData &  sample_copy_data 
)
inline

Constructor. Take an iterator range, the size of a buffer that can hold items, and the sample additional data object that will be passed to each worker and copier function invocation.

Definition at line 308 of file work_stream.h.

Member Function Documentation

◆ operator()()

template<typename Iterator , typename ScratchData , typename CopyData >
virtual void* WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::operator() ( void *  )
inlineoverridevirtual

Create an item and return a pointer to it.

Definition at line 341 of file work_stream.h.

Member Data Documentation

◆ remaining_iterator_range

template<typename Iterator , typename ScratchData , typename CopyData >
std::pair<Iterator, Iterator> WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::remaining_iterator_range
private

The interval of iterators still to be worked on. This range will shrink over time.

Definition at line 396 of file work_stream.h.

◆ item_buffer

template<typename Iterator , typename ScratchData , typename CopyData >
std::vector<ItemType> WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::item_buffer
private

A buffer that will store items.

Definition at line 401 of file work_stream.h.

◆ thread_local_scratch

template<typename Iterator , typename ScratchData , typename CopyData >
Threads::ThreadLocalStorage<typename ItemType::ScratchDataList> WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::thread_local_scratch
private

Pointer to a thread local variable identifying the scratch data objects this thread will use. The initial implementation of this class using thread local variables provided only a single scratch object per thread. This doesn't work, because the worker functions may start tasks itself and then call Threads::TaskGroup::join_all() or a similar function, which the TBB scheduler may use to run something else on the current thread – for example another instance of the worker function. Consequently, there would be two instances of the worker function that use the same scratch object if we only provided a single scratch object per thread. The solution is to provide a list of scratch objects for each thread, together with a flag indicating whether this scratch object is currently used. If a thread needs a scratch object, it walks this list until it finds an unused object, or, if there is none, creates one itself. Note that we need not use synchronization primitives for this process since the lists are thread-local and we are guaranteed that only a single thread accesses them as long as we have no yield point in between the accesses to the list.

The pointers to scratch objects stored in each of these lists must be so that they are deleted on all threads when the thread local object is destroyed. This is achieved by using unique_ptr.

Note that when a worker needs to create a scratch object, it allocates it using sample_scratch_data to copy from. This has the advantage of a first-touch initialization, i.e., the memory for the scratch data object is allocated and initialized by the same thread that will later use it.

Definition at line 434 of file work_stream.h.

◆ sample_scratch_data

template<typename Iterator , typename ScratchData , typename CopyData >
const ScratchData& WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::sample_scratch_data
private

A reference to a sample scratch data that will be used to initialize the thread-local pointers to a scratch data object each of the worker tasks uses.

Definition at line 441 of file work_stream.h.

◆ chunk_size

template<typename Iterator , typename ScratchData , typename CopyData >
const unsigned int WorkStream::internal::Implementation2::IteratorRangeToItemStream< Iterator, ScratchData, CopyData >::chunk_size
private

Number of elements of the iterator range that each thread should work on sequentially; a large number makes sure that each thread gets a significant amount of work before the next task switch happens, whereas a small number is better for load balancing.

Definition at line 449 of file work_stream.h.


The documentation for this class was generated from the following file: