![]() |
deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
|
Namespaces | |
| namespace | distributed |
| namespace | fullydistributed |
| namespace | internal |
| namespace | shared |
Classes | |
| class | CellWeights |
| class | DistributedTriangulationBase |
| struct | ParallelForInteger |
| class | TriangulationBase |
Functions | |
| template<typename Iterator , typename Function > | |
| void | apply_to_subranges (const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const Function &f, const unsigned int grainsize) |
| template<typename ResultType , typename Iterator , typename Function > | |
| ResultType | accumulate_from_subranges (const Function &f, const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const unsigned int grainsize) |
A namespace in which we define classes and algorithms that deal with running in parallel on shared memory machines when deal.II is configured to use multiple threads (see Parallel computing with multiple processors accessing shared memory), as well as running things in parallel on distributed memory machines (see Parallel computing with multiple processors using distributed memory).
| void parallel::apply_to_subranges | ( | const Iterator & | begin, |
| const std_cxx20::type_identity_t< Iterator > & | end, | ||
| const Function & | f, | ||
| const unsigned int | grainsize | ||
| ) |
This function applies the given function argument f to all elements in the range [begin,end) and may do so in parallel. An example of its use is given in step-69.
However, in many cases it is not efficient to call a function on each element, so this function calls the given function object on sub-ranges. In other words: if the given range [begin,end) is smaller than grainsize or if multithreading is not enabled, then we call f(begin,end); otherwise, we may execute, possibly in parallel, a sequence of calls f(b,e) where [b,e) are subintervals of [begin,end) and the collection of calls we do to f(.,.) will happen on disjoint subintervals that collectively cover the original interval [begin,end).
Oftentimes, the called function will of course have to get additional information, such as the object to work on for a given value of the iterator argument. This can be achieved by binding certain arguments. For example, here is an implementation of a matrix-vector multiplication \(y=Ax\) for a full matrix \(A\) and vectors \(x,y\):
Note how we use the lambda function to convert mat_vec_on_subranges from a function that takes 5 arguments to one taking 2 by binding the remaining arguments. The resulting function object requires only two arguments, begin_row and end_row, with all other arguments fixed.
The code, if in single-thread mode, will call mat_vec_on_subranges on the entire range [0,n_rows) exactly once. In multi-threaded mode, however, it may be called multiple times on subranges of this interval, possibly allowing more than one CPU core to take care of part of the work.
The grainsize argument (50 in the example above) makes sure that subranges do not become too small, to avoid spending more time on scheduling subranges to CPU resources than on doing actual work.
For a discussion of the kind of problems to which this function is applicable, see also the Parallel computing with multiple processors topic.
Definition at line 266 of file parallel.h.
| ResultType parallel::accumulate_from_subranges | ( | const Function & | f, |
| const Iterator & | begin, | ||
| const std_cxx20::type_identity_t< Iterator > & | end, | ||
| const unsigned int | grainsize | ||
| ) |
This function works a lot like the apply_to_subranges() function, but it allows to accumulate numerical results computed on each subrange into one number. The type of this number is given by the ResultType template argument that needs to be explicitly specified, and results are added up (i.e., the reduction of results from subranges happens by adding up these results).
An example of use of this function is to compute the value of the expression \(x^T A x\) for a square matrix \(A\) and a vector \(x\). The sum over rows can be parallelized and the whole code might look like this:
Here, mat_norm_sqr_on_subranges is called on the entire range [0,A.n_rows()) if this range is less than the minimum grainsize (above chosen as 50) or if deal.II is configured to not use multithreading. Otherwise, it may be called on subsets of the given range, with results from the individual subranges accumulated internally.
For a discussion of the kind of problems to which this function is applicable, see also the Parallel computing with multiple processors topic.
Definition at line 501 of file parallel.h.