| 1 |
#+TITLE: Coordinates GIDs in MueLu and related issues |
| 2 |
#+AUTHOR: Andrey Prokopenko |
| 3 |
#+EMAIL: [email protected] |
| 4 |
#+DATE: 27 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 |
|
| 13 |
Previously, we were experiencing severe regressions in Drekar/MueLu |
| 14 |
compared to Drekar/ML. We saw that aggregation after repartitioning |
| 15 |
became wacky. We tracked this problem to a fact that Drekar uses |
| 16 |
different GIDs for coordinates than for rows. ML does not have this |
| 17 |
problem as it always assumes that only local ids are the same, meaning |
| 18 |
that local id k in coordinates vector corresponds to local id k in |
| 19 |
rows. |
| 20 |
|
| 21 |
We need to resolve this situation. We would like user not to care |
| 22 |
about matching coordinate GIDs to GIDs in row maps, or even worse, |
| 23 |
matching coordinate GIDs to block IDs in row map, with block sizes |
| 24 |
being variable. |
| 25 |
|
| 26 |
* Scope |
| 27 |
|
| 28 |
This touches several MueLu and Xpetra components: |
| 29 |
|
| 30 |
- =StridedMap= |
| 31 |
|
| 32 |
This class encapsulates block sizes in addition to some |
| 33 |
physics-specific information |
| 34 |
|
| 35 |
- =MapExtractor= |
| 36 |
|
| 37 |
- =Matrix=, =CrsMatrixWrap=, =MatrixView= |
| 38 |
|
| 39 |
These classes are responsible for switching between point and block views |
| 40 |
|
| 41 |
- =AmalgamationFactory= and =AmalgamationInfo= |
| 42 |
|
| 43 |
These classes have some translation routines for matching nodes to |
| 44 |
degrees of freedom |
| 45 |
|
| 46 |
- Multiple =MueLu= classes using coordinates |
| 47 |
|
| 48 |
* =BrickAggregationFactory=, =CoalesceDropFactory=, \\ |
| 49 |
=CoordinatesTransferFactory=, =RebalanceTransferFactory= |
| 50 |
|
| 51 |
Construct and use overlapped coordinates multivector |
| 52 |
|
| 53 |
* =ParameterListInterpreter= |
| 54 |
|
| 55 |
Assumes that it gets an array of pointers, and then constructs a |
| 56 |
=MultiVector= out of those |
| 57 |
|
| 58 |
* =ZoltanInterface=, =Zoltan2Interface= |
| 59 |
|
| 60 |
Need only local coordinates vector |
| 61 |
|
| 62 |
* =UserPFactory= |
| 63 |
|
| 64 |
Reads coordinates from file |
| 65 |
|
| 66 |
* Goals |
| 67 |
|
| 68 |
We want to be able to: |
| 69 |
|
| 70 |
1. Use user provided arrays with no global IDs. |
| 71 |
|
| 72 |
_Assumption_: user is responsible for making sure that index $i$ of |
| 73 |
the local coordinates array corresponds to a local block index $i$ |
| 74 |
in the local row map. |
| 75 |
|
| 76 |
2. Deal with variable block sizes. |
| 77 |
|
| 78 |
3. Have translation routines (node -> DOFs, DOF -> node) in a single |
| 79 |
place in MueLu/Xpetra. |
| 80 |
|
| 81 |
4. Construct imports only once per level if the use the same source |
| 82 |
and target maps. |
| 83 |
|
| 84 |
For instance, we construct overlapped coordinates in several |
| 85 |
places, despite the fact that the target map is often the |
| 86 |
amalgamated column map. |
| 87 |
|
| 88 |
* Current situation |
| 89 |
|
| 90 |
** Xpetra::StridedMap |
| 91 |
|
| 92 |
- =stridingInfo_= |
| 93 |
|
| 94 |
Vector containing sizes of strided blocks. For instance, for 2D |
| 95 |
Navier-Stokes it is {2,1}: 2 velocities and 1 pressure |
| 96 |
|
| 97 |
- =stridedBlockID_= |
| 98 |
|
| 99 |
Denotes which dofs are stored in the map: -1 means the full map is |
| 100 |
stored (with all strided block dofs), > -1 means the only dofs of |
| 101 |
strided block with index =stridedBlockId_= are stored. In the latter |
| 102 |
case, StridedMap behaves exactly like a regular map, and typically |
| 103 |
have gaps in GIDs corresponding to missing variables. |
| 104 |
|
| 105 |
- =offset= |
| 106 |
|
| 107 |
Offsets the minimum GID for a map. This could be done through |
| 108 |
indexBase for a single map, but would lead to errors as you cannot |
| 109 |
perform operations on objects with different indexBase. Therefore, |
| 110 |
the design was for maps to have the same indexBase, and use offsets |
| 111 |
and GIDs from 0 to something. |
| 112 |
|
| 113 |
*Tobias*: |
| 114 |
The main intention of the offset was to be able to quickly generate |
| 115 |
some maps with some offset (e.g. GIDs starting from 500 instead of |
| 116 |
zero or one). Why not using the indexBase flag? In context of |
| 117 |
blocked operators you have to generate block maps and map extractors |
| 118 |
which are basically std::vectors with a set of non-overlapping |
| 119 |
maps. For example, you wanna generate a 2x2 blocked operator from a |
| 120 |
map extractor consisting of two maps. The first maps with GIDs |
| 121 |
0...499, the second with GIDs from 500...999. |
| 122 |
|
| 123 |
Then you have to generate above maps, the first with GIDs 0...499 |
| 124 |
and the second with GIDs from 500...999, both with the same |
| 125 |
indexBase (e.g. 0). The offset flag was just meant to make it easy |
| 126 |
to generate new maps with some offset. You cannot use/mix up the |
| 127 |
index base, since then operations (matrix-vector, matrix-matrix) on |
| 128 |
the blocked operator get very complicated. E/Tpetra will complain |
| 129 |
about incompatible maps (indexBase).... |
| 130 |
|
| 131 |
*Mark*: |
| 132 |
FYI, Tpetra::Map doesn't currently let you have an index base that |
| 133 |
differs from the global minimum GID. This has been a source of |
| 134 |
confusion for a while |
| 135 |
|
| 136 |
*Tobias*: |
| 137 |
In fact, after rethinking (and gettings some sleep) i'm not so sure |
| 138 |
if we really need the offset flag. I'm living more in the Epetra |
| 139 |
world, so i was not aware of the fact, that Tpetra doesn't even |
| 140 |
allow indexBase to be different to the minimal global GID. The only |
| 141 |
place where i use it is in the BlockedCoarseMapFactory, but i don't |
| 142 |
see why we could not use indexBase instead. In fact, some time ago i |
| 143 |
myself added a unit test (BlockedCrsMatrix, |
| 144 |
EpetraMatrixMatrixMult2x1) which uses indexBase instead of offset |
| 145 |
(Epetra only) and all works fine! |
| 146 |
|
| 147 |
*Tobias*: |
| 148 |
I think i've found the reason why i introduced the offset flag |
| 149 |
again. If we have more than one DOF per node we can have different |
| 150 |
scenarios: |
| 151 |
|
| 152 |
1. Strided maps: Let's assume we have a node(!) map with GIDs 0,1,2 |
| 153 |
with 2 DOFs per node. Then the (strided) DOF map would have the |
| 154 |
GIDs 0..5 with the following node<->DOF mapping |
| 155 |
|
| 156 |
node 0 -> 0,1 DOF GIDs |
| 157 |
|
| 158 |
node 1 -> 2,3 DOF GIDs |
| 159 |
|
| 160 |
node 2 -> 4,5 DOF GIDs |
| 161 |
|
| 162 |
2. Offset: Let's assume we have a node(!) map with GIDs 0,1,2 with 2 |
| 163 |
DOFs per node and the following node<->DOF mapping (just as an |
| 164 |
example) |
| 165 |
|
| 166 |
node 0 -> 0,500 DOF GIDs |
| 167 |
|
| 168 |
node 1 -> 1,501 DOF GIDs |
| 169 |
|
| 170 |
node 2 -> 2,502 DOF GIDs |
| 171 |
|
| 172 |
In Munich we have applications for both scenarios (scenario 1 for |
| 173 |
Navier-Stokes with strided maps for velocity and pressure DOFs, |
| 174 |
scenario 2 for optimization problems with displacement DOFs and |
| 175 |
Lagrange multiplier DOFs with some offset). |
| 176 |
|
| 177 |
If we have indexBase = 1 i would expect the following GIDs for |
| 178 |
node and DOF maps: |
| 179 |
|
| 180 |
1. Strided maps: Let's assume we have a node(!) map with GIDs 1,2,3 |
| 181 |
with 2 DOFs per node. Then the (strided) DOF map would have the |
| 182 |
GIDs 1..6 with the following node<->DOF mapping |
| 183 |
|
| 184 |
node 1 -> 1,2 DOF GIDs |
| 185 |
|
| 186 |
node 2 -> 3,4 DOF GIDs |
| 187 |
|
| 188 |
node 3 -> 5,6 DOF GIDs |
| 189 |
|
| 190 |
2. Offset: Let's assume we have a node(!) map with GIDs 1,2,3 with 2 |
| 191 |
DOFs per node and the following node<->DOF mapping (just as an |
| 192 |
example) |
| 193 |
|
| 194 |
node 1 -> 1,501 DOF GIDs |
| 195 |
|
| 196 |
node 2 -> 2,502 DOF GIDs |
| 197 |
|
| 198 |
node 3 -> 3,503 DOF GIDs |
| 199 |
|
| 200 |
|
| 201 |
- =indexBase_= |
| 202 |
|
| 203 |
Standard meaning from Epetra and Tpetra |
| 204 |
|
| 205 |
This class serves dual purpose making it hard to understand. First, it |
| 206 |
incorporates block maps. Second, it incorporates physics information. |
| 207 |
|
| 208 |
*QUESTION 1*: None of the =StridedMap= constructors actually construct a |
| 209 |
map, they simply fill in internal variables. |
| 210 |
|
| 211 |
*QUESTION 2*: Constructor based on elementList uses element GIDs *only* to |
| 212 |
find out the minimum index. |
| 213 |
|
| 214 |
*QUESTION 3*: We have =StridedTpetraMap= and =StridedEpetraMap=. Why? If |
| 215 |
=StridedMap= is based on =Map= anyway, it already abstracts Tpetra and |
| 216 |
Epetra. Could we refactory the =StridedMap= so we don't need those two? |
| 217 |
It should reduce the amount of code. |
| 218 |
+ *ANSWER*: This is unnecessary, and leads to code duplication. |
| 219 |
+ *DONE*: Merge =StridedTpetraMap= and =StridedEpetraMap= |
| 220 |
|
| 221 |
*QUESTION 4*: Why do we have public constructors in =Map= and =StridedMap=? We |
| 222 |
should always use =MapFactory= and =StridedMapFactory= to to construct |
| 223 |
those objects. |
| 224 |
|
| 225 |
** Xpetra::Matrix |
| 226 |
|
| 227 |
- =viewTable_= |
| 228 |
|
| 229 |
Contains a mapping 'view name' -> =MatrixView= |
| 230 |
=MatrixView= is a simple container class containing row and column |
| 231 |
maps, and eigenvalue estimate. |
| 232 |
|
| 233 |
*QUESTION 1*: Why does view contain eigenvalue estimate? Should it not be |
| 234 |
contained in the Matrix itself? Are we talking about different |
| 235 |
meanings of $D^{-1}A$ for point and block matrices? |
| 236 |
|
| 237 |
*QUESTION 2*: Why does not =MatrixView= contain domain and range maps? |
| 238 |
+ *ANSWER*: =MatrixView= has two purely virtual functions |
| 239 |
=getRangeMap= and =getDomainMap=. The =CrsMatrixWrap= inherits |
| 240 |
=Matrix=, and defines these functions as wrappers to the underlying |
| 241 |
=CrsMatrix=. This means that range and domain maps are *always* point-wise. |
| 242 |
|
| 243 |
*QUESTION 3*: =Matrix::CreateView(label, A, transposeA, B, |
| 244 |
transposeB)= tries to do a lot of things and is prone to bugs: |
| 245 |
1 If you call =CreateView(label, null, false, B, false)=, your |
| 246 |
row map is null, and not that of =B=; |
| 247 |
2 If you call it in a point-wise manner, it uses actual point wise |
| 248 |
domain and range maps of matrix to construct a view. However, if |
| 249 |
you call it with 'StridedMap' label, it uses strided row and |
| 250 |
column maps to construct a view. This is very inconsistent. |
| 251 |
+ *ANSWER*: The only place in =MueLu= I see it being called with |
| 252 |
both A and B is in =Utils::Multiply= ML-version. All other places |
| 253 |
call it with a single matrix or with two maps. Sometimes, these |
| 254 |
maps are passed as =<matrix>.getRowMap("StridedMap")=. |
| 255 |
+ *TODO*: remove a two matrix version, leaving one matrix version intact |
| 256 |
|
| 257 |
*QUESTION 4*: We have two versions of =getRowMap=: one with no args, |
| 258 |
and the second with a label. These should be unified to one with a |
| 259 |
default argument. Same with =getColMap= |
| 260 |
|
| 261 |
*QUESTION 5*: =SetFixedBlockSize= always creates two new strided maps |
| 262 |
without checking whether we already have a proper block size. |
| 263 |
|
| 264 |
** Xpetra::CrsMatrixWrap |
| 265 |
|
| 266 |
=CrsMatrixWrap= inherits from =Matrix=. The default view is called 'point'. |
| 267 |
|
| 268 |
- =matrixData_= |
| 269 |
|
| 270 |
Contains a reference to underlying =Xpetra::CrsMatrix= object. |
| 271 |
|
| 272 |
- =finalDefaultView_= |
| 273 |
|
| 274 |
Status of the default view. Is set to true when underlying matrix |
| 275 |
is fill completed. |
| 276 |
|
| 277 |
*QUESTION 1*: Why do we have a default view here instead of the |
| 278 |
=Matrix= class? |
| 279 |
|
| 280 |
*QUESTION 2*: Same as =Matrix=, has two versions of =getRowMap= and =getColMap=. |
| 281 |
|
| 282 |
*QUESTION 3*: =removeEmptyProcessesInPlace= updates view maps for a |
| 283 |
single label, but it *must* update all labels. This becomes tricky as |
| 284 |
we need to construct new strided maps. |
| 285 |
** Xpetra::MapExtractor |
| 286 |
|
| 287 |
- |
| 288 |
|
| 289 |
** AmalgamationInfo |
| 290 |
|
| 291 |
This is a simple container class. |
| 292 |
|
| 293 |
- =nodegid2dofgids_= |
| 294 |
|
| 295 |
Translation of node GID into a set of DOF GIDs. |
| 296 |
|
| 297 |
- =gNodeIds_= |
| 298 |
|
| 299 |
Set of global GID indices for nodes. |
| 300 |
|
| 301 |
- =cntNodes_= |
| 302 |
|
| 303 |
Number of nodes on the current processor |
| 304 |
|
| 305 |
*QUESTION 1*: Why do we have =cntNodes_=? I _assume_ it is equal to |
| 306 |
=gnodeIds->size()=. If not, what is the difference, and is it related |
| 307 |
to overlap in any way? |
| 308 |
+ *ANSWER*: They are the same. The following code in |
| 309 |
=AmalgamationFactory= is the only place where we modify any of them: |
| 310 |
#+BEGIN_SRC C++ |
| 311 |
if (rowMap->isNodeGlobalElement(gDofId)) { |
| 312 |
gNodeIds->push_back(gNodeId); |
| 313 |
cnt_amalRows++; |
| 314 |
} |
| 315 |
#+END_SRC |
| 316 |
+ *DONE*: remove =cntNodes_= and fix =GetNumberOfNodes=. |
| 317 |
|
| 318 |
|
| 319 |
*QUESTION 2*: =nodegid2dofgids_= uses *very* ineffective $map$ |
| 320 |
container. This is particularly bad during construction. |
| 321 |
|
| 322 |
*QUESTION 3*: Why we have =Set= type function and all variables |
| 323 |
mutable in this class? |
| 324 |
+ *ANSWER*: There is no reason. This class is constructed once as a |
| 325 |
result of =AmalgamationFactory=. |
| 326 |
+ *DONE*: Remove all =Set= methods and replace them by a non-default |
| 327 |
constructor. This way we can also remove all mutable keywords from |
| 328 |
it. |
| 329 |
|
| 330 |
** AmalgamationFactory |
| 331 |
|
| 332 |
- =nodegid2dofgids_= |
| 333 |
|
| 334 |
See =AmalgamationInfo= |
| 335 |
|
| 336 |
- =DOFGid2NodeId()= |
| 337 |
|
| 338 |
Main translation function. Currently contains: |
| 339 |
#+BEGIN_SRC C++ |
| 340 |
return (GID - offset - indexBase) / blockSize + indexBase; |
| 341 |
#+END_SRC |
| 342 |
|
| 343 |
- =UnamalgamateAggregates= |
| 344 |
|
| 345 |
Transforms a set of nodes in local aggregates into an array with dof |
| 346 |
GIDs corresponding to these nodes. |
| 347 |
|
| 348 |
- =ComputeUnamalgamatedImportDofMap= |
| 349 |
|
| 350 |
Transforms a set of nodes of =Aggregates= into an array of dofs GIDs |
| 351 |
and constructs a map with those. |
| 352 |
|
| 353 |
*QUESTION 1*: Do we need =nodegid2dofgids_= in this Factory? |
| 354 |
+ *ANSWER*: We don't. Looking at the code, we only need a local |
| 355 |
variable in the =Build= method. |
| 356 |
+ *DONE*: Remove =nodegid2dofgids_=. |
| 357 |
|
| 358 |
*QUESTION 2*: =Build= construct =nodegid2dofgids_= based on column |
| 359 |
map, and not on row map. Why? What happens when a matrix is so sparse |
| 360 |
that column map is a subset of row map? |
| 361 |
|
| 362 |
*QUESTION 3*: =nodegid2dofgids_= contains all node GIDs from column |
| 363 |
map. However, =gNodes_= contains only row block GIDs. That means that |
| 364 |
~nodegid2dofgids_->size() != gNodes_->size()~. Is that a problem? |
| 365 |
|
| 366 |
*QUESTION 4*: Does =UnamalgamateAggregates= really belong to this |
| 367 |
class? A better place would probably be =UnamalgamationInfo=. Same |
| 368 |
question for =ComputeUnamalgamatedImportDofMap=. |
| 369 |
+ *ANSWER*: No, they do not belong here. |
| 370 |
+ *DONE*: Move these functions to =AmalgamationInfo=. |
| 371 |
|
| 372 |
*QUESTION 5*: The way we construct =nodegid2dofgids_= is |
| 373 |
strange. Instead of going through all DOFs of a map, transforming |
| 374 |
those into node ids and pushing into appropriate vector, we go |
| 375 |
through DOFs of a map, get node id, and fill in the whole block |
| 376 |
associated with this node id (which requires calculation of |
| 377 |
=nStridedOffset= and =stridedblocksize=). This necessiates to write |
| 378 |
=StridedMap= specific code. Can we refactor the code so that it would |
| 379 |
be =StridedMap=-independent? |
| 380 |
+ *ANSWER*: We could, if |
| 381 |
#+ATTR_LATEX: :options [(a)] |
| 382 |
a. We somehow get an element list with all valid dofs for this |
| 383 |
map. For strided maps not containing full maps, this is trivial |
| 384 |
as they already have the proper map. For strided maps containing |
| 385 |
full maps, it we would need to create a new array, or use some |
| 386 |
kind of lambda expression/iterator. |
| 387 |
b. Run =DOFGid2NodeId()= and simply push it in its proper place. |
| 388 |
|
| 389 |
+ *TODO* Implement. |
| 390 |
1. Add a function in =StridedMap= to return node id of the GID, |
| 391 |
and return -1 if a we have a full map in =StridedMap=, use only |
| 392 |
a part of it and GID is in the missing |
| 393 |
part. |
| 394 |
2. Remove =DOFGid2NodeId()= from =AmalgamationInfo=. |
| 395 |
3. Rewrite =Build= method. The code would be something like this: |
| 396 |
#+BEGIN_SRC C++ |
| 397 |
for (LO i = 0; i < numDOFs; i++) { |
| 398 |
GO GID = map->getGlobalElement(i); |
| 399 |
GO nodeID = map->getNodeId(GID); |
| 400 |
if (nodeID != -1) { |
| 401 |
nodegid2dofgids_[nodeID].push_back(GID); |
| 402 |
gNodeIds.push_back(GID); |
| 403 |
} |
| 404 |
} |
| 405 |
#+END_SRC |
| 406 |
|
| 407 |
*QUESTION 6*: Both =UnamalgamateAggregates= and |
| 408 |
=ComputeUnamalgamatedImportDofMap= construct an array of dof GIDs |
| 409 |
belonging to local aggregates. What is the difference between |
| 410 |
functions? |
| 411 |
- *ANSWER*: =UnamalgamateAggregates= uses only nodes belonging to |
| 412 |
local aggregates, =ComputeUnamalgamatedImportDofMap= uses all nodes. |
| 413 |
|
| 414 |
** CoalesceDropFactory |
| 415 |
|
| 416 |
- =AmalgamateMap= |
| 417 |
|
| 418 |
Uses =AmalgamationFactory::DOFGid2NodeId= to construct a new map. |
| 419 |
|
| 420 |
- =MergeRows= |
| 421 |
|
| 422 |
* Proposal |