| 1 |
#+TITLE: MueLu aggregation |
| 2 |
#+AUTHOR: Andrey Prokopenko |
| 3 |
#+EMAIL: [email protected] |
| 4 |
#+DATE: 06 Nov 2013 |
| 5 |
#+LATEX_HEADER: \usepackage{listings} |
| 6 |
#+LATEX_HEADER: \usepackage{color} |
| 7 |
#+LATEX_HEADER: \usepackage{enumerate} |
| 8 |
#+LaTeX_HEADER: \usepackage[margin=0.75in]{geometry} |
| 9 |
#+LATEX_HEADER: \setlength{\parindent}{0} |
| 10 |
|
| 11 |
* Motivation |
| 12 |
* Goals |
| 13 |
|
| 14 |
- Better aggregation |
| 15 |
|
| 16 |
In order to be sure that we improve things, we need some |
| 17 |
metrics. However, it is not obvious which ones are most |
| 18 |
important. Particularly, how does having smaller/larger aggregates |
| 19 |
effects setup and solve times. |
| 20 |
|
| 21 |
Some info we can easily gather: |
| 22 |
- Number of aggregates |
| 23 |
- Distribution of the number of points in aggregates (is it Gaussian?) |
| 24 |
- Number of aggregates with distance-2 or more neighbors |
| 25 |
- |
| 26 |
|
| 27 |
|
| 28 |
* Current implementation |
| 29 |
|
| 30 |
** MueLu uncoupled aggregation |
| 31 |
|
| 32 |
The =UncoupledAggregationFactory= is mainly a vector/list of |
| 33 |
algorithms (see below). It is responsible for the parameter handling |
| 34 |
(but we could/should move this into the different aggregation |
| 35 |
algorithms!) and the preparation of the input for the algorithms |
| 36 |
(e.g. marking the boundary nodes, etc...). |
| 37 |
|
| 38 |
First, the =UncoupledAggregationRoutine= generates an empty |
| 39 |
=Aggregates= object (using the amalgamated graph that is provided by |
| 40 |
the =CoalesceDropFactory=). Then the =aggStat= array (of type |
| 41 |
=Teuchos::RCP<unsigned int>=) is generated. Initially, all entries are |
| 42 |
set to =READY=. Then some nodes (the information comes from the graph |
| 43 |
object) are changed from =READY= to =BOUNDARY=. If there are some maps |
| 44 |
provided for =OnePtNodes= and =SmallAggregates=, the corresponding |
| 45 |
entries in =aggStat= are set to =SMALLAG= and =ONEPT=. The ordering is |
| 46 |
important: first all node entries are set to =READY= or |
| 47 |
=BOUNDARY=. Then some nodes are overwritten with =SMALLAGG= and in a |
| 48 |
last step with =ONEPT=. In the end the =aggStats= array has entries |
| 49 |
with =READY=, =BOUNDARY=, and maybe =SMALLAGG= and =ONEPT=. |
| 50 |
|
| 51 |
+ *NOTE 1* |
| 52 |
|
| 53 |
Both small aggregate map and one point map are based on row |
| 54 |
GIDs. This means that we have an extra translation (node GID -> row |
| 55 |
GID) inside. In the current version of code this is done not using |
| 56 |
=AmalgamationFactory= and is incorrect (no Strided maps info) and |
| 57 |
slow (getting map every time??): |
| 58 |
#+BEGIN_SRC CPP |
| 59 |
GO grid = (graph->GetDomainMap()->getGlobalElement(i)-indexBase) * nDofsPerNode + indexBase; |
| 60 |
#+END_SRC |
| 61 |
|
| 62 |
+ *NOTE 2* |
| 63 |
|
| 64 |
The =BOUNDARY= status of a node is set in the factory, but they are |
| 65 |
detected by the =CoalesceAndDropFactory=, and stored in a map that |
| 66 |
is given to the =Graph= object. The =UncoupledAggregationFactory= |
| 67 |
checks whether there is boundary node information stored within the |
| 68 |
=Graph= object and then initializes the corresponding =aggStat= |
| 69 |
entries with =BOUNDARY=. |
| 70 |
|
| 71 |
Then, the =UncoupledAggregationFactory= just builds the aggregates by |
| 72 |
calling the specific =BuildAggregates= routine for each aggregation |
| 73 |
algorithm. Within the aggregation algorithms the =Aggregates= object is |
| 74 |
filled and the status of each node in is tracked in the =aggStat= |
| 75 |
array. In the end, all nodes have the =AGGREGATED= status in the |
| 76 |
=aggStat= array. The ordering of the aggregation algorithms is as |
| 77 |
follows: |
| 78 |
|
| 79 |
*** =OnePtAlgorithm= |
| 80 |
|
| 81 |
The =UncoupledAggregationFactory= allows to define a DOF map whose |
| 82 |
corresponding nodes shall be transferred one-to-one to the coarsest |
| 83 |
level. For the corresponding nodes, the =aggStat= vector is set to |
| 84 |
=ONEPT=. The algorithm loops over all nodes and builds |
| 85 |
one-point aggregates for all nodes with status =ONEPT=. The |
| 86 |
status of the =ONEPT= nodes is then changed to |
| 87 |
=AGGREGATED=. |
| 88 |
|
| 89 |
*** =SmallAggregationAlgorithm= |
| 90 |
|
| 91 |
The =SmallAggregationAlgorithm= works similar as the |
| 92 |
=OnePtAlgorithm=. The =UncoupledAggregationFactory= allows to define |
| 93 |
a DOF map whose corresponding nodes are set to =SMALLAGG=. Then all |
| 94 |
these =SMALLAGG= nodes are aggregated. There are no restrictions for |
| 95 |
the aggregates (no minimum size, ...) except that only nodes with the |
| 96 |
=SMALLAGG= status can be aggregated (and only if they are |
| 97 |
neighbours). |
| 98 |
|
| 99 |
It's currently not used/necessary. The idea was to be able to build |
| 100 |
aggregates in specific regions (e.g. at the contact interface only |
| 101 |
in a structural contact problem). |
| 102 |
|
| 103 |
After =the OnePtAggregationAlgorithm= and the |
| 104 |
=SmallAggAggregationAlgorithm= all nodes which had the status |
| 105 |
=ONEPT= or =SMALLAGG= have now the status =AGGREGATED=. |
| 106 |
|
| 107 |
*** =UncoupledAggregationAlgorithm= |
| 108 |
|
| 109 |
This is the main aggregation algorithm and does basically the same |
| 110 |
as the =LocalAggregationAlgorithm= in the =CoupledAggregation= |
| 111 |
framework! |
| 112 |
|
| 113 |
In principle it's just a loop over all nodes. For each node we check |
| 114 |
all neighbour nodes if they have the status =READY= or =NOTSEL=. Then we |
| 115 |
put all these nodes together to a tentative new aggregate. The |
| 116 |
aggregate is only accepted if it has at least =MinNodesPerAggregate= |
| 117 |
nodes and the number of neighbour nodes, which are already |
| 118 |
aggregated in other aggregates is not above |
| 119 |
=MaxNeighAlreadySelected=. |
| 120 |
|
| 121 |
+ *COMMENT 1* |
| 122 |
|
| 123 |
Parameter =MinNodesPerAggregate= is the problematic |
| 124 |
one. If it's too big (i.e. less neighbours than |
| 125 |
=MinNodesPerAggregate=), then nothing is happening in the |
| 126 |
=UncoupledAggregationAlgorithm=. |
| 127 |
|
| 128 |
+ *NOTE 1* |
| 129 |
|
| 130 |
Parameter =MaxNeighAlreadySelected= is meant to |
| 131 |
build aggregates that are not too close to each other. The |
| 132 |
=MaxLinkAggregationAlgorithm= then can add the in between nodes to the |
| 133 |
aggregates. |
| 134 |
|
| 135 |
Altogether we then obtain bigger aggregates. If the aggregate is not |
| 136 |
accepted, the current node for building the aggregate around itself |
| 137 |
is set to =NOTSEL=. That means, the node shall not be root node for |
| 138 |
an aggregate. It can be added to another aggregate later as a |
| 139 |
neighbour to some root node. |
| 140 |
|
| 141 |
The option "ordering" defines how we loop over all nodes. The |
| 142 |
options are =NATURAL= (follow the numbering of the nodes), =GRAPH= |
| 143 |
(start with one node and then proceed with all it's direct |
| 144 |
neighbours) and =RANDOM= (randomly pick out the next non-aggregated |
| 145 |
node). |
| 146 |
|
| 147 |
#+BEGIN_COMMENT |
| 148 |
+ *COMMENT (AP)* |
| 149 |
|
| 150 |
My intuition tells me that we can probably get rid of |
| 151 |
=MinNodesPerAggregate= and replace it by a dynamic value without |
| 152 |
significantly worsening the aggregation. For instance, something |
| 153 |
like "The aggregate is accepted if the number of nodes in it is |
| 154 |
larger or equal to the average of number of connections for neighbor |
| 155 |
points", or "The aggregate is accepted if it is of the maximal size |
| 156 |
for all neighbor points". Or something similar (we'll need to play |
| 157 |
with it). I would really prefer some dynamic metric, which should |
| 158 |
work much better for unstructured meshes than the static value. One |
| 159 |
use case that comes to mind is when you use different kind of FEM in |
| 160 |
different parts of your domain. You want your aggregation to be able |
| 161 |
to capture the changing connectivity structure. |
| 162 |
|
| 163 |
+ *COMMENT (TW)* |
| 164 |
|
| 165 |
It would be nice if the user would have at least a rough way |
| 166 |
to control the size of the aggregates. E.g. for aggressive |
| 167 |
coarsening one would like to have extremely big aggregates or for |
| 168 |
very complicated problems the user has to choose rather small |
| 169 |
aggregates and use more multigrid levels which tackle more |
| 170 |
different modes. |
| 171 |
|
| 172 |
+ *COMMENT (AP)* |
| 173 |
|
| 174 |
We could try to manage that by using hops. For instance, the |
| 175 |
standard version is to select a root node, and aggregate all nodes |
| 176 |
within one hop of it, which are neighbor nodes. User could specify |
| 177 |
to use two hops, which is a more aggressive setting, in which case |
| 178 |
we also add neighbors of neighbors. I'm not sure, however, that |
| 179 |
this is the right approach, as the aggregates' shapes will |
| 180 |
probably very distorted at the later stage. |
| 181 |
#+END_COMMENT |
| 182 |
|
| 183 |
*** =MaxLinkAggregationAlgorithm= |
| 184 |
|
| 185 |
The =MaxLinkAggregationAlgorithm= loops over all nodes and picks out |
| 186 |
the non-aggregated nodes (with status different to =AGGREGATED=). For |
| 187 |
each non-aggregated node it loops over all its neighbours and looks |
| 188 |
for the aggregate with the most connections to it. |
| 189 |
|
| 190 |
+ *BUG 1* |
| 191 |
|
| 192 |
Both =OnePtAlgorithm= and |
| 193 |
=SmallAggAlgorithm= mark nodes as =AGGREGATED=, so, theoretically, |
| 194 |
we could merge some unaggregated nodes with some of one-points or |
| 195 |
small aggregates, which is _not_ what we want. |
| 196 |
|
| 197 |
+ *BUG 2* |
| 198 |
|
| 199 |
It also loops through all nodes. At this point, some nodes |
| 200 |
may still be =BOUNDARY=, so if boundary nodes are not isolated, |
| 201 |
they are merged into existing aggregates. |
| 202 |
|
| 203 |
*** =PreserveDirichletAggregationAlgorithm= |
| 204 |
|
| 205 |
For some applications, it's necessary to preserve Dirichlet |
| 206 |
boundaries on the the coarse level. In this case, we use this |
| 207 |
factory to aggregate =BOUNDARY= and isolated nodes into 1-point |
| 208 |
aggregates to transfer 1-to-1 to the coarse level. Per default this |
| 209 |
factory is off (i.e. not used unless the user requests it in the |
| 210 |
parameter list of the =UncoupledAggregationFactory=). The default |
| 211 |
behaviour is to use the =IsolatedNodeAggregationAlgorithm= to mark |
| 212 |
those nodes to be aggregated without building an aggregate for them. |
| 213 |
|
| 214 |
*** =IsolatedNodeAggregationAlgorithm= |
| 215 |
|
| 216 |
For all =BOUNDARY= and isolated nodes (node without any neighbour), |
| 217 |
it marks the node as =AGGREGATED= without building an |
| 218 |
aggregate. This way isolated nodes are just dropped. |
| 219 |
|
| 220 |
*** =EmergencyAggregationAlgorithm= |
| 221 |
|
| 222 |
The =EmergencyAggregationAlgorithm= just loops over all nodes and |
| 223 |
tries to put all non-aggregated left over nodes into small |
| 224 |
aggregates. |
| 225 |
|
| 226 |
+ *QUESTION* |
| 227 |
|
| 228 |
Does it actually do anything? It is run after =MaxLinkAggregationAlgorithm=. |
| 229 |
|
| 230 |
** MueLu coupled aggregation |
| 231 |
|
| 232 |
=CoupledAggregationFactory= consists of two stages with a separate |
| 233 |
algorithm for each. |
| 234 |
|
| 235 |
*** =LocalAggregationAlgorithm= |
| 236 |
|
| 237 |
Same as =UncoupledAggregationAlgorithm=, except |
| 238 |
|
| 239 |
- Uses slightly different internal structures (=MueLu_SuperNode=) |
| 240 |
- Has only three node states (=READY=, =NOTSEL=, =SELECTED=) |
| 241 |
|
| 242 |
*** =LeftOverAggregationAlgorithm= |
| 243 |
|
| 244 |
This algorithm is needed to take care of vertices that are left over after |
| 245 |
creating a bunch of ideal aggregates (root plus immediate neighbors). |
| 246 |
|
| 247 |
On input, the structure =Aggregates= describes already aggregated |
| 248 |
vertices. The field =procWinners= indicates the processor owning the |
| 249 |
aggregate to which a vertex is "definitively" assigned. If on entry |
| 250 |
~procWinners[i] == MUELU_UNASSIGNED~, =ArbitrateAndCommunicate()= will |
| 251 |
arbitrate and decide which processor's aggregate really has the |
| 252 |
vertex. If only one processor claims ownership (as in the uncoupled |
| 253 |
case), no real arbitration is needed. Otherwise, random arbitration is |
| 254 |
done. |
| 255 |
|
| 256 |
The stage consists of several phases: |
| 257 |
**** Phase 1b |
| 258 |
|
| 259 |
Invoke =ArbitrateAndCommunicate()= to ensure that all processors have |
| 260 |
the same view of aggregated vertices (e.g., to which aggregate they |
| 261 |
have been assigned and which processor owns that aggregate). |
| 262 |
|
| 263 |
Root nodes have weight 2, regular assigned nodes have |
| 264 |
weight 1. Therefore, root nodes are always assigned to the same |
| 265 |
processor. |
| 266 |
|
| 267 |
**** Phase 2 |
| 268 |
|
| 269 |
Check for vertices (local or nonlocal) which are adjacent |
| 270 |
to root nodes. Tentatively assign these to the aggregate |
| 271 |
associated with the root. Arbitrate any cases where |
| 272 |
several processors claim the same vertex for one of |
| 273 |
their aggregates via =ArbitrateAndCommunicate()=. |
| 274 |
|
| 275 |
**** Phase 3 |
| 276 |
|
| 277 |
Try to create new aggregates if it looks like there are |
| 278 |
root node candidates which have many unaggregated neighbors. |
| 279 |
This decision to make a new aggregate is based on only local |
| 280 |
information. However, the new aggregate will be tentatively |
| 281 |
assigned any unaggregated ghost vertices. Arbitration is again |
| 282 |
done by =ArbitrateAndCommunicate()=, where local vertices |
| 283 |
use a ~weight = 2~ and ghost vertices have ~weight = 1~. |
| 284 |
The basic idea is that after arbitration, each aggregate |
| 285 |
is guaranteed to keep all local vertices assigned in |
| 286 |
this phase. Thus, by basing the aggregation creation logic |
| 287 |
on local information, we are guaranteed to have a sufficiently |
| 288 |
large aggregation. The only local vertices that might be |
| 289 |
assigned to another processor's aggregates are unclaimed |
| 290 |
during this phase of the aggregation. |
| 291 |
|
| 292 |
+ *QUESTION* |
| 293 |
|
| 294 |
Does this phase do anything? Is it actually possible to find |
| 295 |
aggregates that have enough (>= =MinNodesPerAggregate=) local nodes? |
| 296 |
Those should have been gone after first (uncoupled) phase. |
| 297 |
|
| 298 |
+ *ANSWER* |
| 299 |
|
| 300 |
It is possible. First phase contains an extra criterium beside |
| 301 |
=MinNodesPerAggregate=: =MaxNeighAlreadySelected=. |
| 302 |
|
| 303 |
**** Phase 4 (EXPERIMENTAL) |
| 304 |
|
| 305 |
**** Phase 5 |
| 306 |
|
| 307 |
Sweep new points into existing aggregates. Each processor tries |
| 308 |
to assign any (whether it is a ghost or local) unaggregated |
| 309 |
vertex that it has to an aggregate that it owns. In other words, |
| 310 |
processor $p$ attempts to assign vertex $v$ to aggregate $y$ where |
| 311 |
$y$ is owned by $p$ but $v$ may be a ghost vertex (and so really |
| 312 |
assigned to another processor). Deciding which aggregate |
| 313 |
a vertex is assigned to is done by scoring. Roughly, we want |
| 314 |
- larger scores for $y$ if $v$ is close (graph distance) to $y$'s |
| 315 |
root; |
| 316 |
- larger scores for $y$ if $v$ has direct connections to several |
| 317 |
different vertices already assigned to $y$; |
| 318 |
- lower scores for $y$ if several vertices have already been swept |
| 319 |
into $y$ during this phase. |
| 320 |
|
| 321 |
Some care must be taken for vertices that are shared (either local |
| 322 |
vertices that are sent to other processors or ghost vertices) in that |
| 323 |
each processor sharing the vertex will attempt to assign it to |
| 324 |
different aggregates. =ArbitrateAndCommunicate()= is again used for |
| 325 |
arbitration with the score being given as the weight. |
| 326 |
|
| 327 |
The main tricky thing occurs when $v$ is tentatively added to $y$. |
| 328 |
When assigning $v'$ to $y$, the assumed connection with $v$ should not |
| 329 |
be the sole basis of this decision if there is some chance that $v$ |
| 330 |
might be lost in arbitration. This could actually lead to $v'$ being |
| 331 |
disconnected from the rest of the aggregate. This is by building a |
| 332 |
list of shared ids and checking that there is at least one vertex in |
| 333 |
the scoring that is either not shared or has already been definitively |
| 334 |
assigned to this processor's aggregate (i.e. have been assigned to a |
| 335 |
local aggregate and have been through arbitration). |
| 336 |
|
| 337 |
Scoring is done by first giving a mark to vertices that have been |
| 338 |
already been assigned to aggregates. This mark essentially |
| 339 |
reflects the distance of this point to the root. Specifically, |
| 340 |
|
| 341 |
- if $v$ was assigned to an aggregate prior to this phase: |
| 342 |
|
| 343 |
$mark(v) \leftarrow \texttt{MUELU\_DISTONE\_VERTEX\_WEIGHT}$ |
| 344 |
|
| 345 |
- otherwise: |
| 346 |
|
| 347 |
$mark(v) \leftarrow max(mark(v_k))/2$, |
| 348 |
|
| 349 |
where $max(mark(v_k))$ considers all vertices definitively |
| 350 |
assigned to $y$ that have direct connections to $v$. |
| 351 |
|
| 352 |
|
| 353 |
Finally, |
| 354 |
|
| 355 |
$score(\tilde{v},y) \leftarrow \Sigma(mark(\hat{v}_k)) - \texttt{AggregateIncrementPenalty}$, |
| 356 |
|
| 357 |
where $\tilde{v}$ is an unaggregated vertex being considered for |
| 358 |
assignment in aggregate $y$ and $\hat{v}_k$ are all vertices in $y$ |
| 359 |
with a direct connection to $\tilde{v}$. =AggregateIncrementPenalty= |
| 360 |
is equal to |
| 361 |
|
| 362 |
$\max(\texttt{INCR\_SCALING}*NNewVtx, \Sigma(mark(\hat{v}_k))*(1-\texttt{MUELU\_PENALTYFACTOR}))$, |
| 363 |
|
| 364 |
where $NNewVtx$ is the number of phase 5 vertices already assigned to |
| 365 |
$y$. |
| 366 |
|
| 367 |
One last wrinkle, is that we have wrapped the whole scoring/assigning |
| 368 |
of vertices inside a big loop that looks something like |
| 369 |
|
| 370 |
#+BEGIN_SRC CPP |
| 371 |
for (Threshold = big; Threshold >= 0; Reduce(Threshold)); |
| 372 |
#+END_SRC |
| 373 |
|
| 374 |
New vertices are swept into aggregates only if their best score is >= |
| 375 |
a Threshold. This encourages only very good vertices to be assigned |
| 376 |
first followed by somewhat less well connected ones in later |
| 377 |
iterations of the loop. It also helps minimize the number of |
| 378 |
exclusions that would occur to address the issue mentioned above where |
| 379 |
we don't want to make assignment decisions based on connections to |
| 380 |
vertices that might be later lost in arbitration. |
| 381 |
|
| 382 |
**** Phase 6 |
| 383 |
|
| 384 |
Aggregate remaining vertices and avoid small aggregates (e.g., |
| 385 |
singletons) at all costs. Typically, most everything should be |
| 386 |
aggregated by Phases 1-5. One way that we could still have |
| 387 |
unaggregated vertices is if processor $p$ was never assigned a root |
| 388 |
node (perhaps because the number of local vertices on p is less than |
| 389 |
=minNodesPerAggregate=) and additionally $p$ has local ids which are |
| 390 |
not shared with any other processors (so that no other processor's |
| 391 |
aggregate can claim these vertices). |
| 392 |
|
| 393 |
Phase 6 looks at the first unassigned vertex and all of its local |
| 394 |
unassigned neighbors and makes a new aggregate. If this aggregate has |
| 395 |
at least =minNodesPerAggregate= vertices, we continue this process of |
| 396 |
creating new aggregates by examining other unassigned vertices. If the |
| 397 |
new aggregate is too small, we try add the next unassigned vertex and |
| 398 |
its neighbors to the same newly created aggregate. Once again, we |
| 399 |
check the size of this new aggregate to decide whether other |
| 400 |
unassigned vertices should be added to this aggregate or used to |
| 401 |
create a new aggregate. If the last newly created aggregate (of |
| 402 |
course there may be just one newly created aggregate) is too small, we |
| 403 |
then see if there is at least one other aggregate that this processor |
| 404 |
owns. If so, we merge the small newly created aggregate with |
| 405 |
aggregate 0. If not, we accept the fact that a small aggregate has |
| 406 |
been created. |
| 407 |
|
| 408 |
|
| 409 |
One final note about the use of =ArbitrateAndCommunicate()=. No |
| 410 |
arbitration occurs (which means the =procWinner[]= is not set as well) |
| 411 |
for a global shared id if and only if all weights on all processors |
| 412 |
corresponding to this id is zero. Thus, the general idea is that any |
| 413 |
global id where we want arbitration to occur should have at least one |
| 414 |
associated weight on one processor which is nonzero. Any global id |
| 415 |
where we don't want any arbitration should have all weights set to 0. |
| 416 |
|
| 417 |
*NOTE* =procWinners= is also set to =MyPid()= by |
| 418 |
=ArbitrateAndCommunicate()= for any nonshared gid's with a nonzero |
| 419 |
weight. |
| 420 |
|
| 421 |
|
| 422 |
*** =CoupledAggregationCommHelper= |
| 423 |
|
| 424 |
* Proposal |