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