Reference documentation for deal.II version 9.6.0
|
#include <deal.II/base/parallel.h>
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 |
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.
|
virtualdefault |
Destructor. Made virtual to ensure that derived classes also have virtual destructors.
|
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 743 of file parallel.h.
|
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::AlignedVectorCopyConstruct< T >, internal::AlignedVectorDefaultInitialize< T, initialize_memory >, internal::AlignedVectorInitialize< T, initialize_memory >, and internal::AlignedVectorMoveConstruct< T >.