1 2 /* 3 PETSc code to log object creation and destruction and PETSc events. 4 5 This provides the public API used by the rest of PETSc and by users. 6 7 These routines use a private API that is not used elsewhere in PETSc and is not 8 accessible to users. The private API is defined in logimpl.h and the utils directory. 9 10 */ 11 #include <petsc/private/logimpl.h> /*I "petscsys.h" I*/ 12 #include <petsctime.h> 13 #include <petscviewer.h> 14 15 PetscErrorCode PetscLogObjectParent(PetscObject p,PetscObject c) 16 { 17 if (!c || !p) return 0; 18 c->parent = p; 19 c->parentid = p->id; 20 return 0; 21 } 22 23 /*@C 24 PetscLogObjectMemory - Adds to an object a count of additional amount of memory that is used by the object. 25 26 Not collective. 27 28 Input Parameters: 29 + obj - the PETSc object 30 - mem - the amount of memory that is being added to the object 31 32 Level: developer 33 34 Developer Notes: Currently we do not always do a good job of associating all memory allocations with an object. 35 36 .seealso: PetscFinalize(), PetscInitializeFortran(), PetscGetArgs(), PetscInitializeNoArguments() 37 38 @*/ 39 PetscErrorCode PetscLogObjectMemory(PetscObject p,PetscLogDouble m) 40 { 41 if (!p) return 0; 42 p->mem += m; 43 return 0; 44 } 45 46 PetscLogEvent PETSC_LARGEST_EVENT = PETSC_EVENT; 47 48 #if defined(PETSC_USE_LOG) 49 #include <petscmachineinfo.h> 50 #include <petscconfiginfo.h> 51 52 /* used in the MPI_XXX() count macros in petsclog.h */ 53 54 /* Action and object logging variables */ 55 Action *petsc_actions = NULL; 56 Object *petsc_objects = NULL; 57 PetscBool petsc_logActions = PETSC_FALSE; 58 PetscBool petsc_logObjects = PETSC_FALSE; 59 int petsc_numActions = 0, petsc_maxActions = 100; 60 int petsc_numObjects = 0, petsc_maxObjects = 100; 61 int petsc_numObjectsDestroyed = 0; 62 63 /* Global counters */ 64 PetscLogDouble petsc_BaseTime = 0.0; 65 PetscLogDouble petsc_TotalFlops = 0.0; /* The number of flops */ 66 PetscLogDouble petsc_tmp_flops = 0.0; /* The incremental number of flops */ 67 PetscLogDouble petsc_send_ct = 0.0; /* The number of sends */ 68 PetscLogDouble petsc_recv_ct = 0.0; /* The number of receives */ 69 PetscLogDouble petsc_send_len = 0.0; /* The total length of all sent messages */ 70 PetscLogDouble petsc_recv_len = 0.0; /* The total length of all received messages */ 71 PetscLogDouble petsc_isend_ct = 0.0; /* The number of immediate sends */ 72 PetscLogDouble petsc_irecv_ct = 0.0; /* The number of immediate receives */ 73 PetscLogDouble petsc_isend_len = 0.0; /* The total length of all immediate send messages */ 74 PetscLogDouble petsc_irecv_len = 0.0; /* The total length of all immediate receive messages */ 75 PetscLogDouble petsc_wait_ct = 0.0; /* The number of waits */ 76 PetscLogDouble petsc_wait_any_ct = 0.0; /* The number of anywaits */ 77 PetscLogDouble petsc_wait_all_ct = 0.0; /* The number of waitalls */ 78 PetscLogDouble petsc_sum_of_waits_ct = 0.0; /* The total number of waits */ 79 PetscLogDouble petsc_allreduce_ct = 0.0; /* The number of reductions */ 80 PetscLogDouble petsc_gather_ct = 0.0; /* The number of gathers and gathervs */ 81 PetscLogDouble petsc_scatter_ct = 0.0; /* The number of scatters and scattervs */ 82 83 /* Logging functions */ 84 PetscErrorCode (*PetscLogPHC)(PetscObject) = NULL; 85 PetscErrorCode (*PetscLogPHD)(PetscObject) = NULL; 86 PetscErrorCode (*PetscLogPLB)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject) = NULL; 87 PetscErrorCode (*PetscLogPLE)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject) = NULL; 88 89 /* Tracing event logging variables */ 90 FILE *petsc_tracefile = NULL; 91 int petsc_tracelevel = 0; 92 const char *petsc_traceblanks = " "; 93 char petsc_tracespace[128] = " "; 94 PetscLogDouble petsc_tracetime = 0.0; 95 static PetscBool PetscLogInitializeCalled = PETSC_FALSE; 96 97 /*---------------------------------------------- General Functions --------------------------------------------------*/ 98 #undef __FUNCT__ 99 #define __FUNCT__ "PetscLogDestroy" 100 /*@C 101 PetscLogDestroy - Destroys the object and event logging data and resets the global counters. 102 103 Not Collective 104 105 Notes: 106 This routine should not usually be used by programmers. Instead employ 107 PetscLogStagePush() and PetscLogStagePop(). 108 109 Level: developer 110 111 .keywords: log, destroy 112 .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogView(), PetscLogStagePush(), PlogStagePop() 113 @*/ 114 PetscErrorCode PetscLogDestroy(void) 115 { 116 PetscStageLog stageLog; 117 PetscErrorCode ierr; 118 119 PetscFunctionBegin; 120 ierr = PetscFree(petsc_actions);CHKERRQ(ierr); 121 ierr = PetscFree(petsc_objects);CHKERRQ(ierr); 122 ierr = PetscLogSet(NULL, NULL);CHKERRQ(ierr); 123 124 /* Resetting phase */ 125 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 126 ierr = PetscStageLogDestroy(stageLog);CHKERRQ(ierr); 127 128 petsc_TotalFlops = 0.0; 129 petsc_numActions = 0; 130 petsc_numObjects = 0; 131 petsc_numObjectsDestroyed = 0; 132 petsc_maxActions = 100; 133 petsc_maxObjects = 100; 134 petsc_actions = NULL; 135 petsc_objects = NULL; 136 petsc_logActions = PETSC_FALSE; 137 petsc_logObjects = PETSC_FALSE; 138 petsc_BaseTime = 0.0; 139 petsc_TotalFlops = 0.0; 140 petsc_tmp_flops = 0.0; 141 petsc_send_ct = 0.0; 142 petsc_recv_ct = 0.0; 143 petsc_send_len = 0.0; 144 petsc_recv_len = 0.0; 145 petsc_isend_ct = 0.0; 146 petsc_irecv_ct = 0.0; 147 petsc_isend_len = 0.0; 148 petsc_irecv_len = 0.0; 149 petsc_wait_ct = 0.0; 150 petsc_wait_any_ct = 0.0; 151 petsc_wait_all_ct = 0.0; 152 petsc_sum_of_waits_ct = 0.0; 153 petsc_allreduce_ct = 0.0; 154 petsc_gather_ct = 0.0; 155 petsc_scatter_ct = 0.0; 156 PETSC_LARGEST_EVENT = PETSC_EVENT; 157 PetscLogPHC = NULL; 158 PetscLogPHD = NULL; 159 petsc_tracefile = NULL; 160 petsc_tracelevel = 0; 161 petsc_traceblanks = " "; 162 petsc_tracespace[0] = ' '; petsc_tracespace[1] = 0; 163 petsc_tracetime = 0.0; 164 PETSC_LARGEST_CLASSID = PETSC_SMALLEST_CLASSID; 165 PETSC_OBJECT_CLASSID = 0; 166 petsc_stageLog = 0; 167 PetscLogInitializeCalled = PETSC_FALSE; 168 PetscFunctionReturn(0); 169 } 170 171 #undef __FUNCT__ 172 #define __FUNCT__ "PetscLogSet" 173 /*@C 174 PetscLogSet - Sets the logging functions called at the beginning and ending of every event. 175 176 Not Collective 177 178 Input Parameters: 179 + b - The function called at beginning of event 180 - e - The function called at end of event 181 182 Level: developer 183 184 .seealso: PetscLogDump(), PetscLogDefaultBegin(), PetscLogAllBegin(), PetscLogTraceBegin() 185 @*/ 186 PetscErrorCode PetscLogSet(PetscErrorCode (*b)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), 187 PetscErrorCode (*e)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject)) 188 { 189 PetscFunctionBegin; 190 PetscLogPLB = b; 191 PetscLogPLE = e; 192 PetscFunctionReturn(0); 193 } 194 195 /*------------------------------------------- Initialization Functions ----------------------------------------------*/ 196 #undef __FUNCT__ 197 #define __FUNCT__ "PetscLogInitialize" 198 /* 199 The data structures for logging are always created even if no logging is turned on. This is so events etc can 200 be registered in the code before the actually logging is turned on. 201 */ 202 PetscErrorCode PetscLogInitialize(void) 203 { 204 int stage; 205 PetscBool opt; 206 PetscErrorCode ierr; 207 208 PetscFunctionBegin; 209 if (PetscLogInitializeCalled) PetscFunctionReturn(0); 210 PetscLogInitializeCalled = PETSC_TRUE; 211 212 ierr = PetscOptionsHasName(NULL,NULL, "-log_exclude_actions", &opt);CHKERRQ(ierr); 213 if (opt) petsc_logActions = PETSC_FALSE; 214 ierr = PetscOptionsHasName(NULL,NULL, "-log_exclude_objects", &opt);CHKERRQ(ierr); 215 if (opt) petsc_logObjects = PETSC_FALSE; 216 if (petsc_logActions) { 217 ierr = PetscMalloc1(petsc_maxActions, &petsc_actions);CHKERRQ(ierr); 218 } 219 if (petsc_logObjects) { 220 ierr = PetscMalloc1(petsc_maxObjects, &petsc_objects);CHKERRQ(ierr); 221 } 222 PetscLogPHC = PetscLogObjCreateDefault; 223 PetscLogPHD = PetscLogObjDestroyDefault; 224 /* Setup default logging structures */ 225 ierr = PetscStageLogCreate(&petsc_stageLog);CHKERRQ(ierr); 226 ierr = PetscStageLogRegister(petsc_stageLog, "Main Stage", &stage);CHKERRQ(ierr); 227 228 /* All processors sync here for more consistent logging */ 229 ierr = MPI_Barrier(PETSC_COMM_WORLD);CHKERRQ(ierr); 230 PetscTime(&petsc_BaseTime); 231 ierr = PetscLogStagePush(stage);CHKERRQ(ierr); 232 PetscFunctionReturn(0); 233 } 234 235 #undef __FUNCT__ 236 #define __FUNCT__ "PetscLogDefaultBegin" 237 /*@C 238 PetscLogDefaultBegin - Turns on logging of objects and events. This logs flop 239 rates and object creation and should not slow programs down too much. 240 This routine may be called more than once. 241 242 Logically Collective over PETSC_COMM_WORLD 243 244 Options Database Keys: 245 . -log_view [viewertype:filename:viewerformat] - Prints summary of flop and timing information to the 246 screen (for code configured with --with-log=1 (which is the default)) 247 248 Usage: 249 .vb 250 PetscInitialize(...); 251 PetscLogDefaultBegin(); 252 ... code ... 253 PetscLogView(viewer); or PetscLogDump(); 254 PetscFinalize(); 255 .ve 256 257 Notes: 258 PetscLogView(viewer) or PetscLogDump() actually cause the printing of 259 the logging information. 260 261 Level: advanced 262 263 .keywords: log, begin 264 .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogView(), PetscLogTraceBegin() 265 @*/ 266 PetscErrorCode PetscLogDefaultBegin(void) 267 { 268 PetscErrorCode ierr; 269 270 PetscFunctionBegin; 271 ierr = PetscLogSet(PetscLogEventBeginDefault, PetscLogEventEndDefault);CHKERRQ(ierr); 272 PetscFunctionReturn(0); 273 } 274 275 #undef __FUNCT__ 276 #define __FUNCT__ "PetscLogAllBegin" 277 /*@C 278 PetscLogAllBegin - Turns on extensive logging of objects and events. Logs 279 all events. This creates large log files and slows the program down. 280 281 Logically Collective on PETSC_COMM_WORLD 282 283 Options Database Keys: 284 . -log_all - Prints extensive log information 285 286 Usage: 287 .vb 288 PetscInitialize(...); 289 PetscLogAllBegin(); 290 ... code ... 291 PetscLogDump(filename); 292 PetscFinalize(); 293 .ve 294 295 Notes: 296 A related routine is PetscLogDefaultBegin() (with the options key -log), which is 297 intended for production runs since it logs only flop rates and object 298 creation (and shouldn't significantly slow the programs). 299 300 Level: advanced 301 302 .keywords: log, all, begin 303 .seealso: PetscLogDump(), PetscLogDefaultBegin(), PetscLogTraceBegin() 304 @*/ 305 PetscErrorCode PetscLogAllBegin(void) 306 { 307 PetscErrorCode ierr; 308 309 PetscFunctionBegin; 310 ierr = PetscLogSet(PetscLogEventBeginComplete, PetscLogEventEndComplete);CHKERRQ(ierr); 311 PetscFunctionReturn(0); 312 } 313 314 #undef __FUNCT__ 315 #define __FUNCT__ "PetscLogTraceBegin" 316 /*@ 317 PetscLogTraceBegin - Activates trace logging. Every time a PETSc event 318 begins or ends, the event name is printed. 319 320 Logically Collective on PETSC_COMM_WORLD 321 322 Input Parameter: 323 . file - The file to print trace in (e.g. stdout) 324 325 Options Database Key: 326 . -log_trace [filename] - Activates PetscLogTraceBegin() 327 328 Notes: 329 PetscLogTraceBegin() prints the processor number, the execution time (sec), 330 then "Event begin:" or "Event end:" followed by the event name. 331 332 PetscLogTraceBegin() allows tracing of all PETSc calls, which is useful 333 to determine where a program is hanging without running in the 334 debugger. Can be used in conjunction with the -info option. 335 336 Level: intermediate 337 338 .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogView(), PetscLogDefaultBegin() 339 @*/ 340 PetscErrorCode PetscLogTraceBegin(FILE *file) 341 { 342 PetscErrorCode ierr; 343 344 PetscFunctionBegin; 345 petsc_tracefile = file; 346 347 ierr = PetscLogSet(PetscLogEventBeginTrace, PetscLogEventEndTrace);CHKERRQ(ierr); 348 PetscFunctionReturn(0); 349 } 350 351 #undef __FUNCT__ 352 #define __FUNCT__ "PetscLogActions" 353 /*@ 354 PetscLogActions - Determines whether actions are logged for the graphical viewer. 355 356 Not Collective 357 358 Input Parameter: 359 . flag - PETSC_TRUE if actions are to be logged 360 361 Level: intermediate 362 363 Note: Logging of actions continues to consume more memory as the program 364 runs. Long running programs should consider turning this feature off. 365 366 Options Database Keys: 367 . -log_exclude_actions - Turns off actions logging 368 369 .keywords: log, stage, register 370 .seealso: PetscLogStagePush(), PetscLogStagePop() 371 @*/ 372 PetscErrorCode PetscLogActions(PetscBool flag) 373 { 374 PetscFunctionBegin; 375 petsc_logActions = flag; 376 PetscFunctionReturn(0); 377 } 378 379 #undef __FUNCT__ 380 #define __FUNCT__ "PetscLogObjects" 381 /*@ 382 PetscLogObjects - Determines whether objects are logged for the graphical viewer. 383 384 Not Collective 385 386 Input Parameter: 387 . flag - PETSC_TRUE if objects are to be logged 388 389 Level: intermediate 390 391 Note: Logging of objects continues to consume more memory as the program 392 runs. Long running programs should consider turning this feature off. 393 394 Options Database Keys: 395 . -log_exclude_objects - Turns off objects logging 396 397 .keywords: log, stage, register 398 .seealso: PetscLogStagePush(), PetscLogStagePop() 399 @*/ 400 PetscErrorCode PetscLogObjects(PetscBool flag) 401 { 402 PetscFunctionBegin; 403 petsc_logObjects = flag; 404 PetscFunctionReturn(0); 405 } 406 407 /*------------------------------------------------ Stage Functions --------------------------------------------------*/ 408 #undef __FUNCT__ 409 #define __FUNCT__ "PetscLogStageRegister" 410 /*@C 411 PetscLogStageRegister - Attaches a charactor string name to a logging stage. 412 413 Not Collective 414 415 Input Parameter: 416 . sname - The name to associate with that stage 417 418 Output Parameter: 419 . stage - The stage number 420 421 Level: intermediate 422 423 .keywords: log, stage, register 424 .seealso: PetscLogStagePush(), PetscLogStagePop() 425 @*/ 426 PetscErrorCode PetscLogStageRegister(const char sname[],PetscLogStage *stage) 427 { 428 PetscStageLog stageLog; 429 PetscLogEvent event; 430 PetscErrorCode ierr; 431 432 PetscFunctionBegin; 433 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 434 ierr = PetscStageLogRegister(stageLog, sname, stage);CHKERRQ(ierr); 435 /* Copy events already changed in the main stage, this sucks */ 436 ierr = PetscEventPerfLogEnsureSize(stageLog->stageInfo[*stage].eventLog, stageLog->eventLog->numEvents);CHKERRQ(ierr); 437 for (event = 0; event < stageLog->eventLog->numEvents; event++) { 438 ierr = PetscEventPerfInfoCopy(&stageLog->stageInfo[0].eventLog->eventInfo[event],&stageLog->stageInfo[*stage].eventLog->eventInfo[event]);CHKERRQ(ierr); 439 } 440 ierr = PetscClassPerfLogEnsureSize(stageLog->stageInfo[*stage].classLog, stageLog->classLog->numClasses);CHKERRQ(ierr); 441 PetscFunctionReturn(0); 442 } 443 444 #undef __FUNCT__ 445 #define __FUNCT__ "PetscLogStagePush" 446 /*@C 447 PetscLogStagePush - This function pushes a stage on the stack. 448 449 Not Collective 450 451 Input Parameter: 452 . stage - The stage on which to log 453 454 Usage: 455 If the option -log_sumary is used to run the program containing the 456 following code, then 2 sets of summary data will be printed during 457 PetscFinalize(). 458 .vb 459 PetscInitialize(int *argc,char ***args,0,0); 460 [stage 0 of code] 461 PetscLogStagePush(1); 462 [stage 1 of code] 463 PetscLogStagePop(); 464 PetscBarrier(...); 465 [more stage 0 of code] 466 PetscFinalize(); 467 .ve 468 469 Notes: 470 Use PetscLogStageRegister() to register a stage. 471 472 Level: intermediate 473 474 .keywords: log, push, stage 475 .seealso: PetscLogStagePop(), PetscLogStageRegister(), PetscBarrier() 476 @*/ 477 PetscErrorCode PetscLogStagePush(PetscLogStage stage) 478 { 479 PetscStageLog stageLog; 480 PetscErrorCode ierr; 481 482 PetscFunctionBegin; 483 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 484 ierr = PetscStageLogPush(stageLog, stage);CHKERRQ(ierr); 485 PetscFunctionReturn(0); 486 } 487 488 #undef __FUNCT__ 489 #define __FUNCT__ "PetscLogStagePop" 490 /*@C 491 PetscLogStagePop - This function pops a stage from the stack. 492 493 Not Collective 494 495 Usage: 496 If the option -log_sumary is used to run the program containing the 497 following code, then 2 sets of summary data will be printed during 498 PetscFinalize(). 499 .vb 500 PetscInitialize(int *argc,char ***args,0,0); 501 [stage 0 of code] 502 PetscLogStagePush(1); 503 [stage 1 of code] 504 PetscLogStagePop(); 505 PetscBarrier(...); 506 [more stage 0 of code] 507 PetscFinalize(); 508 .ve 509 510 Notes: 511 Use PetscLogStageRegister() to register a stage. 512 513 Level: intermediate 514 515 .keywords: log, pop, stage 516 .seealso: PetscLogStagePush(), PetscLogStageRegister(), PetscBarrier() 517 @*/ 518 PetscErrorCode PetscLogStagePop(void) 519 { 520 PetscStageLog stageLog; 521 PetscErrorCode ierr; 522 523 PetscFunctionBegin; 524 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 525 ierr = PetscStageLogPop(stageLog);CHKERRQ(ierr); 526 PetscFunctionReturn(0); 527 } 528 529 #undef __FUNCT__ 530 #define __FUNCT__ "PetscLogStageSetActive" 531 /*@ 532 PetscLogStageSetActive - Determines stage activity for PetscLogEventBegin() and PetscLogEventEnd(). 533 534 Not Collective 535 536 Input Parameters: 537 + stage - The stage 538 - isActive - The activity flag, PETSC_TRUE for logging, else PETSC_FALSE (defaults to PETSC_TRUE) 539 540 Level: intermediate 541 542 .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogEventBegin(), PetscLogEventEnd(), PetscPreLoadBegin(), PetscPreLoadEnd(), PetscPreLoadStage() 543 @*/ 544 PetscErrorCode PetscLogStageSetActive(PetscLogStage stage, PetscBool isActive) 545 { 546 PetscStageLog stageLog; 547 PetscErrorCode ierr; 548 549 PetscFunctionBegin; 550 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 551 ierr = PetscStageLogSetActive(stageLog, stage, isActive);CHKERRQ(ierr); 552 PetscFunctionReturn(0); 553 } 554 555 #undef __FUNCT__ 556 #define __FUNCT__ "PetscLogStageGetActive" 557 /*@ 558 PetscLogStageGetActive - Returns stage activity for PetscLogEventBegin() and PetscLogEventEnd(). 559 560 Not Collective 561 562 Input Parameter: 563 . stage - The stage 564 565 Output Parameter: 566 . isActive - The activity flag, PETSC_TRUE for logging, else PETSC_FALSE (defaults to PETSC_TRUE) 567 568 Level: intermediate 569 570 .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogEventBegin(), PetscLogEventEnd(), PetscPreLoadBegin(), PetscPreLoadEnd(), PetscPreLoadStage() 571 @*/ 572 PetscErrorCode PetscLogStageGetActive(PetscLogStage stage, PetscBool *isActive) 573 { 574 PetscStageLog stageLog; 575 PetscErrorCode ierr; 576 577 PetscFunctionBegin; 578 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 579 ierr = PetscStageLogGetActive(stageLog, stage, isActive);CHKERRQ(ierr); 580 PetscFunctionReturn(0); 581 } 582 583 #undef __FUNCT__ 584 #define __FUNCT__ "PetscLogStageSetVisible" 585 /*@ 586 PetscLogStageSetVisible - Determines stage visibility in PetscLogView() 587 588 Not Collective 589 590 Input Parameters: 591 + stage - The stage 592 - isVisible - The visibility flag, PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE) 593 594 Level: intermediate 595 596 .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogView() 597 @*/ 598 PetscErrorCode PetscLogStageSetVisible(PetscLogStage stage, PetscBool isVisible) 599 { 600 PetscStageLog stageLog; 601 PetscErrorCode ierr; 602 603 PetscFunctionBegin; 604 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 605 ierr = PetscStageLogSetVisible(stageLog, stage, isVisible);CHKERRQ(ierr); 606 PetscFunctionReturn(0); 607 } 608 609 #undef __FUNCT__ 610 #define __FUNCT__ "PetscLogStageGetVisible" 611 /*@ 612 PetscLogStageGetVisible - Returns stage visibility in PetscLogView() 613 614 Not Collective 615 616 Input Parameter: 617 . stage - The stage 618 619 Output Parameter: 620 . isVisible - The visibility flag, PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE) 621 622 Level: intermediate 623 624 .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogView() 625 @*/ 626 PetscErrorCode PetscLogStageGetVisible(PetscLogStage stage, PetscBool *isVisible) 627 { 628 PetscStageLog stageLog; 629 PetscErrorCode ierr; 630 631 PetscFunctionBegin; 632 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 633 ierr = PetscStageLogGetVisible(stageLog, stage, isVisible);CHKERRQ(ierr); 634 PetscFunctionReturn(0); 635 } 636 637 #undef __FUNCT__ 638 #define __FUNCT__ "PetscLogStageGetId" 639 /*@C 640 PetscLogStageGetId - Returns the stage id when given the stage name. 641 642 Not Collective 643 644 Input Parameter: 645 . name - The stage name 646 647 Output Parameter: 648 . stage - The stage, , or -1 if no stage with that name exists 649 650 Level: intermediate 651 652 .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscPreLoadBegin(), PetscPreLoadEnd(), PetscPreLoadStage() 653 @*/ 654 PetscErrorCode PetscLogStageGetId(const char name[], PetscLogStage *stage) 655 { 656 PetscStageLog stageLog; 657 PetscErrorCode ierr; 658 659 PetscFunctionBegin; 660 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 661 ierr = PetscStageLogGetStage(stageLog, name, stage);CHKERRQ(ierr); 662 PetscFunctionReturn(0); 663 } 664 665 /*------------------------------------------------ Event Functions --------------------------------------------------*/ 666 #undef __FUNCT__ 667 #define __FUNCT__ "PetscLogEventRegister" 668 /*@C 669 PetscLogEventRegister - Registers an event name for logging operations in an application code. 670 671 Not Collective 672 673 Input Parameter: 674 + name - The name associated with the event 675 - classid - The classid associated to the class for this event, obtain either with 676 PetscClassIdRegister() or use a predefined one such as KSP_CLASSID, SNES_CLASSID, the predefined ones 677 are only available in C code 678 679 Output Parameter: 680 . event - The event id for use with PetscLogEventBegin() and PetscLogEventEnd(). 681 682 Example of Usage: 683 .vb 684 PetscLogEvent USER_EVENT; 685 PetscClassId classid; 686 PetscLogDouble user_event_flops; 687 PetscClassIdRegister("class name",&classid); 688 PetscLogEventRegister("User event name",classid,&USER_EVENT); 689 PetscLogEventBegin(USER_EVENT,0,0,0,0); 690 [code segment to monitor] 691 PetscLogFlops(user_event_flops); 692 PetscLogEventEnd(USER_EVENT,0,0,0,0); 693 .ve 694 695 Notes: 696 PETSc automatically logs library events if the code has been 697 configured with --with-log (which is the default) and 698 -log_view or -log_all is specified. PetscLogEventRegister() is 699 intended for logging user events to supplement this PETSc 700 information. 701 702 PETSc can gather data for use with the utilities Jumpshot 703 (part of the MPICH distribution). If PETSc has been compiled 704 with flag -DPETSC_HAVE_MPE (MPE is an additional utility within 705 MPICH), the user can employ another command line option, -log_mpe, 706 to create a logfile, "mpe.log", which can be visualized 707 Jumpshot. 708 709 The classid is associated with each event so that classes of events 710 can be disabled simultaneously, such as all matrix events. The user 711 can either use an existing classid, such as MAT_CLASSID, or create 712 their own as shown in the example. 713 714 If an existing event with the same name exists, its event handle is 715 returned instead of creating a new event. 716 717 Level: intermediate 718 719 .keywords: log, event, register 720 .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogFlops(), 721 PetscLogEventMPEActivate(), PetscLogEventMPEDeactivate(), 722 PetscLogEventActivate(), PetscLogEventDeactivate(), PetscClassIdRegister() 723 @*/ 724 PetscErrorCode PetscLogEventRegister(const char name[],PetscClassId classid,PetscLogEvent *event) 725 { 726 PetscStageLog stageLog; 727 int stage; 728 PetscErrorCode ierr; 729 730 PetscFunctionBegin; 731 *event = PETSC_DECIDE; 732 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 733 ierr = PetscEventRegLogGetEvent(stageLog->eventLog, name, event);CHKERRQ(ierr); 734 if (*event > 0) PetscFunctionReturn(0); 735 ierr = PetscEventRegLogRegister(stageLog->eventLog, name, classid, event);CHKERRQ(ierr); 736 for (stage = 0; stage < stageLog->numStages; stage++) { 737 ierr = PetscEventPerfLogEnsureSize(stageLog->stageInfo[stage].eventLog, stageLog->eventLog->numEvents);CHKERRQ(ierr); 738 ierr = PetscClassPerfLogEnsureSize(stageLog->stageInfo[stage].classLog, stageLog->classLog->numClasses);CHKERRQ(ierr); 739 } 740 PetscFunctionReturn(0); 741 } 742 743 #undef __FUNCT__ 744 #define __FUNCT__ "PetscLogEventActivate" 745 /*@ 746 PetscLogEventActivate - Indicates that a particular event should be logged. 747 748 Not Collective 749 750 Input Parameter: 751 . event - The event id 752 753 Usage: 754 .vb 755 PetscLogEventDeactivate(VEC_SetValues); 756 [code where you do not want to log VecSetValues()] 757 PetscLogEventActivate(VEC_SetValues); 758 [code where you do want to log VecSetValues()] 759 .ve 760 761 Note: 762 The event may be either a pre-defined PETSc event (found in include/petsclog.h) 763 or an event number obtained with PetscLogEventRegister(). 764 765 Level: advanced 766 767 .keywords: log, event, activate 768 .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventDeactivate() 769 @*/ 770 PetscErrorCode PetscLogEventActivate(PetscLogEvent event) 771 { 772 PetscStageLog stageLog; 773 int stage; 774 PetscErrorCode ierr; 775 776 PetscFunctionBegin; 777 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 778 ierr = PetscStageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); 779 ierr = PetscEventPerfLogActivate(stageLog->stageInfo[stage].eventLog, event);CHKERRQ(ierr); 780 PetscFunctionReturn(0); 781 } 782 783 #undef __FUNCT__ 784 #define __FUNCT__ "PetscLogEventDeactivate" 785 /*@ 786 PetscLogEventDeactivate - Indicates that a particular event should not be logged. 787 788 Not Collective 789 790 Input Parameter: 791 . event - The event id 792 793 Usage: 794 .vb 795 PetscLogEventDeactivate(VEC_SetValues); 796 [code where you do not want to log VecSetValues()] 797 PetscLogEventActivate(VEC_SetValues); 798 [code where you do want to log VecSetValues()] 799 .ve 800 801 Note: 802 The event may be either a pre-defined PETSc event (found in 803 include/petsclog.h) or an event number obtained with PetscLogEventRegister()). 804 805 Level: advanced 806 807 .keywords: log, event, deactivate 808 .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventActivate() 809 @*/ 810 PetscErrorCode PetscLogEventDeactivate(PetscLogEvent event) 811 { 812 PetscStageLog stageLog; 813 int stage; 814 PetscErrorCode ierr; 815 816 PetscFunctionBegin; 817 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 818 ierr = PetscStageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); 819 ierr = PetscEventPerfLogDeactivate(stageLog->stageInfo[stage].eventLog, event);CHKERRQ(ierr); 820 PetscFunctionReturn(0); 821 } 822 823 #undef __FUNCT__ 824 #define __FUNCT__ "PetscLogEventSetActiveAll" 825 /*@ 826 PetscLogEventSetActiveAll - Sets the event activity in every stage. 827 828 Not Collective 829 830 Input Parameters: 831 + event - The event id 832 - isActive - The activity flag determining whether the event is logged 833 834 Level: advanced 835 836 .keywords: log, event, activate 837 .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventActivate(),PlogEventDeactivate() 838 @*/ 839 PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent event, PetscBool isActive) 840 { 841 PetscStageLog stageLog; 842 int stage; 843 PetscErrorCode ierr; 844 845 PetscFunctionBegin; 846 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 847 for (stage = 0; stage < stageLog->numStages; stage++) { 848 if (isActive) { 849 ierr = PetscEventPerfLogActivate(stageLog->stageInfo[stage].eventLog, event);CHKERRQ(ierr); 850 } else { 851 ierr = PetscEventPerfLogDeactivate(stageLog->stageInfo[stage].eventLog, event);CHKERRQ(ierr); 852 } 853 } 854 PetscFunctionReturn(0); 855 } 856 857 #undef __FUNCT__ 858 #define __FUNCT__ "PetscLogEventActivateClass" 859 /*@ 860 PetscLogEventActivateClass - Activates event logging for a PETSc object class. 861 862 Not Collective 863 864 Input Parameter: 865 . classid - The event class, for example MAT_CLASSID, SNES_CLASSID, etc. 866 867 Level: developer 868 869 .keywords: log, event, activate, class 870 .seealso: PetscInfoActivate(),PetscInfo(),PetscInfoAllow(),PetscLogEventDeactivateClass(), PetscLogEventActivate(),PetscLogEventDeactivate() 871 @*/ 872 PetscErrorCode PetscLogEventActivateClass(PetscClassId classid) 873 { 874 PetscStageLog stageLog; 875 int stage; 876 PetscErrorCode ierr; 877 878 PetscFunctionBegin; 879 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 880 ierr = PetscStageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); 881 ierr = PetscEventPerfLogActivateClass(stageLog->stageInfo[stage].eventLog, stageLog->eventLog, classid);CHKERRQ(ierr); 882 PetscFunctionReturn(0); 883 } 884 885 #undef __FUNCT__ 886 #define __FUNCT__ "PetscLogEventDeactivateClass" 887 /*@ 888 PetscLogEventDeactivateClass - Deactivates event logging for a PETSc object class. 889 890 Not Collective 891 892 Input Parameter: 893 . classid - The event class, for example MAT_CLASSID, SNES_CLASSID, etc. 894 895 Level: developer 896 897 .keywords: log, event, deactivate, class 898 .seealso: PetscInfoActivate(),PetscInfo(),PetscInfoAllow(),PetscLogEventActivateClass(), PetscLogEventActivate(),PetscLogEventDeactivate() 899 @*/ 900 PetscErrorCode PetscLogEventDeactivateClass(PetscClassId classid) 901 { 902 PetscStageLog stageLog; 903 int stage; 904 PetscErrorCode ierr; 905 906 PetscFunctionBegin; 907 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 908 ierr = PetscStageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); 909 ierr = PetscEventPerfLogDeactivateClass(stageLog->stageInfo[stage].eventLog, stageLog->eventLog, classid);CHKERRQ(ierr); 910 PetscFunctionReturn(0); 911 } 912 913 /*MC 914 PetscLogEventBegin - Logs the beginning of a user event. 915 916 Synopsis: 917 #include <petsclog.h> 918 PetscErrorCode PetscLogEventBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4) 919 920 Not Collective 921 922 Input Parameters: 923 + e - integer associated with the event obtained from PetscLogEventRegister() 924 - o1,o2,o3,o4 - objects associated with the event, or 0 925 926 927 Fortran Synopsis: 928 void PetscLogEventBegin(int e,PetscErrorCode ierr) 929 930 Usage: 931 .vb 932 PetscLogEvent USER_EVENT; 933 PetscLogDouble user_event_flops; 934 PetscLogEventRegister("User event",0,&USER_EVENT); 935 PetscLogEventBegin(USER_EVENT,0,0,0,0); 936 [code segment to monitor] 937 PetscLogFlops(user_event_flops); 938 PetscLogEventEnd(USER_EVENT,0,0,0,0); 939 .ve 940 941 Notes: 942 You need to register each integer event with the command 943 PetscLogEventRegister(). 944 945 Level: intermediate 946 947 .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops() 948 949 .keywords: log, event, begin 950 M*/ 951 952 /*MC 953 PetscLogEventEnd - Log the end of a user event. 954 955 Synopsis: 956 #include <petsclog.h> 957 PetscErrorCode PetscLogEventEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4) 958 959 Not Collective 960 961 Input Parameters: 962 + e - integer associated with the event obtained with PetscLogEventRegister() 963 - o1,o2,o3,o4 - objects associated with the event, or 0 964 965 966 Fortran Synopsis: 967 void PetscLogEventEnd(int e,PetscErrorCode ierr) 968 969 Usage: 970 .vb 971 PetscLogEvent USER_EVENT; 972 PetscLogDouble user_event_flops; 973 PetscLogEventRegister("User event",0,&USER_EVENT,); 974 PetscLogEventBegin(USER_EVENT,0,0,0,0); 975 [code segment to monitor] 976 PetscLogFlops(user_event_flops); 977 PetscLogEventEnd(USER_EVENT,0,0,0,0); 978 .ve 979 980 Notes: 981 You should also register each additional integer event with the command 982 PetscLogEventRegister(). 983 984 Level: intermediate 985 986 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogFlops() 987 988 .keywords: log, event, end 989 M*/ 990 991 /*MC 992 PetscLogEventBarrierBegin - Logs the time in a barrier before an event. 993 994 Synopsis: 995 #include <petsclog.h> 996 PetscErrorCode PetscLogEventBarrierBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4,MPI_Comm comm) 997 998 Not Collective 999 1000 Input Parameters: 1001 . e - integer associated with the event obtained from PetscLogEventRegister() 1002 . o1,o2,o3,o4 - objects associated with the event, or 0 1003 . comm - communicator the barrier takes place over 1004 1005 1006 Usage: 1007 .vb 1008 PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm); 1009 MPIU_Allreduce() 1010 PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm); 1011 .ve 1012 1013 Notes: 1014 This is for logging the amount of time spent in a barrier for an event 1015 that requires synchronization. 1016 1017 Additional Notes: 1018 Synchronization events always come in pairs; for example, VEC_NormBarrier and 1019 VEC_NormComm = VEC_NormBarrier + 1 1020 1021 Level: advanced 1022 1023 .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(), 1024 PetscLogEventBarrierEnd() 1025 1026 .keywords: log, event, begin, barrier 1027 M*/ 1028 1029 /*MC 1030 PetscLogEventBarrierEnd - Logs the time in a barrier before an event. 1031 1032 Synopsis: 1033 #include <petsclog.h> 1034 PetscErrorCode PetscLogEventBarrierEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,PetscObject o4,MPI_Comm comm) 1035 1036 Logically Collective on MPI_Comm 1037 1038 Input Parameters: 1039 . e - integer associated with the event obtained from PetscLogEventRegister() 1040 . o1,o2,o3,o4 - objects associated with the event, or 0 1041 . comm - communicator the barrier takes place over 1042 1043 1044 Usage: 1045 .vb 1046 PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm); 1047 MPIU_Allreduce() 1048 PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm); 1049 .ve 1050 1051 Notes: 1052 This is for logging the amount of time spent in a barrier for an event 1053 that requires synchronization. 1054 1055 Additional Notes: 1056 Synchronization events always come in pairs; for example, VEC_NormBarrier and 1057 VEC_NormComm = VEC_NormBarrier + 1 1058 1059 Level: advanced 1060 1061 .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(), 1062 PetscLogEventBarrierBegin() 1063 1064 .keywords: log, event, begin, barrier 1065 M*/ 1066 1067 #undef __FUNCT__ 1068 #define __FUNCT__ "PetscLogEventGetId" 1069 /*@C 1070 PetscLogEventGetId - Returns the event id when given the event name. 1071 1072 Not Collective 1073 1074 Input Parameter: 1075 . name - The event name 1076 1077 Output Parameter: 1078 . event - The event, or -1 if no event with that name exists 1079 1080 Level: intermediate 1081 1082 .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStageGetId() 1083 @*/ 1084 PetscErrorCode PetscLogEventGetId(const char name[], PetscLogEvent *event) 1085 { 1086 PetscStageLog stageLog; 1087 PetscErrorCode ierr; 1088 1089 PetscFunctionBegin; 1090 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 1091 ierr = PetscEventRegLogGetEvent(stageLog->eventLog, name, event);CHKERRQ(ierr); 1092 PetscFunctionReturn(0); 1093 } 1094 1095 1096 /*------------------------------------------------ Output Functions -------------------------------------------------*/ 1097 #undef __FUNCT__ 1098 #define __FUNCT__ "PetscLogDump" 1099 /*@C 1100 PetscLogDump - Dumps logs of objects to a file. This file is intended to 1101 be read by bin/petscview. This program no longer exists. 1102 1103 Collective on PETSC_COMM_WORLD 1104 1105 Input Parameter: 1106 . name - an optional file name 1107 1108 Usage: 1109 .vb 1110 PetscInitialize(...); 1111 PetscLogDefaultBegin(); or PetscLogAllBegin(); 1112 ... code ... 1113 PetscLogDump(filename); 1114 PetscFinalize(); 1115 .ve 1116 1117 Notes: 1118 The default file name is 1119 $ Log.<rank> 1120 where <rank> is the processor number. If no name is specified, 1121 this file will be used. 1122 1123 Level: advanced 1124 1125 .keywords: log, dump 1126 .seealso: PetscLogDefaultBegin(), PetscLogAllBegin(), PetscLogView() 1127 @*/ 1128 PetscErrorCode PetscLogDump(const char sname[]) 1129 { 1130 PetscStageLog stageLog; 1131 PetscEventPerfInfo *eventInfo; 1132 FILE *fd; 1133 char file[PETSC_MAX_PATH_LEN], fname[PETSC_MAX_PATH_LEN]; 1134 PetscLogDouble flops, _TotalTime; 1135 PetscMPIInt rank; 1136 int action, object, curStage; 1137 PetscLogEvent event; 1138 PetscErrorCode ierr; 1139 1140 PetscFunctionBegin; 1141 /* Calculate the total elapsed time */ 1142 PetscTime(&_TotalTime); 1143 _TotalTime -= petsc_BaseTime; 1144 /* Open log file */ 1145 ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);CHKERRQ(ierr); 1146 if (sname) sprintf(file, "%s.%d", sname, rank); 1147 else sprintf(file, "Log.%d", rank); 1148 ierr = PetscFixFilename(file, fname);CHKERRQ(ierr); 1149 ierr = PetscFOpen(PETSC_COMM_WORLD, fname, "w", &fd);CHKERRQ(ierr); 1150 if ((!rank) && (!fd)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN, "Cannot open file: %s", fname); 1151 /* Output totals */ 1152 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Total Flops %14e %16.8e\n", petsc_TotalFlops, _TotalTime);CHKERRQ(ierr); 1153 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Clock Resolution %g\n", 0.0);CHKERRQ(ierr); 1154 /* Output actions */ 1155 if (petsc_logActions) { 1156 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Actions accomplished %d\n", petsc_numActions);CHKERRQ(ierr); 1157 for (action = 0; action < petsc_numActions; action++) { 1158 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "%g %d %d %d %d %d %d %g %g %g\n", 1159 petsc_actions[action].time, petsc_actions[action].action, (int)petsc_actions[action].event, (int)petsc_actions[action].classid, petsc_actions[action].id1, 1160 petsc_actions[action].id2, petsc_actions[action].id3, petsc_actions[action].flops, petsc_actions[action].mem, petsc_actions[action].maxmem);CHKERRQ(ierr); 1161 } 1162 } 1163 /* Output objects */ 1164 if (petsc_logObjects) { 1165 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Objects created %d destroyed %d\n", petsc_numObjects, petsc_numObjectsDestroyed);CHKERRQ(ierr); 1166 for (object = 0; object < petsc_numObjects; object++) { 1167 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Parent ID: %d Memory: %d\n", petsc_objects[object].parent, (int) petsc_objects[object].mem);CHKERRQ(ierr); 1168 if (!petsc_objects[object].name[0]) { 1169 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd,"No Name\n");CHKERRQ(ierr); 1170 } else { 1171 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Name: %s\n", petsc_objects[object].name);CHKERRQ(ierr); 1172 } 1173 if (petsc_objects[object].info[0] != 0) { 1174 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "No Info\n");CHKERRQ(ierr); 1175 } else { 1176 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Info: %s\n", petsc_objects[object].info);CHKERRQ(ierr); 1177 } 1178 } 1179 } 1180 /* Output events */ 1181 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "Event log:\n");CHKERRQ(ierr); 1182 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 1183 ierr = PetscIntStackTop(stageLog->stack, &curStage);CHKERRQ(ierr); 1184 eventInfo = stageLog->stageInfo[curStage].eventLog->eventInfo; 1185 for (event = 0; event < stageLog->stageInfo[curStage].eventLog->numEvents; event++) { 1186 if (eventInfo[event].time != 0.0) flops = eventInfo[event].flops/eventInfo[event].time; 1187 else flops = 0.0; 1188 ierr = PetscFPrintf(PETSC_COMM_WORLD, fd, "%d %16d %16g %16g %16g\n", event, eventInfo[event].count, 1189 eventInfo[event].flops, eventInfo[event].time, flops);CHKERRQ(ierr); 1190 } 1191 ierr = PetscFClose(PETSC_COMM_WORLD, fd);CHKERRQ(ierr); 1192 PetscFunctionReturn(0); 1193 } 1194 1195 #undef __FUNCT__ 1196 #define __FUNCT__ "PetscLogView_Detailed" 1197 /* 1198 PetscLogView_Detailed - Each process prints the times for its own events 1199 1200 */ 1201 PetscErrorCode PetscLogView_Detailed(PetscViewer viewer) 1202 { 1203 MPI_Comm comm = PetscObjectComm((PetscObject) viewer); 1204 PetscEventPerfInfo *eventInfo = NULL; 1205 PetscLogDouble locTotalTime, numRed, maxMem; 1206 PetscStageLog stageLog; 1207 int numStages,numEvents,stage,event; 1208 PetscMPIInt rank,size; 1209 PetscErrorCode ierr; 1210 1211 PetscFunctionBegin; 1212 ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 1213 ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 1214 /* Must preserve reduction count before we go on */ 1215 numRed = petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct; 1216 /* Get the total elapsed time */ 1217 PetscTime(&locTotalTime); locTotalTime -= petsc_BaseTime; 1218 ierr = PetscViewerASCIIPrintf(viewer,"numProcs = %d\n",size);CHKERRQ(ierr); 1219 ierr = PetscViewerASCIIPrintf(viewer,"LocalTimes = {}\n");CHKERRQ(ierr); 1220 ierr = PetscViewerASCIIPrintf(viewer,"LocalFlops = {}\n");CHKERRQ(ierr); 1221 ierr = PetscViewerASCIIPrintf(viewer,"LocalMessageLens = {}\n");CHKERRQ(ierr); 1222 ierr = PetscViewerASCIIPrintf(viewer,"LocalMessages = {}\n");CHKERRQ(ierr); 1223 ierr = PetscViewerASCIIPrintf(viewer,"LocalReductions = {}\n");CHKERRQ(ierr); 1224 ierr = PetscViewerASCIIPrintf(viewer,"LocalObjects = {}\n");CHKERRQ(ierr); 1225 ierr = PetscViewerASCIIPrintf(viewer,"LocalMemory = {}\n");CHKERRQ(ierr); 1226 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 1227 ierr = MPIU_Allreduce(&stageLog->numStages, &numStages, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1228 ierr = PetscViewerASCIIPrintf(viewer,"Stages = {}\n");CHKERRQ(ierr); 1229 for (stage=0; stage<numStages; stage++) { 1230 ierr = PetscViewerASCIIPrintf(viewer,"Stages[\"%s\"] = {}\n",stageLog->stageInfo[stage].name);CHKERRQ(ierr); 1231 ierr = PetscViewerASCIIPrintf(viewer,"Stages[\"%s\"][\"summary\"] = {}\n",stageLog->stageInfo[stage].name);CHKERRQ(ierr); 1232 ierr = MPIU_Allreduce(&stageLog->stageInfo[stage].eventLog->numEvents, &numEvents, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1233 for (event = 0; event < numEvents; event++) { 1234 ierr = PetscViewerASCIIPrintf(viewer,"Stages[\"%s\"][\"%s\"] = {}\n",stageLog->stageInfo[stage].name,stageLog->eventLog->eventInfo[event].name);CHKERRQ(ierr); 1235 } 1236 } 1237 ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr); 1238 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalTimes[%d] = %g\n",rank,locTotalTime);CHKERRQ(ierr); 1239 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalFlops[%d] = %g\n",rank,petsc_TotalFlops);CHKERRQ(ierr); 1240 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalMessageLens[%d] = %g\n",rank,(petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len));CHKERRQ(ierr); 1241 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalMessages[%d] = %g\n",rank,(petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct));CHKERRQ(ierr); 1242 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalReductions[%d] = %g\n",rank,numRed);CHKERRQ(ierr); 1243 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalObjects[%d] = %g\n",rank,petsc_numObjects);CHKERRQ(ierr); 1244 ierr = PetscMallocGetMaximumUsage(&maxMem);CHKERRQ(ierr); 1245 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"LocalMemory[%d] = %g\n",rank,maxMem);CHKERRQ(ierr); 1246 ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 1247 for (stage=0; stage<numStages; stage++) { 1248 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Stages[\"%s\"][\"summary\"][%d] = {\"time\" : %g, \"numMessages\" : %g, \"messageLength\" : %g, \"numReductions\" : %g, \"flops\" : %g}\n", 1249 stageLog->stageInfo[stage].name,rank, 1250 stageLog->stageInfo[stage].perfInfo.time,stageLog->stageInfo[stage].perfInfo.numMessages,stageLog->stageInfo[stage].perfInfo.messageLength, 1251 stageLog->stageInfo[stage].perfInfo.numReductions,stageLog->stageInfo[stage].perfInfo.flops);CHKERRQ(ierr); 1252 ierr = MPIU_Allreduce(&stageLog->stageInfo[stage].eventLog->numEvents, &numEvents, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1253 for (event = 0; event < numEvents; event++) { 1254 eventInfo = stageLog->stageInfo[stage].eventLog->eventInfo; 1255 ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Stages[\"%s\"][\"%s\"][%d] = {\"count\" : %D, \"time\" : %g, \"numMessages\" : %g, \"messageLength\" : %g, \"numReductions\" : %g, \"flops\" : %g}\n",stageLog->stageInfo[stage].name,stageLog->eventLog->eventInfo[event].name,rank, 1256 eventInfo[event].count, eventInfo[event].time,eventInfo[event].numMessages, eventInfo[event].messageLength, 1257 eventInfo[event].numReductions,eventInfo[event].flops);CHKERRQ(ierr); 1258 } 1259 } 1260 ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); 1261 ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr); 1262 PetscFunctionReturn(0); 1263 } 1264 1265 #undef __FUNCT__ 1266 #define __FUNCT__ "PetscLogViewWarnDebugging" 1267 static PetscErrorCode PetscLogViewWarnDebugging(MPI_Comm comm,FILE *fd) 1268 { 1269 #if defined(PETSC_USE_DEBUG) 1270 PetscErrorCode ierr; 1271 1272 PetscFunctionBegin; 1273 ierr = PetscFPrintf(comm, fd, "\n\n");CHKERRQ(ierr); 1274 ierr = PetscFPrintf(comm, fd, " ##########################################################\n");CHKERRQ(ierr); 1275 ierr = PetscFPrintf(comm, fd, " # #\n");CHKERRQ(ierr); 1276 ierr = PetscFPrintf(comm, fd, " # WARNING!!! #\n");CHKERRQ(ierr); 1277 ierr = PetscFPrintf(comm, fd, " # #\n");CHKERRQ(ierr); 1278 ierr = PetscFPrintf(comm, fd, " # This code was compiled with a debugging option, #\n");CHKERRQ(ierr); 1279 ierr = PetscFPrintf(comm, fd, " # To get timing results run ./configure #\n");CHKERRQ(ierr); 1280 ierr = PetscFPrintf(comm, fd, " # using --with-debugging=no, the performance will #\n");CHKERRQ(ierr); 1281 ierr = PetscFPrintf(comm, fd, " # be generally two or three times faster. #\n");CHKERRQ(ierr); 1282 ierr = PetscFPrintf(comm, fd, " # #\n");CHKERRQ(ierr); 1283 ierr = PetscFPrintf(comm, fd, " ##########################################################\n\n\n");CHKERRQ(ierr); 1284 PetscFunctionReturn(0); 1285 #else 1286 return 0; 1287 #endif 1288 } 1289 1290 #undef __FUNCT__ 1291 #define __FUNCT__ "PetscLogView_Default" 1292 PetscErrorCode PetscLogView_Default(PetscViewer viewer) 1293 { 1294 FILE *fd; 1295 PetscLogDouble zero = 0.0; 1296 PetscStageLog stageLog; 1297 PetscStageInfo *stageInfo = NULL; 1298 PetscEventPerfInfo *eventInfo = NULL; 1299 PetscClassPerfInfo *classInfo; 1300 char arch[128],hostname[128],username[128],pname[PETSC_MAX_PATH_LEN],date[128]; 1301 const char *name; 1302 PetscLogDouble locTotalTime, TotalTime, TotalFlops; 1303 PetscLogDouble numMessages, messageLength, avgMessLen, numReductions; 1304 PetscLogDouble stageTime, flops, flopr, mem, mess, messLen, red; 1305 PetscLogDouble fracTime, fracFlops, fracMessages, fracLength, fracReductions, fracMess, fracMessLen, fracRed; 1306 PetscLogDouble fracStageTime, fracStageFlops, fracStageMess, fracStageMessLen, fracStageRed; 1307 PetscLogDouble min, max, tot, ratio, avg, x, y; 1308 PetscLogDouble minf, maxf, totf, ratf, mint, maxt, tott, ratt, ratCt, totm, totml, totr; 1309 PetscMPIInt minCt, maxCt; 1310 PetscMPIInt size, rank; 1311 PetscBool *localStageUsed, *stageUsed; 1312 PetscBool *localStageVisible, *stageVisible; 1313 int numStages, localNumEvents, numEvents; 1314 int stage, oclass; 1315 PetscLogEvent event; 1316 PetscErrorCode ierr; 1317 char version[256]; 1318 MPI_Comm comm; 1319 1320 PetscFunctionBegin; 1321 ierr = PetscObjectGetComm((PetscObject)viewer,&comm);CHKERRQ(ierr); 1322 ierr = PetscViewerASCIIGetPointer(viewer,&fd);CHKERRQ(ierr); 1323 ierr = MPI_Comm_size(comm, &size);CHKERRQ(ierr); 1324 ierr = MPI_Comm_rank(comm, &rank);CHKERRQ(ierr); 1325 /* Get the total elapsed time */ 1326 PetscTime(&locTotalTime); locTotalTime -= petsc_BaseTime; 1327 1328 ierr = PetscFPrintf(comm, fd, "************************************************************************************************************************\n");CHKERRQ(ierr); 1329 ierr = PetscFPrintf(comm, fd, "*** WIDEN YOUR WINDOW TO 120 CHARACTERS. Use 'enscript -r -fCourier9' to print this document ***\n");CHKERRQ(ierr); 1330 ierr = PetscFPrintf(comm, fd, "************************************************************************************************************************\n");CHKERRQ(ierr); 1331 ierr = PetscFPrintf(comm, fd, "\n---------------------------------------------- PETSc Performance Summary: ----------------------------------------------\n\n");CHKERRQ(ierr); 1332 ierr = PetscLogViewWarnDebugging(comm,fd);CHKERRQ(ierr); 1333 ierr = PetscGetArchType(arch,sizeof(arch));CHKERRQ(ierr); 1334 ierr = PetscGetHostName(hostname,sizeof(hostname));CHKERRQ(ierr); 1335 ierr = PetscGetUserName(username,sizeof(username));CHKERRQ(ierr); 1336 ierr = PetscGetProgramName(pname,sizeof(pname));CHKERRQ(ierr); 1337 ierr = PetscGetDate(date,sizeof(date));CHKERRQ(ierr); 1338 ierr = PetscGetVersion(version,sizeof(version));CHKERRQ(ierr); 1339 if (size == 1) { 1340 ierr = PetscFPrintf(comm,fd,"%s on a %s named %s with %d processor, by %s %s\n", pname, arch, hostname, size, username, date);CHKERRQ(ierr); 1341 } else { 1342 ierr = PetscFPrintf(comm,fd,"%s on a %s named %s with %d processors, by %s %s\n", pname, arch, hostname, size, username, date);CHKERRQ(ierr); 1343 } 1344 1345 ierr = PetscFPrintf(comm, fd, "Using %s\n", version);CHKERRQ(ierr); 1346 1347 /* Must preserve reduction count before we go on */ 1348 red = petsc_allreduce_ct + petsc_gather_ct + petsc_scatter_ct; 1349 1350 /* Calculate summary information */ 1351 ierr = PetscFPrintf(comm, fd, "\n Max Max/Min Avg Total \n");CHKERRQ(ierr); 1352 /* Time */ 1353 ierr = MPIU_Allreduce(&locTotalTime, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1354 ierr = MPIU_Allreduce(&locTotalTime, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1355 ierr = MPIU_Allreduce(&locTotalTime, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1356 avg = (tot)/((PetscLogDouble) size); 1357 if (min != 0.0) ratio = max/min; 1358 else ratio = 0.0; 1359 ierr = PetscFPrintf(comm, fd, "Time (sec): %5.3e %10.5f %5.3e\n", max, ratio, avg);CHKERRQ(ierr); 1360 TotalTime = tot; 1361 /* Objects */ 1362 avg = (PetscLogDouble) petsc_numObjects; 1363 ierr = MPIU_Allreduce(&avg, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1364 ierr = MPIU_Allreduce(&avg, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1365 ierr = MPIU_Allreduce(&avg, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1366 avg = (tot)/((PetscLogDouble) size); 1367 if (min != 0.0) ratio = max/min; 1368 else ratio = 0.0; 1369 ierr = PetscFPrintf(comm, fd, "Objects: %5.3e %10.5f %5.3e\n", max, ratio, avg);CHKERRQ(ierr); 1370 /* Flops */ 1371 ierr = MPIU_Allreduce(&petsc_TotalFlops, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1372 ierr = MPIU_Allreduce(&petsc_TotalFlops, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1373 ierr = MPIU_Allreduce(&petsc_TotalFlops, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1374 avg = (tot)/((PetscLogDouble) size); 1375 if (min != 0.0) ratio = max/min; 1376 else ratio = 0.0; 1377 ierr = PetscFPrintf(comm, fd, "Flops: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);CHKERRQ(ierr); 1378 TotalFlops = tot; 1379 /* Flops/sec -- Must talk to Barry here */ 1380 if (locTotalTime != 0.0) flops = petsc_TotalFlops/locTotalTime; 1381 else flops = 0.0; 1382 ierr = MPIU_Allreduce(&flops, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1383 ierr = MPIU_Allreduce(&flops, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1384 ierr = MPIU_Allreduce(&flops, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1385 avg = (tot)/((PetscLogDouble) size); 1386 if (min != 0.0) ratio = max/min; 1387 else ratio = 0.0; 1388 ierr = PetscFPrintf(comm, fd, "Flops/sec: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);CHKERRQ(ierr); 1389 /* Memory */ 1390 ierr = PetscMallocGetMaximumUsage(&mem);CHKERRQ(ierr); 1391 if (mem > 0.0) { 1392 ierr = MPIU_Allreduce(&mem, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1393 ierr = MPIU_Allreduce(&mem, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1394 ierr = MPIU_Allreduce(&mem, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1395 avg = (tot)/((PetscLogDouble) size); 1396 if (min != 0.0) ratio = max/min; 1397 else ratio = 0.0; 1398 ierr = PetscFPrintf(comm, fd, "Memory: %5.3e %10.5f %5.3e\n", max, ratio, tot);CHKERRQ(ierr); 1399 } 1400 /* Messages */ 1401 mess = 0.5*(petsc_irecv_ct + petsc_isend_ct + petsc_recv_ct + petsc_send_ct); 1402 ierr = MPIU_Allreduce(&mess, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1403 ierr = MPIU_Allreduce(&mess, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1404 ierr = MPIU_Allreduce(&mess, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1405 avg = (tot)/((PetscLogDouble) size); 1406 if (min != 0.0) ratio = max/min; 1407 else ratio = 0.0; 1408 ierr = PetscFPrintf(comm, fd, "MPI Messages: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);CHKERRQ(ierr); 1409 numMessages = tot; 1410 /* Message Lengths */ 1411 mess = 0.5*(petsc_irecv_len + petsc_isend_len + petsc_recv_len + petsc_send_len); 1412 ierr = MPIU_Allreduce(&mess, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1413 ierr = MPIU_Allreduce(&mess, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1414 ierr = MPIU_Allreduce(&mess, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1415 if (numMessages != 0) avg = (tot)/(numMessages); 1416 else avg = 0.0; 1417 if (min != 0.0) ratio = max/min; 1418 else ratio = 0.0; 1419 ierr = PetscFPrintf(comm, fd, "MPI Message Lengths: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);CHKERRQ(ierr); 1420 messageLength = tot; 1421 /* Reductions */ 1422 ierr = MPIU_Allreduce(&red, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1423 ierr = MPIU_Allreduce(&red, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1424 ierr = MPIU_Allreduce(&red, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1425 if (min != 0.0) ratio = max/min; 1426 else ratio = 0.0; 1427 ierr = PetscFPrintf(comm, fd, "MPI Reductions: %5.3e %10.5f\n", max, ratio);CHKERRQ(ierr); 1428 numReductions = red; /* wrong because uses count from process zero */ 1429 ierr = PetscFPrintf(comm, fd, "\nFlop counting convention: 1 flop = 1 real number operation of type (multiply/divide/add/subtract)\n");CHKERRQ(ierr); 1430 ierr = PetscFPrintf(comm, fd, " e.g., VecAXPY() for real vectors of length N --> 2N flops\n");CHKERRQ(ierr); 1431 ierr = PetscFPrintf(comm, fd, " and VecAXPY() for complex vectors of length N --> 8N flops\n");CHKERRQ(ierr); 1432 1433 /* Get total number of stages -- 1434 Currently, a single processor can register more stages than another, but stages must all be registered in order. 1435 We can removed this requirement if necessary by having a global stage numbering and indirection on the stage ID. 1436 This seems best accomplished by assoicating a communicator with each stage. 1437 */ 1438 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 1439 ierr = MPIU_Allreduce(&stageLog->numStages, &numStages, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1440 ierr = PetscMalloc1(numStages, &localStageUsed);CHKERRQ(ierr); 1441 ierr = PetscMalloc1(numStages, &stageUsed);CHKERRQ(ierr); 1442 ierr = PetscMalloc1(numStages, &localStageVisible);CHKERRQ(ierr); 1443 ierr = PetscMalloc1(numStages, &stageVisible);CHKERRQ(ierr); 1444 if (numStages > 0) { 1445 stageInfo = stageLog->stageInfo; 1446 for (stage = 0; stage < numStages; stage++) { 1447 if (stage < stageLog->numStages) { 1448 localStageUsed[stage] = stageInfo[stage].used; 1449 localStageVisible[stage] = stageInfo[stage].perfInfo.visible; 1450 } else { 1451 localStageUsed[stage] = PETSC_FALSE; 1452 localStageVisible[stage] = PETSC_TRUE; 1453 } 1454 } 1455 ierr = MPIU_Allreduce(localStageUsed, stageUsed, numStages, MPIU_BOOL, MPI_LOR, comm);CHKERRQ(ierr); 1456 ierr = MPIU_Allreduce(localStageVisible, stageVisible, numStages, MPIU_BOOL, MPI_LAND, comm);CHKERRQ(ierr); 1457 for (stage = 0; stage < numStages; stage++) { 1458 if (stageUsed[stage]) { 1459 ierr = PetscFPrintf(comm, fd, "\nSummary of Stages: ----- Time ------ ----- Flops ----- --- Messages --- -- Message Lengths -- -- Reductions --\n");CHKERRQ(ierr); 1460 ierr = PetscFPrintf(comm, fd, " Avg %%Total Avg %%Total counts %%Total Avg %%Total counts %%Total \n");CHKERRQ(ierr); 1461 break; 1462 } 1463 } 1464 for (stage = 0; stage < numStages; stage++) { 1465 if (!stageUsed[stage]) continue; 1466 /* CANNOT use MPIU_Allreduce() since it might fail the line number check */ 1467 if (localStageUsed[stage]) { 1468 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1469 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1470 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1471 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1472 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1473 name = stageInfo[stage].name; 1474 } else { 1475 ierr = MPI_Allreduce(&zero, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1476 ierr = MPI_Allreduce(&zero, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1477 ierr = MPI_Allreduce(&zero, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1478 ierr = MPI_Allreduce(&zero, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1479 ierr = MPI_Allreduce(&zero, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1480 name = ""; 1481 } 1482 mess *= 0.5; messLen *= 0.5; red /= size; 1483 if (TotalTime != 0.0) fracTime = stageTime/TotalTime; else fracTime = 0.0; 1484 if (TotalFlops != 0.0) fracFlops = flops/TotalFlops; else fracFlops = 0.0; 1485 /* Talk to Barry if (stageTime != 0.0) flops = (size*flops)/stageTime; else flops = 0.0; */ 1486 if (numMessages != 0.0) fracMessages = mess/numMessages; else fracMessages = 0.0; 1487 if (numMessages != 0.0) avgMessLen = messLen/numMessages; else avgMessLen = 0.0; 1488 if (messageLength != 0.0) fracLength = messLen/messageLength; else fracLength = 0.0; 1489 if (numReductions != 0.0) fracReductions = red/numReductions; else fracReductions = 0.0; 1490 ierr = PetscFPrintf(comm, fd, "%2d: %15s: %6.4e %5.1f%% %6.4e %5.1f%% %5.3e %5.1f%% %5.3e %5.1f%% %5.3e %5.1f%% \n", 1491 stage, name, stageTime/size, 100.0*fracTime, flops, 100.0*fracFlops, 1492 mess, 100.0*fracMessages, avgMessLen, 100.0*fracLength, red, 100.0*fracReductions);CHKERRQ(ierr); 1493 } 1494 } 1495 1496 ierr = PetscFPrintf(comm, fd,"\n------------------------------------------------------------------------------------------------------------------------\n");CHKERRQ(ierr); 1497 ierr = PetscFPrintf(comm, fd, "See the 'Profiling' chapter of the users' manual for details on interpreting output.\n");CHKERRQ(ierr); 1498 ierr = PetscFPrintf(comm, fd, "Phase summary info:\n");CHKERRQ(ierr); 1499 ierr = PetscFPrintf(comm, fd, " Count: number of times phase was executed\n");CHKERRQ(ierr); 1500 ierr = PetscFPrintf(comm, fd, " Time and Flops: Max - maximum over all processors\n");CHKERRQ(ierr); 1501 ierr = PetscFPrintf(comm, fd, " Ratio - ratio of maximum to minimum over all processors\n");CHKERRQ(ierr); 1502 ierr = PetscFPrintf(comm, fd, " Mess: number of messages sent\n");CHKERRQ(ierr); 1503 ierr = PetscFPrintf(comm, fd, " Avg. len: average message length (bytes)\n");CHKERRQ(ierr); 1504 ierr = PetscFPrintf(comm, fd, " Reduct: number of global reductions\n");CHKERRQ(ierr); 1505 ierr = PetscFPrintf(comm, fd, " Global: entire computation\n");CHKERRQ(ierr); 1506 ierr = PetscFPrintf(comm, fd, " Stage: stages of a computation. Set stages with PetscLogStagePush() and PetscLogStagePop().\n");CHKERRQ(ierr); 1507 ierr = PetscFPrintf(comm, fd, " %%T - percent time in this phase %%F - percent flops in this phase\n");CHKERRQ(ierr); 1508 ierr = PetscFPrintf(comm, fd, " %%M - percent messages in this phase %%L - percent message lengths in this phase\n");CHKERRQ(ierr); 1509 ierr = PetscFPrintf(comm, fd, " %%R - percent reductions in this phase\n");CHKERRQ(ierr); 1510 ierr = PetscFPrintf(comm, fd, " Total Mflop/s: 10e-6 * (sum of flops over all processors)/(max time over all processors)\n");CHKERRQ(ierr); 1511 ierr = PetscFPrintf(comm, fd, "------------------------------------------------------------------------------------------------------------------------\n");CHKERRQ(ierr); 1512 1513 ierr = PetscLogViewWarnDebugging(comm,fd);CHKERRQ(ierr); 1514 1515 /* Report events */ 1516 ierr = PetscFPrintf(comm, fd,"Event Count Time (sec) Flops --- Global --- --- Stage --- Total\n");CHKERRQ(ierr); 1517 ierr = PetscFPrintf(comm, fd," Max Ratio Max Ratio Max Ratio Mess Avg len Reduct %%T %%F %%M %%L %%R %%T %%F %%M %%L %%R Mflop/s\n");CHKERRQ(ierr); 1518 ierr = PetscFPrintf(comm,fd,"------------------------------------------------------------------------------------------------------------------------\n");CHKERRQ(ierr); 1519 1520 /* Problem: The stage name will not show up unless the stage executed on proc 1 */ 1521 for (stage = 0; stage < numStages; stage++) { 1522 if (!stageVisible[stage]) continue; 1523 /* CANNOT use MPIU_Allreduce() since it might fail the line number check */ 1524 if (localStageUsed[stage]) { 1525 ierr = PetscFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);CHKERRQ(ierr); 1526 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1527 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1528 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1529 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1530 ierr = MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1531 } else { 1532 ierr = PetscFPrintf(comm, fd, "\n--- Event Stage %d: Unknown\n\n", stage);CHKERRQ(ierr); 1533 ierr = MPI_Allreduce(&zero, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1534 ierr = MPI_Allreduce(&zero, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1535 ierr = MPI_Allreduce(&zero, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1536 ierr = MPI_Allreduce(&zero, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1537 ierr = MPI_Allreduce(&zero, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1538 } 1539 mess *= 0.5; messLen *= 0.5; red /= size; 1540 1541 /* Get total number of events in this stage -- 1542 Currently, a single processor can register more events than another, but events must all be registered in order, 1543 just like stages. We can removed this requirement if necessary by having a global event numbering and indirection 1544 on the event ID. This seems best accomplished by assoicating a communicator with each stage. 1545 1546 Problem: If the event did not happen on proc 1, its name will not be available. 1547 Problem: Event visibility is not implemented 1548 */ 1549 if (localStageUsed[stage]) { 1550 eventInfo = stageLog->stageInfo[stage].eventLog->eventInfo; 1551 localNumEvents = stageLog->stageInfo[stage].eventLog->numEvents; 1552 } else localNumEvents = 0; 1553 ierr = MPIU_Allreduce(&localNumEvents, &numEvents, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1554 for (event = 0; event < numEvents; event++) { 1555 /* CANNOT use MPIU_Allreduce() since it might fail the line number check */ 1556 if (localStageUsed[stage] && (event < stageLog->stageInfo[stage].eventLog->numEvents) && (eventInfo[event].depth == 0)) { 1557 if ((eventInfo[event].count > 0) && (eventInfo[event].time > 0.0)) flopr = eventInfo[event].flops; 1558 else flopr = 0.0; 1559 1560 ierr = MPI_Allreduce(&flopr, &minf, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1561 ierr = MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1562 ierr = MPI_Allreduce(&eventInfo[event].flops, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1563 ierr = MPI_Allreduce(&eventInfo[event].time, &mint, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1564 ierr = MPI_Allreduce(&eventInfo[event].time, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1565 ierr = MPI_Allreduce(&eventInfo[event].time, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1566 ierr = MPI_Allreduce(&eventInfo[event].numMessages, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1567 ierr = MPI_Allreduce(&eventInfo[event].messageLength, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1568 ierr = MPI_Allreduce(&eventInfo[event].numReductions, &totr, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1569 ierr = MPI_Allreduce(&eventInfo[event].count, &minCt, 1, MPI_INT, MPI_MIN, comm);CHKERRQ(ierr); 1570 ierr = MPI_Allreduce(&eventInfo[event].count, &maxCt, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1571 name = stageLog->eventLog->eventInfo[event].name; 1572 } else { 1573 flopr = 0.0; 1574 ierr = MPI_Allreduce(&flopr, &minf, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1575 ierr = MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1576 ierr = MPI_Allreduce(&zero, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1577 ierr = MPI_Allreduce(&zero, &mint, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);CHKERRQ(ierr); 1578 ierr = MPI_Allreduce(&zero, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);CHKERRQ(ierr); 1579 ierr = MPI_Allreduce(&zero, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1580 ierr = MPI_Allreduce(&zero, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1581 ierr = MPI_Allreduce(&zero, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1582 ierr = MPI_Allreduce(&zero, &totr, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);CHKERRQ(ierr); 1583 ierr = MPI_Allreduce(&ierr, &minCt, 1, MPI_INT, MPI_MIN, comm);CHKERRQ(ierr); 1584 ierr = MPI_Allreduce(&ierr, &maxCt, 1, MPI_INT, MPI_MAX, comm);CHKERRQ(ierr); 1585 name = ""; 1586 } 1587 if (mint < 0.0) { 1588 ierr = PetscFPrintf(comm, fd, "WARNING!!! Minimum time %g over all processors for %s is negative! This happens\n on some machines whose times cannot handle too rapid calls.!\n artificially changing minimum to zero.\n",mint,name); 1589 mint = 0; 1590 } 1591 if (minf < 0.0) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Minimum flops %g over all processors for %s is negative! Not possible!",minf,name); 1592 totm *= 0.5; totml *= 0.5; totr /= size; 1593 1594 if (maxCt != 0) { 1595 if (minCt != 0) ratCt = ((PetscLogDouble) maxCt)/minCt; else ratCt = 0.0; 1596 if (mint != 0.0) ratt = maxt/mint; else ratt = 0.0; 1597 if (minf != 0.0) ratf = maxf/minf; else ratf = 0.0; 1598 if (TotalTime != 0.0) fracTime = tott/TotalTime; else fracTime = 0.0; 1599 if (TotalFlops != 0.0) fracFlops = totf/TotalFlops; else fracFlops = 0.0; 1600 if (stageTime != 0.0) fracStageTime = tott/stageTime; else fracStageTime = 0.0; 1601 if (flops != 0.0) fracStageFlops = totf/flops; else fracStageFlops = 0.0; 1602 if (numMessages != 0.0) fracMess = totm/numMessages; else fracMess = 0.0; 1603 if (messageLength != 0.0) fracMessLen = totml/messageLength; else fracMessLen = 0.0; 1604 if (numReductions != 0.0) fracRed = totr/numReductions; else fracRed = 0.0; 1605 if (mess != 0.0) fracStageMess = totm/mess; else fracStageMess = 0.0; 1606 if (messLen != 0.0) fracStageMessLen = totml/messLen; else fracStageMessLen = 0.0; 1607 if (red != 0.0) fracStageRed = totr/red; else fracStageRed = 0.0; 1608 if (totm != 0.0) totml /= totm; else totml = 0.0; 1609 if (maxt != 0.0) flopr = totf/maxt; else flopr = 0.0; 1610 if (fracStageTime > 1.00) ierr = PetscFPrintf(comm, fd,"Warning -- total time of event greater than time of entire stage -- something is wrong with the timer\n");CHKERRQ(ierr); 1611 ierr = PetscFPrintf(comm, fd, 1612 "%-16s %7d%4.1f %5.4e%4.1f %3.2e%4.1f %2.1e %2.1e %2.1e%3.0f%3.0f%3.0f%3.0f%3.0f %3.0f%3.0f%3.0f%3.0f%3.0f %5.0f\n", 1613 name, maxCt, ratCt, maxt, ratt, maxf, ratf, totm, totml, totr, 1614 100.0*fracTime, 100.0*fracFlops, 100.0*fracMess, 100.0*fracMessLen, 100.0*fracRed, 1615 100.0*fracStageTime, 100.0*fracStageFlops, 100.0*fracStageMess, 100.0*fracStageMessLen, 100.0*fracStageRed, 1616 PetscAbsReal(flopr/1.0e6));CHKERRQ(ierr); 1617 } 1618 } 1619 } 1620 1621 /* Memory usage and object creation */ 1622 ierr = PetscFPrintf(comm, fd, "------------------------------------------------------------------------------------------------------------------------\n");CHKERRQ(ierr); 1623 ierr = PetscFPrintf(comm, fd, "\n");CHKERRQ(ierr); 1624 ierr = PetscFPrintf(comm, fd, "Memory usage is given in bytes:\n\n");CHKERRQ(ierr); 1625 1626 /* Right now, only stages on the first processor are reported here, meaning only objects associated with 1627 the global communicator, or MPI_COMM_SELF for proc 1. We really should report global stats and then 1628 stats for stages local to processor sets. 1629 */ 1630 /* We should figure out the longest object name here (now 20 characters) */ 1631 ierr = PetscFPrintf(comm, fd, "Object Type Creations Destructions Memory Descendants' Mem.\n");CHKERRQ(ierr); 1632 ierr = PetscFPrintf(comm, fd, "Reports information only for process 0.\n");CHKERRQ(ierr); 1633 for (stage = 0; stage < numStages; stage++) { 1634 if (localStageUsed[stage]) { 1635 classInfo = stageLog->stageInfo[stage].classLog->classInfo; 1636 ierr = PetscFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);CHKERRQ(ierr); 1637 for (oclass = 0; oclass < stageLog->stageInfo[stage].classLog->numClasses; oclass++) { 1638 if ((classInfo[oclass].creations > 0) || (classInfo[oclass].destructions > 0)) { 1639 ierr = PetscFPrintf(comm, fd, "%20s %5d %5d %11.0f %g\n", stageLog->classLog->classInfo[oclass].name, 1640 classInfo[oclass].creations, classInfo[oclass].destructions, classInfo[oclass].mem, 1641 classInfo[oclass].descMem);CHKERRQ(ierr); 1642 } 1643 } 1644 } else { 1645 ierr = PetscFPrintf(comm, fd, "\n--- Event Stage %d: Unknown\n\n", stage);CHKERRQ(ierr); 1646 } 1647 } 1648 1649 ierr = PetscFree(localStageUsed);CHKERRQ(ierr); 1650 ierr = PetscFree(stageUsed);CHKERRQ(ierr); 1651 ierr = PetscFree(localStageVisible);CHKERRQ(ierr); 1652 ierr = PetscFree(stageVisible);CHKERRQ(ierr); 1653 1654 /* Information unrelated to this particular run */ 1655 ierr = PetscFPrintf(comm, fd, "========================================================================================================================\n");CHKERRQ(ierr); 1656 PetscTime(&y); 1657 PetscTime(&x); 1658 PetscTime(&y); PetscTime(&y); PetscTime(&y); PetscTime(&y); PetscTime(&y); 1659 PetscTime(&y); PetscTime(&y); PetscTime(&y); PetscTime(&y); PetscTime(&y); 1660 ierr = PetscFPrintf(comm,fd,"Average time to get PetscTime(): %g\n", (y-x)/10.0);CHKERRQ(ierr); 1661 /* MPI information */ 1662 if (size > 1) { 1663 MPI_Status status; 1664 PetscMPIInt tag; 1665 MPI_Comm newcomm; 1666 1667 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1668 PetscTime(&x); 1669 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1670 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1671 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1672 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1673 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1674 PetscTime(&y); 1675 ierr = PetscFPrintf(comm, fd, "Average time for MPI_Barrier(): %g\n", (y-x)/5.0);CHKERRQ(ierr); 1676 ierr = PetscCommDuplicate(comm,&newcomm, &tag);CHKERRQ(ierr); 1677 ierr = MPI_Barrier(comm);CHKERRQ(ierr); 1678 if (rank) { 1679 ierr = MPI_Recv(0, 0, MPI_INT, rank-1, tag, newcomm, &status);CHKERRQ(ierr); 1680 ierr = MPI_Send(0, 0, MPI_INT, (rank+1)%size, tag, newcomm);CHKERRQ(ierr); 1681 } else { 1682 PetscTime(&x); 1683 ierr = MPI_Send(0, 0, MPI_INT, 1, tag, newcomm);CHKERRQ(ierr); 1684 ierr = MPI_Recv(0, 0, MPI_INT, size-1, tag, newcomm, &status);CHKERRQ(ierr); 1685 PetscTime(&y); 1686 ierr = PetscFPrintf(comm,fd,"Average time for zero size MPI_Send(): %g\n", (y-x)/size);CHKERRQ(ierr); 1687 } 1688 ierr = PetscCommDestroy(&newcomm);CHKERRQ(ierr); 1689 } 1690 ierr = PetscOptionsView(NULL,viewer);CHKERRQ(ierr); 1691 1692 /* Machine and compile information */ 1693 #if defined(PETSC_USE_FORTRAN_KERNELS) 1694 ierr = PetscFPrintf(comm, fd, "Compiled with FORTRAN kernels\n");CHKERRQ(ierr); 1695 #else 1696 ierr = PetscFPrintf(comm, fd, "Compiled without FORTRAN kernels\n");CHKERRQ(ierr); 1697 #endif 1698 #if defined(PETSC_USE_REAL_SINGLE) 1699 ierr = PetscFPrintf(comm, fd, "Compiled with single precision PetscScalar and PetscReal\n");CHKERRQ(ierr); 1700 #elif defined(PETSC_USE_LONGDOUBLE) 1701 ierr = PetscFPrintf(comm, fd, "Compiled with long double precision PetscScalar and PetscReal\n");CHKERRQ(ierr); 1702 #endif 1703 1704 #if defined(PETSC_USE_REAL_MAT_SINGLE) 1705 ierr = PetscFPrintf(comm, fd, "Compiled with single precision matrices\n");CHKERRQ(ierr); 1706 #else 1707 ierr = PetscFPrintf(comm, fd, "Compiled with full precision matrices (default)\n");CHKERRQ(ierr); 1708 #endif 1709 ierr = PetscFPrintf(comm, fd, "sizeof(short) %d sizeof(int) %d sizeof(long) %d sizeof(void*) %d sizeof(PetscScalar) %d sizeof(PetscInt) %d\n", 1710 (int) sizeof(short), (int) sizeof(int), (int) sizeof(long), (int) sizeof(void*),(int) sizeof(PetscScalar),(int) sizeof(PetscInt));CHKERRQ(ierr); 1711 1712 ierr = PetscFPrintf(comm, fd, "Configure options: %s",petscconfigureoptions);CHKERRQ(ierr); 1713 ierr = PetscFPrintf(comm, fd, "%s", petscmachineinfo);CHKERRQ(ierr); 1714 ierr = PetscFPrintf(comm, fd, "%s", petsccompilerinfo);CHKERRQ(ierr); 1715 ierr = PetscFPrintf(comm, fd, "%s", petsccompilerflagsinfo);CHKERRQ(ierr); 1716 ierr = PetscFPrintf(comm, fd, "%s", petsclinkerinfo);CHKERRQ(ierr); 1717 1718 /* Cleanup */ 1719 ierr = PetscFPrintf(comm, fd, "\n");CHKERRQ(ierr); 1720 ierr = PetscLogViewWarnDebugging(comm,fd);CHKERRQ(ierr); 1721 PetscFunctionReturn(0); 1722 } 1723 1724 PetscErrorCode PetscLogView_Nested(PetscViewer); 1725 1726 #undef __FUNCT__ 1727 #define __FUNCT__ "PetscLogView" 1728 /*@C 1729 PetscLogView - Prints a summary of the logging. 1730 1731 Collective over MPI_Comm 1732 1733 Input Parameter: 1734 . viewer - an ASCII viewer 1735 1736 Options Database Keys: 1737 + -log_view [:filename] - Prints summary of log information 1738 . -log_view :filename.py:ascii_info_detail - Saves logging information from each process as a Python file 1739 . -log_view :filename.xml:ascii_xml - Saves a summary of the logging information in a nested format, use a browser to open this file, for example on 1740 Apple MacOS systems use open -a Safari filename.xml 1741 . -log_all - Saves a file Log.rank for each MPI process with details of each step of the computation 1742 - -log_trace [filename] - Displays a trace of what each process is doing 1743 1744 Notes: 1745 It is possible to control the logging programatically but we recommend using the options database approach whenever possible 1746 By default the summary is printed to stdout. 1747 1748 Before calling this routine you must have called either PetscLogDefaultBegin() or PetscLogNestedBegin() 1749 1750 If PETSc is configured with --with-logging=0 then this functionality is not available 1751 1752 The nested XML format was kindly donated by Koos Huijssen and Christiaan M. Klaij MARITIME RESEARCH INSTITUTE NETHERLANDS 1753 1754 Level: beginner 1755 1756 .keywords: log, dump, print 1757 .seealso: PetscLogDefaultBegin(), PetscLogDump() 1758 @*/ 1759 PetscErrorCode PetscLogView(PetscViewer viewer) 1760 { 1761 PetscErrorCode ierr; 1762 PetscBool isascii; 1763 PetscViewerFormat format; 1764 int stage, lastStage; 1765 PetscStageLog stageLog; 1766 1767 PetscFunctionBegin; 1768 if (!PetscLogPLB) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Must use -log_summary or PetscLogDefaultBegin() before calling this routine"); 1769 /* Pop off any stages the user forgot to remove */ 1770 lastStage = 0; 1771 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 1772 ierr = PetscStageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); 1773 while (stage >= 0) { 1774 lastStage = stage; 1775 ierr = PetscStageLogPop(stageLog);CHKERRQ(ierr); 1776 ierr = PetscStageLogGetCurrent(stageLog, &stage);CHKERRQ(ierr); 1777 } 1778 ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);CHKERRQ(ierr); 1779 if (!isascii) SETERRQ(PetscObjectComm((PetscObject)viewer),PETSC_ERR_SUP,"Currently can only view logging to ASCII"); 1780 ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 1781 if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO) { 1782 ierr = PetscLogView_Default(viewer);CHKERRQ(ierr); 1783 } else if (format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 1784 ierr = PetscLogView_Detailed(viewer);CHKERRQ(ierr); 1785 } else if (format == PETSC_VIEWER_ASCII_XML) { 1786 ierr = PetscLogView_Nested(viewer);CHKERRQ(ierr); 1787 } 1788 ierr = PetscStageLogPush(stageLog, lastStage);CHKERRQ(ierr); 1789 PetscFunctionReturn(0); 1790 } 1791 1792 #undef __FUNCT__ 1793 #define __FUNCT__ "PetscLogViewFromOptions" 1794 /*@C 1795 PetscLogViewFromOptions - Processes command line options to determine if/how a PetscLog is to be viewed. 1796 1797 Collective on PETSC_COMM_WORLD 1798 1799 Not normally called by user 1800 1801 Level: intermediate 1802 1803 @*/ 1804 PetscErrorCode PetscLogViewFromOptions(void) 1805 { 1806 PetscErrorCode ierr; 1807 PetscViewer viewer; 1808 PetscBool flg; 1809 PetscViewerFormat format; 1810 1811 PetscFunctionBegin; 1812 ierr = PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,"-log_view",&viewer,&format,&flg);CHKERRQ(ierr); 1813 if (flg) { 1814 ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr); 1815 ierr = PetscLogView(viewer);CHKERRQ(ierr); 1816 ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr); 1817 ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); 1818 } 1819 PetscFunctionReturn(0); 1820 } 1821 1822 1823 1824 /*----------------------------------------------- Counter Functions -------------------------------------------------*/ 1825 #undef __FUNCT__ 1826 #define __FUNCT__ "PetscGetFlops" 1827 /*@C 1828 PetscGetFlops - Returns the number of flops used on this processor 1829 since the program began. 1830 1831 Not Collective 1832 1833 Output Parameter: 1834 flops - number of floating point operations 1835 1836 Notes: 1837 A global counter logs all PETSc flop counts. The user can use 1838 PetscLogFlops() to increment this counter to include flops for the 1839 application code. 1840 1841 Level: intermediate 1842 1843 .keywords: log, flops, floating point operations 1844 1845 .seealso: PetscTime(), PetscLogFlops() 1846 @*/ 1847 PetscErrorCode PetscGetFlops(PetscLogDouble *flops) 1848 { 1849 PetscFunctionBegin; 1850 *flops = petsc_TotalFlops; 1851 PetscFunctionReturn(0); 1852 } 1853 1854 #undef __FUNCT__ 1855 #define __FUNCT__ "PetscLogObjectState" 1856 PetscErrorCode PetscLogObjectState(PetscObject obj, const char format[], ...) 1857 { 1858 PetscErrorCode ierr; 1859 size_t fullLength; 1860 va_list Argp; 1861 1862 PetscFunctionBegin; 1863 if (!petsc_logObjects) PetscFunctionReturn(0); 1864 va_start(Argp, format); 1865 ierr = PetscVSNPrintf(petsc_objects[obj->id].info, 64,format,&fullLength, Argp);CHKERRQ(ierr); 1866 va_end(Argp); 1867 PetscFunctionReturn(0); 1868 } 1869 1870 1871 /*MC 1872 PetscLogFlops - Adds floating point operations to the global counter. 1873 1874 Synopsis: 1875 #include <petsclog.h> 1876 PetscErrorCode PetscLogFlops(PetscLogDouble f) 1877 1878 Not Collective 1879 1880 Input Parameter: 1881 . f - flop counter 1882 1883 1884 Usage: 1885 .vb 1886 PetscLogEvent USER_EVENT; 1887 PetscLogEventRegister("User event",0,&USER_EVENT); 1888 PetscLogEventBegin(USER_EVENT,0,0,0,0); 1889 [code segment to monitor] 1890 PetscLogFlops(user_flops) 1891 PetscLogEventEnd(USER_EVENT,0,0,0,0); 1892 .ve 1893 1894 Notes: 1895 A global counter logs all PETSc flop counts. The user can use 1896 PetscLogFlops() to increment this counter to include flops for the 1897 application code. 1898 1899 Level: intermediate 1900 1901 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscGetFlops() 1902 1903 .keywords: log, flops, floating point operations 1904 M*/ 1905 1906 /*MC 1907 PetscPreLoadBegin - Begin a segment of code that may be preloaded (run twice) 1908 to get accurate timings 1909 1910 Synopsis: 1911 #include <petsclog.h> 1912 void PetscPreLoadBegin(PetscBool flag,char *name); 1913 1914 Not Collective 1915 1916 Input Parameter: 1917 + flag - PETSC_TRUE to run twice, PETSC_FALSE to run once, may be overridden 1918 with command line option -preload true or -preload false 1919 - name - name of first stage (lines of code timed separately with -log_summary) to 1920 be preloaded 1921 1922 Usage: 1923 .vb 1924 PetscPreLoadBegin(PETSC_TRUE,"first stage); 1925 lines of code 1926 PetscPreLoadStage("second stage"); 1927 lines of code 1928 PetscPreLoadEnd(); 1929 .ve 1930 1931 Notes: Only works in C/C++, not Fortran 1932 1933 Flags available within the macro. 1934 + PetscPreLoadingUsed - true if we are or have done preloading 1935 . PetscPreLoadingOn - true if it is CURRENTLY doing preload 1936 . PetscPreLoadIt - 0 for the first computation (with preloading turned off it is only 0) 1 for the second 1937 - PetscPreLoadMax - number of times it will do the computation, only one when preloading is turned on 1938 The first two variables are available throughout the program, the second two only between the PetscPreLoadBegin() 1939 and PetscPreLoadEnd() 1940 1941 Level: intermediate 1942 1943 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscPreLoadEnd(), PetscPreLoadStage() 1944 1945 Concepts: preloading 1946 Concepts: timing^accurate 1947 Concepts: paging^eliminating effects of 1948 1949 1950 M*/ 1951 1952 /*MC 1953 PetscPreLoadEnd - End a segment of code that may be preloaded (run twice) 1954 to get accurate timings 1955 1956 Synopsis: 1957 #include <petsclog.h> 1958 void PetscPreLoadEnd(void); 1959 1960 Not Collective 1961 1962 Usage: 1963 .vb 1964 PetscPreLoadBegin(PETSC_TRUE,"first stage); 1965 lines of code 1966 PetscPreLoadStage("second stage"); 1967 lines of code 1968 PetscPreLoadEnd(); 1969 .ve 1970 1971 Notes: only works in C/C++ not fortran 1972 1973 Level: intermediate 1974 1975 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscPreLoadBegin(), PetscPreLoadStage() 1976 1977 M*/ 1978 1979 /*MC 1980 PetscPreLoadStage - Start a new segment of code to be timed separately. 1981 to get accurate timings 1982 1983 Synopsis: 1984 #include <petsclog.h> 1985 void PetscPreLoadStage(char *name); 1986 1987 Not Collective 1988 1989 Usage: 1990 .vb 1991 PetscPreLoadBegin(PETSC_TRUE,"first stage); 1992 lines of code 1993 PetscPreLoadStage("second stage"); 1994 lines of code 1995 PetscPreLoadEnd(); 1996 .ve 1997 1998 Notes: only works in C/C++ not fortran 1999 2000 Level: intermediate 2001 2002 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscPreLoadBegin(), PetscPreLoadEnd() 2003 2004 M*/ 2005 2006 2007 #else /* end of -DPETSC_USE_LOG section */ 2008 2009 #undef __FUNCT__ 2010 #define __FUNCT__ "PetscLogObjectState" 2011 PetscErrorCode PetscLogObjectState(PetscObject obj, const char format[], ...) 2012 { 2013 PetscFunctionBegin; 2014 PetscFunctionReturn(0); 2015 } 2016 2017 #endif /* PETSC_USE_LOG*/ 2018 2019 2020 PetscClassId PETSC_LARGEST_CLASSID = PETSC_SMALLEST_CLASSID; 2021 PetscClassId PETSC_OBJECT_CLASSID = 0; 2022 2023 #undef __FUNCT__ 2024 #define __FUNCT__ "PetscClassIdRegister" 2025 /*@C 2026 PetscClassIdRegister - Registers a new class name for objects and logging operations in an application code. 2027 2028 Not Collective 2029 2030 Input Parameter: 2031 . name - The class name 2032 2033 Output Parameter: 2034 . oclass - The class id or classid 2035 2036 Level: developer 2037 2038 .keywords: log, class, register 2039 2040 @*/ 2041 PetscErrorCode PetscClassIdRegister(const char name[],PetscClassId *oclass) 2042 { 2043 #if defined(PETSC_USE_LOG) 2044 PetscStageLog stageLog; 2045 PetscInt stage; 2046 PetscErrorCode ierr; 2047 #endif 2048 2049 PetscFunctionBegin; 2050 *oclass = ++PETSC_LARGEST_CLASSID; 2051 #if defined(PETSC_USE_LOG) 2052 ierr = PetscLogGetStageLog(&stageLog);CHKERRQ(ierr); 2053 ierr = PetscClassRegLogRegister(stageLog->classLog, name, *oclass);CHKERRQ(ierr); 2054 for (stage = 0; stage < stageLog->numStages; stage++) { 2055 ierr = PetscClassPerfLogEnsureSize(stageLog->stageInfo[stage].classLog, stageLog->classLog->numClasses);CHKERRQ(ierr); 2056 } 2057 #endif 2058 PetscFunctionReturn(0); 2059 } 2060 2061 #if defined(PETSC_USE_LOG) && defined(PETSC_HAVE_MPE) 2062 #include <mpe.h> 2063 2064 PetscBool PetscBeganMPE = PETSC_FALSE; 2065 2066 PETSC_INTERN PetscErrorCode PetscLogEventBeginMPE(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 2067 PETSC_INTERN PetscErrorCode PetscLogEventEndMPE(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 2068 2069 #undef __FUNCT__ 2070 #define __FUNCT__ "PetscLogMPEBegin" 2071 /*@C 2072 PetscLogMPEBegin - Turns on MPE logging of events. This creates large log files 2073 and slows the program down. 2074 2075 Collective over PETSC_COMM_WORLD 2076 2077 Options Database Keys: 2078 . -log_mpe - Prints extensive log information 2079 2080 Notes: 2081 A related routine is PetscLogDefaultBegin() (with the options key -log_summary), which is 2082 intended for production runs since it logs only flop rates and object 2083 creation (and should not significantly slow the programs). 2084 2085 Level: advanced 2086 2087 Concepts: logging^MPE 2088 Concepts: logging^message passing 2089 2090 .seealso: PetscLogDump(), PetscLogDefaultBegin(), PetscLogAllBegin(), PetscLogEventActivate(), 2091 PetscLogEventDeactivate() 2092 @*/ 2093 PetscErrorCode PetscLogMPEBegin(void) 2094 { 2095 PetscErrorCode ierr; 2096 2097 PetscFunctionBegin; 2098 /* Do MPE initialization */ 2099 if (!MPE_Initialized_logging()) { /* This function exists in mpich 1.1.2 and higher */ 2100 ierr = PetscInfo(0,"Initializing MPE.\n");CHKERRQ(ierr); 2101 ierr = MPE_Init_log();CHKERRQ(ierr); 2102 2103 PetscBeganMPE = PETSC_TRUE; 2104 } else { 2105 ierr = PetscInfo(0,"MPE already initialized. Not attempting to reinitialize.\n");CHKERRQ(ierr); 2106 } 2107 ierr = PetscLogSet(PetscLogEventBeginMPE, PetscLogEventEndMPE);CHKERRQ(ierr); 2108 PetscFunctionReturn(0); 2109 } 2110 2111 #undef __FUNCT__ 2112 #define __FUNCT__ "PetscLogMPEDump" 2113 /*@C 2114 PetscLogMPEDump - Dumps the MPE logging info to file for later use with Jumpshot. 2115 2116 Collective over PETSC_COMM_WORLD 2117 2118 Level: advanced 2119 2120 .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogMPEBegin() 2121 @*/ 2122 PetscErrorCode PetscLogMPEDump(const char sname[]) 2123 { 2124 char name[PETSC_MAX_PATH_LEN]; 2125 PetscErrorCode ierr; 2126 2127 PetscFunctionBegin; 2128 if (PetscBeganMPE) { 2129 ierr = PetscInfo(0,"Finalizing MPE.\n");CHKERRQ(ierr); 2130 if (sname) { 2131 ierr = PetscStrcpy(name,sname);CHKERRQ(ierr); 2132 } else { 2133 ierr = PetscGetProgramName(name,PETSC_MAX_PATH_LEN);CHKERRQ(ierr); 2134 } 2135 ierr = MPE_Finish_log(name);CHKERRQ(ierr); 2136 } else { 2137 ierr = PetscInfo(0,"Not finalizing MPE (not started by PETSc).\n");CHKERRQ(ierr); 2138 } 2139 PetscFunctionReturn(0); 2140 } 2141 2142 #define PETSC_RGB_COLORS_MAX 39 2143 static const char *PetscLogMPERGBColors[PETSC_RGB_COLORS_MAX] = { 2144 "OliveDrab: ", 2145 "BlueViolet: ", 2146 "CadetBlue: ", 2147 "CornflowerBlue: ", 2148 "DarkGoldenrod: ", 2149 "DarkGreen: ", 2150 "DarkKhaki: ", 2151 "DarkOliveGreen: ", 2152 "DarkOrange: ", 2153 "DarkOrchid: ", 2154 "DarkSeaGreen: ", 2155 "DarkSlateGray: ", 2156 "DarkTurquoise: ", 2157 "DeepPink: ", 2158 "DarkKhaki: ", 2159 "DimGray: ", 2160 "DodgerBlue: ", 2161 "GreenYellow: ", 2162 "HotPink: ", 2163 "IndianRed: ", 2164 "LavenderBlush: ", 2165 "LawnGreen: ", 2166 "LemonChiffon: ", 2167 "LightCoral: ", 2168 "LightCyan: ", 2169 "LightPink: ", 2170 "LightSalmon: ", 2171 "LightSlateGray: ", 2172 "LightYellow: ", 2173 "LimeGreen: ", 2174 "MediumPurple: ", 2175 "MediumSeaGreen: ", 2176 "MediumSlateBlue:", 2177 "MidnightBlue: ", 2178 "MintCream: ", 2179 "MistyRose: ", 2180 "NavajoWhite: ", 2181 "NavyBlue: ", 2182 "OliveDrab: " 2183 }; 2184 2185 #undef __FUNCT__ 2186 #define __FUNCT__ "PetscLogMPEGetRGBColor" 2187 /*@C 2188 PetscLogMPEGetRGBColor - This routine returns a rgb color useable with PetscLogEventRegister() 2189 2190 Not collective. Maybe it should be? 2191 2192 Output Parameter 2193 . str - character string representing the color 2194 2195 Level: developer 2196 2197 .keywords: log, mpe , color 2198 .seealso: PetscLogEventRegister 2199 @*/ 2200 PetscErrorCode PetscLogMPEGetRGBColor(const char *str[]) 2201 { 2202 static int idx = 0; 2203 2204 PetscFunctionBegin; 2205 *str = PetscLogMPERGBColors[idx]; 2206 idx = (idx + 1)% PETSC_RGB_COLORS_MAX; 2207 PetscFunctionReturn(0); 2208 } 2209 2210 #endif /* PETSC_USE_LOG && PETSC_HAVE_MPE */ 2211