![]() |
Reference documentation for deal.II version 9.6.0
|
#include <deal.II/base/work_stream.h>
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) | |
ItemType * | get_item () |
Private Attributes | |
std::pair< Iterator, Iterator > | remaining_iterator_range |
std::vector< ItemType > | item_buffer |
Threads::ThreadLocalStorage< typename ItemType::ScratchDataList > | thread_local_scratch |
const ScratchData & | sample_scratch_data |
const unsigned int | chunk_size |
A class that creates a sequence of items from a range of iterators.
Definition at line 188 of file work_stream.h.
|
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 322 of file work_stream.h.
|
inline |
Create an item and return a pointer to it.
Definition at line 352 of file work_stream.h.
|
private |
The interval of iterators still to be worked on. This range will shrink over time.
Definition at line 407 of file work_stream.h.
|
private |
A buffer that will store items.
Definition at line 412 of file work_stream.h.
|
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 445 of file work_stream.h.
|
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 452 of file work_stream.h.
|
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 460 of file work_stream.h.