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 | List of all members
parallel::ParallelForInteger Struct Referenceabstract

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

Inheritance diagram for parallel::ParallelForInteger:
[legend]

Public Member Functions

virtual ~ParallelForInteger ()=default
 
void apply_parallel (const std::size_t begin, const std::size_t end, const std::size_t minimum_parallel_grain_size) const
 
virtual void apply_to_subrange (const std::size_t, const std::size_t) const =0
 

Detailed Description

This is a class specialized to for loops with a fixed range given by unsigned integers. This is an abstract base class that an actual worker function is derived from. There is a public function apply that issues a for loop in parallel, subdividing the work onto available processor cores whenever there is enough work to be done (i.e., the number of elements is larger than grain_size). Inside the function, a virtual function apply_to_subrange specifying a range of two integers [lower, upper) is called which needs to be defined in a derived class.

The parallelization cases covered by this class are a subset of what is possible with the function apply_to_subranges (which also covers the case of more general iterators that might not be described by an integer range). However, for simple integer ranges one might prefer this class, like when there are many structurally similar loops, e.g., some simple copy or arithmetic operations on an array of pointers. In that case, apply_to_subranges will generate a lot of code (or rather, a lot of symbols) because it passes the long names generated by std::bind to the templated parallel for functions in TBB. This can considerably increase compile times and the size of the object code. Similarly, the incorrect use of std::bind often results in very cryptic error messages, which can be avoided by this class (only a virtual function needs to be defined in a derived class). Finally, the additional cost of a virtual function is negligible in the context of parallel functions: It is much more expensive to actually issue the work onto a thread, which in turn should be much less than the actual work done in the for loop.

Definition at line 503 of file parallel.h.

Constructor & Destructor Documentation

◆ ~ParallelForInteger()

virtual parallel::ParallelForInteger::~ParallelForInteger ( )
virtualdefault

Destructor. Made virtual to ensure that derived classes also have virtual destructors.

Member Function Documentation

◆ apply_parallel()

void parallel::ParallelForInteger::apply_parallel ( const std::size_t  begin,
const std::size_t  end,
const std::size_t  minimum_parallel_grain_size 
) const
inline

This function runs the for loop over the given range [lower,upper), possibly in parallel when end-begin is larger than the minimum parallel grain size. This function is marked const because it any operation that changes the data of a derived class will inherently not be thread-safe when several threads work with the same data simultaneously.

Definition at line 851 of file parallel.h.

◆ apply_to_subrange()

virtual void parallel::ParallelForInteger::apply_to_subrange ( const std::size_t  ,
const std::size_t   
) const
pure virtual

Virtual function for working on subrange to be defined in a derived class. This function is marked const because it any operation that changes the data of a derived class will inherently not be thread-safe when several threads work with the same data simultaneously.

Implemented in internal::AlignedVectorDefaultInitialize< T, initialize_memory >, internal::AlignedVectorSet< T, initialize_memory >, internal::AlignedVectorMove< T >, and internal::AlignedVectorCopy< T >.


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