Debian Codegraph @

dune/uggrid/parallel/dddif/priority.cc

raw
1 // SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4 // vi: set et ts=4 sw=2 sts=2:
5 /****************************************************************************/
6 /* */
7 /* File: priority.c */
8 /* */
9 /* Purpose: functions for managing priorities of distributed objects */
10 /* */
11 /* Author: Stefan Lang */
12 /* Institut fuer Computeranwendungen III */
13 /* Universitaet Stuttgart */
14 /* Pfaffenwaldring 27 */
15 /* 70550 Stuttgart */
16 /* email: [email protected] */
17 /* */
18 /* History: 980201 sl begin */
19 /* */
20 /* Remarks: */
21 /* */
22 /****************************************************************************/
23
24 #ifdef ModelP
25
26 /****************************************************************************/
27 /* */
28 /* include files */
29 /* system include files */
30 /* application include files */
31 /* */
32 /****************************************************************************/
33
34 #include <config.h>
35 #include <cstdlib>
36
37 #include "parallel.h"
38 #include <dune/uggrid/ugdevices.h>
39 #include <dune/uggrid/gm/evm.h>
40 #include <dune/uggrid/gm/gm.h>
41 #include <dune/uggrid/gm/refine.h>
42 #include <dune/uggrid/gm/shapes.h>
43 #include <dune/uggrid/gm/ugm.h>
44 #include <dune/uggrid/low/debug.h>
45 #include <dune/uggrid/low/namespace.h>
46
47 /* UG namespaces: */
48 USING_UG_NAMESPACES
49
50 /* PPIF namespace: */
51 using namespace PPIF;
52
53
54 /****************************************************************************/
55 /* */
56 /* defines in the following order */
57 /* */
58 /* compile time constants defining static data size (i.e. arrays) */
59 /* other constants */
60 /* macros */
61 /* */
62 /****************************************************************************/
63
64 /* macros for merge new priority with objects existing one */
65 /* valid only for all types of ghost priorities */
66 #define PRIO_CALC(e) ((USED(e) && THEFLAG(e)) ? PrioVHGhost : \
67 (THEFLAG(e)) ? PrioVGhost : (USED(e)) ? \
68 PrioHGhost : (assert(0),0))
69
70 #define SETPRIOPV SETPRIOX
71
72 /* macros for setting object priorities with related objects */
73 inline void NODE_PRIORITY_SET(DDD::DDDContext& context, GRID* grid, NODE* node, INT prio)
74 {
75 /* set priorities of node */
76 SETPRIOX(context, node, prio);
77 }
78
79 inline void PRIO_SET_EDGE(DDD::DDDContext& context, EDGE* edge, INT prio)
80 {
81 SETPRIOX(context, edge, prio);
82 }
83
84 inline void EDGE_PRIORITY_SET(DDD::DDDContext& context, GRID* grid, EDGE* edge, INT prio)
85 {
86 /* set priorities of node for 3D */
87 PRIO_SET_EDGE(context, edge, prio);
88 }
89
90
91 /****************************************************************************/
92 /* */
93 /* data structures used in this source file (exported data structures are */
94 /* in the corresponding include file!) */
95 /* */
96 /****************************************************************************/
97
98
99 /****************************************************************************/
100 /* */
101 /* definition of exported global variables */
102 /* */
103 /****************************************************************************/
104
105
106 /****************************************************************************/
107 /* */
108 /* forward declarations of functions used before they are defined */
109 /* */
110 /****************************************************************************/
111
112
113 /*
114 for all PrioMaster-nodes with remote copies, set exactly one
115 to PrioMaster, the other copies to PrioBorder in order to establish
116 the BorderNodeIF. this is done for one grid.
117 */
118
119
120 /****************************************************************************/
121 /*
122 ComputeNodeBorderPrios -
123
124 SYNOPSIS:
125 static int ComputeNodeBorderPrios (DDD_OBJ obj);
126
127 PARAMETERS:
128 . obj -
129
130 DESCRIPTION:
131
132 RETURN VALUE:
133 int
134 */
135 /****************************************************************************/
136
137 static int ComputeNodeBorderPrios (DDD::DDDContext& context, DDD_OBJ obj)
138 {
139 NODE *node = (NODE *)obj;
140 int min_proc = context.procs();
141
142 /*
143 minimum processor number will get Master-node,
144 all others get Border-nodes
145 */
146 for (auto&& [proc, prio] : DDD_InfoProcListRange(context, PARHDR(node))) {
147 if (prio == PrioMaster && proc < min_proc)
148 min_proc = proc;
149 }
150
151 if (min_proc == context.procs())
152 return(0);
153
154 if (context.me() != min_proc)
155 SETPRIO(context, node, PrioBorder);
156 return 0;
157 }
158
159
160 /****************************************************************************/
161 /*
162 ComputeVectorBorderPrios -
163
164 SYNOPSIS:
165 static int ComputeVectorBorderPrios (DDD_OBJ obj);
166
167 PARAMETERS:
168 . obj -
169
170 DESCRIPTION:
171
172 RETURN VALUE:
173 int
174 */
175 /****************************************************************************/
176
177 static int ComputeVectorBorderPrios (DDD::DDDContext& context, DDD_OBJ obj)
178 {
179 VECTOR *vector = (VECTOR *)obj;
180 int min_proc = context.procs();
181
182 /*
183 minimum processor number will get Master-node,
184 all others get Border-nodes
185 */
186 for (auto&& [proc, prio] : DDD_InfoProcListRange(context, PARHDR(vector))) {
187 if (prio == PrioMaster && proc < min_proc)
188 min_proc = proc;
189 }
190
191 if (min_proc == context.procs())
192 return(0);
193
194 if (context.me() != min_proc)
195 SETPRIO(context, vector, PrioBorder);
196 return 0;
197 }
198
199
200
201 /****************************************************************************/
202 /*
203 ComputeEdgeBorderPrios -
204
205 SYNOPSIS:
206 static int ComputeEdgeBorderPrios (DDD_OBJ obj);
207
208 PARAMETERS:
209 . obj -
210
211 DESCRIPTION:
212
213 RETURN VALUE:
214 void
215 */
216 /****************************************************************************/
217
218 static int ComputeEdgeBorderPrios (DDD::DDDContext& context, DDD_OBJ obj)
219 {
220 EDGE *edge = (EDGE *)obj;
221 int min_proc = context.procs();
222
223 /*
224 minimum processor number will get Master-node,
225 all others get Border-nodes
226 */
227 for (auto&& [proc, prio] : DDD_InfoProcListRange(context, PARHDR(edge))) {
228 if (prio == PrioMaster && proc < min_proc)
229 min_proc = proc;
230 }
231
232 if (min_proc == context.procs())
233 return(0);
234
235 if (context.me() != min_proc)
236 SETPRIO(context, edge, PrioBorder);
237 return 0;
238 }
239
240
241 /****************************************************************************/
242 /*
243 SetGhostObjectPriorities -
244
245 SYNOPSIS:
246 void SetGhostObjectPriorities (GRID *theGrid);
247
248 PARAMETERS:
249 . theGrid
250
251 DESCRIPTION:
252
253 RETURN VALUE:
254 void
255 */
256 /****************************************************************************/
257
258 void NS_DIM_PREFIX SetGhostObjectPriorities (GRID *theGrid)
259 {
260 ELEMENT *theElement,*theNeighbor,*SonList[MAX_SONS];
261 NODE *theNode;
262 EDGE *theEdge;
263 INT i,prio,hghost,vghost;
264
265 auto& context = theGrid->dddContext();
266 const auto& me = context.me();
267
268 /* reset USED flag for objects of ghostelements */
269 for (theElement=PFIRSTELEMENT(theGrid);
270 theElement!=NULL;
271 theElement=SUCCE(theElement))
272 {
273 SETUSED(theElement,0); SETTHEFLAG(theElement,0);
274 for (i=0; i<EDGES_OF_ELEM(theElement); i++)
275 {
276 theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)),
277 CORNER(theElement,CORNER_OF_EDGE(theElement,i,1)));
278 ASSERT(theEdge != NULL);
279 SETUSED(theEdge,0); SETTHEFLAG(theEdge,0);
280 }
281 #ifdef UG_DIM_3
282 if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
283 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
284 {
285 VECTOR *theVector = SVECTOR(theElement,i);
286 if (theVector != NULL) {
287 SETUSED(theVector,0);
288 SETTHEFLAG(theVector,0);
289 }
290 }
291 #endif
292 }
293 /* to reset also nodes which are at corners of the boundary */
294 /* reset of nodes need to be done through the node list */
295 for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
296 {
297 SETUSED(theNode,0); SETTHEFLAG(theNode,0);
298 SETMODIFIED(theNode,0);
299 }
300
301 /* set FLAG for objects of horizontal and vertical overlap */
302 for (theElement=PFIRSTELEMENT(theGrid);
303 theElement!=NULL;
304 theElement=SUCCE(theElement))
305 {
306 if (PARTITION(theElement) == me) continue;
307
308 /* check for horizontal ghost */
309 hghost = 0;
310 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
311 {
312 theNeighbor = NBELEM(theElement,i);
313 if (theNeighbor == NULL) continue;
314
315 if (PARTITION(theNeighbor) == me)
316 {
317 hghost = 1;
318 break;
319 }
320 }
321
322 /* check for vertical ghost */
323 vghost = 0;
324 GetAllSons(theElement,SonList);
325 for (i=0; SonList[i]!=NULL; i++)
326 {
327 if (PARTITION(SonList[i]) == me)
328 {
329 vghost = 1;
330 break;
331 }
332 }
333
334 /* one or both of vghost and hghost should be true here */
335 /* except for elements which will be disposed during Xfer */
336
337 if (vghost) SETTHEFLAG(theElement,1);
338 if (hghost) SETUSED(theElement,1);
339 for (i=0; i<CORNERS_OF_ELEM(theElement); i++)
340 {
341 theNode = CORNER(theElement,i);
342 if (vghost) SETTHEFLAG(theNode,1);
343 if (hghost) SETUSED(theNode,1);
344 }
345 for (i=0; i<EDGES_OF_ELEM(theElement); i++)
346 {
347 theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0),
348 CORNER_OF_EDGE_PTR(theElement,i,1));
349 ASSERT(theEdge != NULL);
350 if (vghost) SETTHEFLAG(theEdge,1);
351 if (hghost) SETUSED(theEdge,1);
352 }
353 #ifdef UG_DIM_3
354 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
355 {
356 VECTOR *theVector = SVECTOR(theElement,i);
357 if (theVector != NULL) {
358 if (vghost) SETTHEFLAG(theVector,1);
359 if (hghost) SETUSED(theVector,1);
360 }
361 }
362 #endif
363 }
364
365 /* set USED flag for objects of master elements */
366 /* reset FLAG for objects of master elements */
367 for (theElement=PFIRSTELEMENT(theGrid);
368 theElement!=NULL;
369 theElement=SUCCE(theElement))
370 {
371 if (PARTITION(theElement) != me) continue;
372
373 SETUSED(theElement,0); SETTHEFLAG(theElement,0);
374 for (i=0; i<CORNERS_OF_ELEM(theElement); i++)
375 {
376 theNode = CORNER(theElement,i);
377 SETUSED(theNode,0); SETTHEFLAG(theNode,0);
378 SETMODIFIED(theNode,1);
379 }
380 for (i=0; i<EDGES_OF_ELEM(theElement); i++)
381 {
382 theEdge = GetEdge(CORNER_OF_EDGE_PTR(theElement,i,0),
383 CORNER_OF_EDGE_PTR(theElement,i,1));
384 ASSERT(theEdge != NULL);
385 SETUSED(theEdge,0); SETTHEFLAG(theEdge,0);
386 }
387
388 #ifdef UG_DIM_3
389 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
390 {
391 VECTOR *theVector = SVECTOR(theElement,i);
392 if (theVector != NULL) {
393 SETUSED(theVector,0);
394 SETTHEFLAG(theVector,0);
395 }
396 }
397 #endif
398 }
399
400 /* set object priorities for ghostelements */
401 for (theElement=PFIRSTELEMENT(theGrid);
402 theElement!=NULL;
403 theElement=SUCCE(theElement))
404 {
405 if (PARTITION(theElement) == me) continue;
406
407 if (USED(theElement) || THEFLAG(theElement))
408 {
409 prio = PRIO_CALC(theElement);
410 PRINTDEBUG(gm,1,("SetGhostObjectPriorities(): e=" EID_FMTX " new prio=%d\n",
411 EID_PRTX(theElement),prio))
412 SETEPRIOX(context, theElement, prio);
413 }
414
415 /* set edge priorities */
416 for (i=0; i<EDGES_OF_ELEM(theElement); i++)
417 {
418
419 theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,i,0)),
420 CORNER(theElement,CORNER_OF_EDGE(theElement,i,1)));
421 ASSERT(theEdge != NULL);
422
423 if (USED(theEdge) || THEFLAG(theEdge))
424 {
425 PRINTDEBUG(dddif,3,(PFMT " dddif_SetGhostObjectPriorities():"
426 " downgrade edge=" EDID_FMTX " from=%d to PrioHGhost\n",
427 me,EDID_PRTX(theEdge),prio));
428
429 EDGE_PRIORITY_SET(context, theGrid,theEdge,PRIO_CALC(theEdge));
430 }
431 else
432 EDGE_PRIORITY_SET(context, theGrid,theEdge,PrioMaster);
433 }
434
435 #ifdef UG_DIM_3
436 /* if one(all) of the side nodes is (are) a hghost (vghost) node */
437 /* then its a hghost (vghost) side vector */
438 if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
439 for (i=0; i<SIDES_OF_ELEM(theElement); i++)
440 {
441 VECTOR *theVector = SVECTOR(theElement,i);
442 if (USED(theVector) || THEFLAG(theVector))
443 SETPRIOX(context, theVector,PRIO_CALC(theVector));
444 }
445 #endif
446
447 }
448 /* to set also nodes which are at corners of the boundary */
449 /* set them through the node list */
450 for (theNode=PFIRSTNODE(theGrid); theNode!=NULL; theNode=SUCCN(theNode))
451 {
452 /* check if its a master node */
453 if (USED(theNode) || THEFLAG(theNode))
454 {
455 PRINTDEBUG(dddif,3,(PFMT " dddif_SetGhostObjectPriorities():"
456 " downgrade node=" ID_FMTX " from=%d to PrioHGhost\n",
457 me,ID_PRTX(theNode),prio));
458
459 /* set node priorities of node to ghost */
460 NODE_PRIORITY_SET(context, theGrid,theNode,PRIO_CALC(theNode));
461 }
462 else if (MODIFIED(theNode) == 0)
463 {
464 /* this is a node of the boundary without connection to master elements */
465 NODE_PRIORITY_SET(context, theGrid,theNode,PrioHGhost);
466 }
467 /* this is needed only for consistency after refinement */
468 /* ghost nodes which belong after refinement to master */
469 /* elements have to be upgraded explicitly (980126 s.l.)*/
470 else if (MODIFIED(theNode) == 1)
471 {
472 NODE_PRIORITY_SET(context, theGrid,theNode,PrioMaster);
473 }
474 }
475 }
476
477
478 /****************************************************************************/
479 /*
480 SetBorderPriorities -
481
482 SYNOPSIS:
483 INT SetBorderPriorities (GRID *theGrid);
484
485 PARAMETERS:
486 . theGrid
487
488 DESCRIPTION:
489
490 RETURN VALUE:
491 INT
492 */
493 /****************************************************************************/
494
495 INT NS_DIM_PREFIX SetBorderPriorities (GRID *theGrid)
496 {
497 auto& context = theGrid->dddContext();
498 const auto& dddctrl = ddd_ctrl(context);
499
500 DDD_IFAExecLocal(context,
501 dddctrl.BorderNodeSymmIF,GRID_ATTR(theGrid),
502 ComputeNodeBorderPrios);
503
504 /* TODO: distinguish two cases:
505 1. only nodevectors then setting of vector prios can
506 be done in ComputeNodeBorderPrios without extra communiction
507 2. with other vectortypes (side and/or edgevectors) use
508 ComputeVectorBorderPrios
509 */
510 DDD_IFAExecLocal(context,
511 dddctrl.BorderVectorSymmIF,GRID_ATTR(theGrid),
512 ComputeVectorBorderPrios);
513
514 DDD_IFAExecLocal(context,
515 dddctrl.BorderEdgeSymmIF,GRID_ATTR(theGrid),
516 ComputeEdgeBorderPrios);
517
518 return(GM_OK);
519 }
520
521
522 /****************************************************************************/
523 /*
524 SetGridBorderPriorities -
525
526 SYNOPSIS:
527 INT SetGridBorderPriorities (GRID *theGrid);
528
529 PARAMETERS:
530 . theGrid
531
532 DESCRIPTION:
533
534 RETURN VALUE:
535 INT
536 */
537 /****************************************************************************/
538
539
540 INT NS_DIM_PREFIX SetGridBorderPriorities (GRID *theGrid)
541 {
542 /* set border priorities on next higher level */
543 if (SetBorderPriorities(UPGRID(theGrid)) != GM_OK) return(GM_FATAL);
544
545 return(GM_OK);
546 }
547
548 #endif