Debian Codegraph @

examples/step-50/doc/intro.dox

raw
1 <i>
2 This program was contributed by Thomas C. Clevenger and Timo Heister.
3 <br>
4 This material is based upon work partly supported by the National
5 Science Foundation Award DMS-2028346, OAC-2015848, EAR-1925575, by the Computational
6 Infrastructure in Geodynamics initiative (CIG), through the NSF under Award
7 EAR-0949446 and EAR-1550901 and The University of California -- Davis.
8 </i>
9
10 @dealiiTutorialDOI{10.5281/zenodo.4004166,https://zenodo.org/badge/DOI/10.5281/zenodo.4004166.svg}
11
12 @note As a prerequisite of this program, you need to have both p4est and either the PETSc
13 or Trilinos library installed. The installation of deal.II together with these additional
14 libraries is described in the <a href="../../readme.html" target="body">README</a> file.
15
16
17 <a name="step_50-Intro"></a>
18 <h1>Introduction</h1>
19
20
21 This example shows the usage of the multilevel functions in deal.II on
22 parallel, distributed
23 meshes and gives a comparison between geometric and algebraic multigrid methods.
24 The algebraic multigrid (AMG) preconditioner is the same used in step-40. Two geometric
25 multigrid (GMG) preconditioners are considered: a matrix-based version similar to that
26 in step-16 (but for parallel computations) and a matrix-free version
27 discussed in step-37. The goal is to find out which approach leads to
28 the best solver for large parallel computations.
29
30 This tutorial is based on one of the numerical examples in
31 @cite clevenger_par_gmg. Please see that publication for a detailed background
32 on the multigrid implementation in deal.II. We will summarize some of the
33 results in the following text.
34
35 Algebraic multigrid methods are obviously the easiest to implement
36 with deal.II since classes such as TrilinosWrappers::PreconditionAMG
37 and PETScWrappers::PreconditionBoomerAMG are, in essence, black box
38 preconditioners that require only a couple of lines to set up even for
39 parallel computations. On the other hand, geometric multigrid methods
40 require changes throughout a code base -- not very many, but one has
41 to know what one is doing.
42
43 What the results of this program will show
44 is that algebraic and geometric multigrid methods are roughly
45 comparable in performance <i>when using matrix-based formulations</i>,
46 and that matrix-free geometric multigrid methods are vastly better for
47 the problem under consideration here. A secondary conclusion will be
48 that matrix-based geometric multigrid methods really don't scale well
49 strongly when the number of unknowns per processor becomes smaller than
50 20,000 or so.
51
52
53 <h3>The testcase</h3>
54
55 We consider the variable-coefficient Laplacian weak formulation
56 @f{align*}{
57 (\epsilon \nabla u, \nabla v) = (f,v) \quad \forall v \in V_h
58 @f}
59 on the domain $\Omega = [-1,1]^\text{dim} \setminus [0,1]^\text{dim}$ (an L-shaped domain
60 for 2D and a Fichera corner for 3D) with $\epsilon = 1$ if $\min(x,y,z)>-\frac{1}{2}$ and
61 $\epsilon = 100$ otherwise. In other words, $\epsilon$ is small along the edges
62 or faces of the domain that run into the reentrant corner, as will be visible
63 in the figure below.
64
65 The boundary conditions are $u=0$ on the whole boundary and
66 the right-hand side is $f=1$. We use continuous $Q_2$ elements for the
67 discrete finite element space $V_h$, and use a
68 residual-based, cell-wise a posteriori error estimator
69 $e(K) = e_{\text{cell}}(K) + e_{\text{face}}(K)$ from @cite karakashian2003posteriori with
70 @f{align*}{
71 e_{\text{cell}}(K) &= h^2 \| f + \epsilon \triangle u \|_K^2, \\
72 e_{\text{face}}(K) &= \sum_F h_F \| \jump{ \epsilon \nabla u \cdot n } \|_F^2,
73 @f}
74 to adaptively refine the mesh. (This is a generalization of the Kelly
75 error estimator used in the KellyErrorEstimator class that drives mesh
76 refinement in most of the other tutorial programs.)
77 The following figure visualizes the solution and refinement for 2D:
78 <img width="400px" src="https://www.dealii.org/images/steps/developer/step-50-2d-solution.png" alt="">
79 In 3D, the solution looks similar (see below). On the left you can see the solution and on the right we show a slice for $x$ close to the
80 center of the domain showing the adaptively refined mesh.
81 <table width="60%" align="center">
82 <tr>
83 <td align="center">
84 <img width="400px" src="https://www.dealii.org/images/steps/developer/step-50-3d-solution.png" alt="">
85 </td>
86 <td align="center">
87 <img width="400px" src="https://www.dealii.org/images/steps/developer/step-50-refinement.png" alt="">
88 </td>
89 </tr>
90 </table>
91 Both in 2D and 3D you can see the adaptive refinement picking up the corner singularity and the inner singularity where the viscosity jumps, while the interface along the line that separates the two viscosities is (correctly) not refined as it is resolved adequately.
92 This is because the kink in the solution that results from the jump
93 in the coefficient is aligned with cell interfaces.
94
95
96 <h3>Workload imbalance for geometric multigrid methods</h3>
97
98 As mentioned above, the purpose of this program is to demonstrate the
99 use of algebraic and geometric multigrid methods for this problem, and
100 to do so for parallel computations. An important component of making
101 algorithms scale to large parallel machines is ensuring that every
102 processor has the same amount of work to do. (More precisely, what
103 matters is that there are no small fraction of processors that have
104 substantially more work than the rest since, if that were so, a large
105 fraction of processors will sit idle waiting for the small fraction to
106 finish. Conversely, a small fraction of processors having
107 substantially <i>less</i> work is not a problem because the majority
108 of processors continues to be productive and only the small fraction
109 sits idle once finished with their work.)
110
111 For the active mesh, we use the parallel::distributed::Triangulation class as done
112 in step-40 which uses functionality in the external library
113 <a href="http://www.p4est.org/">p4est</a> for the distribution of the active cells
114 among processors. For the non-active cells in the multilevel hierarchy, deal.II
115 implements what we will refer to as the "first-child rule" where, for each cell
116 in the hierarchy, we recursively assign the parent of a cell to the owner of the
117 first child cell. The following figures give an example of such a distribution. Here
118 the left image represents the active cells for a sample 2D mesh partitioned using a
119 space-filling curve (which is what p4est uses to partition cells);
120 the center image gives the tree representation
121 of the active mesh; and the right image gives the multilevel hierarchy of cells. The
122 colors and numbers represent the different processors. The circular nodes in the tree
123 are the non-active cells which are distributed using the "first-child rule".
124
125 <img width="800px" src="https://www.dealii.org/images/steps/developer/step-50-workload-example.png" alt="">
126
127 Included among the output to screen in this example is a value "Partition efficiency"
128 given by one over MGTools::workload_imbalance(). This value, which will be denoted
129 by $\mathbb{E}$, quantifies the overhead produced by not having a perfect work balance
130 on each level of the multigrid hierarchy. This imbalance is evident from the
131 example above: while level $\ell=2$ is about as well balanced as is possible
132 with four cells among three processors, the coarse
133 level $\ell=0$ has work for only one processor, and level $\ell=1$ has work
134 for only two processors of which one has three times as much work as
135 the other.
136
137 For defining $\mathbb{E}$, it is important to note that, as we are using local smoothing
138 to define the multigrid hierarchy (see the @ref mg_paper "multigrid paper" for a description of
139 local smoothing), the refinement level of a cell corresponds to that cell's multigrid
140 level. Now, let $N_{\ell}$ be the number of cells on level $\ell$
141 (both active and non-active cells) and $N_{\ell,p}$ be the subset owned by process
142 $p$. We will also denote by $P$ the total number of processors.
143 Assuming that the workload for any one processor is proportional to the number
144 of cells owned by that processor, the optimal workload per processor is given by
145 @f{align*}{
146 W_{\text{opt}} = \frac1{P}\sum_{\ell} N_{\ell} = \sum_{\ell}\left(\frac1{P}\sum_{p}N_{\ell,p}\right).
147 @f}
148 Next, assuming a synchronization of work on each level (i.e., on each level of a V-cycle,
149 work must be completed by all processors before moving on to the next level), the
150 limiting effort on each level is given by
151 @f{align*}{
152 W_\ell = \max_{p} N_{\ell,p},
153 @f}
154 and the total parallel complexity
155 @f{align*}{
156 W = \sum_{\ell} W_\ell.
157 @f}
158 Then we define $\mathbb{E}$ as a ratio of the optimal partition to the parallel
159 complexity of the current partition
160 @f{align*}{
161 \mathbb{E} = \frac{W_{\text{opt}}}{W}.
162 @f}
163 For the example distribution above, we have
164 @f{align*}{
165 W_{\text{opt}}&=\frac{1}{P}\sum_{\ell} N_{\ell} = \frac{1}{3} \left(1+4+4\right)= 3 \qquad
166 \\
167 W &= \sum_\ell W_\ell = 1 + 2 + 3 = 6
168 \\
169 \mathbb{E} &= \frac{W_{\text{opt}}}{W} = \frac12.
170 @f}
171 The value MGTools::workload_imbalance()$= 1/\mathbb{E}$ then represents the factor increase
172 in timings we expect for GMG methods (vmults, assembly, etc.) due to the imbalance of the
173 mesh partition compared to a perfectly load-balanced workload. We will
174 report on these in the results section below for a sequence of meshes,
175 and compare with the observed slow-downs as we go to larger and larger
176 processor numbers (where, typically, the load imbalance becomes larger
177 as well).
178
179 These sorts of considerations are considered in much greater detail in
180 @cite clevenger_par_gmg, which contains a full discussion of the partition efficiency model
181 and the effect the imbalance has on the GMG V-cycle timing. In summary, the value
182 of $\mathbb{E}$ is highly dependent on the degree of local mesh refinement used and has
183 an optimal value $\mathbb{E} \approx 1$ for globally refined meshes. Typically for adaptively
184 refined meshes, the number of processors used to distribute a single mesh has a
185 negative impact on $\mathbb{E}$ but only up to a leveling off point, where the imbalance
186 remains relatively constant for an increasing number of processors, and further refinement
187 has very little impact on $\mathbb{E}$. Finally, $1/\mathbb{E}$ was shown to give an
188 accurate representation of the slowdown in parallel scaling expected for the timing of
189 a V-cycle.
190
191 It should be noted that there is potential for some asynchronous work between multigrid
192 levels, specifically with purely nearest neighbor MPI communication, and an adaptive mesh
193 could be constructed such that the efficiency model would far overestimate the V-cycle slowdown
194 due to the asynchronous work "covering up" the imbalance (which assumes synchronization over levels).
195 However, for most realistic adaptive meshes the expectation is that this asynchronous work will
196 only cover up a very small portion of the imbalance and the efficiency model will describe the
197 slowdown very well.
198
199
200 <h3>Workload imbalance for algebraic multigrid methods</h3>
201
202 The considerations above show that one has to expect certain limits on
203 the scalability of the geometric multigrid algorithm as it is implemented in deal.II because even in cases
204 where the finest levels of a mesh are perfectly load balanced, the
205 coarser levels may not be. At the same time, the coarser levels are
206 weighted less (the contributions of $W_\ell$ to $W$ are small) because
207 coarser levels have fewer cells and, consequently, do not contribute
208 to the overall run time as much as finer levels. In other words,
209 imbalances in the coarser levels may not lead to large effects in the
210 big picture.
211
212 Algebraic multigrid methods are of course based on an entirely
213 different approach to creating a hierarchy of levels. In particular,
214 they create these purely based on analyzing the system matrix, and
215 very sophisticated algorithms for ensuring that the problem is well
216 load-balanced on every level are implemented in both the hypre and
217 ML/MueLu packages that underly the TrilinosWrappers::PreconditionAMG
218 and PETScWrappers::PreconditionBoomerAMG classes. In some sense, these
219 algorithms are simpler than for geometric multigrid methods because
220 they only deal with the matrix itself, rather than all of the
221 connotations of meshes, neighbors, parents, and other geometric
222 entities. At the same time, much work has also been put into making
223 algebraic multigrid methods scale to very large problems, including
224 questions such as reducing the number of processors that work on a
225 given level of the hierarchy to a subset of all processors, if
226 otherwise processors would spend less time on computations than on
227 communication. (One might note that it is of course possible to
228 implement these same kinds of ideas also in geometric multigrid
229 algorithms where one purposefully idles some processors on coarser
230 levels to reduce the amount of communication. deal.II just doesn't do
231 this at this time.)
232
233 These are not considerations we typically have to worry about here,
234 however: For most purposes, we use algebraic multigrid methods as
235 black-box methods.
236
237
238
239 <h3>Running the program</h3>
240
241 As mentioned above, this program can use three different ways of
242 solving the linear system: matrix-based geometric multigrid ("MB"),
243 matrix-free geometric multigrid ("MF"), and algebraic multigrid
244 ("AMG"). The directory in which this program resides has input files
245 with suffix `.prm` for all three of these options, and for both 2d and
246 3d.
247
248 You can execute the program as in
249 @code
250 ./step-50 gmg_mb_2d.prm
251 @endcode
252 and this will take the run-time parameters from the given input
253 file (here, `gmg_mb_2d.prm`).
254
255 The program is intended to be run in parallel, and you can achieve
256 this using a command such as
257 @code
258 mpirun -np 4 ./step-50 gmg_mb_2d.prm
259 @endcode
260 if you want to, for example, run on four processors. (That said, the
261 program is also ready to run with, say, `-np 28672` if that's how many
262 processors you have available.)