Actual source code: plog.c
1: #define PETSC_DLL
2: /*
3: PETSc code to log object creation and destruction and PETSc events.
4: */
5: #include petscsys.h
6: #include petsctime.h
7: #if defined(PETSC_HAVE_MPE)
8: #include "mpe.h"
9: #endif
10: #include <stdarg.h>
11: #include <sys/types.h>
12: #if defined(PETSC_HAVE_STDLIB_H)
13: #include <stdlib.h>
14: #endif
15: #if defined(PETSC_HAVE_MALLOC_H)
16: #include <malloc.h>
17: #endif
18: #include ../src/sys/plog/plog.h
20: PetscLogEvent PETSC_LARGEST_EVENT = PETSC_EVENT;
23: std::map<std::string,PETSc::LogEvent> PETSc::Log::event_registry;
24: std::map<std::string,PETSc::LogStage> PETSc::Log::stage_registry;
25: #endif
27: #if defined(PETSC_USE_LOG)
28: #include "petscmachineinfo.h"
29: #include "petscconfiginfo.h"
31: /* used in the MPI_XXX() count macros in petsclog.h */
33: /* Action and object logging variables */
34: Action *actions = PETSC_NULL;
35: Object *objects = PETSC_NULL;
36: PetscTruth logActions = PETSC_FALSE;
37: PetscTruth logObjects = PETSC_FALSE;
38: int numActions = 0, maxActions = 100;
39: int numObjects = 0, maxObjects = 100;
40: int numObjectsDestroyed = 0;
42: /* Global counters */
43: PetscLogDouble BaseTime = 0.0;
44: PetscLogDouble _TotalFlops = 0.0; /* The number of flops */
45: PetscLogDouble petsc_tmp_flops = 0.0; /* The incremental number of flops */
46: PetscLogDouble send_ct = 0.0; /* The number of sends */
47: PetscLogDouble recv_ct = 0.0; /* The number of receives */
48: PetscLogDouble send_len = 0.0; /* The total length of all sent messages */
49: PetscLogDouble recv_len = 0.0; /* The total length of all received messages */
50: PetscLogDouble isend_ct = 0.0; /* The number of immediate sends */
51: PetscLogDouble irecv_ct = 0.0; /* The number of immediate receives */
52: PetscLogDouble isend_len = 0.0; /* The total length of all immediate send messages */
53: PetscLogDouble irecv_len = 0.0; /* The total length of all immediate receive messages */
54: PetscLogDouble wait_ct = 0.0; /* The number of waits */
55: PetscLogDouble wait_any_ct = 0.0; /* The number of anywaits */
56: PetscLogDouble wait_all_ct = 0.0; /* The number of waitalls */
57: PetscLogDouble sum_of_waits_ct = 0.0; /* The total number of waits */
58: PetscLogDouble allreduce_ct = 0.0; /* The number of reductions */
59: PetscLogDouble gather_ct = 0.0; /* The number of gathers and gathervs */
60: PetscLogDouble scatter_ct = 0.0; /* The number of scatters and scattervs */
62: /* Logging functions */
63: PetscErrorCode (*_PetscLogPHC)(PetscObject) = PETSC_NULL;
64: PetscErrorCode (*_PetscLogPHD)(PetscObject) = PETSC_NULL;
65: PetscErrorCode (*_PetscLogPLB)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject) = PETSC_NULL;
66: PetscErrorCode (*_PetscLogPLE)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject) = PETSC_NULL;
68: /* Tracing event logging variables */
69: FILE *tracefile = PETSC_NULL;
70: int tracelevel = 0;
71: const char *traceblanks = " ";
72: char tracespace[128] = " ";
73: PetscLogDouble tracetime = 0.0;
74: PetscTruth PetscLogBegin_PrivateCalled = PETSC_FALSE;
76: /*---------------------------------------------- General Functions --------------------------------------------------*/
79: /*@C
80: PetscLogDestroy - Destroys the object and event logging data and resets the global counters.
82: Not Collective
84: Notes:
85: This routine should not usually be used by programmers. Instead employ
86: PetscLogStagePush() and PetscLogStagePop().
88: Level: developer
90: .keywords: log, destroy
91: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogStagePush(), PlogStagePop()
92: @*/
93: PetscErrorCode PetscLogDestroy(void)
94: {
95: StageLog stageLog;
99: PetscFree(actions);
100: actions = PETSC_NULL;
101: PetscFree(objects);
102: objects = PETSC_NULL;
103: PetscLogSet(PETSC_NULL, PETSC_NULL);
105: /* Resetting phase */
106: PetscLogGetStageLog(&stageLog);
107: StageLogDestroy(stageLog);
108: _TotalFlops = 0.0;
109: numActions = 0;
110: numObjects = 0;
111: numObjectsDestroyed = 0;
112: maxActions = 100;
113: maxObjects = 100;
114: actions = PETSC_NULL;
115: objects = PETSC_NULL;
116: logActions = PETSC_FALSE;
117: logObjects = PETSC_FALSE;
118: BaseTime = 0.0;
119: _TotalFlops = 0.0;
120: petsc_tmp_flops = 0.0;
121: send_ct = 0.0;
122: recv_ct = 0.0;
123: send_len = 0.0;
124: recv_len = 0.0;
125: isend_ct = 0.0;
126: irecv_ct = 0.0;
127: isend_len = 0.0;
128: irecv_len = 0.0;
129: wait_ct = 0.0;
130: wait_any_ct = 0.0;
131: wait_all_ct = 0.0;
132: sum_of_waits_ct = 0.0;
133: allreduce_ct = 0.0;
134: gather_ct = 0.0;
135: scatter_ct = 0.0;
136: PETSC_LARGEST_EVENT = PETSC_EVENT;
137: _PetscLogPHC = PETSC_NULL;
138: _PetscLogPHD = PETSC_NULL;
139: tracefile = PETSC_NULL;
140: tracelevel = 0;
141: traceblanks = " ";
142: tracespace[0] = ' '; tracespace[1] = 0;
143: tracetime = 0.0;
144: PETSC_LARGEST_COOKIE = PETSC_SMALLEST_COOKIE;
145: PETSC_OBJECT_COOKIE = 0;
146: _stageLog = 0;
147: PetscLogBegin_PrivateCalled = PETSC_FALSE;
148: return(0);
149: }
153: /*@C
154: PetscLogSet - Sets the logging functions called at the beginning and ending of every event.
156: Not Collective
158: Input Parameters:
159: + b - The function called at beginning of event
160: - e - The function called at end of event
162: Level: developer
164: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogAllBegin(), PetscLogTraceBegin()
165: @*/
166: PetscErrorCode PetscLogSet(PetscErrorCode (*b)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject),
167: PetscErrorCode (*e)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject))
168: {
170: _PetscLogPLB = b;
171: _PetscLogPLE = e;
172: return(0);
173: }
175: #if defined(PETSC_HAVE_CHUD)
176: #include <CHUD/CHUD.h>
177: #endif
178: #if defined(PETSC_HAVE_PAPI)
179: #include "papi.h"
180: int PAPIEventSet = PAPI_NULL;
181: #endif
183: /*------------------------------------------- Initialization Functions ----------------------------------------------*/
186: PetscErrorCode PetscLogBegin_Private(void)
187: {
188: int stage;
189: PetscTruth opt;
190: PetscErrorCode ierr;
193: if (PetscLogBegin_PrivateCalled) return(0);
194: PetscLogBegin_PrivateCalled = PETSC_TRUE;
196: PetscOptionsHasName(PETSC_NULL, "-log_exclude_actions", &opt);
197: if (opt) {
198: logActions = PETSC_FALSE;
199: }
200: PetscOptionsHasName(PETSC_NULL, "-log_exclude_objects", &opt);
201: if (opt) {
202: logObjects = PETSC_FALSE;
203: }
204: if (logActions) {
205: PetscMalloc(maxActions * sizeof(Action), &actions);
206: }
207: if (logObjects) {
208: PetscMalloc(maxObjects * sizeof(Object), &objects);
209: }
210: _PetscLogPHC = PetscLogObjCreateDefault;
211: _PetscLogPHD = PetscLogObjDestroyDefault;
212: /* Setup default logging structures */
213: StageLogCreate(&_stageLog);
214: StageLogRegister(_stageLog, "Main Stage", &stage);
215: #if defined(PETSC_HAVE_CHUD)
216: chudInitialize();
217: chudAcquireSamplingFacility(CHUD_BLOCKING);
218: chudSetSamplingDevice(chudCPU1Dev);
219: chudSetStartDelay(0,chudNanoSeconds);
220: chudClearPMCMode(chudCPU1Dev,chudUnused);
221: chudClearPMCs();
222: /* chudSetPMCMuxPosition(chudCPU1Dev,0,0); */
223: printf("%s\n",chudGetEventName(chudCPU1Dev,PMC_1,193));
224: printf("%s\n",chudGetEventDescription(chudCPU1Dev,PMC_1,193));
225: printf("%s\n",chudGetEventNotes(chudCPU1Dev,PMC_1,193));
226: chudSetPMCEvent(chudCPU1Dev,PMC_1,193);
227: chudSetPMCMode(chudCPU1Dev,PMC_1,chudCounter);
228: chudSetPrivilegeFilter(chudCPU1Dev,PMC_1,chudCountUserEvents);
229: chudSetPMCEventMask(chudCPU1Dev,PMC_1,0xFE);
230: if (!chudIsEventValid(chudCPU1Dev,PMC_1,193)) SETERRQ1(PETSC_ERR_SUP,"Event is not valid %d",193);
231: chudStartPMCs();
232: #endif
233: #if defined(PETSC_HAVE_PAPI)
234: PAPI_library_init(PAPI_VER_CURRENT);
235: if (ierr != PAPI_VER_CURRENT) SETERRQ(PETSC_ERR_LIB,"Cannot initialize PAPI");
236: PAPI_query_event(PAPI_FP_INS);
237: PAPI_create_eventset(&PAPIEventSet);
238: PAPI_add_event(PAPIEventSet,PAPI_FP_INS);
239: PAPI_start(PAPIEventSet);
240: #endif
242: /* All processors sync here for more consistent logging */
243: MPI_Barrier(PETSC_COMM_WORLD);
244: PetscTime(BaseTime);
245: PetscLogStagePush(stage);
246: return(0);
247: }
251: /*@C
252: PetscLogBegin - Turns on logging of objects and events. This logs flop
253: rates and object creation and should not slow programs down too much.
254: This routine may be called more than once.
256: Collective over PETSC_COMM_WORLD
258: Options Database Keys:
259: + -log_summary - Prints summary of flop and timing information to the
260: screen (for code compiled with PETSC_USE_LOG)
261: - -log - Prints detailed log information (for code compiled with PETSC_USE_LOG)
263: Usage:
264: .vb
265: PetscInitialize(...);
266: PetscLogBegin();
267: ... code ...
268: PetscLogPrintSummary(MPI_Comm,filename); or PetscLogDump();
269: PetscFinalize();
270: .ve
272: Notes:
273: PetscLogPrintSummary(MPI_Comm,filename) or PetscLogDump() actually cause the printing of
274: the logging information.
276: Level: advanced
278: .keywords: log, begin
279: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogTraceBegin()
280: @*/
281: PetscErrorCode PetscLogBegin(void)
282: {
286: PetscLogSet(PetscLogEventBeginDefault, PetscLogEventEndDefault);
287: PetscLogBegin_Private();
288: return(0);
289: }
293: /*@C
294: PetscLogAllBegin - Turns on extensive logging of objects and events. Logs
295: all events. This creates large log files and slows the program down.
297: Collective on PETSC_COMM_WORLD
299: Options Database Keys:
300: . -log_all - Prints extensive log information (for code compiled with PETSC_USE_LOG)
302: Usage:
303: .vb
304: PetscInitialize(...);
305: PetscLogAllBegin();
306: ... code ...
307: PetscLogDump(filename);
308: PetscFinalize();
309: .ve
311: Notes:
312: A related routine is PetscLogBegin (with the options key -log), which is
313: intended for production runs since it logs only flop rates and object
314: creation (and shouldn't significantly slow the programs).
316: Level: advanced
318: .keywords: log, all, begin
319: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogTraceBegin()
320: @*/
321: PetscErrorCode PetscLogAllBegin(void)
322: {
326: PetscLogSet(PetscLogEventBeginComplete, PetscLogEventEndComplete);
327: PetscLogBegin_Private();
328: return(0);
329: }
333: /*@
334: PetscLogTraceBegin - Activates trace logging. Every time a PETSc event
335: begins or ends, the event name is printed.
337: Collective on PETSC_COMM_WORLD
339: Input Parameter:
340: . file - The file to print trace in (e.g. stdout)
342: Options Database Key:
343: . -log_trace [filename] - Activates PetscLogTraceBegin()
345: Notes:
346: PetscLogTraceBegin() prints the processor number, the execution time (sec),
347: then "Event begin:" or "Event end:" followed by the event name.
349: PetscLogTraceBegin() allows tracing of all PETSc calls, which is useful
350: to determine where a program is hanging without running in the
351: debugger. Can be used in conjunction with the -info option.
353: Level: intermediate
355: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogBegin()
356: @*/
357: PetscErrorCode PetscLogTraceBegin(FILE *file)
358: {
362: tracefile = file;
363: PetscLogSet(PetscLogEventBeginTrace, PetscLogEventEndTrace);
364: PetscLogBegin_Private();
365: return(0);
366: }
370: /*@
371: PetscLogActions - Determines whether actions are logged for the graphical viewer.
373: Not Collective
375: Input Parameter:
376: . flag - PETSC_TRUE if actions are to be logged
378: Level: intermediate
380: Note: Logging of actions continues to consume more memory as the program
381: runs. Long running programs should consider turning this feature off.
383: Options Database Keys:
384: . -log_exclude_actions - Turns off actions logging
386: .keywords: log, stage, register
387: .seealso: PetscLogStagePush(), PetscLogStagePop()
388: @*/
389: PetscErrorCode PetscLogActions(PetscTruth flag)
390: {
392: logActions = flag;
393: return(0);
394: }
398: /*@
399: PetscLogObjects - Determines whether objects are logged for the graphical viewer.
401: Not Collective
403: Input Parameter:
404: . flag - PETSC_TRUE if objects are to be logged
406: Level: intermediate
408: Note: Logging of objects continues to consume more memory as the program
409: runs. Long running programs should consider turning this feature off.
411: Options Database Keys:
412: . -log_exclude_objects - Turns off objects logging
414: .keywords: log, stage, register
415: .seealso: PetscLogStagePush(), PetscLogStagePop()
416: @*/
417: PetscErrorCode PetscLogObjects(PetscTruth flag)
418: {
420: logObjects = flag;
421: return(0);
422: }
424: /*------------------------------------------------ Stage Functions --------------------------------------------------*/
427: /*@C
428: PetscLogStageRegister - Attaches a charactor string name to a logging stage.
430: Not Collective
432: Input Parameter:
433: . sname - The name to associate with that stage
435: Output Parameter:
436: . stage - The stage number
438: Level: intermediate
440: .keywords: log, stage, register
441: .seealso: PetscLogStagePush(), PetscLogStagePop()
442: @*/
443: PetscErrorCode PetscLogStageRegister(const char sname[],PetscLogStage *stage)
444: {
445: StageLog stageLog;
446: PetscLogEvent event;
450: PetscLogGetStageLog(&stageLog);
451: StageLogRegister(stageLog, sname, stage);
452: /* Copy events already changed in the main stage, this sucks */
453: EventPerfLogEnsureSize(stageLog->stageInfo[*stage].eventLog, stageLog->eventLog->numEvents);
454: for(event = 0; event < stageLog->eventLog->numEvents; event++) {
455: EventPerfInfoCopy(&stageLog->stageInfo[0].eventLog->eventInfo[event],
456: &stageLog->stageInfo[*stage].eventLog->eventInfo[event]);
457: }
458: ClassPerfLogEnsureSize(stageLog->stageInfo[*stage].classLog, stageLog->classLog->numClasses);
459: return(0);
460: }
464: /*@C
465: PetscLogStagePush - This function pushes a stage on the stack.
467: Not Collective
469: Input Parameter:
470: . stage - The stage on which to log
472: Usage:
473: If the option -log_sumary is used to run the program containing the
474: following code, then 2 sets of summary data will be printed during
475: PetscFinalize().
476: .vb
477: PetscInitialize(int *argc,char ***args,0,0);
478: [stage 0 of code]
479: PetscLogStagePush(1);
480: [stage 1 of code]
481: PetscLogStagePop();
482: PetscBarrier(...);
483: [more stage 0 of code]
484: PetscFinalize();
485: .ve
486:
487: Notes:
488: Use PetscLogStageRegister() to register a stage.
490: Level: intermediate
492: .keywords: log, push, stage
493: .seealso: PetscLogStagePop(), PetscLogStageRegister(), PetscBarrier()
494: @*/
495: PetscErrorCode PetscLogStagePush(PetscLogStage stage)
496: {
497: StageLog stageLog;
501: PetscLogGetStageLog(&stageLog);
502: StageLogPush(stageLog, stage);
503: return(0);
504: }
508: /*@C
509: PetscLogStagePop - This function pops a stage from the stack.
511: Not Collective
513: Usage:
514: If the option -log_sumary is used to run the program containing the
515: following code, then 2 sets of summary data will be printed during
516: PetscFinalize().
517: .vb
518: PetscInitialize(int *argc,char ***args,0,0);
519: [stage 0 of code]
520: PetscLogStagePush(1);
521: [stage 1 of code]
522: PetscLogStagePop();
523: PetscBarrier(...);
524: [more stage 0 of code]
525: PetscFinalize();
526: .ve
528: Notes:
529: Use PetscLogStageRegister() to register a stage.
531: Level: intermediate
533: .keywords: log, pop, stage
534: .seealso: PetscLogStagePush(), PetscLogStageRegister(), PetscBarrier()
535: @*/
536: PetscErrorCode PetscLogStagePop(void)
537: {
538: StageLog stageLog;
542: PetscLogGetStageLog(&stageLog);
543: StageLogPop(stageLog);
544: return(0);
545: }
549: /*@
550: PetscLogStageSetActive - Determines stage activity for PetscLogEventBegin() and PetscLogEventEnd().
552: Not Collective
554: Input Parameters:
555: + stage - The stage
556: - isActive - The activity flag, PETSC_TRUE for logging, else PETSC_FALSE (defaults to PETSC_TRUE)
558: Level: intermediate
560: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
561: @*/
562: PetscErrorCode PetscLogStageSetActive(PetscLogStage stage, PetscTruth isActive)
563: {
564: StageLog stageLog;
568: PetscLogGetStageLog(&stageLog);
569: StageLogSetActive(stageLog, stage, isActive);
570: return(0);
571: }
575: /*@
576: PetscLogStageGetActive - Returns stage activity for PetscLogEventBegin() and PetscLogEventEnd().
578: Not Collective
580: Input Parameter:
581: . stage - The stage
583: Output Parameter:
584: . isActive - The activity flag, PETSC_TRUE for logging, else PETSC_FALSE (defaults to PETSC_TRUE)
586: Level: intermediate
588: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
589: @*/
590: PetscErrorCode PetscLogStageGetActive(PetscLogStage stage, PetscTruth *isActive)
591: {
592: StageLog stageLog;
596: PetscLogGetStageLog(&stageLog);
597: StageLogGetActive(stageLog, stage, isActive);
598: return(0);
599: }
603: /*@
604: PetscLogStageSetVisible - Determines stage visibility in PetscLogPrintSummary()
606: Not Collective
608: Input Parameters:
609: + stage - The stage
610: - isVisible - The visibility flag, PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE)
612: Level: intermediate
614: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogPrintSummary()
615: @*/
616: PetscErrorCode PetscLogStageSetVisible(PetscLogStage stage, PetscTruth isVisible)
617: {
618: StageLog stageLog;
622: PetscLogGetStageLog(&stageLog);
623: StageLogSetVisible(stageLog, stage, isVisible);
624: return(0);
625: }
629: /*@
630: PetscLogStageGetVisible - Returns stage visibility in PetscLogPrintSummary()
632: Not Collective
634: Input Parameter:
635: . stage - The stage
637: Output Parameter:
638: . isVisible - The visibility flag, PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE)
640: Level: intermediate
642: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogPrintSummary()
643: @*/
644: PetscErrorCode PetscLogStageGetVisible(PetscLogStage stage, PetscTruth *isVisible)
645: {
646: StageLog stageLog;
650: PetscLogGetStageLog(&stageLog);
651: StageLogGetVisible(stageLog, stage, isVisible);
652: return(0);
653: }
657: /*@C
658: PetscLogStageGetId - Returns the stage id when given the stage name.
660: Not Collective
662: Input Parameter:
663: . name - The stage name
665: Output Parameter:
666: . stage - The stage
668: Level: intermediate
670: .seealso: PetscLogStagePush(), PetscLogStagePop(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
671: @*/
672: PetscErrorCode PetscLogStageGetId(const char name[], PetscLogStage *stage)
673: {
674: StageLog stageLog;
678: PetscLogGetStageLog(&stageLog);
679: StageLogGetStage(stageLog, name, stage);
680: return(0);
681: }
683: /*------------------------------------------------ Event Functions --------------------------------------------------*/
686: /*@C
687: PetscLogEventRegister - Registers an event name for logging operations in an application code.
689: Not Collective
691: Input Parameter:
692: + name - The name associated with the event
693: - cookie - The cookie associated to the class for this event, obtain either with
694: PetscCookieRegister() or use a predefined one such as KSP_COOKIE, SNES_COOKIE
695:
696: Output Parameter:
697: . event - The event id for use with PetscLogEventBegin() and PetscLogEventEnd().
699: Example of Usage:
700: .vb
701: PetscLogEvent USER_EVENT;
702: PetscCookie cookie;
703: PetscLogDouble user_event_flops;
704: PetscCookieRegister("class name",&cookie);
705: PetscLogEventRegister("User event name",cookie,&USER_EVENT);
706: PetscLogEventBegin(USER_EVENT,0,0,0,0);
707: [code segment to monitor]
708: PetscLogFlops(user_event_flops);
709: PetscLogEventEnd(USER_EVENT,0,0,0,0);
710: .ve
712: Notes:
713: PETSc automatically logs library events if the code has been
714: compiled with -DPETSC_USE_LOG (which is the default) and -log,
715: -log_summary, or -log_all are specified. PetscLogEventRegister() is
716: intended for logging user events to supplement this PETSc
717: information.
719: PETSc can gather data for use with the utilities Upshot/Nupshot
720: (part of the MPICH distribution). If PETSc has been compiled
721: with flag -DPETSC_HAVE_MPE (MPE is an additional utility within
722: MPICH), the user can employ another command line option, -log_mpe,
723: to create a logfile, "mpe.log", which can be visualized
724: Upshot/Nupshot.
726: The cookie is associated with each event so that classes of events
727: can be disabled simultaneously, such as all matrix events. The user
728: can either use an existing cookie, such as MAT_COOKIE, or create
729: their own as shown in the example.
731: Level: intermediate
733: .keywords: log, event, register
734: .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogFlops(),
735: PetscLogEventMPEActivate(), PetscLogEventMPEDeactivate(),
736: PetscLogEventActivate(), PetscLogEventDeactivate(), PetscCookieRegister()
737: @*/
738: PetscErrorCode PetscLogEventRegister(const char name[],PetscCookie cookie,PetscLogEvent *event)
739: {
740: StageLog stageLog;
741: int stage;
745: *event = PETSC_DECIDE;
746: PetscLogGetStageLog(&stageLog);
747: EventRegLogRegister(stageLog->eventLog, name, cookie, event);
748: for(stage = 0; stage < stageLog->numStages; stage++) {
749: EventPerfLogEnsureSize(stageLog->stageInfo[stage].eventLog, stageLog->eventLog->numEvents);
750: ClassPerfLogEnsureSize(stageLog->stageInfo[stage].classLog, stageLog->classLog->numClasses);
751: }
752: return(0);
753: }
757: /*@
758: PetscLogEventActivate - Indicates that a particular event should be logged.
760: Not Collective
762: Input Parameter:
763: . event - The event id
765: Usage:
766: .vb
767: PetscLogEventDeactivate(VEC_SetValues);
768: [code where you do not want to log VecSetValues()]
769: PetscLogEventActivate(VEC_SetValues);
770: [code where you do want to log VecSetValues()]
771: .ve
773: Note:
774: The event may be either a pre-defined PETSc event (found in include/petsclog.h)
775: or an event number obtained with PetscLogEventRegister().
777: Level: advanced
779: .keywords: log, event, activate
780: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventDeactivate()
781: @*/
782: PetscErrorCode PetscLogEventActivate(PetscLogEvent event)
783: {
784: StageLog stageLog;
785: int stage;
789: PetscLogGetStageLog(&stageLog);
790: StageLogGetCurrent(stageLog, &stage);
791: EventPerfLogActivate(stageLog->stageInfo[stage].eventLog, event);
792: return(0);
793: }
797: /*@
798: PetscLogEventDeactivate - Indicates that a particular event should not be logged.
800: Not Collective
802: Input Parameter:
803: . event - The event id
805: Usage:
806: .vb
807: PetscLogEventDeactivate(VEC_SetValues);
808: [code where you do not want to log VecSetValues()]
809: PetscLogEventActivate(VEC_SetValues);
810: [code where you do want to log VecSetValues()]
811: .ve
813: Note:
814: The event may be either a pre-defined PETSc event (found in
815: include/petsclog.h) or an event number obtained with PetscLogEventRegister()).
817: Level: advanced
819: .keywords: log, event, deactivate
820: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventActivate()
821: @*/
822: PetscErrorCode PetscLogEventDeactivate(PetscLogEvent event)
823: {
824: StageLog stageLog;
825: int stage;
829: PetscLogGetStageLog(&stageLog);
830: StageLogGetCurrent(stageLog, &stage);
831: EventPerfLogDeactivate(stageLog->stageInfo[stage].eventLog, event);
832: return(0);
833: }
837: /*@
838: PetscLogEventSetActiveAll - Sets the event activity in every stage.
840: Not Collective
842: Input Parameters:
843: + event - The event id
844: - isActive - The activity flag determining whether the event is logged
846: Level: advanced
848: .keywords: log, event, activate
849: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventActivate(),PlogEventDeactivate()
850: @*/
851: PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent event, PetscTruth isActive)
852: {
853: StageLog stageLog;
854: int stage;
858: PetscLogGetStageLog(&stageLog);
859: for(stage = 0; stage < stageLog->numStages; stage++) {
860: if (isActive) {
861: EventPerfLogActivate(stageLog->stageInfo[stage].eventLog, event);
862: } else {
863: EventPerfLogDeactivate(stageLog->stageInfo[stage].eventLog, event);
864: }
865: }
866: return(0);
867: }
871: /*@
872: PetscLogEventActivateClass - Activates event logging for a PETSc object class.
874: Not Collective
876: Input Parameter:
877: . cookie - The event class, for example MAT_COOKIE, SNES_COOKIE, etc.
879: Level: developer
881: .keywords: log, event, activate, class
882: .seealso: PetscInfoActivate(),PetscInfo(),PetscInfoAllow(),PetscLogEventDeactivateClass(), PetscLogEventActivate(),PetscLogEventDeactivate()
883: @*/
884: PetscErrorCode PetscLogEventActivateClass(PetscCookie cookie)
885: {
886: StageLog stageLog;
887: int stage;
891: PetscLogGetStageLog(&stageLog);
892: StageLogGetCurrent(stageLog, &stage);
893: EventPerfLogActivateClass(stageLog->stageInfo[stage].eventLog, stageLog->eventLog, cookie);
894: return(0);
895: }
899: /*@
900: PetscLogEventDeactivateClass - Deactivates event logging for a PETSc object class.
902: Not Collective
904: Input Parameter:
905: . cookie - The event class, for example MAT_COOKIE, SNES_COOKIE, etc.
907: Level: developer
909: .keywords: log, event, deactivate, class
910: .seealso: PetscInfoActivate(),PetscInfo(),PetscInfoAllow(),PetscLogEventActivateClass(), PetscLogEventActivate(),PetscLogEventDeactivate()
911: @*/
912: PetscErrorCode PetscLogEventDeactivateClass(PetscCookie cookie)
913: {
914: StageLog stageLog;
915: int stage;
919: PetscLogGetStageLog(&stageLog);
920: StageLogGetCurrent(stageLog, &stage);
921: EventPerfLogDeactivateClass(stageLog->stageInfo[stage].eventLog, stageLog->eventLog, cookie);
922: return(0);
923: }
925: /*MC
926: PetscLogEventBegin - Logs the beginning of a user event.
928: Input Parameters:
929: + e - integer associated with the event obtained from PetscLogEventRegister()
930: - o1,o2,o3,o4 - objects associated with the event, or 0
932: Synopsis:
933: void PetscLogEventBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
934: PetscObject o4)
936: Fortran Synopsis:
937: void PetscLogEventBegin(int e,PetscErrorCode ierr)
939: Usage:
940: .vb
941: int USER_EVENT;
942: PetscLogDouble user_event_flops;
943: PetscLogEventRegister("User event",0,&USER_EVENT);
944: PetscLogEventBegin(USER_EVENT,0,0,0,0);
945: [code segment to monitor]
946: PetscLogFlops(user_event_flops);
947: PetscLogEventEnd(USER_EVENT,0,0,0,0);
948: .ve
950: Notes:
951: You need to register each integer event with the command
952: PetscLogEventRegister(). The source code must be compiled with
953: -DPETSC_USE_LOG, which is the default.
955: PETSc automatically logs library events if the code has been
956: compiled with -DPETSC_USE_LOG, and -log, -log_summary, or -log_all are
957: specified. PetscLogEventBegin() is intended for logging user events
958: to supplement this PETSc information.
960: Level: intermediate
962: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops()
964: .keywords: log, event, begin
965: M*/
967: /*MC
968: PetscLogEventEnd - Log the end of a user event.
970: Input Parameters:
971: + e - integer associated with the event obtained with PetscLogEventRegister()
972: - o1,o2,o3,o4 - objects associated with the event, or 0
974: Synopsis:
975: void PetscLogEventEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
976: PetscObject o4)
978: Fortran Synopsis:
979: void PetscLogEventEnd(int e,PetscErrorCode ierr)
981: Usage:
982: .vb
983: int USER_EVENT;
984: PetscLogDouble user_event_flops;
985: PetscLogEventRegister("User event",0,&USER_EVENT,);
986: PetscLogEventBegin(USER_EVENT,0,0,0,0);
987: [code segment to monitor]
988: PetscLogFlops(user_event_flops);
989: PetscLogEventEnd(USER_EVENT,0,0,0,0);
990: .ve
992: Notes:
993: You should also register each additional integer event with the command
994: PetscLogEventRegister(). Source code must be compiled with
995: -DPETSC_USE_LOG, which is the default.
997: PETSc automatically logs library events if the code has been
998: compiled with -DPETSC_USE_LOG, and -log, -log_summary, or -log_all are
999: specified. PetscLogEventEnd() is intended for logging user events
1000: to supplement this PETSc information.
1002: Level: intermediate
1004: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogFlops()
1006: .keywords: log, event, end
1007: M*/
1009: /*MC
1010: PetscLogEventBarrierBegin - Logs the time in a barrier before an event.
1012: Input Parameters:
1013: . e - integer associated with the event obtained from PetscLogEventRegister()
1014: . o1,o2,o3,o4 - objects associated with the event, or 0
1015: . comm - communicator the barrier takes place over
1017: Synopsis:
1018: void PetscLogEventBarrierBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
1019: PetscObject o4,MPI_Comm comm)
1021: Usage:
1022: .vb
1023: PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm);
1024: MPI_Allreduce()
1025: PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm);
1026: .ve
1028: Notes:
1029: This is for logging the amount of time spent in a barrier for an event
1030: that requires synchronization.
1032: Additional Notes:
1033: Synchronization events always come in pairs; for example, VEC_NormBarrier and
1034: VEC_NormComm = VEC_NormBarrier + 1
1036: Level: advanced
1038: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(),
1039: PetscLogEventBarrierEnd()
1041: .keywords: log, event, begin, barrier
1042: M*/
1044: /*MC
1045: PetscLogEventBarrierEnd - Logs the time in a barrier before an event.
1047: Input Parameters:
1048: . e - integer associated with the event obtained from PetscLogEventRegister()
1049: . o1,o2,o3,o4 - objects associated with the event, or 0
1050: . comm - communicator the barrier takes place over
1052: Synopsis:
1053: void PetscLogEventBarrierEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
1054: PetscObject o4,MPI_Comm comm)
1056: Usage:
1057: .vb
1058: PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm);
1059: MPI_Allreduce()
1060: PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm);
1061: .ve
1063: Notes:
1064: This is for logging the amount of time spent in a barrier for an event
1065: that requires synchronization.
1067: Additional Notes:
1068: Synchronization events always come in pairs; for example, VEC_NormBarrier and
1069: VEC_NormComm = VEC_NormBarrier + 1
1071: Level: advanced
1073: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(),
1074: PetscLogEventBarrierBegin()
1076: .keywords: log, event, begin, barrier
1077: M*/
1081: /*@C
1082: PetscLogEventGetId - Returns the event id when given the event name.
1084: Not Collective
1086: Input Parameter:
1087: . name - The event name
1089: Output Parameter:
1090: . event - The event
1092: Level: intermediate
1094: .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStageGetId()
1095: @*/
1096: PetscErrorCode PetscLogEventGetId(const char name[], PetscLogEvent *event)
1097: {
1098: StageLog stageLog;
1102: PetscLogGetStageLog(&stageLog);
1103: EventRegLogGetEvent(stageLog->eventLog, name, event);
1104: return(0);
1105: }
1108: /*------------------------------------------------ Output Functions -------------------------------------------------*/
1111: /*@C
1112: PetscLogDump - Dumps logs of objects to a file. This file is intended to
1113: be read by bin/petscview. This program no longer exists.
1115: Collective on PETSC_COMM_WORLD
1117: Input Parameter:
1118: . name - an optional file name
1120: Options Database Keys:
1121: + -log - Prints basic log information (for code compiled with PETSC_USE_LOG)
1122: - -log_all - Prints extensive log information (for code compiled with PETSC_USE_LOG)
1123:
1124: Usage:
1125: .vb
1126: PetscInitialize(...);
1127: PetscLogBegin(); or PetscLogAllBegin();
1128: ... code ...
1129: PetscLogDump(filename);
1130: PetscFinalize();
1131: .ve
1133: Notes:
1134: The default file name is
1135: $ Log.<rank>
1136: where <rank> is the processor number. If no name is specified,
1137: this file will be used.
1139: Level: advanced
1141: .keywords: log, dump
1142: .seealso: PetscLogBegin(), PetscLogAllBegin(), PetscLogPrintSummary()
1143: @*/
1144: PetscErrorCode PetscLogDump(const char sname[])
1145: {
1146: StageLog stageLog;
1147: EventPerfInfo *eventInfo;
1148: FILE *fd;
1149: char file[PETSC_MAX_PATH_LEN], fname[PETSC_MAX_PATH_LEN];
1150: PetscLogDouble flops, _TotalTime;
1151: PetscMPIInt rank;
1152: int action, object, curStage;
1153: PetscLogEvent event;
1155:
1157: /* Calculate the total elapsed time */
1158: PetscTime(_TotalTime);
1159: _TotalTime -= BaseTime;
1160: /* Open log file */
1161: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
1162: if (sname) {
1163: sprintf(file, "%s.%d", sname, rank);
1164: } else {
1165: sprintf(file, "Log.%d", rank);
1166: }
1167: PetscFixFilename(file, fname);
1168: PetscFOpen(PETSC_COMM_WORLD, fname, "w", &fd);
1169: if ((!rank) && (!fd)) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open file: %s", fname);
1170: /* Output totals */
1171: PetscFPrintf(PETSC_COMM_WORLD, fd, "Total Flops %14e %16.8e\n", _TotalFlops, _TotalTime);
1172: PetscFPrintf(PETSC_COMM_WORLD, fd, "Clock Resolution %g\n", 0.0);
1173: /* Output actions */
1174: if (logActions) {
1175: PetscFPrintf(PETSC_COMM_WORLD, fd, "Actions accomplished %d\n", numActions);
1176: for(action = 0; action < numActions; action++) {
1177: PetscFPrintf(PETSC_COMM_WORLD, fd, "%g %d %d %d %d %d %d %g %g %g\n",
1178: actions[action].time, actions[action].action, (int)actions[action].event, (int)actions[action].cookie, actions[action].id1,
1179: actions[action].id2, actions[action].id3, actions[action].flops, actions[action].mem, actions[action].maxmem);
1180: }
1181: }
1182: /* Output objects */
1183: if (logObjects) {
1184: PetscFPrintf(PETSC_COMM_WORLD, fd, "Objects created %d destroyed %d\n", numObjects, numObjectsDestroyed);
1185: for(object = 0; object < numObjects; object++) {
1186: PetscFPrintf(PETSC_COMM_WORLD, fd, "Parent ID: %d Memory: %d\n", objects[object].parent, (int) objects[object].mem);
1187: if (!objects[object].name[0]) {
1188: PetscFPrintf(PETSC_COMM_WORLD, fd,"No Name\n");
1189: } else {
1190: PetscFPrintf(PETSC_COMM_WORLD, fd, "Name: %s\n", objects[object].name);
1191: }
1192: if (objects[object].info[0] != 0) {
1193: PetscFPrintf(PETSC_COMM_WORLD, fd, "No Info\n");
1194: } else {
1195: PetscFPrintf(PETSC_COMM_WORLD, fd, "Info: %s\n", objects[object].info);
1196: }
1197: }
1198: }
1199: /* Output events */
1200: PetscFPrintf(PETSC_COMM_WORLD, fd, "Event log:\n");
1201: PetscLogGetStageLog(&stageLog);
1202: StackTop(stageLog->stack, &curStage);
1203: eventInfo = stageLog->stageInfo[curStage].eventLog->eventInfo;
1204: for(event = 0; event < stageLog->stageInfo[curStage].eventLog->numEvents; event++) {
1205: if (eventInfo[event].time != 0.0) {
1206: flops = eventInfo[event].flops/eventInfo[event].time;
1207: } else {
1208: flops = 0.0;
1209: }
1210: PetscFPrintf(PETSC_COMM_WORLD, fd, "%d %16d %16g %16g %16g\n", event, eventInfo[event].count,
1211: eventInfo[event].flops, eventInfo[event].time, flops);
1212: }
1213: PetscFClose(PETSC_COMM_WORLD, fd);
1214: return(0);
1215: }
1219: /*@C
1220: PetscLogPrintSummary - Prints a summary of the logging.
1222: Collective over MPI_Comm
1224: Input Parameter:
1225: + comm - The MPI communicator (only one processor prints output)
1226: - file - [Optional] The output file name
1228: Options Database Keys:
1229: . -log_summary - Prints summary of log information (for code compiled with PETSC_USE_LOG)
1231: Usage:
1232: .vb
1233: PetscInitialize(...);
1234: PetscLogBegin();
1235: ... code ...
1236: PetscLogPrintSummary(MPI_Comm,filename);
1237: PetscFinalize(...);
1238: .ve
1240: Notes:
1241: By default the summary is printed to stdout.
1243: Level: beginner
1244:
1245: .keywords: log, dump, print
1246: .seealso: PetscLogBegin(), PetscLogDump()
1247: @*/
1248: PetscErrorCode PetscLogPrintSummary(MPI_Comm comm, const char filename[])
1249: {
1250: FILE *fd = PETSC_STDOUT;
1251: PetscLogDouble zero = 0.0;
1252: StageLog stageLog;
1253: StageInfo *stageInfo = PETSC_NULL;
1254: EventPerfInfo *eventInfo = PETSC_NULL;
1255: ClassPerfInfo *classInfo;
1256: char arch[10], hostname[64], username[16], pname[PETSC_MAX_PATH_LEN], date[64];
1257: const char *name;
1258: PetscLogDouble locTotalTime, TotalTime, TotalFlops;
1259: PetscLogDouble numMessages, messageLength, avgMessLen, numReductions;
1260: PetscLogDouble stageTime, flops, flopr, mem, mess, messLen, red;
1261: PetscLogDouble fracTime, fracFlops, fracMessages, fracLength, fracReductions, fracMess, fracMessLen, fracRed;
1262: PetscLogDouble fracStageTime, fracStageFlops, fracStageMess, fracStageMessLen, fracStageRed;
1263: PetscLogDouble min, max, tot, ratio, avg, x, y;
1264: PetscLogDouble minf, maxf, totf, ratf, mint, maxt, tott, ratt, ratCt, totm, totml, totr;
1265: PetscMPIInt minCt, maxCt;
1266: PetscMPIInt size, rank;
1267: PetscTruth *localStageUsed, *stageUsed;
1268: PetscTruth *localStageVisible, *stageVisible;
1269: int numStages, localNumEvents, numEvents;
1270: int stage, lastStage, oclass;
1271: PetscLogEvent event;
1273: char version[256];
1276: MPI_Comm_size(comm, &size);
1277: MPI_Comm_rank(comm, &rank);
1278: /* Pop off any stages the user forgot to remove */
1279: lastStage = 0;
1280: PetscLogGetStageLog(&stageLog);
1281: StageLogGetCurrent(stageLog, &stage);
1282: while (stage >= 0) {
1283: lastStage = stage;
1284: StageLogPop(stageLog);
1285: StageLogGetCurrent(stageLog, &stage);
1286: }
1287: /* Get the total elapsed time */
1288: PetscTime(locTotalTime); locTotalTime -= BaseTime;
1289: /* Open the summary file */
1290: if (filename) {
1291: PetscFOpen(comm, filename, "w", &fd);
1292: }
1294: PetscFPrintf(comm, fd, "************************************************************************************************************************\n");
1295: PetscFPrintf(comm, fd, "*** WIDEN YOUR WINDOW TO 120 CHARACTERS. Use 'enscript -r -fCourier9' to print this document ***\n");
1296: PetscFPrintf(comm, fd, "************************************************************************************************************************\n");
1297: PetscFPrintf(comm, fd, "\n---------------------------------------------- PETSc Performance Summary: ----------------------------------------------\n\n");
1298: PetscGetArchType(arch, 10);
1299: PetscGetHostName(hostname, 64);
1300: PetscGetUserName(username, 16);
1301: PetscGetProgramName(pname, PETSC_MAX_PATH_LEN);
1302: PetscGetDate(date, 64);
1303: PetscGetVersion(version,256);
1304: if (size == 1) {
1305: PetscFPrintf(comm,fd,"%s on a %s named %s with %d processor, by %s %s\n", pname, arch, hostname, size, username, date);
1306: } else {
1307: PetscFPrintf(comm,fd,"%s on a %s named %s with %d processors, by %s %s\n", pname, arch, hostname, size, username, date);
1308: }
1309: PetscFPrintf(comm, fd, "Using %s\n", version);
1311: /* Must preserve reduction count before we go on */
1312: red = allreduce_ct + gather_ct + scatter_ct;
1314: /* Calculate summary information */
1315: PetscFPrintf(comm, fd, "\n Max Max/Min Avg Total \n");
1316: /* Time */
1317: MPI_Allreduce(&locTotalTime, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1318: MPI_Allreduce(&locTotalTime, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1319: MPI_Allreduce(&locTotalTime, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1320: avg = (tot)/((PetscLogDouble) size);
1321: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1322: PetscFPrintf(comm, fd, "Time (sec): %5.3e %10.5f %5.3e\n", max, ratio, avg);
1323: TotalTime = tot;
1324: /* Objects */
1325: avg = (PetscLogDouble) numObjects;
1326: MPI_Allreduce(&avg, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1327: MPI_Allreduce(&avg, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1328: MPI_Allreduce(&avg, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1329: avg = (tot)/((PetscLogDouble) size);
1330: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1331: PetscFPrintf(comm, fd, "Objects: %5.3e %10.5f %5.3e\n", max, ratio, avg);
1332: /* Flops */
1333: MPI_Allreduce(&_TotalFlops, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1334: MPI_Allreduce(&_TotalFlops, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1335: MPI_Allreduce(&_TotalFlops, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1336: avg = (tot)/((PetscLogDouble) size);
1337: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1338: PetscFPrintf(comm, fd, "Flops: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1339: TotalFlops = tot;
1340: /* Flops/sec -- Must talk to Barry here */
1341: if (locTotalTime != 0.0) flops = _TotalFlops/locTotalTime; else flops = 0.0;
1342: MPI_Allreduce(&flops, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1343: MPI_Allreduce(&flops, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1344: MPI_Allreduce(&flops, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1345: avg = (tot)/((PetscLogDouble) size);
1346: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1347: PetscFPrintf(comm, fd, "Flops/sec: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1348: /* Memory */
1349: PetscMallocGetMaximumUsage(&mem);
1350: if (mem > 0.0) {
1351: MPI_Allreduce(&mem, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1352: MPI_Allreduce(&mem, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1353: MPI_Allreduce(&mem, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1354: avg = (tot)/((PetscLogDouble) size);
1355: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1356: PetscFPrintf(comm, fd, "Memory: %5.3e %10.5f %5.3e\n", max, ratio, tot);
1357: }
1358: /* Messages */
1359: mess = 0.5*(irecv_ct + isend_ct + recv_ct + send_ct);
1360: MPI_Allreduce(&mess, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1361: MPI_Allreduce(&mess, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1362: MPI_Allreduce(&mess, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1363: avg = (tot)/((PetscLogDouble) size);
1364: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1365: PetscFPrintf(comm, fd, "MPI Messages: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1366: numMessages = tot;
1367: /* Message Lengths */
1368: mess = 0.5*(irecv_len + isend_len + recv_len + send_len);
1369: MPI_Allreduce(&mess, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1370: MPI_Allreduce(&mess, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1371: MPI_Allreduce(&mess, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1372: if (numMessages != 0) avg = (tot)/(numMessages); else avg = 0.0;
1373: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1374: PetscFPrintf(comm, fd, "MPI Message Lengths: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1375: messageLength = tot;
1376: /* Reductions */
1377: MPI_Allreduce(&red, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1378: MPI_Allreduce(&red, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1379: MPI_Allreduce(&red, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1380: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1381: PetscFPrintf(comm, fd, "MPI Reductions: %5.3e %10.5f\n", max, ratio);
1382: numReductions = red; /* wrong because uses count from process zero */
1383: PetscFPrintf(comm, fd, "\nFlop counting convention: 1 flop = 1 real number operation of type (multiply/divide/add/subtract)\n");
1384: PetscFPrintf(comm, fd, " e.g., VecAXPY() for real vectors of length N --> 2N flops\n");
1385: PetscFPrintf(comm, fd, " and VecAXPY() for complex vectors of length N --> 8N flops\n");
1387: /* Get total number of stages --
1388: Currently, a single processor can register more stages than another, but stages must all be registered in order.
1389: We can removed this requirement if necessary by having a global stage numbering and indirection on the stage ID.
1390: This seems best accomplished by assoicating a communicator with each stage.
1391: */
1392: MPI_Allreduce(&stageLog->numStages, &numStages, 1, MPI_INT, MPI_MAX, comm);
1393: PetscMalloc(numStages * sizeof(PetscTruth), &localStageUsed);
1394: PetscMalloc(numStages * sizeof(PetscTruth), &stageUsed);
1395: PetscMalloc(numStages * sizeof(PetscTruth), &localStageVisible);
1396: PetscMalloc(numStages * sizeof(PetscTruth), &stageVisible);
1397: if (numStages > 0) {
1398: stageInfo = stageLog->stageInfo;
1399: for(stage = 0; stage < numStages; stage++) {
1400: if (stage < stageLog->numStages) {
1401: localStageUsed[stage] = stageInfo[stage].used;
1402: localStageVisible[stage] = stageInfo[stage].perfInfo.visible;
1403: } else {
1404: localStageUsed[stage] = PETSC_FALSE;
1405: localStageVisible[stage] = PETSC_TRUE;
1406: }
1407: }
1408: MPI_Allreduce(localStageUsed, stageUsed, numStages, MPI_INT, MPI_LOR, comm);
1409: MPI_Allreduce(localStageVisible, stageVisible, numStages, MPI_INT, MPI_LAND, comm);
1410: for(stage = 0; stage < numStages; stage++) {
1411: if (stageUsed[stage]) {
1412: PetscFPrintf(comm, fd, "\nSummary of Stages: ----- Time ------ ----- Flops ----- --- Messages --- -- Message Lengths -- -- Reductions --\n");
1413: PetscFPrintf(comm, fd, " Avg %%Total Avg %%Total counts %%Total Avg %%Total counts %%Total \n");
1414: break;
1415: }
1416: }
1417: for(stage = 0; stage < numStages; stage++) {
1418: if (!stageUsed[stage]) continue;
1419: if (localStageUsed[stage]) {
1420: MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1421: MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1422: MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1423: MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1424: MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1425: name = stageInfo[stage].name;
1426: } else {
1427: MPI_Allreduce(&zero, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1428: MPI_Allreduce(&zero, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1429: MPI_Allreduce(&zero, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1430: MPI_Allreduce(&zero, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1431: MPI_Allreduce(&zero, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1432: name = "";
1433: }
1434: mess *= 0.5; messLen *= 0.5; red /= size;
1435: if (TotalTime != 0.0) fracTime = stageTime/TotalTime; else fracTime = 0.0;
1436: if (TotalFlops != 0.0) fracFlops = flops/TotalFlops; else fracFlops = 0.0;
1437: /* Talk to Barry if (stageTime != 0.0) flops = (size*flops)/stageTime; else flops = 0.0; */
1438: if (numMessages != 0.0) fracMessages = mess/numMessages; else fracMessages = 0.0;
1439: if (numMessages != 0.0) avgMessLen = messLen/numMessages; else avgMessLen = 0.0;
1440: if (messageLength != 0.0) fracLength = messLen/messageLength; else fracLength = 0.0;
1441: if (numReductions != 0.0) fracReductions = red/numReductions; else fracReductions = 0.0;
1442: 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",
1443: stage, name, stageTime/size, 100.0*fracTime, flops, 100.0*fracFlops,
1444: mess, 100.0*fracMessages, avgMessLen, 100.0*fracLength, red, 100.0*fracReductions);
1445: }
1446: }
1448: PetscFPrintf(comm, fd,
1449: "\n------------------------------------------------------------------------------------------------------------------------\n");
1450:
1451: PetscFPrintf(comm, fd, "See the 'Profiling' chapter of the users' manual for details on interpreting output.\n");
1452: PetscFPrintf(comm, fd, "Phase summary info:\n");
1453: PetscFPrintf(comm, fd, " Count: number of times phase was executed\n");
1454: PetscFPrintf(comm, fd, " Time and Flops: Max - maximum over all processors\n");
1455: PetscFPrintf(comm, fd, " Ratio - ratio of maximum to minimum over all processors\n");
1456: PetscFPrintf(comm, fd, " Mess: number of messages sent\n");
1457: PetscFPrintf(comm, fd, " Avg. len: average message length\n");
1458: PetscFPrintf(comm, fd, " Reduct: number of global reductions\n");
1459: PetscFPrintf(comm, fd, " Global: entire computation\n");
1460: PetscFPrintf(comm, fd, " Stage: stages of a computation. Set stages with PetscLogStagePush() and PetscLogStagePop().\n");
1461: PetscFPrintf(comm, fd, " %%T - percent time in this phase %%F - percent flops in this phase\n");
1462: PetscFPrintf(comm, fd, " %%M - percent messages in this phase %%L - percent message lengths in this phase\n");
1463: PetscFPrintf(comm, fd, " %%R - percent reductions in this phase\n");
1464: PetscFPrintf(comm, fd, " Total Mflop/s: 10e-6 * (sum of flops over all processors)/(max time over all processors)\n");
1465: PetscFPrintf(comm, fd,
1466: "------------------------------------------------------------------------------------------------------------------------\n");
1467:
1469: #if defined(PETSC_USE_DEBUG)
1470: PetscFPrintf(comm, fd, "\n\n");
1471: PetscFPrintf(comm, fd, " ##########################################################\n");
1472: PetscFPrintf(comm, fd, " # #\n");
1473: PetscFPrintf(comm, fd, " # WARNING!!! #\n");
1474: PetscFPrintf(comm, fd, " # #\n");
1475: PetscFPrintf(comm, fd, " # This code was compiled with a debugging option, #\n");
1476: PetscFPrintf(comm, fd, " # To get timing results run config/configure.py #\n");
1477: PetscFPrintf(comm, fd, " # using --with-debugging=no, the performance will #\n");
1478: PetscFPrintf(comm, fd, " # be generally two or three times faster. #\n");
1479: PetscFPrintf(comm, fd, " # #\n");
1480: PetscFPrintf(comm, fd, " ##########################################################\n\n\n");
1481: #endif
1482: #if defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_FORTRAN_KERNELS)
1483: PetscFPrintf(comm, fd, "\n\n");
1484: PetscFPrintf(comm, fd, " ##########################################################\n");
1485: PetscFPrintf(comm, fd, " # #\n");
1486: PetscFPrintf(comm, fd, " # WARNING!!! #\n");
1487: PetscFPrintf(comm, fd, " # #\n");
1488: PetscFPrintf(comm, fd, " # The code for various complex numbers numerical #\n");
1489: PetscFPrintf(comm, fd, " # kernels uses C++, which generally is not well #\n");
1490: PetscFPrintf(comm, fd, " # optimized. For performance that is about 4-5 times #\n");
1491: PetscFPrintf(comm, fd, " # faster, specify --with-fortran-kernels=1 #\n");
1492: PetscFPrintf(comm, fd, " # when running config/configure.py. #\n");
1493: PetscFPrintf(comm, fd, " # #\n");
1494: PetscFPrintf(comm, fd, " ##########################################################\n\n\n");
1495: #endif
1497: /* Report events */
1498: PetscFPrintf(comm, fd,
1499: "Event Count Time (sec) Flops --- Global --- --- Stage --- Total\n");
1500:
1501: PetscFPrintf(comm, fd,
1502: " Max Ratio Max Ratio Max Ratio Mess Avg len Reduct %%T %%F %%M %%L %%R %%T %%F %%M %%L %%R Mflop/s\n");
1503:
1504: PetscFPrintf(comm,fd,
1505: "------------------------------------------------------------------------------------------------------------------------\n");
1507:
1508: /* Problem: The stage name will not show up unless the stage executed on proc 1 */
1509: for(stage = 0; stage < numStages; stage++) {
1510: if (!stageVisible[stage]) continue;
1511: if (localStageUsed[stage]) {
1512: PetscFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);
1513: MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1514: MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1515: MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1516: MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1517: MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1518: } else {
1519: PetscFPrintf(comm, fd, "\n--- Event Stage %d: Unknown\n\n", stage);
1520: MPI_Allreduce(&zero, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1521: MPI_Allreduce(&zero, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1522: MPI_Allreduce(&zero, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1523: MPI_Allreduce(&zero, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1524: MPI_Allreduce(&zero, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1525: }
1526: mess *= 0.5; messLen *= 0.5; red /= size;
1528: /* Get total number of events in this stage --
1529: Currently, a single processor can register more events than another, but events must all be registered in order,
1530: just like stages. We can removed this requirement if necessary by having a global event numbering and indirection
1531: on the event ID. This seems best accomplished by assoicating a communicator with each stage.
1533: Problem: If the event did not happen on proc 1, its name will not be available.
1534: Problem: Event visibility is not implemented
1535: */
1536: if (localStageUsed[stage]) {
1537: eventInfo = stageLog->stageInfo[stage].eventLog->eventInfo;
1538: localNumEvents = stageLog->stageInfo[stage].eventLog->numEvents;
1539: } else {
1540: localNumEvents = 0;
1541: }
1542: MPI_Allreduce(&localNumEvents, &numEvents, 1, MPI_INT, MPI_MAX, comm);
1543: for(event = 0; event < numEvents; event++) {
1544: if (localStageUsed[stage] && (event < stageLog->stageInfo[stage].eventLog->numEvents) && (eventInfo[event].depth == 0)) {
1545: if ((eventInfo[event].count > 0) && (eventInfo[event].time > 0.0)) {
1546: flopr = eventInfo[event].flops;
1547: } else {
1548: flopr = 0.0;
1549: }
1550: MPI_Allreduce(&flopr, &minf, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1551: MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1552: MPI_Allreduce(&eventInfo[event].flops, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1553: MPI_Allreduce(&eventInfo[event].time, &mint, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1554: MPI_Allreduce(&eventInfo[event].time, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1555: MPI_Allreduce(&eventInfo[event].time, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1556: MPI_Allreduce(&eventInfo[event].numMessages, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1557: MPI_Allreduce(&eventInfo[event].messageLength, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1558: MPI_Allreduce(&eventInfo[event].numReductions, &totr, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1559: MPI_Allreduce(&eventInfo[event].count, &minCt, 1, MPI_INT, MPI_MIN, comm);
1560: MPI_Allreduce(&eventInfo[event].count, &maxCt, 1, MPI_INT, MPI_MAX, comm);
1561: name = stageLog->eventLog->eventInfo[event].name;
1562: } else {
1563: flopr = 0.0;
1564: MPI_Allreduce(&flopr, &minf, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1565: MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1566: MPI_Allreduce(&zero, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1567: MPI_Allreduce(&zero, &mint, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1568: MPI_Allreduce(&zero, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1569: MPI_Allreduce(&zero, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1570: MPI_Allreduce(&zero, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1571: MPI_Allreduce(&zero, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1572: MPI_Allreduce(&zero, &totr, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1573: MPI_Allreduce(&ierr, &minCt, 1, MPI_INT, MPI_MIN, comm);
1574: MPI_Allreduce(&ierr, &maxCt, 1, MPI_INT, MPI_MAX, comm);
1575: name = "";
1576: }
1577: if (mint < 0.0) {
1578: 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);
1579: mint = 0;
1580: }
1581: if (minf < 0.0) SETERRQ2(PETSC_ERR_PLIB,"Minimum flops %g over all processors for %s is negative! Not possible!",minf,name);
1582: totm *= 0.5; totml *= 0.5; totr /= size;
1583:
1584: if (maxCt != 0) {
1585: if (minCt != 0) ratCt = ((PetscLogDouble) maxCt)/minCt; else ratCt = 0.0;
1586: if (mint != 0.0) ratt = maxt/mint; else ratt = 0.0;
1587: if (minf != 0.0) ratf = maxf/minf; else ratf = 0.0;
1588: if (TotalTime != 0.0) fracTime = tott/TotalTime; else fracTime = 0.0;
1589: if (TotalFlops != 0.0) fracFlops = totf/TotalFlops; else fracFlops = 0.0;
1590: if (stageTime != 0.0) fracStageTime = tott/stageTime; else fracStageTime = 0.0;
1591: if (flops != 0.0) fracStageFlops = totf/flops; else fracStageFlops = 0.0;
1592: if (numMessages != 0.0) fracMess = totm/numMessages; else fracMess = 0.0;
1593: if (messageLength != 0.0) fracMessLen = totml/messageLength; else fracMessLen = 0.0;
1594: if (numReductions != 0.0) fracRed = totr/numReductions; else fracRed = 0.0;
1595: if (mess != 0.0) fracStageMess = totm/mess; else fracStageMess = 0.0;
1596: if (messLen != 0.0) fracStageMessLen = totml/messLen; else fracStageMessLen = 0.0;
1597: if (red != 0.0) fracStageRed = totr/red; else fracStageRed = 0.0;
1598: if (totm != 0.0) totml /= totm; else totml = 0.0;
1599: if (maxt != 0.0) flopr = totf/maxt; else flopr = 0.0;
1600: PetscFPrintf(comm, fd,
1601: "%-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",
1602: name, maxCt, ratCt, maxt, ratt, maxf, ratf, totm, totml, totr,
1603: 100.0*fracTime, 100.0*fracFlops, 100.0*fracMess, 100.0*fracMessLen, 100.0*fracRed,
1604: 100.0*fracStageTime, 100.0*fracStageFlops, 100.0*fracStageMess, 100.0*fracStageMessLen, 100.0*fracStageRed,
1605: flopr/1.0e6);
1606: }
1607: }
1608: }
1610: /* Memory usage and object creation */
1611: PetscFPrintf(comm, fd,
1612: "------------------------------------------------------------------------------------------------------------------------\n");
1613: PetscFPrintf(comm, fd, "\n");
1614: PetscFPrintf(comm, fd, "Memory usage is given in bytes:\n\n");
1616: /* Right now, only stages on the first processor are reported here, meaning only objects associated with
1617: the global communicator, or MPI_COMM_SELF for proc 1. We really should report global stats and then
1618: stats for stages local to processor sets.
1619: */
1620: /* We should figure out the longest object name here (now 20 characters) */
1621: PetscFPrintf(comm, fd, "Object Type Creations Destructions Memory Descendants' Mem.\n");
1622: PetscFPrintf(comm, fd, "Reports information only for process 0.\n");
1623: for(stage = 0; stage < numStages; stage++) {
1624: if (localStageUsed[stage]) {
1625: classInfo = stageLog->stageInfo[stage].classLog->classInfo;
1626: PetscFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);
1627: for(oclass = 0; oclass < stageLog->stageInfo[stage].classLog->numClasses; oclass++) {
1628: if ((classInfo[oclass].creations > 0) || (classInfo[oclass].destructions > 0)) {
1629: PetscFPrintf(comm, fd, "%20s %5d %5d %11.0f %g\n", stageLog->classLog->classInfo[oclass].name,
1630: classInfo[oclass].creations, classInfo[oclass].destructions, classInfo[oclass].mem,
1631: classInfo[oclass].descMem);
1632: }
1633: }
1634: } else {
1635: PetscFPrintf(comm, fd, "\n--- Event Stage %d: Unknown\n\n", stage);
1636: }
1637: }
1639: PetscFree(localStageUsed);
1640: PetscFree(stageUsed);
1641: PetscFree(localStageVisible);
1642: PetscFree(stageVisible);
1644: /* Information unrelated to this particular run */
1645: PetscFPrintf(comm, fd,
1646: "========================================================================================================================\n");
1647: PetscTime(y);
1648: PetscTime(x);
1649: PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y);
1650: PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y);
1651: PetscFPrintf(comm,fd,"Average time to get PetscTime(): %g\n", (y-x)/10.0);
1652: /* MPI information */
1653: if (size > 1) {
1654: MPI_Status status;
1655: PetscMPIInt tag;
1656: MPI_Comm newcomm;
1658: MPI_Barrier(comm);
1659: PetscTime(x);
1660: MPI_Barrier(comm);
1661: MPI_Barrier(comm);
1662: MPI_Barrier(comm);
1663: MPI_Barrier(comm);
1664: MPI_Barrier(comm);
1665: PetscTime(y);
1666: PetscFPrintf(comm, fd, "Average time for MPI_Barrier(): %g\n", (y-x)/5.0);
1667: PetscCommDuplicate(comm,&newcomm, &tag);
1668: MPI_Barrier(comm);
1669: if (rank) {
1670: MPI_Recv(0, 0, MPI_INT, rank-1, tag, newcomm, &status);
1671: MPI_Send(0, 0, MPI_INT, (rank+1)%size, tag, newcomm);
1672: } else {
1673: PetscTime(x);
1674: MPI_Send(0, 0, MPI_INT, 1, tag, newcomm);
1675: MPI_Recv(0, 0, MPI_INT, size-1, tag, newcomm, &status);
1676: PetscTime(y);
1677: PetscFPrintf(comm,fd,"Average time for zero size MPI_Send(): %g\n", (y-x)/size);
1678: }
1679: PetscCommDestroy(&newcomm);
1680: }
1681: if (!rank) {
1682: PetscOptionsPrint(fd);
1683: }
1684: /* Machine and compile information */
1685: #if defined(PETSC_USE_FORTRAN_KERNELS)
1686: PetscFPrintf(comm, fd, "Compiled with FORTRAN kernels\n");
1687: #else
1688: PetscFPrintf(comm, fd, "Compiled without FORTRAN kernels\n");
1689: #endif
1690: #if defined(PETSC_USE_SCALAR_SINGLE)
1691: PetscFPrintf(comm, fd, "Compiled with single precision PetscScalar and PetscReal\n");
1692: #elif defined(PETSC_USE_LONGDOUBLE)
1693: PetscFPrintf(comm, fd, "Compiled with long double precision PetscScalar and PetscReal\n");
1694: #elif defined(PETSC_USE_SCALAR_INT)
1695: PetscFPrintf(comm, fd, "Compiled with int PetscScalar and PetscReal\n");
1696: #endif
1698: #if defined(PETSC_USE_SCALAR_MAT_SINGLE)
1699: PetscFPrintf(comm, fd, "Compiled with single precision matrices\n");
1700: #else
1701: PetscFPrintf(comm, fd, "Compiled with full precision matrices (default)\n");
1702: #endif
1703: PetscFPrintf(comm, fd, "sizeof(short) %d sizeof(int) %d sizeof(long) %d sizeof(void*) %d sizeof(PetscScalar) %d\n",
1704: (int) sizeof(short), (int) sizeof(int), (int) sizeof(long), (int) sizeof(void*),(int) sizeof(PetscScalar));
1706: PetscFPrintf(comm, fd, "Configure run at: %s\n",petscconfigureruntime);
1707: PetscFPrintf(comm, fd, "Configure options: %s",petscconfigureoptions);
1708: PetscFPrintf(comm, fd, "%s", petscmachineinfo);
1709: PetscFPrintf(comm, fd, "%s", petsccompilerinfo);
1710: PetscFPrintf(comm, fd, "%s", petsccompilerflagsinfo);
1711: PetscFPrintf(comm, fd, "%s", petsclinkerinfo);
1713: /* Cleanup */
1714: PetscFPrintf(comm, fd, "\n");
1715: PetscFClose(comm, fd);
1716: StageLogPush(stageLog, lastStage);
1717: return(0);
1718: }
1722: /*@C
1723: PetscLogPrintDetailed - Each process prints the times for its own events
1725: Collective over MPI_Comm
1727: Input Parameter:
1728: + comm - The MPI communicator (only one processor prints output)
1729: - file - [Optional] The output file name
1731: Options Database Keys:
1732: . -log_summary_detailed - Prints summary of log information (for code compiled with PETSC_USE_LOG)
1734: Usage:
1735: .vb
1736: PetscInitialize(...);
1737: PetscLogBegin();
1738: ... code ...
1739: PetscLogPrintDetailed(MPI_Comm,filename);
1740: PetscFinalize(...);
1741: .ve
1743: Notes:
1744: By default the summary is printed to stdout.
1746: Level: beginner
1747:
1748: .keywords: log, dump, print
1749: .seealso: PetscLogBegin(), PetscLogDump(), PetscLogPrintSummary()
1750: @*/
1751: PetscErrorCode PetscLogPrintDetailed(MPI_Comm comm, const char filename[])
1752: {
1753: FILE *fd = PETSC_STDOUT;
1754: StageLog stageLog;
1755: StageInfo *stageInfo = PETSC_NULL;
1756: EventPerfInfo *eventInfo = PETSC_NULL;
1757: const char *name = PETSC_NULL;
1758: PetscLogDouble TotalTime;
1759: PetscLogDouble stageTime, flops, flopr, mess, messLen, red;
1760: PetscLogDouble maxf, totf, maxt, tott, totm, totml, totr = 0.0;
1761: PetscMPIInt maxCt;
1762: PetscMPIInt size, rank;
1763: PetscTruth *stageUsed;
1764: PetscTruth *stageVisible;
1765: int numStages, numEvents;
1766: int stage;
1767: PetscLogEvent event;
1771: MPI_Comm_size(comm, &size);
1772: MPI_Comm_rank(comm, &rank);
1773: /* Pop off any stages the user forgot to remove */
1774: PetscLogGetStageLog(&stageLog);
1775: StageLogGetCurrent(stageLog, &stage);
1776: while (stage >= 0) {
1777: StageLogPop(stageLog);
1778: StageLogGetCurrent(stageLog, &stage);
1779: }
1780: /* Get the total elapsed time */
1781: PetscTime(TotalTime); TotalTime -= BaseTime;
1782: /* Open the summary file */
1783: if (filename) {
1784: PetscFOpen(comm, filename, "w", &fd);
1785: }
1787: PetscFPrintf(comm, fd, "************************************************************************************************************************\n");
1788: PetscFPrintf(comm, fd, "*** WIDEN YOUR WINDOW TO 120 CHARACTERS. Use 'enscript -r -fCourier9' to print this document ***\n");
1789: PetscFPrintf(comm, fd, "************************************************************************************************************************\n");
1792: numStages = stageLog->numStages;
1793: PetscMalloc(numStages * sizeof(PetscTruth), &stageUsed);
1794: PetscMalloc(numStages * sizeof(PetscTruth), &stageVisible);
1795: if (numStages > 0) {
1796: stageInfo = stageLog->stageInfo;
1797: for(stage = 0; stage < numStages; stage++) {
1798: if (stage < stageLog->numStages) {
1799: stageUsed[stage] = stageInfo[stage].used;
1800: stageVisible[stage] = stageInfo[stage].perfInfo.visible;
1801: } else {
1802: stageUsed[stage] = PETSC_FALSE;
1803: stageVisible[stage] = PETSC_TRUE;
1804: }
1805: }
1806: }
1808: /* Report events */
1809: PetscFPrintf(comm, fd,"Event Count Time (sec) Flops/sec \n");
1810: PetscFPrintf(comm, fd," Mess Avg len Reduct \n");
1811: PetscFPrintf(comm,fd,"-----------------------------------------------------------------------------------\n");
1812: /* Problem: The stage name will not show up unless the stage executed on proc 1 */
1813: for(stage = 0; stage < numStages; stage++) {
1814: if (!stageVisible[stage]) continue;
1815: if (stageUsed[stage]) {
1816: PetscSynchronizedFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);
1817: MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1818: MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1819: MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1820: MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1821: MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1822: }
1823: mess *= 0.5; messLen *= 0.5;
1825: /* Get total number of events in this stage --
1826: */
1827: if (stageUsed[stage]) {
1828: eventInfo = stageLog->stageInfo[stage].eventLog->eventInfo;
1829: numEvents = stageLog->stageInfo[stage].eventLog->numEvents;
1830: } else {
1831: numEvents = 0;
1832: }
1833: for(event = 0; event < numEvents; event++) {
1834: if (stageUsed[stage] && (event < stageLog->stageInfo[stage].eventLog->numEvents)) {
1835: if ((eventInfo[event].count > 0) && (eventInfo[event].time > 0.0)) {
1836: flopr = eventInfo[event].flops/eventInfo[event].time;
1837: } else {
1838: flopr = 0.0;
1839: }
1840: MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, PETSC_COMM_SELF);
1841: MPI_Allreduce(&eventInfo[event].flops, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1842: MPI_Allreduce(&eventInfo[event].time, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, PETSC_COMM_SELF);
1843: MPI_Allreduce(&eventInfo[event].time, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1844: MPI_Allreduce(&eventInfo[event].numMessages, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1845: MPI_Allreduce(&eventInfo[event].messageLength, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, PETSC_COMM_SELF);
1846: totr = eventInfo[event].numReductions;
1847: MPI_Allreduce(&eventInfo[event].count, &maxCt, 1, MPI_INT, MPI_MAX, PETSC_COMM_SELF);
1848: name = stageLog->eventLog->eventInfo[event].name;
1849: totm *= 0.5; totml *= 0.5;
1850: }
1851:
1852: if (maxCt != 0) {
1853: if (totm != 0.0) totml /= totm; else totml = 0.0;
1854: PetscSynchronizedFPrintf(comm, fd,"%-16s %7d %5.4e %3.2e %2.1e %2.1e %2.1e\n",name, maxCt, maxt, maxf, totm, totml, totr);
1855: }
1856: }
1857: }
1858: PetscSynchronizedFlush(comm);
1860: PetscFree(stageUsed);
1861: PetscFree(stageVisible);
1863: PetscFClose(comm, fd);
1864: return(0);
1865: }
1867: /*----------------------------------------------- Counter Functions -------------------------------------------------*/
1870: /*@C
1871: PetscGetFlops - Returns the number of flops used on this processor
1872: since the program began.
1874: Not Collective
1876: Output Parameter:
1877: flops - number of floating point operations
1879: Notes:
1880: A global counter logs all PETSc flop counts. The user can use
1881: PetscLogFlops() to increment this counter to include flops for the
1882: application code.
1884: PETSc automatically logs library events if the code has been
1885: compiled with -DPETSC_USE_LOG (which is the default), and -log,
1886: -log_summary, or -log_all are specified. PetscLogFlops() is
1887: intended for logging user flops to supplement this PETSc
1888: information.
1890: Level: intermediate
1892: .keywords: log, flops, floating point operations
1894: .seealso: PetscGetTime(), PetscLogFlops()
1895: @*/
1896: PetscErrorCode PetscGetFlops(PetscLogDouble *flops)
1897: {
1899: *flops = _TotalFlops;
1900: return(0);
1901: }
1905: PetscErrorCode PetscLogObjectState(PetscObject obj, const char format[], ...)
1906: {
1908: int fullLength;
1909: va_list Argp;
1912: if (!logObjects) return(0);
1913: va_start(Argp, format);
1914: PetscVSNPrintf(objects[obj->id].info, 64,format,&fullLength, Argp);
1915: va_end(Argp);
1916: return(0);
1917: }
1921: /*@
1922: PetscLogGetStageLog - This function returns the default stage logging object.
1924: Not collective
1926: Output Parameter:
1927: . stageLog - The default StageLog
1929: Level: beginner
1931: .keywords: log, stage
1932: .seealso: StageLogCreate()
1933: @*/
1934: PetscErrorCode PetscLogGetStageLog(StageLog *stageLog)
1935: {
1938: if (_stageLog == PETSC_NULL) {
1939: fprintf(stderr, "Logging has not been enabled.\nYou might have forgotten to call PetscInitialize().\n");
1940: MPI_Abort(MPI_COMM_WORLD, PETSC_ERR_SUP);
1941: }
1942: *stageLog = _stageLog;
1943: return(0);
1944: }
1946: /*MC
1947: PetscLogFlops - Adds floating point operations to the global counter.
1949: Input Parameter:
1950: . f - flop counter
1952: Synopsis:
1953: void PetscLogFlops(PetscLogDouble f)
1955: Usage:
1956: .vb
1957: int USER_EVENT;
1958: PetscLogEventRegister("User event",0,&USER_EVENT);
1959: PetscLogEventBegin(USER_EVENT,0,0,0,0);
1960: [code segment to monitor]
1961: PetscLogFlops(user_flops)
1962: PetscLogEventEnd(USER_EVENT,0,0,0,0);
1963: .ve
1965: Notes:
1966: A global counter logs all PETSc flop counts. The user can use
1967: PetscLogFlops() to increment this counter to include flops for the
1968: application code.
1970: PETSc automatically logs library events if the code has been
1971: compiled with -DPETSC_USE_LOG (which is the default), and -log,
1972: -log_summary, or -log_all are specified. PetscLogFlops() is
1973: intended for logging user flops to supplement this PETSc
1974: information.
1976: Level: intermediate
1978: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscGetFlops()
1980: .keywords: log, flops, floating point operations
1981: M*/
1983: /*MC
1984: PreLoadBegin - Begin a segment of code that may be preloaded (run twice)
1985: to get accurate timings
1987: Input Parameter:
1988: + flag - PETSC_TRUE to run twice, PETSC_FALSE to run once, may be overridden
1989: with command line option -preload true or -preload false
1990: - name - name of first stage (lines of code timed separately with -log_summary) to
1991: be preloaded
1993: Synopsis:
1994: void PreLoadBegin(PetscTruth flag,char *name);
1996: Usage:
1997: .vb
1998: PreLoadBegin(PETSC_TRUE,"first stage);
1999: lines of code
2000: PreLoadStage("second stage");
2001: lines of code
2002: PreLoadEnd();
2003: .ve
2005: Notes: Only works in C/C++, not Fortran
2007: Flags available within the macro.
2008: + PetscPreLoadingUsed - true if we are or have done preloading
2009: . PetscPreLoadingOn - true if it is CURRENTLY doing preload
2010: . PreLoadIt - 0 for the first computation (with preloading turned off it is only 0) 1 for the second
2011: - PreLoadMax - number of times it will do the computation, only one when preloading is turned on
2012: The first two variables are available throughout the program, the second two only between the PreLoadBegin()
2013: and PreLoadEnd()
2015: Level: intermediate
2017: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadEnd(), PreLoadStage()
2019: Concepts: preloading
2020: Concepts: timing^accurate
2021: Concepts: paging^eliminating effects of
2024: M*/
2026: /*MC
2027: PreLoadEnd - End a segment of code that may be preloaded (run twice)
2028: to get accurate timings
2030: Synopsis:
2031: void PreLoadEnd(void);
2033: Usage:
2034: .vb
2035: PreLoadBegin(PETSC_TRUE,"first stage);
2036: lines of code
2037: PreLoadStage("second stage");
2038: lines of code
2039: PreLoadEnd();
2040: .ve
2042: Notes: only works in C/C++ not fortran
2044: Level: intermediate
2046: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadStage()
2048: M*/
2050: /*MC
2051: PreLoadStage - Start a new segment of code to be timed separately.
2052: to get accurate timings
2054: Synopsis:
2055: void PreLoadStage(char *name);
2057: Usage:
2058: .vb
2059: PreLoadBegin(PETSC_TRUE,"first stage);
2060: lines of code
2061: PreLoadStage("second stage");
2062: lines of code
2063: PreLoadEnd();
2064: .ve
2066: Notes: only works in C/C++ not fortran
2068: Level: intermediate
2070: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd()
2072: M*/
2074: /*----------------------------------------------- Stack Functions ---------------------------------------------------*/
2077: /*@C
2078: StackDestroy - This function destroys a stack.
2080: Not Collective
2082: Input Parameter:
2083: . stack - The stack
2085: Level: beginner
2087: .keywords: log, stack, destroy
2088: .seealso: StackCreate(), StackEmpty(), StackPush(), StackPop(), StackTop()
2089: @*/
2090: PetscErrorCode StackDestroy(IntStack stack)
2091: {
2095: PetscFree(stack->stack);
2096: PetscFree(stack);
2097: return(0);
2098: }
2102: /*@C
2103: StackEmpty - This function determines whether any items have been pushed.
2105: Not Collective
2107: Input Parameter:
2108: . stack - The stack
2110: Output Parameter:
2111: . empty - PETSC_TRUE if the stack is empty
2113: Level: intermediate
2115: .keywords: log, stack, empty
2116: .seealso: StackCreate(), StackDestroy(), StackPush(), StackPop(), StackTop()
2117: @*/
2118: PetscErrorCode StackEmpty(IntStack stack, PetscTruth *empty)
2119: {
2122: if (stack->top == -1) {
2123: *empty = PETSC_TRUE;
2124: } else {
2125: *empty = PETSC_FALSE;
2126: }
2127: return(0);
2128: }
2132: /*@C
2133: StackTop - This function returns the top of the stack.
2135: Not Collective
2137: Input Parameter:
2138: . stack - The stack
2140: Output Parameter:
2141: . top - The integer on top of the stack
2143: Level: intermediate
2145: .keywords: log, stack, top
2146: .seealso: StackCreate(), StackDestroy(), StackEmpty(), StackPush(), StackPop()
2147: @*/
2148: PetscErrorCode StackTop(IntStack stack, int *top)
2149: {
2152: *top = stack->stack[stack->top];
2153: return(0);
2154: }
2158: /*@C
2159: StackPush - This function pushes an integer on the stack.
2161: Not Collective
2163: Input Parameters:
2164: + stack - The stack
2165: - item - The integer to push
2167: Level: intermediate
2169: .keywords: log, stack, push
2170: .seealso: StackCreate(), StackDestroy(), StackEmpty(), StackPop(), StackTop()
2171: @*/
2172: PetscErrorCode StackPush(IntStack stack, int item)
2173: {
2174: int *array;
2178: stack->top++;
2179: if (stack->top >= stack->max) {
2180: PetscMalloc(stack->max*2 * sizeof(int), &array);
2181: PetscMemcpy(array, stack->stack, stack->max * sizeof(int));
2182: PetscFree(stack->stack);
2183: stack->stack = array;
2184: stack->max *= 2;
2185: }
2186: stack->stack[stack->top] = item;
2187: return(0);
2188: }
2192: /*@C
2193: StackPop - This function pops an integer from the stack.
2195: Not Collective
2197: Input Parameter:
2198: . stack - The stack
2200: Output Parameter:
2201: . item - The integer popped
2203: Level: intermediate
2205: .keywords: log, stack, pop
2206: .seealso: StackCreate(), StackDestroy(), StackEmpty(), StackPush(), StackTop()
2207: @*/
2208: PetscErrorCode StackPop(IntStack stack, int *item)
2209: {
2212: if (stack->top == -1) SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Stack is empty");
2213: *item = stack->stack[stack->top--];
2214: return(0);
2215: }
2219: /*@C
2220: StackCreate - This function creates a stack.
2222: Not Collective
2224: Output Parameter:
2225: . stack - The stack
2227: Level: beginner
2229: .keywords: log, stack, pop
2230: .seealso: StackDestroy(), StackEmpty(), StackPush(), StackPop(), StackTop()
2231: @*/
2232: PetscErrorCode StackCreate(IntStack *stack)
2233: {
2234: IntStack s;
2239: PetscNew(struct _n_IntStack, &s);
2240: s->top = -1;
2241: s->max = 128;
2242: PetscMalloc(s->max * sizeof(int), &s->stack);
2243: PetscMemzero(s->stack, s->max * sizeof(int));
2244: *stack = s;
2245: return(0);
2246: }
2248: #else /* end of -DPETSC_USE_LOG section */
2252: PetscErrorCode PetscLogObjectState(PetscObject obj, const char format[], ...)
2253: {
2255: return(0);
2256: }
2258: #endif /* PETSC_USE_LOG*/
2261: PetscCookie PETSC_LARGEST_COOKIE = PETSC_SMALLEST_COOKIE;
2262: PetscCookie PETSC_OBJECT_COOKIE = 0;
2266: /*@C
2267: PetscCookieRegister - Registers a new class name for objects and logging operations in an application code.
2269: Not Collective
2271: Input Parameter:
2272: . name - The class name
2273:
2274: Output Parameter:
2275: . oclass - The class id or cookie
2277: Level: developer
2279: .keywords: log, class, register
2281: @*/
2282: PetscErrorCode PetscCookieRegister(const char name[],PetscCookie *oclass )
2283: {
2284: #if defined(PETSC_USE_LOG)
2285: StageLog stageLog;
2286: PetscInt stage;
2288: #endif
2291: *oclass = ++PETSC_LARGEST_COOKIE;
2292: #if defined(PETSC_USE_LOG)
2293: PetscLogGetStageLog(&stageLog);
2294: ClassRegLogRegister(stageLog->classLog, name, *oclass);
2295: for(stage = 0; stage < stageLog->numStages; stage++) {
2296: ClassPerfLogEnsureSize(stageLog->stageInfo[stage].classLog, stageLog->classLog->numClasses);
2297: }
2298: #endif
2299: return(0);
2300: }