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\}}\)
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
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

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 1262 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 1266 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 1308 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 1318 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 1264 of file vector_operations_internal.h.

◆ op

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

Definition at line 1331 of file vector_operations_internal.h.

◆ start

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

Definition at line 1332 of file vector_operations_internal.h.

◆ end

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

Definition at line 1333 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 1335 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 1336 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 1337 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 1338 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 1341 of file vector_operations_internal.h.


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