Debian Codegraph @

dune/uggrid/parallel/dddif/debugger.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
8 #ifdef ModelP
9
10 #include <config.h>
11 #include <cstdio>
12
13 #include <dune/uggrid/gm/ugm.h>
14 #include <dune/uggrid/ugdevices.h>
15 #include <dune/uggrid/low/namespace.h>
16
17 #include <dune/uggrid/parallel/ddd/include/memmgr.h>
18 #include <dune/uggrid/parallel/ppif/ppifcontext.hh>
19
20 #include "debugger.h"
21 #include "parallel.h"
22
23 USING_UG_NAMESPACES
24 using namespace PPIF;
25
26
27
28 /****************************************************************************/
29
30
31 /****************************************************************************/
32 /*
33 dddif_DisplayMemoryUsage -
34
35 SYNOPSIS:
36 static void dddif_DisplayMemoryUsage (void);
37
38 PARAMETERS:
39 . void
40
41 DESCRIPTION:
42
43 RETURN VALUE:
44 void
45 */
46 /****************************************************************************/
47
48 static void dddif_DisplayMemoryUsage (const DDD::DDDContext& context)
49 {
50 UserWriteF("mem for interfaces: %8ld bytes\n",
51 (unsigned long) DDD_IFInfoMemoryAll(context)
52 );
53
54 UserWriteF("mem for couplings: %8ld bytes\n",
55 (unsigned long) DDD_InfoCplMemory(context)
56 );
57 }
58
59
60 /****************************************************************************/
61 /*
62 ddd_pstat -
63
64 SYNOPSIS:
65 void ddd_pstat (const DDD::DDDContext& context, char *arg);
66
67 PARAMETERS:
68 . context
69 . arg
70
71 DESCRIPTION:
72
73 RETURN VALUE:
74 void
75 */
76 /****************************************************************************/
77
78
79 void NS_DIM_PREFIX ddd_pstat(DDD::DDDContext& context, char *arg)
80 {
81 int cmd;
82
83 if (arg==NULL)
84 return;
85
86 cmd = arg[0];
87
88 switch (cmd)
89 {
90 case 'X' :
91 dddif_PrintGridRelations(ddd_ctrl(context).currMG);
92 break;
93
94 case 'm' :
95 dddif_DisplayMemoryUsage(context);
96 break;
97
98 case 'c' :
99 DDD_ConsCheck(context);
100 UserWrite("\n");
101 break;
102
103 case 's' :
104 DDD_Status(context);
105 UserWrite("\n");
106 break;
107
108 case 't' :
109 if (context.isMaster())
110 {
111 const auto& dddctrl = ddd_ctrl(context);
112 /* display ddd types */
113 DDD_TypeDisplay(context, dddctrl.TypeVector);
114 DDD_TypeDisplay(context, dddctrl.TypeIVertex);
115 DDD_TypeDisplay(context, dddctrl.TypeBVertex);
116 DDD_TypeDisplay(context, dddctrl.TypeNode);
117 #ifdef UG_DIM_3
118 DDD_TypeDisplay(context, dddctrl.TypeEdge);
119 #endif
120
121 #ifdef UG_DIM_2
122 DDD_TypeDisplay(context, dddctrl.TypeTrElem);
123 DDD_TypeDisplay(context, dddctrl.TypeTrBElem);
124 DDD_TypeDisplay(context, dddctrl.TypeQuElem);
125 DDD_TypeDisplay(context, dddctrl.TypeQuBElem);
126 #endif
127
128 #ifdef UG_DIM_3
129 DDD_TypeDisplay(context, dddctrl.TypeTeElem);
130 DDD_TypeDisplay(context, dddctrl.TypeTeBElem);
131 DDD_TypeDisplay(context, dddctrl.TypePyElem);
132 DDD_TypeDisplay(context, dddctrl.TypePyBElem);
133 DDD_TypeDisplay(context, dddctrl.TypePrElem);
134 DDD_TypeDisplay(context, dddctrl.TypePrBElem);
135 DDD_TypeDisplay(context, dddctrl.TypeHeElem);
136 DDD_TypeDisplay(context, dddctrl.TypeHeBElem);
137 #endif
138
139 /* display dependent types */
140 #ifdef UG_DIM_2
141 DDD_TypeDisplay(context, dddctrl.TypeEdge);
142 #endif
143 }
144 break;
145
146
147 case 'i' :
148 {
149 DDD_IF ifId = atoi(arg+1);
150
151 if (ifId<=0)
152 DDD_IFDisplayAll(context);
153 else
154 DDD_IFDisplay(context, ifId);
155
156 UserWrite("\n");
157 }
158 break;
159
160 case 'l' :
161 DDD_ListLocalObjects(context);
162 UserWrite("\n");
163 break;
164
165 case 'b' :
166 buggy(ddd_ctrl(context).currMG);
167 UserWrite("BUGGY: returning control to caller\n");
168 break;
169 }
170 }
171
172
173 /****************************************************************************/
174
175 /*
176 buggy - interactive debugging tool for distributed grids ug/ddd
177
178 960603 kb copied from pceq, modified, integrated
179 */
180
181
182 /****************************************************************************/
183
184
185 /****************************************************************************/
186 /*
187 buggy_ShowCopies -
188
189 SYNOPSIS:
190 static void buggy_ShowCopies (DDD_HDR hdr);
191
192 PARAMETERS:
193 . hdr -
194
195 DESCRIPTION:
196
197 RETURN VALUE:
198 void
199 */
200 /****************************************************************************/
201
202 static void buggy_ShowCopies (DDD::DDDContext& context, DDD_HDR hdr)
203 {
204 for (auto&& [proc, prio] : DDD_InfoProcListRange(context, hdr))
205 {
206 printf("%4d: copy on %3d with prio %d\n",
207 context.me(), proc, prio);
208 }
209 }
210
211
212
213 /****************************************************************************/
214
215
216 /****************************************************************************/
217 /*
218 buggy_ElemShow -
219
220 SYNOPSIS:
221 static void buggy_ElemShow (ELEMENT *e);
222
223 PARAMETERS:
224 . e -
225
226 DESCRIPTION:
227
228 RETURN VALUE:
229 void
230 */
231 /****************************************************************************/
232
233 static void buggy_ElemShow (ELEMENT *e)
234 {
235 ELEMENT *SonList[MAX_SONS];
236 int i;
237
238 printf(" ID=%06d LEVEL=%02d corners=%03d\n",
239 ID(e), LEVEL(e), CORNERS_OF_ELEM(e));
240
241 if (EFATHER(e))
242 printf(" father=" DDD_GID_FMT "\n",
243 DDD_InfoGlobalId(PARHDRE(EFATHER(e))));
244
245 if (PREDE(e))
246 printf(" pred=" DDD_GID_FMT "\n",
247 DDD_InfoGlobalId(PARHDRE(PREDE(e))));
248
249 if (SUCCE(e))
250 printf(" succ=" DDD_GID_FMT "\n",
251 DDD_InfoGlobalId(PARHDRE(SUCCE(e))));
252
253 for(i=0; i<SIDES_OF_ELEM(e); i++)
254 {
255 if (NBELEM(e,i)!=NULL)
256 {
257 printf(" nb[%d]=" DDD_GID_FMT "\n",
258 i, DDD_InfoGlobalId(PARHDRE(NBELEM(e,i))));
259 }
260 }
261
262 if (GetAllSons(e,SonList)==0)
263 {
264 for(i=0; SonList[i]!=NULL; i++)
265 {
266 printf(" son[%d]=" DDD_GID_FMT " prio=%d\n",
267 i,
268 DDD_InfoGlobalId(PARHDRE(SonList[i])),
269 DDD_InfoPriority(PARHDRE(SonList[i]))
270 );
271 }
272 }
273 }
274
275
276 /****************************************************************************/
277 /*
278 buggy_NodeShow -
279
280 SYNOPSIS:
281 static void buggy_NodeShow (NODE *n);
282
283 PARAMETERS:
284 . n -
285
286 DESCRIPTION:
287
288 RETURN VALUE:
289 void
290 */
291 /****************************************************************************/
292
293 static void buggy_NodeShow (NODE *n)
294 {
295 int i;
296
297 printf(" ID=%06d LEVEL=%02d\n",
298 ID(n), LEVEL(n));
299
300 /* print coordinates of that node */
301 printf(" VERTEXID=%06d LEVEL=%02d",
302 ID(MYVERTEX(n)), LEVEL(MYVERTEX(n)));
303 for(i=0; i<DIM; i++)
304 {
305 printf(" x%1d=%11.4E",i, (float)(CVECT(MYVERTEX(n))[i]) );
306 }
307 printf("\n");
308
309
310 if (NFATHER(n))
311 printf(" father=" DDD_GID_FMT "\n",
312 DDD_InfoGlobalId(PARHDR((NODE *)NFATHER(n))));
313
314 if (PREDN(n))
315 printf(" pred=" DDD_GID_FMT "\n",
316 DDD_InfoGlobalId(PARHDR(PREDN(n))));
317
318 if (SUCCN(n))
319 printf(" succ=" DDD_GID_FMT "\n",
320 DDD_InfoGlobalId(PARHDR(SUCCN(n))));
321 }
322
323
324 /****************************************************************************/
325 /*
326 buggy_Search -
327
328 SYNOPSIS:
329 static void buggy_Search (MULTIGRID *theMG, DDD_GID gid);
330
331 PARAMETERS:
332 . the MG -
333 . gid -
334
335 DESCRIPTION:
336
337 RETURN VALUE:
338 void
339 */
340 /****************************************************************************/
341
342 static void buggy_Search (MULTIGRID *theMG, DDD_GID gid)
343 {
344 auto& context = theMG->dddContext();
345
346 int level, found;
347
348 found = false;
349 for(level=0; level<=TOPLEVEL(theMG); level++)
350 {
351 GRID *theGrid = GRID_ON_LEVEL(theMG,level);
352 ELEMENT *e;
353 NODE *n;
354
355 /* search for element */
356 for(e=PFIRSTELEMENT(theGrid); e!=NULL; e=SUCCE(e))
357 {
358 if (DDD_InfoGlobalId(PARHDRE(e))==gid)
359 {
360 printf("ELEMENT gid=" DDD_GID_FMT ", adr=%p, level=%d\n",
361 gid, (void*) e, level);
362 buggy_ShowCopies(context, PARHDRE(e));
363 buggy_ElemShow(e);
364 found = true;
365 }
366 }
367
368
369 /* search for node */
370 for(n=PFIRSTNODE(theGrid); n!=NULL; n=SUCCN(n))
371 {
372 if (DDD_InfoGlobalId(PARHDR(n))==gid)
373 {
374 printf("NODE gid=" DDD_GID_FMT ", adr=%p, level=%d\n",
375 gid, (void*) n, level);
376 buggy_ShowCopies(context, PARHDR(n));
377 buggy_NodeShow(n);
378 found = true;
379 }
380 }
381 }
382
383 if (!found)
384 {
385 DDD_HDR hdr = DDD_SearchHdr(theMG->dddContext(), gid);
386
387 if (hdr!=NULL)
388 {
389 printf("DDDOBJ gid=" DDD_GID_FMT ", typ=%d, level=%d\n",
390 gid, DDD_InfoType(hdr), DDD_InfoAttr(hdr));
391 buggy_ShowCopies(context, hdr);
392 }
393 else
394 {
395 printf("unknown gid=" DDD_GID_FMT "\n", gid);
396 }
397 }
398 }
399
400
401
402 /****************************************************************************/
403
404 /*
405 static void bug_eg_item (Elem *item)
406 {
407 char fname[30];
408 FILE *f;
409
410 sprintf(fname,"buggy%08x.%03d.gnu",item->InfoGlobalId(),me);
411 f = fopen(fname,"w");
412 if (f==0)
413 {
414 Cout<<me<<": can't open "<<fname<<cr;
415 return;
416 }
417
418 {
419 ConnIterator(Side) siter(item->conn_dn());
420 Side *side;
421 for(; siter; ++siter)
422 {
423 side = siter.rel()->obj();
424 Cout << me<<" side "<< hex << side->InfoGlobalId() <<dec<< cr;
425 {
426 ConnIterator(Node) niter(side->conn_dn());
427 Node *node;
428 for(; niter; ++niter)
429 {
430 node = niter.rel()->obj();
431 Cout << me <<" node " << hex
432 << node->InfoGlobalId()
433 << dec << cr;
434 fprintf(f,"%f %f\n",node->x[0],node->x[1]);
435 }
436 fprintf(f,"\n");
437 }
438 }
439 }
440
441 fclose(f);
442 }
443
444
445 static void bug_elem_graphics (GridSegment &target, unsigned int gid)
446 {
447 Elem *item=0;
448
449 {
450 Iterator(Elem) iter(target.elem_list());
451
452 for (; iter && item==0; ++iter)
453 {
454 if (iter.obj()->InfoGlobalId()==gid)
455 {
456 item = iter.obj();
457 }
458 }
459 }
460
461 if (item==0)
462 {
463 Iterator(Elem) iter(target.ghostlist);
464
465 for (; iter && item==0; ++iter)
466 {
467 if (iter.obj()->InfoGlobalId()==gid)
468 {
469 item = iter.obj();
470 }
471 }
472
473 }
474
475 if (item==0)
476 {
477 Cout<<me<<": no current elem/ghost"<<cr;
478 return;
479 }
480
481 bug_eg_item(item);
482 }
483 */
484
485
486 /****************************************************************************/
487 /*
488 buggy_help -
489
490 SYNOPSIS:
491 static void buggy_help (void);
492
493 PARAMETERS:
494 . void
495
496 DESCRIPTION:
497
498 RETURN VALUE:
499 void
500 */
501 /****************************************************************************/
502
503 /****************************************************************************/
504
505 static void buggy_help (void)
506 {
507 printf(
508 " *\n"
509 " * BUGGY ug debugger\n"
510 " *\n"
511 " * x or q quit\n"
512 " * p<no> change current processor\n"
513 " * l list DDD objects on current proc\n"
514 " * <gid> change to object with gid\n"
515 " * ? or h this help message\n"
516 " *\n");
517 }
518
519
520
521 /****************************************************************************/
522
523
524 /****************************************************************************/
525 /*
526 buggy -
527
528 SYNOPSIS:
529 void buggy (MULTIGRID *theMG);
530
531 PARAMETERS:
532 . the MG
533
534 DESCRIPTION:
535
536 RETURN VALUE:
537 void
538 */
539 /****************************************************************************/
540
541 void NS_DIM_PREFIX buggy (MULTIGRID *theMG)
542 {
543 char buff[100];
544 DDD_GID gid;
545 int proc, cmd, received;
546
547 Synchronize(theMG->ppifContext());
548
549 const int me = theMG->ppifContext().me();
550
551 if (me==0)
552 {
553 printf("%04d: started buggy.\n", me);
554 fflush(stdout);
555 }
556
557 proc = 0;
558 gid = 0x0;
559 do
560 {
561 if (me==0)
562 {
563 do {
564 printf("%04d: buggy> ", proc);
565 fflush(stdout);
566 received = scanf("%s", buff);
567 } while (received > 0 && buff[0] == 0);
568
569 switch (buff[0])
570 {
571 case 'x' :
572 case 'q' :
573 proc = -1;
574 cmd = 0;
575 break;
576
577 case 'p' :
578 proc = (int) strtol(buff+1, 0, 0);
579 cmd = 1;
580 break;
581
582 case 'l' :
583 cmd = 2;
584 break;
585
586 case '?' :
587 case 'h' :
588 cmd=99;
589 break;
590
591 default :
592 cmd = 3;
593 gid = /*(DDD_GID)*/ strtol(buff, 0, 0);
594 }
595 }
596
597 Broadcast(theMG->ppifContext(), &cmd, sizeof(int));
598 Broadcast(theMG->ppifContext(), &proc, sizeof(int));
599 Broadcast(theMG->ppifContext(), &gid, sizeof(unsigned int));
600
601 if (me==proc)
602 {
603 switch (cmd)
604 {
605 case 99 :
606 buggy_help();
607 break;
608
609 case 2 :
610 DDD_ListLocalObjects(theMG->dddContext());
611 break;
612
613 default :
614 buggy_Search(theMG, gid);
615 /*
616 bug_ghost(target, gid);
617 bug_side(target, gid);
618 */
619 break;
620 }
621 }
622
623 fflush(stdout);
624 Synchronize(theMG->ppifContext());
625 }
626 while (proc>=0);
627 }
628
629
630 /****************************************************************************/
631 /* */
632 /* Function: PrintGridRelations */
633 /* */
634 /* Purpose: print certain information about a grid in order to test */
635 /* the formal approach to parallelisation. */
636 /* */
637 /****************************************************************************/
638
639 #define PREFIX "__"
640
641 void NS_DIM_PREFIX dddif_PrintGridRelations (MULTIGRID *theMG)
642 {
643 ELEMENT *e, *enb;
644 GRID *theGrid = GRID_ON_LEVEL(theMG,TOPLEVEL(theMG));
645 INT j;
646
647 const auto& me = theMG->dddContext().me();
648
649 for(e=FIRSTELEMENT(theGrid); e!=NULL; e=SUCCE(e))
650 {
651 printf(PREFIX "master(e" EGID_FMT ", p%02d).\n", EGID(e), me);
652
653 for(j=0; j<SIDES_OF_ELEM(e); j++)
654 {
655 enb = NBELEM(e,j);
656 if (enb!=NULL)
657 {
658 printf(PREFIX "nb(e" EGID_FMT ", e" EGID_FMT ").\n", EGID(e), EGID(enb));
659 }
660 }
661 }
662
663 }
664
665 #undef PREFIX
666
667
668 /****************************************************************************/
669
670
671
672 #endif /* ModelP */