Reference documentation for deal.II version 9.6.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\}}\)
Loading...
Searching...
No Matches
internal::VectorOperations::TBBReduceFunctor< Operation, ResultType > Struct Template Reference

#include <deal.II/lac/vector_operations_internal.h>

Public Member Functions

 TBBReduceFunctor (const Operation &op, const size_type start, const size_type end)
 
void operator() (const tbb::blocked_range< size_type > &range) const
 
ResultType do_sum () const
 

Public Attributes

const Operation & op
 
const size_type start
 
const size_type end
 
unsigned int n_chunks
 
unsigned int chunk_size
 
ResultType small_array [threshold_array_allocate]
 
std::vector< ResultType > large_array
 
ResultType * array_ptr
 

Static Public Attributes

static const unsigned int threshold_array_allocate = 512
 

Detailed Description

template<typename Operation, typename ResultType>
struct internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >

This struct takes the loop range from the tbb parallel for loop and translates it to the actual ranges of the reduction loop inside the vector. It encodes the grain size but might choose larger values of chunks than the minimum grain size. The minimum grain size given to tbb is 1. For affinity reasons, the layout in this loop must be kept in sync with the respective class for plain for loops further up.

Due to this construction, TBB usually only sees a loop of length 4*num_threads with grain size 1. The actual ranges inside the vector are computed outside of TBB because otherwise TBB would split the ranges in some unpredictable position which destroys exact bitwise reproducibility. An important part of this is that inside TBBReduceFunctor::operator() the recursive calls to accumulate are done sequentially on one item a time (even though we could directly run it on the whole range given through the tbb::blocked_range times the chunk size

  • but that would be unpredictable). Thus, the values we cannot control are the positions in the array that gets filled - but up to that point the algorithm TBB sees is just a parallel for and nothing unpredictable can happen.

To sum up: Once the number of threads and the vector size are fixed, we have an exact layout of how the calls into the recursive function will happen. Inside the recursive function, we again only depend on the length. Finally, the concurrent threads write into different positions in a result vector in a thread-safe way and the addition in the short array is again serial.

Definition at line 1317 of file vector_operations_internal.h.

Constructor & Destructor Documentation

◆ TBBReduceFunctor()

template<typename Operation , typename ResultType >
internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::TBBReduceFunctor ( const Operation & op,
const size_type start,
const size_type end )
inline

Definition at line 1321 of file vector_operations_internal.h.

Member Function Documentation

◆ operator()()

template<typename Operation , typename ResultType >
void internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::operator() ( const tbb::blocked_range< size_type > & range) const
inline

An operator used by TBB to work on a given range of chunks [range.begin(), range.end()).

Definition at line 1363 of file vector_operations_internal.h.

◆ do_sum()

template<typename Operation , typename ResultType >
ResultType internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::do_sum ( ) const
inline

Definition at line 1373 of file vector_operations_internal.h.

Member Data Documentation

◆ threshold_array_allocate

template<typename Operation , typename ResultType >
const unsigned int internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::threshold_array_allocate = 512
static

Definition at line 1319 of file vector_operations_internal.h.

◆ op

template<typename Operation , typename ResultType >
const Operation& internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::op

Definition at line 1386 of file vector_operations_internal.h.

◆ start

template<typename Operation , typename ResultType >
const size_type internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::start

Definition at line 1387 of file vector_operations_internal.h.

◆ end

template<typename Operation , typename ResultType >
const size_type internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::end

Definition at line 1388 of file vector_operations_internal.h.

◆ n_chunks

template<typename Operation , typename ResultType >
unsigned int internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::n_chunks
mutable

Definition at line 1390 of file vector_operations_internal.h.

◆ chunk_size

template<typename Operation , typename ResultType >
unsigned int internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::chunk_size

Definition at line 1391 of file vector_operations_internal.h.

◆ small_array

template<typename Operation , typename ResultType >
ResultType internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::small_array[threshold_array_allocate]

Definition at line 1392 of file vector_operations_internal.h.

◆ large_array

template<typename Operation , typename ResultType >
std::vector<ResultType> internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::large_array

Definition at line 1393 of file vector_operations_internal.h.

◆ array_ptr

template<typename Operation , typename ResultType >
ResultType* internal::VectorOperations::TBBReduceFunctor< Operation, ResultType >::array_ptr
mutable

Definition at line 1396 of file vector_operations_internal.h.


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