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