Actual source code: plog.c
1: /*$Id: plog.c,v 1.262 2001/08/22 17:59:37 balay Exp $*/
2: /*
3: PETSc code to log object creation and destruction and PETSc events.
4: */
5: #include petsc.h
6: #include "petscmachineinfo.h"
7: #if defined(PETSC_HAVE_MPE)
8: #include "mpe.h"
9: #endif
10: #include <stdarg.h>
11: #include <sys/types.h>
12: #include petscsys.h
13: #if defined(PETSC_HAVE_STDLIB_H)
14: #include <stdlib.h>
15: #endif
16: #if defined(PETSC_HAVE_MALLOC_H) && !defined(__cplusplus)
17: #include <malloc.h>
18: #endif
19: #include "petscfix.h"
20: #include src/sys/src/plog/ptime.h
21: #include plog.h
23: int PETSC_LARGEST_COOKIE = PETSC_COOKIE;
24: int PETSC_LARGEST_EVENT = PETSC_EVENT;
26: #if defined(PETSC_USE_LOG)
28: /* used in the MPI_XXX() count macros in petsclog.h */
29: int PETSC_DUMMY = 0,PETSC_DUMMY_SIZE = 0;
31: /* Action and object logging variables */
32: Action *actions = PETSC_NULL;
33: Object *objects = PETSC_NULL;
34: PetscTruth logActions = PETSC_FALSE;
35: PetscTruth logObjects = PETSC_FALSE;
36: int numActions = 0, maxActions = 100;
37: int numObjects = 0, maxObjects = 100;
38: int numObjectsDestroyed = 0;
40: /* Global counters */
41: PetscLogDouble BaseTime = 0.0;
42: PetscLogDouble _TotalFlops = 0.0; /* The number of flops */
43: PetscLogDouble send_ct = 0.0; /* The number of sends */
44: PetscLogDouble recv_ct = 0.0; /* The number of receives */
45: PetscLogDouble send_len = 0.0; /* The total length of all sent messages */
46: PetscLogDouble recv_len = 0.0; /* The total length of all received messages */
47: PetscLogDouble isend_ct = 0.0; /* The number of immediate sends */
48: PetscLogDouble irecv_ct = 0.0; /* The number of immediate receives */
49: PetscLogDouble isend_len = 0.0; /* The total length of all immediate send messages */
50: PetscLogDouble irecv_len = 0.0; /* The total length of all immediate receive messages */
51: PetscLogDouble wait_ct = 0.0; /* The number of waits */
52: PetscLogDouble wait_any_ct = 0.0; /* The number of anywaits */
53: PetscLogDouble wait_all_ct = 0.0; /* The number of waitalls */
54: PetscLogDouble sum_of_waits_ct = 0.0; /* The total number of waits */
55: PetscLogDouble allreduce_ct = 0.0; /* The number of reductions */
57: /* Logging functions */
58: int (*_PetscLogPHC)(PetscObject) = PETSC_NULL;
59: int (*_PetscLogPHD)(PetscObject) = PETSC_NULL;
60: int (*_PetscLogPLB)(int, int, PetscObject, PetscObject, PetscObject, PetscObject) = PETSC_NULL;
61: int (*_PetscLogPLE)(int, int, PetscObject, PetscObject, PetscObject, PetscObject) = PETSC_NULL;
63: /* Tracing event logging variables */
64: FILE *tracefile = PETSC_NULL;
65: int tracelevel = 0;
66: const char *traceblanks = " ";
67: char tracespace[128] = " ";
68: PetscLogDouble tracetime = 0.0;
70: /*---------------------------------------------- General Functions --------------------------------------------------*/
73: /*@C
74: PetscLogDestroy - Destroys the object and event logging data and resets the global counters.
76: Not Collective
78: Notes:
79: This routine should not usually be used by programmers. Instead employ
80: PetscLogStagePush() and PetscLogStagePop().
82: Level: developer
84: .keywords: log, destroy
85: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogStagePush(), PlogStagePop()
86: @*/
87: int PetscLogDestroy(void) {
88: StageLog stageLog;
89: int ierr;
92: if (actions != PETSC_NULL) {
93: PetscFree(actions);
94: actions = PETSC_NULL;
95: }
96: if (objects != PETSC_NULL) {
97: PetscFree(objects);
98: objects = PETSC_NULL;
99: }
100: PetscLogSet(PETSC_NULL, PETSC_NULL);
102: /* Resetting phase */
103: PetscLogGetStageLog(&stageLog);
104: StageLogDestroy(stageLog);
105: _TotalFlops = 0.0;
106: numActions = 0;
107: numObjects = 0;
108: numObjectsDestroyed = 0;
109: return(0);
110: }
114: /*@C
115: PetscLogSet - Sets the logging functions called at the beginning and ending of every event.
117: Not Collective
119: Input Parameters:
120: + b - The function called at beginning of event
121: - e - The function called at end of event
123: Level: developer
125: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogAllBegin(), PetscLogTraceBegin()
126: @*/
127: int PetscLogSet(int (*b)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
128: int (*e)(int, int, PetscObject, PetscObject, PetscObject, PetscObject))
129: {
131: _PetscLogPLB = b;
132: _PetscLogPLE = e;
133: return(0);
134: }
136: /*------------------------------------------- Initialization Functions ----------------------------------------------*/
139: int PetscLogBegin_Private(void) {
140: static int initialized = 0;
141: int stage;
142: PetscTruth opt;
143: int ierr;
146: if (initialized) return(0);
147: initialized = 1;
148: PetscOptionsHasName(PETSC_NULL, "-log_exclude_actions", &opt);
149: if (opt == PETSC_TRUE) {
150: logActions = PETSC_FALSE;
151: }
152: PetscOptionsHasName(PETSC_NULL, "-log_exclude_objects", &opt);
153: if (opt == PETSC_TRUE) {
154: logObjects = PETSC_FALSE;
155: }
156: if (logActions == PETSC_TRUE) {
157: PetscMalloc(maxActions * sizeof(Action), &actions);
158: }
159: if (logObjects == PETSC_TRUE) {
160: PetscMalloc(maxObjects * sizeof(Object), &objects);
161: }
162: _PetscLogPHC = PetscLogObjCreateDefault;
163: _PetscLogPHD = PetscLogObjDestroyDefault;
164: /* Setup default logging structures */
165: StageLogCreate(&_stageLog);
166: StageLogRegister(_stageLog, "Main Stage", &stage);
167: /* All processors sync here for more consistent logging */
168: MPI_Barrier(PETSC_COMM_WORLD);
169: PetscTime(BaseTime);
170: PetscLogStagePush(stage);
171: return(0);
172: }
176: /*@C
177: PetscLogBegin - Turns on logging of objects and events. This logs flop
178: rates and object creation and should not slow programs down too much.
179: This routine may be called more than once.
181: Collective over PETSC_COMM_WORLD
183: Options Database Keys:
184: + -log_summary - Prints summary of flop and timing information to the
185: screen (for code compiled with PETSC_USE_LOG)
186: - -log - Prints detailed log information (for code compiled with PETSC_USE_LOG)
188: Usage:
189: .vb
190: PetscInitialize(...);
191: PetscLogBegin();
192: ... code ...
193: PetscLogPrintSummary(MPI_Comm,filename); or PetscLogDump();
194: PetscFinalize();
195: .ve
197: Notes:
198: PetscLogPrintSummary(MPI_Comm,filename) or PetscLogDump() actually cause the printing of
199: the logging information.
201: Level: advanced
203: .keywords: log, begin
204: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogTraceBegin()
205: @*/
206: int PetscLogBegin(void)
207: {
211: PetscLogSet(PetscLogEventBeginDefault, PetscLogEventEndDefault);
212: PetscLogBegin_Private();
213: return(0);
214: }
218: /*@C
219: PetscLogAllBegin - Turns on extensive logging of objects and events. Logs
220: all events. This creates large log files and slows the program down.
222: Collective on PETSC_COMM_WORLD
224: Options Database Keys:
225: . -log_all - Prints extensive log information (for code compiled with PETSC_USE_LOG)
227: Usage:
228: .vb
229: PetscInitialize(...);
230: PetscLogAllBegin();
231: ... code ...
232: PetscLogDump(filename);
233: PetscFinalize();
234: .ve
236: Notes:
237: A related routine is PetscLogBegin (with the options key -log), which is
238: intended for production runs since it logs only flop rates and object
239: creation (and shouldn't significantly slow the programs).
241: Level: advanced
243: .keywords: log, all, begin
244: .seealso: PetscLogDump(), PetscLogBegin(), PetscLogTraceBegin()
245: @*/
246: int PetscLogAllBegin(void)
247: {
251: PetscLogSet(PetscLogEventBeginComplete, PetscLogEventEndComplete);
252: PetscLogBegin_Private();
253: return(0);
254: }
258: /*@
259: PetscLogTraceBegin - Activates trace logging. Every time a PETSc event
260: begins or ends, the event name is printed.
262: Collective on PETSC_COMM_WORLD
264: Input Parameter:
265: . file - The file to print trace in (e.g. stdout)
267: Options Database Key:
268: . -log_trace [filename] - Activates PetscLogTraceBegin()
270: Notes:
271: PetscLogTraceBegin() prints the processor number, the execution time (sec),
272: then "Event begin:" or "Event end:" followed by the event name.
274: PetscLogTraceBegin() allows tracing of all PETSc calls, which is useful
275: to determine where a program is hanging without running in the
276: debugger. Can be used in conjunction with the -log_info option.
278: Level: intermediate
280: .seealso: PetscLogDump(), PetscLogAllBegin(), PetscLogPrintSummary(), PetscLogBegin()
281: @*/
282: int PetscLogTraceBegin(FILE *file)
283: {
287: tracefile = file;
288: PetscLogSet(PetscLogEventBeginTrace, PetscLogEventEndTrace);
289: PetscLogBegin_Private();
290: return(0);
291: }
295: /*@
296: PetscLogActions - Determines whether actions are logged for the graphical viewer.
298: Not Collective
300: Input Parameter:
301: . flag - PETSC_TRUE if actions are to be logged
303: Level: intermediate
305: Note: Logging of actions continues to consume more memory as the program
306: runs. Long running programs should consider turning this feature off.
308: Options Database Keys:
309: . -log_exclude_actions - Turns off actions logging
311: .keywords: log, stage, register
312: .seealso: PetscLogStagePush(), PetscLogStagePop()
313: @*/
314: int PetscLogActions(PetscTruth flag) {
316: logActions = flag;
317: return(0);
318: }
322: /*@
323: PetscLogObjects - Determines whether objects are logged for the graphical viewer.
325: Not Collective
327: Input Parameter:
328: . flag - PETSC_TRUE if objects are to be logged
330: Level: intermediate
332: Note: Logging of objects continues to consume more memory as the program
333: runs. Long running programs should consider turning this feature off.
335: Options Database Keys:
336: . -log_exclude_objects - Turns off objects logging
338: .keywords: log, stage, register
339: .seealso: PetscLogStagePush(), PetscLogStagePop()
340: @*/
341: int PetscLogObjects(PetscTruth flag) {
343: logObjects = flag;
344: return(0);
345: }
347: /*------------------------------------------------ Stage Functions --------------------------------------------------*/
350: /*@C
351: PetscLogStageRegister - Attaches a charactor string name to a logging stage.
353: Not Collective
355: Input Parameter:
356: . sname - The name to associate with that stage
358: Output Parameter:
359: . stage - The stage number
361: Level: intermediate
363: .keywords: log, stage, register
364: .seealso: PetscLogStagePush(), PetscLogStagePop()
365: @*/
366: int PetscLogStageRegister(int *stage, const char sname[]) {
367: StageLog stageLog;
368: int event;
369: int ierr;
372: PetscLogGetStageLog(&stageLog);
373: StageLogRegister(stageLog, sname, stage);
374: /* Copy events already changed in the main stage, this sucks */
375: EventPerfLogEnsureSize(stageLog->stageInfo[*stage].eventLog, stageLog->eventLog->numEvents);
376: for(event = 0; event < stageLog->eventLog->numEvents; event++) {
377: EventPerfInfoCopy(&stageLog->stageInfo[0].eventLog->eventInfo[event],
378: &stageLog->stageInfo[*stage].eventLog->eventInfo[event]);
379:
380: }
381: ClassPerfLogEnsureSize(stageLog->stageInfo[*stage].classLog, stageLog->classLog->numClasses);
382: return(0);
383: }
387: /*@C
388: PetscLogStagePush - This function pushes a stage on the stack.
390: Not Collective
392: Input Parameter:
393: . stage - The stage on which to log
395: Usage:
396: If the option -log_sumary is used to run the program containing the
397: following code, then 2 sets of summary data will be printed during
398: PetscFinalize().
399: .vb
400: PetscInitialize(int *argc,char ***args,0,0);
401: [stage 0 of code]
402: PetscLogStagePush(1);
403: [stage 1 of code]
404: PetscLogStagePop();
405: PetscBarrier(...);
406: [more stage 0 of code]
407: PetscFinalize();
408: .ve
409:
410: Notes:
411: Use PetscLogStageRegister() to register a stage.
413: Level: intermediate
415: .keywords: log, push, stage
416: .seealso: PetscLogStagePop(), PetscLogStageRegister(), PetscBarrier()
417: @*/
418: int PetscLogStagePush(int stage)
419: {
420: StageLog stageLog;
421: int ierr;
424: PetscLogGetStageLog(&stageLog);
425: StageLogPush(stageLog, stage);
426: return(0);
427: }
431: /*@C
432: PetscLogStagePop - This function pops a stage from the stack.
434: Not Collective
436: Usage:
437: If the option -log_sumary is used to run the program containing the
438: following code, then 2 sets of summary data will be printed during
439: PetscFinalize().
440: .vb
441: PetscInitialize(int *argc,char ***args,0,0);
442: [stage 0 of code]
443: PetscLogStagePush(1);
444: [stage 1 of code]
445: PetscLogStagePop();
446: PetscBarrier(...);
447: [more stage 0 of code]
448: PetscFinalize();
449: .ve
451: Notes:
452: Use PetscLogStageRegister() to register a stage.
454: Level: intermediate
456: .keywords: log, pop, stage
457: .seealso: PetscLogStagePush(), PetscLogStageRegister(), PetscBarrier()
458: @*/
459: int PetscLogStagePop(void)
460: {
461: StageLog stageLog;
462: int ierr;
465: PetscLogGetStageLog(&stageLog);
466: StageLogPop(stageLog);
467: return(0);
468: }
472: /*@
473: PetscLogStageSetActive - Determines stage activity for PetscLogEventBegin() and PetscLogEventEnd().
475: Not Collective
477: Input Parameters:
478: + stage - The stage
479: - isActive - The activity flag, PETSC_TRUE for logging, else PETSC_FALSE (defaults to PETSC_TRUE)
481: Level: intermediate
483: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
484: @*/
485: int PetscLogStageSetActive(int stage, PetscTruth isActive) {
486: StageLog stageLog;
487: int ierr;
490: PetscLogGetStageLog(&stageLog);
491: StageLogSetActive(stageLog, stage, isActive);
492: return(0);
493: }
497: /*@
498: PetscLogStageGetActive - Returns stage activity for PetscLogEventBegin() and PetscLogEventEnd().
500: Not Collective
502: Input Parameter:
503: . stage - The stage
505: Output Parameter:
506: . isActive - The activity flag, PETSC_TRUE for logging, else PETSC_FALSE (defaults to PETSC_TRUE)
508: Level: intermediate
510: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
511: @*/
512: int PetscLogStageGetActive(int stage, PetscTruth *isActive) {
513: StageLog stageLog;
514: int ierr;
517: PetscLogGetStageLog(&stageLog);
518: StageLogGetActive(stageLog, stage, isActive);
519: return(0);
520: }
524: /*@
525: PetscLogStageSetVisible - Determines stage visibility in PetscLogPrintSummary()
527: Not Collective
529: Input Parameters:
530: + stage - The stage
531: - isVisible - The visibility flag, PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE)
533: Level: intermediate
535: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogPrintSummary()
536: @*/
537: int PetscLogStageSetVisible(int stage, PetscTruth isVisible)
538: {
539: StageLog stageLog;
540: int ierr;
543: PetscLogGetStageLog(&stageLog);
544: StageLogSetVisible(stageLog, stage, isVisible);
545: return(0);
546: }
550: /*@
551: PetscLogStageGetVisible - Returns stage visibility in PetscLogPrintSummary()
553: Not Collective
555: Input Parameter:
556: . stage - The stage
558: Output Parameter:
559: . isVisible - The visibility flag, PETSC_TRUE to print, else PETSC_FALSE (defaults to PETSC_TRUE)
561: Level: intermediate
563: .seealso: PetscLogStagePush(), PetscLogStagePop(), PetscLogPrintSummary()
564: @*/
565: int PetscLogStageGetVisible(int stage, PetscTruth *isVisible)
566: {
567: StageLog stageLog;
568: int ierr;
571: PetscLogGetStageLog(&stageLog);
572: StageLogGetVisible(stageLog, stage, isVisible);
573: return(0);
574: }
578: /*@
579: PetscLogStageGetId - Returns the stage id when given the stage name.
581: Not Collective
583: Input Parameter:
584: . name - The stage name
586: Output Parameter:
587: . stage - The stage
589: Level: intermediate
591: .seealso: PetscLogStagePush(), PetscLogStagePop(), PreLoadBegin(), PreLoadEnd(), PreLoadStage()
592: @*/
593: int PetscLogStageGetId(const char name[], int *stage)
594: {
595: StageLog stageLog;
596: int ierr;
599: PetscLogGetStageLog(&stageLog);
600: StageLogGetStage(stageLog, name, stage);
601: return(0);
602: }
604: /*------------------------------------------------ Event Functions --------------------------------------------------*/
607: /*@C
608: PetscLogEventRegister - Registers an event name for logging operations in an application code.
610: Not Collective
612: Input Parameter:
613: + name - The name associated with the event
614: - cookie - The cookie associated to the class for this event
615:
616: Output Parameter:
617: . event - The event id for use with PetscLogEventBegin() and PetscLogEventEnd().
619: Example of Usage:
620: .vb
621: int USER_EVENT;
622: int user_event_flops;
623: PetscLogEventRegister(&USER_EVENT,"User event name");
624: PetscLogEventBegin(USER_EVENT,0,0,0,0);
625: [code segment to monitor]
626: PetscLogFlops(user_event_flops);
627: PetscLogEventEnd(USER_EVENT,0,0,0,0);
628: .ve
630: Notes:
631: PETSc automatically logs library events if the code has been
632: compiled with -DPETSC_USE_LOG (which is the default) and -log,
633: -log_summary, or -log_all are specified. PetscLogEventRegister() is
634: intended for logging user events to supplement this PETSc
635: information.
637: PETSc can gather data for use with the utilities Upshot/Nupshot
638: (part of the MPICH distribution). If PETSc has been compiled
639: with flag -DPETSC_HAVE_MPE (MPE is an additional utility within
640: MPICH), the user can employ another command line option, -log_mpe,
641: to create a logfile, "mpe.log", which can be visualized
642: Upshot/Nupshot.
644: Level: intermediate
646: .keywords: log, event, register
647: .seealso: PetscLogEventBegin(), PetscLogEventEnd(), PetscLogFlops(),
648: PetscLogEventMPEActivate(), PetscLogEventMPEDeactivate(),
649: PetscLogEventActivate(), PetscLogEventDeactivate()
650: @*/
651: int PetscLogEventRegister(int *event, const char name[],int cookie) {
652: StageLog stageLog;
653: int stage;
654: int ierr;
657: *event = PETSC_DECIDE;
658: PetscLogGetStageLog(&stageLog);
659: EventRegLogRegister(stageLog->eventLog, name, cookie, event);
660: for(stage = 0; stage < stageLog->numStages; stage++) {
661: EventPerfLogEnsureSize(stageLog->stageInfo[stage].eventLog, stageLog->eventLog->numEvents);
662: ClassPerfLogEnsureSize(stageLog->stageInfo[stage].classLog, stageLog->classLog->numClasses);
663: }
664: return(0);
665: }
669: /*@
670: PetscLogEventActivate - Indicates that a particular event should be logged.
672: Not Collective
674: Input Parameter:
675: . event - The event id
677: Usage:
678: .vb
679: PetscLogEventDeactivate(VEC_SetValues);
680: [code where you do not want to log VecSetValues()]
681: PetscLogEventActivate(VEC_SetValues);
682: [code where you do want to log VecSetValues()]
683: .ve
685: Note:
686: The event may be either a pre-defined PETSc event (found in include/petsclog.h)
687: or an event number obtained with PetscLogEventRegister().
689: Level: advanced
691: .keywords: log, event, activate
692: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventDeactivate()
693: @*/
694: int PetscLogEventActivate(int event) {
695: StageLog stageLog;
696: int stage;
697: int ierr;
700: PetscLogGetStageLog(&stageLog);
701: StageLogGetCurrent(stageLog, &stage);
702: EventPerfLogActivate(stageLog->stageInfo[stage].eventLog, event);
703: return(0);
704: }
708: /*@
709: PetscLogEventDeactivate - Indicates that a particular event should not be logged.
711: Not Collective
713: Input Parameter:
714: . event - The event id
716: Usage:
717: .vb
718: PetscLogEventDeactivate(VEC_SetValues);
719: [code where you do not want to log VecSetValues()]
720: PetscLogEventActivate(VEC_SetValues);
721: [code where you do want to log VecSetValues()]
722: .ve
724: Note:
725: The event may be either a pre-defined PETSc event (found in
726: include/petsclog.h) or an event number obtained with PetscLogEventRegister()).
728: Level: advanced
730: .keywords: log, event, deactivate
731: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventActivate()
732: @*/
733: int PetscLogEventDeactivate(int event) {
734: StageLog stageLog;
735: int stage;
736: int ierr;
739: PetscLogGetStageLog(&stageLog);
740: StageLogGetCurrent(stageLog, &stage);
741: EventPerfLogDeactivate(stageLog->stageInfo[stage].eventLog, event);
742: return(0);
743: }
747: /*@
748: PetscLogEventSetActiveAll - Sets the event activity in every stage.
750: Not Collective
752: Input Parameters:
753: + event - The event id
754: - isActive - The activity flag determining whether the event is logged
756: Level: advanced
758: .keywords: log, event, activate
759: .seealso: PetscLogEventMPEDeactivate(),PetscLogEventMPEActivate(),PlogEventActivate(),PlogEventDeactivate()
760: @*/
761: int PetscLogEventSetActiveAll(int event, PetscTruth isActive) {
762: StageLog stageLog;
763: int stage;
764: int ierr;
767: PetscLogGetStageLog(&stageLog);
768: for(stage = 0; stage < stageLog->numStages; stage++) {
769: if (isActive == PETSC_TRUE) {
770: EventPerfLogActivate(stageLog->stageInfo[stage].eventLog, event);
771: } else {
772: EventPerfLogDeactivate(stageLog->stageInfo[stage].eventLog, event);
773: }
774: }
775: return(0);
776: }
780: /*@
781: PetscLogEventActivateClass - Activates event logging for a PETSc object class.
783: Not Collective
785: Input Parameter:
786: . cookie - The event class, for example MAT_COOKIE, SNES_COOKIE, etc.
788: Level: developer
790: .keywords: log, event, activate, class
791: .seealso: PetscLogInfoActivate(),PetscLogInfo(),PetscLogInfoAllow(),PetscLogEventDeactivateClass(), PetscLogEventActivate(),PetscLogEventDeactivate()
792: @*/
793: int PetscLogEventActivateClass(int cookie) {
794: StageLog stageLog;
795: int stage;
796: int ierr;
799: PetscLogGetStageLog(&stageLog);
800: StageLogGetCurrent(stageLog, &stage);
801: EventPerfLogActivateClass(stageLog->stageInfo[stage].eventLog, stageLog->eventLog, cookie);
802: return(0);
803: }
807: /*@
808: PetscLogEventDeactivateClass - Deactivates event logging for a PETSc object class.
810: Not Collective
812: Input Parameter:
813: . cookie - The event class, for example MAT_COOKIE, SNES_COOKIE, etc.
815: Level: developer
817: .keywords: log, event, deactivate, class
818: .seealso: PetscLogInfoActivate(),PetscLogInfo(),PetscLogInfoAllow(),PetscLogEventActivateClass(), PetscLogEventActivate(),PetscLogEventDeactivate()
819: @*/
820: int PetscLogEventDeactivateClass(int cookie) {
821: StageLog stageLog;
822: int stage;
823: int ierr;
826: PetscLogGetStageLog(&stageLog);
827: StageLogGetCurrent(stageLog, &stage);
828: EventPerfLogDeactivateClass(stageLog->stageInfo[stage].eventLog, stageLog->eventLog, cookie);
829: return(0);
830: }
832: /*MC
833: PetscLogEventBegin - Logs the beginning of a user event.
835: Input Parameters:
836: + e - integer associated with the event obtained from PetscLogEventRegister()
837: - o1,o2,o3,o4 - objects associated with the event, or 0
839: Synopsis:
840: void PetscLogEventBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
841: PetscObject o4)
843: Fortran Synopsis:
844: void PetscLogEventEnd(int e,int ierr)
846: Usage:
847: .vb
848: int USER_EVENT;
849: int user_event_flops;
850: PetscLogEventRegister(&USER_EVENT,"User event");
851: PetscLogEventBegin(USER_EVENT,0,0,0,0);
852: [code segment to monitor]
853: PetscLogFlops(user_event_flops);
854: PetscLogEventEnd(USER_EVENT,0,0,0,0);
855: .ve
857: Notes:
858: You need to register each integer event with the command
859: PetscLogEventRegister(). The source code must be compiled with
860: -DPETSC_USE_LOG, which is the default.
862: PETSc automatically logs library events if the code has been
863: compiled with -DPETSC_USE_LOG, and -log, -log_summary, or -log_all are
864: specified. PetscLogEventBegin() is intended for logging user events
865: to supplement this PETSc information.
867: Level: intermediate
869: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops()
871: .keywords: log, event, begin
872: M*/
874: /*MC
875: PetscLogEventEnd - Log the end of a user event.
877: Input Parameters:
878: + e - integer associated with the event obtained with PetscLogEventRegister()
879: - o1,o2,o3,o4 - objects associated with the event, or 0
881: Synopsis:
882: void PetscLogEventEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
883: PetscObject o4)
885: Fortran Synopsis:
886: void PetscLogEventEnd(int e,int ierr)
888: Usage:
889: .vb
890: int USER_EVENT;
891: int user_event_flops;
892: PetscLogEventRegister(&USER_EVENT,"User event");
893: PetscLogEventBegin(USER_EVENT,0,0,0,0);
894: [code segment to monitor]
895: PetscLogFlops(user_event_flops);
896: PetscLogEventEnd(USER_EVENT,0,0,0,0);
897: .ve
899: Notes:
900: You should also register each additional integer event with the command
901: PetscLogEventRegister(). Source code must be compiled with
902: -DPETSC_USE_LOG, which is the default.
904: PETSc automatically logs library events if the code has been
905: compiled with -DPETSC_USE_LOG, and -log, -log_summary, or -log_all are
906: specified. PetscLogEventEnd() is intended for logging user events
907: to supplement this PETSc information.
909: Level: intermediate
911: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogFlops()
913: .keywords: log, event, end
914: M*/
916: /*MC
917: PetscLogEventBarrierBegin - Logs the time in a barrier before an event.
919: Input Parameters:
920: . e - integer associated with the event obtained from PetscLogEventRegister()
921: . o1,o2,o3,o4 - objects associated with the event, or 0
922: . comm - communicator the barrier takes place over
924: Synopsis:
925: void PetscLogEventBarrierBegin(int e,PetscObject o1,PetscObject o2,PetscObject o3,
926: PetscObject o4,MPI_Comm comm)
928: Usage:
929: .vb
930: PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm);
931: MPI_Allreduce()
932: PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm);
933: .ve
935: Notes:
936: This is for logging the amount of time spent in a barrier for an event
937: that requires synchronization.
939: Additional Notes:
940: Synchronization events always come in pairs; for example, VEC_NormBarrier and
941: VEC_NormComm = VEC_NormBarrier + 1
943: Level: advanced
945: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(),
946: PetscLogEventBarrierEnd()
948: .keywords: log, event, begin, barrier
949: M*/
951: /*MC
952: PetscLogEventBarrierEnd - Logs the time in a barrier before an event.
954: Input Parameters:
955: . e - integer associated with the event obtained from PetscLogEventRegister()
956: . o1,o2,o3,o4 - objects associated with the event, or 0
957: . comm - communicator the barrier takes place over
959: Synopsis:
960: void PetscLogEventBarrierEnd(int e,PetscObject o1,PetscObject o2,PetscObject o3,
961: PetscObject o4,MPI_Comm comm)
963: Usage:
964: .vb
965: PetscLogEventBarrierBegin(VEC_NormBarrier,0,0,0,0,comm);
966: MPI_Allreduce()
967: PetscLogEventBarrierEnd(VEC_NormBarrier,0,0,0,0,comm);
968: .ve
970: Notes:
971: This is for logging the amount of time spent in a barrier for an event
972: that requires synchronization.
974: Additional Notes:
975: Synchronization events always come in pairs; for example, VEC_NormBarrier and
976: VEC_NormComm = VEC_NormBarrier + 1
978: Level: advanced
980: .seealso: PetscLogEventRegister(), PetscLogEventEnd(), PetscLogFlops(), PetscLogEventBegin(),
981: PetscLogEventBarrierBegin()
983: .keywords: log, event, begin, barrier
984: M*/
986: /*------------------------------------------------ Class Functions --------------------------------------------------*/
989: /*@C
990: PetscLogClassRegister - Registers a class name for logging operations in an application code.
992: Not Collective
994: Input Parameter:
995: . name - The class name
996:
997: Output Parameter:
998: . oclass - The class id or cookie
1000: Level: developer
1002: .keywords: log, class, register
1003: .seealso: ClassLogRegister()
1004: @*/
1005: int PetscLogClassRegister(int *oclass, const char name[])
1006: {
1007: StageLog stageLog;
1008: int stage;
1009: int ierr;
1012: *oclass = PETSC_DECIDE;
1013: PetscLogGetStageLog(&stageLog);
1014: ClassRegLogRegister(stageLog->classLog, name, oclass);
1015: for(stage = 0; stage < stageLog->numStages; stage++) {
1016: ClassPerfLogEnsureSize(stageLog->stageInfo[stage].classLog, stageLog->classLog->numClasses);
1017: }
1018: return(0);
1019: }
1021: /*------------------------------------------------ Output Functions -------------------------------------------------*/
1024: /*@C
1025: PetscLogDump - Dumps logs of objects to a file. This file is intended to
1026: be read by petsc/bin/petscview.
1028: Collective on PETSC_COMM_WORLD
1030: Input Parameter:
1031: . name - an optional file name
1033: Options Database Keys:
1034: + -log - Prints basic log information (for code compiled with PETSC_USE_LOG)
1035: - -log_all - Prints extensive log information (for code compiled with PETSC_USE_LOG)
1036:
1037: Usage:
1038: .vb
1039: PetscInitialize(...);
1040: PetscLogBegin(); or PetscLogAllBegin();
1041: ... code ...
1042: PetscLogDump(filename);
1043: PetscFinalize();
1044: .ve
1046: Notes:
1047: The default file name is
1048: $ Log.<rank>
1049: where <rank> is the processor number. If no name is specified,
1050: this file will be used.
1052: Level: advanced
1054: .keywords: log, dump
1055: .seealso: PetscLogBegin(), PetscLogAllBegin(), PetscLogPrintSummary()
1056: @*/
1057: int PetscLogDump(const char sname[]) {
1058: StageLog stageLog;
1059: EventPerfInfo *eventInfo;
1060: FILE *fd;
1061: char file[PETSC_MAX_PATH_LEN], fname[PETSC_MAX_PATH_LEN];
1062: PetscLogDouble flops, _TotalTime;
1063: int rank, curStage;
1064: int action, object, event;
1065: int ierr;
1066:
1068: /* Calculate the total elapsed time */
1069: PetscTime(_TotalTime);
1070: _TotalTime -= BaseTime;
1071: /* Open log file */
1072: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
1073: if (sname != PETSC_NULL) {
1074: sprintf(file, "%s.%d", sname, rank);
1075: } else {
1076: sprintf(file, "Log.%d", rank);
1077: }
1078: PetscFixFilename(file, fname);
1079: PetscFOpen(PETSC_COMM_WORLD, fname, "w", &fd);
1080: if ((rank == 0) && (fd == PETSC_NULL)) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open file: %s", fname);
1081: /* Output totals */
1082: PetscFPrintf(PETSC_COMM_WORLD, fd, "Total Flops %14e %16.8e\n", _TotalFlops, _TotalTime);
1083: PetscFPrintf(PETSC_COMM_WORLD, fd, "Clock Resolution %g\n", 0.0);
1084: /* Output actions */
1085: PetscFPrintf(PETSC_COMM_WORLD, fd, "Actions accomplished %d\n", numActions);
1086: for(action = 0; action < numActions; action++) {
1087: PetscFPrintf(PETSC_COMM_WORLD, fd, "%g %d %d %d %d %d %d %g %g %g\n",
1088: actions[action].time, actions[action].action, actions[action].event, actions[action].cookie, actions[action].id1,
1089: actions[action].id2, actions[action].id3, actions[action].flops, actions[action].mem, actions[action].maxmem);
1090: }
1091: /* Output objects */
1092: PetscFPrintf(PETSC_COMM_WORLD, fd, "Objects created %d destroyed %d\n", numObjects, numObjectsDestroyed);
1093: for(object = 0; object < numObjects; object++) {
1094: PetscFPrintf(PETSC_COMM_WORLD, fd, "Parent ID: %d Memory: %d\n", objects[object].parent, (int) objects[object].mem);
1095: if (!objects[object].name[0]) {
1096: PetscFPrintf(PETSC_COMM_WORLD, fd,"No Name\n");
1097: } else {
1098: PetscFPrintf(PETSC_COMM_WORLD, fd, "Name: %s\n", objects[object].name);
1099: }
1100: if (objects[object].info[0] != 0) {
1101: PetscFPrintf(PETSC_COMM_WORLD, fd, "No Info\n");
1102: } else {
1103: PetscFPrintf(PETSC_COMM_WORLD, fd, "Info: %s\n", objects[object].info);
1104: }
1105: }
1106: /* Output events */
1107: PetscFPrintf(PETSC_COMM_WORLD, fd, "Event log:\n");
1108: PetscLogGetStageLog(&stageLog);
1109: StackTop(stageLog->stack, &curStage);
1110: eventInfo = stageLog->stageInfo[curStage].eventLog->eventInfo;
1111: for(event = 0; event < stageLog->stageInfo[curStage].eventLog->numEvents; event++) {
1112: if (eventInfo[event].time != 0.0) {
1113: flops = eventInfo[event].flops/eventInfo[event].time;
1114: } else {
1115: flops = 0.0;
1116: }
1117: PetscFPrintf(PETSC_COMM_WORLD, fd, "%d %16d %16g %16g %16g\n", event, eventInfo[event].count,
1118: eventInfo[event].flops, eventInfo[event].time, flops);
1119: }
1120: PetscFClose(PETSC_COMM_WORLD, fd);
1121: return(0);
1122: }
1126: /*@C
1127: PetscLogPrintSummary - Prints a summary of the logging.
1129: Collective over MPI_Comm
1131: Input Parameter:
1132: + comm - The MPI communicator (only one processor prints output)
1133: - file - [Optional] The output file name
1135: Options Database Keys:
1136: . -log_summary - Prints summary of log information (for code compiled with PETSC_USE_LOG)
1138: Usage:
1139: .vb
1140: PetscInitialize(...);
1141: PetscLogBegin();
1142: ... code ...
1143: PetscLogPrintSummary(MPI_Comm,filename);
1144: PetscFinalize(...);
1145: .ve
1147: Notes:
1148: By default the summary is printed to stdout.
1149: More extensive examination of the log information can be done with
1150: PetscLogDump(), which is activated by the option -log or -log_all, in
1151: combination with petsc/bin/petscview.
1153: Level: beginner
1154:
1155: .keywords: log, dump, print
1156: .seealso: PetscLogBegin(), PetscLogDump()
1157: @*/
1158: int PetscLogPrintSummary(MPI_Comm comm, const char filename[]) {
1159: FILE *fd = stdout;
1160: PetscScalar zero = 0.0;
1161: StageLog stageLog;
1162: StageInfo *stageInfo = PETSC_NULL;
1163: EventPerfInfo *eventInfo = PETSC_NULL;
1164: ClassPerfInfo *classInfo;
1165: char arch[10], hostname[64], username[16], pname[PETSC_MAX_PATH_LEN], date[64];
1166: const char *name;
1167: PetscLogDouble locTotalTime, TotalTime, TotalFlops;
1168: PetscLogDouble numMessages, messageLength, avgMessLen, numReductions;
1169: PetscLogDouble stageTime, flops, flopr, mem, mess, messLen, red;
1170: PetscLogDouble fracTime, fracFlops, fracMessages, fracLength, fracReductions, fracMess, fracMessLen, fracRed;
1171: PetscLogDouble fracStageTime, fracStageFlops, fracStageMess, fracStageMessLen, fracStageRed;
1172: PetscLogDouble min, max, tot, ratio, avg, x, y;
1173: PetscLogDouble minf, maxf, totf, ratf, mint, maxt, tott, ratt, ratCt, totm, totml, totr;
1174: int minCt, maxCt;
1175: int numProcs, rank;
1176: PetscTruth *localStageUsed, *stageUsed;
1177: PetscTruth *localStageVisible, *stageVisible;
1178: int numStages, localNumEvents, numEvents;
1179: int stage, event, oclass;
1180: int ierr;
1181: char version[256];
1184: MPI_Comm_size(comm, &numProcs);
1185: MPI_Comm_rank(comm, &rank);
1186: /* Pop off any stages the user forgot to remove */
1187: PetscLogGetStageLog(&stageLog);
1188: StageLogGetCurrent(stageLog, &stage);
1189: while (stage >= 0) {
1190: StageLogPop(stageLog);
1191: StageLogGetCurrent(stageLog, &stage);
1192: }
1193: /* Get the total elapsed time */
1194: PetscTime(locTotalTime); locTotalTime -= BaseTime;
1195: /* Open the summary file */
1196: if (filename != PETSC_NULL) {
1197: PetscFOpen(comm, filename, "w", &fd);
1198: }
1200: PetscFPrintf(comm, fd, "************************************************************************************************************************\n");
1201: PetscFPrintf(comm, fd, "*** WIDEN YOUR WINDOW TO 120 CHARACTERS. Use 'enscript -r -fCourier9' to print this document ***\n");
1202: PetscFPrintf(comm, fd, "************************************************************************************************************************\n");
1203: PetscFPrintf(comm, fd, "\n---------------------------------------------- PETSc Performance Summary: ----------------------------------------------\n\n");
1204: PetscGetArchType(arch, 10);
1205: PetscGetHostName(hostname, 64);
1206: PetscGetUserName(username, 16);
1207: PetscGetProgramName(pname, PETSC_MAX_PATH_LEN);
1208: PetscGetDate(date, 64);
1209: PetscGetVersion(&version);
1210: if (numProcs == 1) {
1211: PetscFPrintf(comm,fd,"%s on a %s named %s with %d processor, by %s %s\n", pname, arch, hostname, numProcs, username, date);
1212:
1213: } else {
1214: PetscFPrintf(comm,fd,"%s on a %s named %s with %d processors, by %s %s\n", pname, arch, hostname, numProcs, username, date);
1215:
1216: }
1217: PetscFPrintf(comm, fd, "Using %s\n", version);
1219: /* Must preserve reduction count before we go on */
1220: red = allreduce_ct/((PetscLogDouble) numProcs);
1222: /* Calculate summary information */
1223: PetscFPrintf(comm, fd, "\n Max Max/Min Avg Total \n");
1224: /* Time */
1225: MPI_Allreduce(&locTotalTime, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1226: MPI_Allreduce(&locTotalTime, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1227: MPI_Allreduce(&locTotalTime, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1228: avg = (tot)/((PetscLogDouble) numProcs);
1229: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1230: PetscFPrintf(comm, fd, "Time (sec): %5.3e %10.5f %5.3e\n", max, ratio, avg);
1231: TotalTime = tot;
1232: /* Objects */
1233: avg = (PetscLogDouble) numObjects;
1234: MPI_Allreduce(&avg, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1235: MPI_Allreduce(&avg, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1236: MPI_Allreduce(&avg, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1237: avg = (tot)/((PetscLogDouble) numProcs);
1238: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1239: PetscFPrintf(comm, fd, "Objects: %5.3e %10.5f %5.3e\n", max, ratio, avg);
1240: /* Flops */
1241: MPI_Allreduce(&_TotalFlops, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1242: MPI_Allreduce(&_TotalFlops, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1243: MPI_Allreduce(&_TotalFlops, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1244: avg = (tot)/((PetscLogDouble) numProcs);
1245: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1246: PetscFPrintf(comm, fd, "Flops: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1247: TotalFlops = tot;
1248: /* Flops/sec -- Must talk to Barry here */
1249: if (locTotalTime != 0.0) flops = _TotalFlops/locTotalTime; else flops = 0.0;
1250: MPI_Allreduce(&flops, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1251: MPI_Allreduce(&flops, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1252: MPI_Allreduce(&flops, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1253: avg = (tot)/((PetscLogDouble) numProcs);
1254: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1255: PetscFPrintf(comm, fd, "Flops/sec: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1256: /* Memory */
1257: PetscTrSpace(PETSC_NULL, PETSC_NULL, &mem);
1258: if (mem > 0.0) {
1259: MPI_Allreduce(&mem, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1260: MPI_Allreduce(&mem, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1261: MPI_Allreduce(&mem, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1262: avg = (tot)/((PetscLogDouble) numProcs);
1263: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1264: PetscFPrintf(comm, fd, "Memory: %5.3e %10.5f %5.3e\n", max, ratio, tot);
1265: }
1266: /* Messages */
1267: mess = 0.5*(irecv_ct + isend_ct + recv_ct + send_ct);
1268: MPI_Allreduce(&mess, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1269: MPI_Allreduce(&mess, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1270: MPI_Allreduce(&mess, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1271: avg = (tot)/((PetscLogDouble) numProcs);
1272: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1273: PetscFPrintf(comm, fd, "MPI Messages: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1274: numMessages = tot;
1275: /* Message Lengths */
1276: mess = 0.5*(irecv_len + isend_len + recv_len + send_len);
1277: MPI_Allreduce(&mess, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1278: MPI_Allreduce(&mess, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1279: MPI_Allreduce(&mess, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1280: if (numMessages != 0) avg = (tot)/(numMessages); else avg = 0.0;
1281: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1282: PetscFPrintf(comm, fd, "MPI Message Lengths: %5.3e %10.5f %5.3e %5.3e\n", max, ratio, avg, tot);
1283: messageLength = tot;
1284: /* Reductions */
1285: MPI_Allreduce(&red, &min, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1286: MPI_Allreduce(&red, &max, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1287: MPI_Allreduce(&red, &tot, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1288: if (min != 0.0) ratio = max/min; else ratio = 0.0;
1289: PetscFPrintf(comm, fd, "MPI Reductions: %5.3e %10.5f\n", max, ratio);
1290: numReductions = tot;
1291: PetscFPrintf(comm, fd, "\nFlop counting convention: 1 flop = 1 real number operation of type (multiply/divide/add/subtract)\n");
1292: PetscFPrintf(comm, fd, " e.g., VecAXPY() for real vectors of length N --> 2N flops\n");
1293: PetscFPrintf(comm, fd, " and VecAXPY() for complex vectors of length N --> 8N flops\n");
1295: /* Get total number of stages --
1296: Currently, a single processor can register more stages than another, but stages must all be registered in order.
1297: We can removed this requirement if necessary by having a global stage numbering and indirection on the stage ID.
1298: This seems best accomplished by assoicating a communicator with each stage.
1299: */
1300: MPI_Allreduce(&stageLog->numStages, &numStages, 1, MPI_INT, MPI_MAX, comm);
1301: PetscMalloc(numStages * sizeof(PetscTruth), &localStageUsed);
1302: PetscMalloc(numStages * sizeof(PetscTruth), &stageUsed);
1303: PetscMalloc(numStages * sizeof(PetscTruth), &localStageVisible);
1304: PetscMalloc(numStages * sizeof(PetscTruth), &stageVisible);
1305: if (numStages > 0) {
1306: stageInfo = stageLog->stageInfo;
1307: for(stage = 0; stage < numStages; stage++) {
1308: if (stage < stageLog->numStages) {
1309: localStageUsed[stage] = stageInfo[stage].used;
1310: localStageVisible[stage] = stageInfo[stage].perfInfo.visible;
1311: } else {
1312: localStageUsed[stage] = PETSC_FALSE;
1313: localStageVisible[stage] = PETSC_TRUE;
1314: }
1315: }
1316: MPI_Allreduce(localStageUsed, stageUsed, numStages, MPI_INT, MPI_LOR, comm);
1317: MPI_Allreduce(localStageVisible, stageVisible, numStages, MPI_INT, MPI_LAND, comm);
1318: for(stage = 0; stage < numStages; stage++) {
1319: if (stageUsed[stage] == PETSC_TRUE) {
1320: PetscFPrintf(comm, fd, "\nSummary of Stages: ----- Time ------ ----- Flops ----- --- Messages --- -- Message Lengths -- -- Reductions --\n");
1321: PetscFPrintf(comm, fd, " Avg %%Total Avg %%Total counts %%Total Avg %%Total counts %%Total \n");
1322: break;
1323: }
1324: }
1325: for(stage = 0; stage < numStages; stage++) {
1326: if (stageUsed[stage] == PETSC_FALSE) continue;
1327: if (localStageUsed[stage] == PETSC_TRUE) {
1328: MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1329: MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1330: MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1331: MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1332: MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1333: name = stageInfo[stage].name;
1334: } else {
1335: MPI_Allreduce(&zero, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1336: MPI_Allreduce(&zero, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1337: MPI_Allreduce(&zero, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1338: MPI_Allreduce(&zero, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1339: MPI_Allreduce(&zero, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1340: name = "";
1341: }
1342: mess *= 0.5; messLen *= 0.5; red /= numProcs;
1343: if (TotalTime != 0.0) fracTime = stageTime/TotalTime; else fracTime = 0.0;
1344: if (TotalFlops != 0.0) fracFlops = flops/TotalFlops; else fracFlops = 0.0;
1345: /* Talk to Barry if (stageTime != 0.0) flops = (numProcs*flops)/stageTime; else flops = 0.0; */
1346: if (numMessages != 0.0) fracMessages = mess/numMessages; else fracMessages = 0.0;
1347: if (numMessages != 0.0) avgMessLen = messLen/numMessages; else avgMessLen = 0.0;
1348: if (messageLength != 0.0) fracLength = messLen/messageLength; else fracLength = 0.0;
1349: if (numReductions != 0.0) fracReductions = red/numReductions; else fracReductions = 0.0;
1350: 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",
1351: stage, name, stageTime/numProcs, 100.0*fracTime, flops, 100.0*fracFlops,
1352: mess, 100.0*fracMessages, avgMessLen, 100.0*fracLength, red, 100.0*fracReductions);
1353:
1354: }
1355: }
1357: PetscFPrintf(comm, fd,
1358: "\n------------------------------------------------------------------------------------------------------------------------\n");
1359:
1360: PetscFPrintf(comm, fd, "See the 'Profiling' chapter of the users' manual for details on interpreting output.\n");
1361: PetscFPrintf(comm, fd, "Phase summary info:\n");
1362: PetscFPrintf(comm, fd, " Count: number of times phase was executed\n");
1363: PetscFPrintf(comm, fd, " Time and Flops/sec: Max - maximum over all processors\n");
1364: PetscFPrintf(comm, fd, " Ratio - ratio of maximum to minimum over all processors\n");
1365: PetscFPrintf(comm, fd, " Mess: number of messages sent\n");
1366: PetscFPrintf(comm, fd, " Avg. len: average message length\n");
1367: PetscFPrintf(comm, fd, " Reduct: number of global reductions\n");
1368: PetscFPrintf(comm, fd, " Global: entire computation\n");
1369: PetscFPrintf(comm, fd, " Stage: stages of a computation. Set stages with PetscLogStagePush() and PetscLogStagePop().\n");
1370: PetscFPrintf(comm, fd, " %%T - percent time in this phase %%F - percent flops in this phase\n");
1371: PetscFPrintf(comm, fd, " %%M - percent messages in this phase %%L - percent message lengths in this phase\n");
1372: PetscFPrintf(comm, fd, " %%R - percent reductions in this phase\n");
1373: PetscFPrintf(comm, fd, " Total Mflop/s: 10e-6 * (sum of flops over all processors)/(max time over all processors)\n");
1374: PetscFPrintf(comm, fd,
1375: "------------------------------------------------------------------------------------------------------------------------\n");
1376:
1378: #if defined(PETSC_USE_BOPT_g)
1379: PetscFPrintf(comm, fd, "\n\n");
1380: PetscFPrintf(comm, fd, " ##########################################################\n");
1381: PetscFPrintf(comm, fd, " # #\n");
1382: PetscFPrintf(comm, fd, " # WARNING!!! #\n");
1383: PetscFPrintf(comm, fd, " # #\n");
1384: PetscFPrintf(comm, fd, " # This code was compiled with a debugging option, #\n");
1385: PetscFPrintf(comm, fd, " # BOPT=<g,g_c++,g_complex>. To get timing results #\n");
1386: PetscFPrintf(comm, fd, " # ALWAYS compile your code with an optimized version, #\n");
1387: PetscFPrintf(comm, fd, " # BOPT=<O,O_c++,O_complex>; the performance will #\n");
1388: PetscFPrintf(comm, fd, " # be generally two or three times faster. #\n");
1389: PetscFPrintf(comm, fd, " # #\n");
1390: PetscFPrintf(comm, fd, " ##########################################################\n\n\n");
1391: #endif
1392: #if defined(PETSC_USE_COMPLEX) && !defined(PETSC_USE_FORTRAN_KERNELS)
1393: PetscFPrintf(comm, fd, "\n\n");
1394: PetscFPrintf(comm, fd, " ##########################################################\n");
1395: PetscFPrintf(comm, fd, " # #\n");
1396: PetscFPrintf(comm, fd, " # WARNING!!! #\n");
1397: PetscFPrintf(comm, fd, " # #\n");
1398: PetscFPrintf(comm, fd, " # The code for various complex numbers numerical #\n");
1399: PetscFPrintf(comm, fd, " # kernels uses C++, which generally is not well #\n");
1400: PetscFPrintf(comm, fd, " # optimized. For performance that is about 4-5 times #\n");
1401: PetscFPrintf(comm, fd, " # faster, specify the flag -DPETSC_USE_FORTRAN_KERNELS #\n");
1402: PetscFPrintf(comm, fd, " # in base_variables and recompile the PETSc libraries. #\n");
1403: PetscFPrintf(comm, fd, " # #\n");
1404: PetscFPrintf(comm, fd, " ##########################################################\n\n\n");
1405: #endif
1407: if (!PetscPreLoadingUsed) {
1408: PetscFPrintf(comm,fd,"\n\n");
1409: PetscFPrintf(comm,fd," ##########################################################\n");
1410: PetscFPrintf(comm,fd," # #\n");
1411: PetscFPrintf(comm,fd," # WARNING!!! #\n");
1412: PetscFPrintf(comm,fd," # #\n");
1413: PetscFPrintf(comm,fd," # This code was run without the PreLoadBegin() #\n");
1414: PetscFPrintf(comm,fd," # macros. To get timing results we always recommend #\n");
1415: PetscFPrintf(comm,fd," # preloading. otherwise timing numbers may be #\n");
1416: PetscFPrintf(comm,fd," # meaningless. #\n");
1417: PetscFPrintf(comm,fd," ##########################################################\n\n\n");
1418: }
1420: /* Report events */
1421: PetscFPrintf(comm, fd,
1422: "Event Count Time (sec) Flops/sec --- Global --- --- Stage --- Total\n");
1423:
1424: PetscFPrintf(comm, fd,
1425: " Max Ratio Max Ratio Max Ratio Mess Avg len Reduct %%T %%F %%M %%L %%R %%T %%F %%M %%L %%R Mflop/s\n");
1426:
1427: PetscFPrintf(comm,fd,
1428: "------------------------------------------------------------------------------------------------------------------------\n");
1430:
1431: /* Problem: The stage name will not show up unless the stage executed on proc 1 */
1432: for(stage = 0; stage < numStages; stage++) {
1433: if (stageVisible[stage] == PETSC_FALSE) continue;
1434: if (localStageUsed[stage] == PETSC_TRUE) {
1435: PetscFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);
1436: MPI_Allreduce(&stageInfo[stage].perfInfo.time, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1437: MPI_Allreduce(&stageInfo[stage].perfInfo.flops, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1438: MPI_Allreduce(&stageInfo[stage].perfInfo.numMessages, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1439: MPI_Allreduce(&stageInfo[stage].perfInfo.messageLength, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1440: MPI_Allreduce(&stageInfo[stage].perfInfo.numReductions, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1441: } else {
1442: PetscFPrintf(comm, fd, "\n--- Event Stage %d: Unknown\n\n", stage);
1443: MPI_Allreduce(&zero, &stageTime, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1444: MPI_Allreduce(&zero, &flops, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1445: MPI_Allreduce(&zero, &mess, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1446: MPI_Allreduce(&zero, &messLen, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1447: MPI_Allreduce(&zero, &red, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1448: }
1449: mess *= 0.5; messLen *= 0.5; red /= numProcs;
1451: /* Get total number of events in this stage --
1452: Currently, a single processor can register more events than another, but events must all be registered in order,
1453: just like stages. We can removed this requirement if necessary by having a global event numbering and indirection
1454: on the event ID. This seems best accomplished by assoicating a communicator with each stage.
1456: Problem: If the event did not happen on proc 1, its name will not be available.
1457: Problem: Event visibility is not implemented
1458: */
1459: if (localStageUsed[stage] == PETSC_TRUE) {
1460: eventInfo = stageLog->stageInfo[stage].eventLog->eventInfo;
1461: localNumEvents = stageLog->stageInfo[stage].eventLog->numEvents;
1462: } else {
1463: localNumEvents = 0;
1464: }
1465: MPI_Allreduce(&localNumEvents, &numEvents, 1, MPI_INT, MPI_MAX, comm);
1466: for(event = 0; event < numEvents; event++) {
1467: if ((localStageUsed[stage] == PETSC_TRUE) && (event < stageLog->stageInfo[stage].eventLog->numEvents)) {
1468: if ((eventInfo[event].count > 0) && (eventInfo[event].time > 0.0)) {
1469: flopr = eventInfo[event].flops/eventInfo[event].time;
1470: } else {
1471: flopr = 0.0;
1472: }
1473: MPI_Allreduce(&flopr, &minf, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1474: MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1475: MPI_Allreduce(&eventInfo[event].flops, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1476: MPI_Allreduce(&eventInfo[event].time, &mint, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1477: MPI_Allreduce(&eventInfo[event].time, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1478: MPI_Allreduce(&eventInfo[event].time, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1479: MPI_Allreduce(&eventInfo[event].numMessages, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1480: MPI_Allreduce(&eventInfo[event].messageLength, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1481: MPI_Allreduce(&eventInfo[event].numReductions, &totr, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1482: MPI_Allreduce(&eventInfo[event].count, &minCt, 1, MPI_INT, MPI_MIN, comm);
1483: MPI_Allreduce(&eventInfo[event].count, &maxCt, 1, MPI_INT, MPI_MAX, comm);
1484: name = stageLog->eventLog->eventInfo[event].name;
1485: } else {
1486: flopr = 0.0;
1487: MPI_Allreduce(&flopr, &minf, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1488: MPI_Allreduce(&flopr, &maxf, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1489: MPI_Allreduce(&zero, &totf, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1490: MPI_Allreduce(&zero, &mint, 1, MPIU_PETSCLOGDOUBLE, MPI_MIN, comm);
1491: MPI_Allreduce(&zero, &maxt, 1, MPIU_PETSCLOGDOUBLE, MPI_MAX, comm);
1492: MPI_Allreduce(&zero, &tott, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1493: MPI_Allreduce(&zero, &totm, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1494: MPI_Allreduce(&zero, &totml, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1495: MPI_Allreduce(&zero, &totr, 1, MPIU_PETSCLOGDOUBLE, MPI_SUM, comm);
1496: MPI_Allreduce(&ierr, &minCt, 1, MPI_INT, MPI_MIN, comm);
1497: MPI_Allreduce(&ierr, &maxCt, 1, MPI_INT, MPI_MAX, comm);
1498: name = "";
1499: }
1500: totm *= 0.5; totml *= 0.5; totr /= numProcs;
1501:
1502: if (maxCt != 0) {
1503: if (minCt != 0) ratCt = ((PetscLogDouble) maxCt)/minCt; else ratCt = 0.0;
1504: if (mint != 0.0) ratt = maxt/mint; else ratt = 0.0;
1505: if (minf != 0.0) ratf = maxf/minf; else ratf = 0.0;
1506: if (TotalTime != 0.0) fracTime = tott/TotalTime; else fracTime = 0.0;
1507: if (TotalFlops != 0.0) fracFlops = totf/TotalFlops; else fracFlops = 0.0;
1508: if (stageTime != 0.0) fracStageTime = tott/stageTime; else fracStageTime = 0.0;
1509: if (flops != 0.0) fracStageFlops = totf/flops; else fracStageFlops = 0.0;
1510: if (numMessages != 0.0) fracMess = totm/numMessages; else fracMess = 0.0;
1511: if (messageLength != 0.0) fracMessLen = totml/messageLength; else fracMessLen = 0.0;
1512: if (numReductions != 0.0) fracRed = totr/numReductions; else fracRed = 0.0;
1513: if (mess != 0.0) fracStageMess = totm/mess; else fracStageMess = 0.0;
1514: if (messLen != 0.0) fracStageMessLen = totml/messLen; else fracStageMessLen = 0.0;
1515: if (red != 0.0) fracStageRed = totr/red; else fracStageRed = 0.0;
1516: if (totm != 0.0) totml /= totm; else totml = 0.0;
1517: if (maxt != 0.0) flopr = totf/maxt; else flopr = 0.0;
1518: PetscFPrintf(comm, fd,
1519: "%-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",
1520: name, maxCt, ratCt, maxt, ratt, maxf, ratf, totm, totml, totr,
1521: 100.0*fracTime, 100.0*fracFlops, 100.0*fracMess, 100.0*fracMessLen, 100.0*fracRed,
1522: 100.0*fracStageTime, 100.0*fracStageFlops, 100.0*fracStageMess, 100.0*fracStageMessLen, 100.0*fracStageRed,
1523: flopr/1.0e6);
1524:
1525: }
1526: }
1527: }
1529: /* Memory usage and object creation */
1530: PetscFPrintf(comm, fd,
1531: "------------------------------------------------------------------------------------------------------------------------\n");
1532:
1533: PetscFPrintf(comm, fd, "\n");
1534: PetscFPrintf(comm, fd, "Memory usage is given in bytes:\n\n");
1536: /* Right now, only stages on the first processor are reported here, meaning only objects associated with
1537: the global communicator, or MPI_COMM_SELF for proc 1. We really should report global stats and then
1538: stats for stages local to processor sets.
1539: */
1540: /* We should figure out the longest object name here (now 20 characters) */
1541: PetscFPrintf(comm, fd, "Object Type Creations Destructions Memory Descendants' Mem.\n");
1542: for(stage = 0; stage < numStages; stage++) {
1543: if (localStageUsed[stage] == PETSC_TRUE) {
1544: classInfo = stageLog->stageInfo[stage].classLog->classInfo;
1545: PetscFPrintf(comm, fd, "\n--- Event Stage %d: %s\n\n", stage, stageInfo[stage].name);
1546: for(oclass = 0; oclass < stageLog->stageInfo[stage].classLog->numClasses; oclass++) {
1547: if ((classInfo[oclass].creations > 0) || (classInfo[oclass].destructions > 0)) {
1548: PetscFPrintf(comm, fd, "%20s %5d %5d %9d %g\n", stageLog->classLog->classInfo[oclass].name,
1549: classInfo[oclass].creations, classInfo[oclass].destructions, (int) classInfo[oclass].mem,
1550: classInfo[oclass].descMem);
1551:
1552: }
1553: }
1554: } else {
1555: PetscFPrintf(comm, fd, "\n--- Event Stage %d: Unknown\n\n", stage);
1556: }
1557: }
1559: PetscFree(localStageUsed);
1560: PetscFree(stageUsed);
1561: PetscFree(localStageVisible);
1562: PetscFree(stageVisible);
1564: /* Information unrelated to this particular run */
1565: PetscFPrintf(comm, fd,
1566: "========================================================================================================================\n");
1567:
1568: PetscTime(y);
1569: PetscTime(x);
1570: PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y);
1571: PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y); PetscTime(y);
1572: PetscFPrintf(comm,fd,"Average time to get PetscTime(): %g\n", (y-x)/10.0);
1573: /* MPI information */
1574: if (numProcs > 1) {
1575: MPI_Status status;
1576: int tag;
1578: MPI_Barrier(comm);
1579: PetscTime(x);
1580: MPI_Barrier(comm);
1581: MPI_Barrier(comm);
1582: MPI_Barrier(comm);
1583: MPI_Barrier(comm);
1584: MPI_Barrier(comm);
1585: PetscTime(y);
1586: PetscFPrintf(comm, fd, "Average time for MPI_Barrier(): %g\n", (y-x)/5.0);
1587: PetscCommGetNewTag(comm, &tag);
1588: MPI_Barrier(comm);
1589: if (rank) {
1590: MPI_Recv(0, 0, MPI_INT, rank-1, tag, comm, &status);
1591: MPI_Send(0, 0, MPI_INT, (rank+1)%numProcs, tag, comm);
1592: } else {
1593: PetscTime(x);
1594: MPI_Send(0, 0, MPI_INT, 1, tag, comm);
1595: MPI_Recv(0, 0, MPI_INT, numProcs-1, tag, comm, &status);
1596: PetscTime(y);
1597: PetscFPrintf(comm,fd,"Average time for zero size MPI_Send(): %g\n", (y-x)/numProcs);
1598: }
1599: }
1600: /* Machine and compile information */
1601: #if defined(PETSC_USE_FORTRAN_KERNELS)
1602: PetscFPrintf(comm, fd, "Compiled with FORTRAN kernels\n");
1603: #else
1604: PetscFPrintf(comm, fd, "Compiled without FORTRAN kernels\n");
1605: #endif
1606: #if defined(PETSC_USE_MAT_SINGLE)
1607: PetscFPrintf(comm, fd, "Compiled with single precision matrices\n");
1608: #else
1609: PetscFPrintf(comm, fd, "Compiled with double precision matrices (default)\n");
1610: #endif
1611: PetscFPrintf(comm, fd, "sizeof(short) %d sizeof(int) %d sizeof(long) %d sizeof(void *) %d",
1612: (int) sizeof(short), (int) sizeof(int), (int) sizeof(long), (int) sizeof(void*));
1613:
1615: PetscFPrintf(comm, fd, "%s", petscmachineinfo);
1616: PetscFPrintf(comm, fd, "%s", petsccompilerinfo);
1617: PetscFPrintf(comm, fd, "%s", petsccompilerflagsinfo);
1618: PetscFPrintf(comm, fd, "%s", petsclinkerinfo);
1620: /* Cleanup */
1621: PetscFPrintf(comm, fd, "\n");
1622: PetscFClose(comm, fd);
1623: return(0);
1624: }
1626: /*----------------------------------------------- Counter Functions -------------------------------------------------*/
1629: /*@C
1630: PetscGetFlops - Returns the number of flops used on this processor
1631: since the program began.
1633: Not Collective
1635: Output Parameter:
1636: flops - number of floating point operations
1638: Notes:
1639: A global counter logs all PETSc flop counts. The user can use
1640: PetscLogFlops() to increment this counter to include flops for the
1641: application code.
1643: PETSc automatically logs library events if the code has been
1644: compiled with -DPETSC_USE_LOG (which is the default), and -log,
1645: -log_summary, or -log_all are specified. PetscLogFlops() is
1646: intended for logging user flops to supplement this PETSc
1647: information.
1649: Level: intermediate
1651: .keywords: log, flops, floating point operations
1653: .seealso: PetscGetTime(), PetscLogFlops()
1654: @*/
1655: int PetscGetFlops(PetscLogDouble *flops)
1656: {
1658: *flops = _TotalFlops;
1659: return(0);
1660: }
1664: int PetscLogObjectState(PetscObject obj, const char format[], ...)
1665: {
1666: va_list Argp;
1669: if (logObjects == PETSC_FALSE) return(0);
1670: va_start(Argp, format);
1671: #if defined(PETSC_HAVE_VPRINTF_CHAR)
1672: vsprintf(objects[obj->id].info, format, (char *) Argp);
1673: #else
1674: vsprintf(objects[obj->id].info, format, Argp);
1675: #endif
1676: va_end(Argp);
1677: return(0);
1678: }
1680: #else /* end of -DPETSC_USE_LOG section */
1684: int PetscLogObjectState(PetscObject obj, const char format[], ...)
1685: {
1687: return(0);
1688: }
1690: #endif /* PETSC_USE_LOG*/
1694: /*@
1695: PetscGetTime - Returns the current time of day in seconds. This
1696: returns wall-clock time.
1698: Not Collective
1700: Output Parameter:
1701: . v - time counter
1703: Usage:
1704: .vb
1705: PetscLogDouble v1,v2,elapsed_time;
1706: PetscGetTime(&v1);CHKERR(ierr);
1707: .... perform some calculation ...
1708: PetscGetTime(&v2);CHKERR(ierr);
1709: elapsed_time = v2 - v1;
1710: .ve
1712: Notes:
1713: Since the PETSc libraries incorporate timing of phases and operations,
1714: PetscGetTime() is intended only for timing of application codes.
1715: The options database commands -log, -log_summary, and -log_all activate
1716: PETSc library timing. See the users manual for further details.
1718: Level: intermediate
1720: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStagePush(),
1721: PetscLogStagePop(), PetscLogStageRegister(), PetscGetFlops()
1723: .keywords: get, time
1724: @*/
1725: int PetscGetTime(PetscLogDouble *t)
1726: {
1728: PetscTime(*t);
1729: return(0);
1730: }
1734: /*@
1735: PetscLogGetStageLog - This function returns the default stage logging object.
1737: Not collective
1739: Output Parameter:
1740: . stageLog - The default StageLog
1742: Level: beginner
1744: .keywords: log, stage
1745: .seealso: StageLogCreate()
1746: @*/
1747: int PetscLogGetStageLog(StageLog *stageLog)
1748: {
1751: *stageLog = _stageLog;
1752: return(0);
1753: }
1755: /*MC
1756: PetscLogFlops - Adds floating point operations to the global counter.
1758: Input Parameter:
1759: . f - flop counter
1761: Synopsis:
1762: void PetscLogFlops(int f)
1764: Usage:
1765: .vb
1766: int USER_EVENT;
1767: PetscLogEventRegister(&USER_EVENT,"User event");
1768: PetscLogEventBegin(USER_EVENT,0,0,0,0);
1769: [code segment to monitor]
1770: PetscLogFlops(user_flops)
1771: PetscLogEventEnd(USER_EVENT,0,0,0,0);
1772: .ve
1774: Notes:
1775: A global counter logs all PETSc flop counts. The user can use
1776: PetscLogFlops() to increment this counter to include flops for the
1777: application code.
1779: PETSc automatically logs library events if the code has been
1780: compiled with -DPETSC_USE_LOG (which is the default), and -log,
1781: -log_summary, or -log_all are specified. PetscLogFlops() is
1782: intended for logging user flops to supplement this PETSc
1783: information.
1785: Level: intermediate
1787: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscGetFlops()
1789: .keywords: log, flops, floating point operations
1790: M*/
1792: PetscTruth PetscPreLoadingUsed = PETSC_FALSE;
1793: PetscTruth PetscPreLoadingOn = PETSC_FALSE;
1795: /*MC
1796: PreLoadBegin - Begin a segment of code that may be preloaded (run twice)
1797: to get accurate timings
1799: Input Parameter:
1800: + flag - PETSC_TRUE to run twice, PETSC_FALSE to run once, may be overridden
1801: with command line option -preload true or -preload false
1802: - name - name of first stage (lines of code timed seperately with -log_summary) to
1803: be preloaded
1805: Synopsis:
1806: void PreLoadBegin(PetscTruth flag,char *name);
1808: Usage:
1809: .vb
1810: PreLoadBegin(PETSC_TRUE,"first stage);
1811: lines of code
1812: PreLoadStage("second stage");
1813: lines of code
1814: PreLoadEnd();
1815: .ve
1817: Level: intermediate
1819: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadEnd(), PreLoadStage()
1821: Concepts: preloading
1822: Concepts: timing^accurate
1823: Concepts: paging^eliminating effects of
1826: M*/
1828: /*MC
1829: PreLoadEnd - End a segment of code that may be preloaded (run twice)
1830: to get accurate timings
1832: Synopsis:
1833: void PreLoadEnd(void);
1835: Usage:
1836: .vb
1837: PreLoadBegin(PETSC_TRUE,"first stage);
1838: lines of code
1839: PreLoadStage("second stage");
1840: lines of code
1841: PreLoadEnd();
1842: .ve
1844: Level: intermediate
1846: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadStage()
1848: M*/
1850: /*MC
1851: PreLoadStage - Start a new segment of code to be timed seperately.
1852: to get accurate timings
1854: Synopsis:
1855: void PreLoadStage(char *name);
1857: Usage:
1858: .vb
1859: PreLoadBegin(PETSC_TRUE,"first stage);
1860: lines of code
1861: PreLoadStage("second stage");
1862: lines of code
1863: PreLoadEnd();
1864: .ve
1866: Level: intermediate
1868: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PreLoadBegin(), PreLoadEnd()
1870: M*/
1872: /*----------------------------------------------- Stack Functions ---------------------------------------------------*/
1875: /*@C
1876: StackDestroy - This function destroys a stack.
1878: Not Collective
1880: Input Parameter:
1881: . stack - The stack
1883: Level: beginner
1885: .keywords: log, stack, destroy
1886: .seealso: StackCreate(), StackEmpty(), StackPush(), StackPop(), StackTop()
1887: @*/
1888: int StackDestroy(IntStack stack)
1889: {
1893: PetscFree(stack->stack);
1894: PetscFree(stack);
1895: return(0);
1896: }
1900: /*@C
1901: StackEmpty - This function determines whether any items have been pushed.
1903: Not Collective
1905: Input Parameter:
1906: . stack - The stack
1908: Output Parameter:
1909: . empty - PETSC_TRUE if the stack is empty
1911: Level: intermediate
1913: .keywords: log, stack, empty
1914: .seealso: StackCreate(), StackDestroy(), StackPush(), StackPop(), StackTop()
1915: @*/
1916: int StackEmpty(IntStack stack, PetscTruth *empty)
1917: {
1920: if (stack->top == -1) {
1921: *empty = PETSC_TRUE;
1922: } else {
1923: *empty = PETSC_FALSE;
1924: }
1925: return(0);
1926: }
1930: /*@C
1931: StackTop - This function returns the top of the stack.
1933: Not Collective
1935: Input Parameter:
1936: . stack - The stack
1938: Output Parameter:
1939: . top - The integer on top of the stack
1941: Level: intermediate
1943: .keywords: log, stack, top
1944: .seealso: StackCreate(), StackDestroy(), StackEmpty(), StackPush(), StackPop()
1945: @*/
1946: int StackTop(IntStack stack, int *top)
1947: {
1950: *top = stack->stack[stack->top];
1951: return(0);
1952: }
1956: /*@C
1957: StackPush - This function pushes an integer on the stack.
1959: Not Collective
1961: Input Parameters:
1962: + stack - The stack
1963: - item - The integer to push
1965: Level: intermediate
1967: .keywords: log, stack, push
1968: .seealso: StackCreate(), StackDestroy(), StackEmpty(), StackPop(), StackTop()
1969: @*/
1970: int StackPush(IntStack stack, int item)
1971: {
1972: int *array;
1973: int ierr;
1976: stack->top++;
1977: if (stack->top >= stack->max) {
1978: PetscMalloc(stack->max*2 * sizeof(int), &array);
1979: PetscMemcpy(array, stack->stack, stack->max * sizeof(int));
1980: PetscFree(stack->stack);
1981: stack->stack = array;
1982: stack->max *= 2;
1983: }
1984: stack->stack[stack->top] = item;
1985: return(0);
1986: }
1990: /*@C
1991: StackPop - This function pops an integer from the stack.
1993: Not Collective
1995: Input Parameter:
1996: . stack - The stack
1998: Output Parameter:
1999: . item - The integer popped
2001: Level: intermediate
2003: .keywords: log, stack, pop
2004: .seealso: StackCreate(), StackDestroy(), StackEmpty(), StackPush(), StackTop()
2005: @*/
2006: int StackPop(IntStack stack, int *item)
2007: {
2010: if (stack->top == -1) SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "Stack is empty");
2011: *item = stack->stack[stack->top--];
2012: return(0);
2013: }
2017: /*@C
2018: StackCreate - This function creates a stack.
2020: Not Collective
2022: Output Parameter:
2023: . stack - The stack
2025: Level: beginner
2027: .keywords: log, stack, pop
2028: .seealso: StackDestroy(), StackEmpty(), StackPush(), StackPop(), StackTop()
2029: @*/
2030: int StackCreate(IntStack *stack)
2031: {
2032: IntStack s;
2033: int ierr;
2037: PetscNew(struct _IntStack, &s);
2038: s->top = -1;
2039: s->max = 128;
2040: PetscMalloc(s->max * sizeof(int), &s->stack);
2041: PetscMemzero(s->stack, s->max * sizeof(int));
2042: *stack = s;
2043: return(0);
2044: }