Actual source code: petsclog.h
1: /*
2: Defines profile/logging in PETSc.
3: */
7: #include petsc.h
10: #define PETSC_EVENT 1311311
13: /* Global flop counter */
16: /* General logging of information; different from event logging */
17: EXTERN PetscErrorCode PetscInfo_Private(const char[],void*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
18: #if defined(PETSC_USE_INFO)
19: #define PetscInfo(A,S) PetscInfo_Private(__FUNCT__,A,S)
20: #define PetscInfo1(A,S,a1) PetscInfo_Private(__FUNCT__,A,S,a1)
21: #define PetscInfo2(A,S,a1,a2) PetscInfo_Private(__FUNCT__,A,S,a1,a2)
22: #define PetscInfo3(A,S,a1,a2,a3) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3)
23: #define PetscInfo4(A,S,a1,a2,a3,a4) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4)
24: #define PetscInfo5(A,S,a1,a2,a3,a4,a5) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4,a5)
25: #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4,a5,a6)
26: #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4,a5,a6,a7)
27: #else
28: #define PetscInfo(A,S) 0
29: #define PetscInfo1(A,S,a1) 0
30: #define PetscInfo2(A,S,a1,a2) 0
31: #define PetscInfo3(A,S,a1,a2,a3) 0
32: #define PetscInfo4(A,S,a1,a2,a3,a4) 0
33: #define PetscInfo5(A,S,a1,a2,a3,a4,a5) 0
34: #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) 0
35: #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
36: #endif
37: EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscCookie);
38: EXTERN PetscErrorCode PetscInfoActivateClass(PetscCookie);
41: /* We must make these structures available if we are to access the event
43: function call each time, we could make these private.
44: */
45: /* Default log */
46: typedef struct _n_StageLog *StageLog;
49: /* A simple stack (should replace) */
50: typedef struct _n_IntStack *IntStack;
52: /* The structures for logging performance */
53: typedef struct {
54: int id; /* The integer identifying this section */
55: PetscTruth active; /* The flag to activate logging */
56: PetscTruth visible; /* The flag to print info in summary */
57: int depth; /* The nesting depth of the event call */
58: int count; /* The number of times this section was executed */
59: PetscLogDouble flops; /* The flops used in this section */
60: PetscLogDouble time; /* The time taken for this section */
61: PetscLogDouble numMessages; /* The number of messages in this section */
62: PetscLogDouble messageLength; /* The total message lengths in this section */
63: PetscLogDouble numReductions; /* The number of reductions in this section */
64: } EventPerfInfo;
66: typedef struct {
67: int id; /* The integer identifying this class */
68: int creations; /* The number of objects of this class created */
69: int destructions; /* The number of objects of this class destroyed */
70: PetscLogDouble mem; /* The total memory allocated by objects of this class */
71: PetscLogDouble descMem; /* The total memory allocated by descendents of these objects */
72: } ClassPerfInfo;
74: /* The structures for logging registration */
75: typedef struct {
76: char *name; /* The class name */
77: PetscCookie cookie; /* The integer identifying this class */
78: } ClassRegInfo;
80: typedef struct {
81: char *name; /* The name of this event */
82: PetscCookie cookie; /* The class id for this event (should maybe give class ID instead) */
83: #if defined (PETSC_HAVE_MPE)
84: int mpe_id_begin; /* MPE IDs that define the event */
85: int mpe_id_end;
86: #endif
87: } EventRegInfo;
89: typedef struct _n_EventRegLog *EventRegLog;
90: struct _n_EventRegLog {
91: int numEvents; /* The number of registered events */
92: int maxEvents; /* The maximum number of events */
93: EventRegInfo *eventInfo; /* The registration information for each event */
94: };
96: typedef struct _n_EventPerfLog *EventPerfLog;
97: struct _n_EventPerfLog {
98: int numEvents; /* The number of logging events */
99: int maxEvents; /* The maximum number of events */
100: EventPerfInfo *eventInfo; /* The performance information for each event */
101: };
103: /* The structure for logging class information */
104: typedef struct _n_ClassRegLog *ClassRegLog;
105: struct _n_ClassRegLog {
106: int numClasses; /* The number of classes registered */
107: int maxClasses; /* The maximum number of classes */
108: ClassRegInfo *classInfo; /* The structure for class information (cookies are monotonicly increasing) */
109: };
111: typedef struct _n_ClassPerfLog *ClassPerfLog;
112: struct _n_ClassPerfLog {
113: int numClasses; /* The number of logging classes */
114: int maxClasses; /* The maximum number of classes */
115: ClassPerfInfo *classInfo; /* The structure for class information (cookies are monotonicly increasing) */
116: };
118: /* The structures for logging in stages */
119: typedef struct _StageInfo {
120: char *name; /* The stage name */
121: PetscTruth used; /* The stage was pushed on this processor */
122: EventPerfInfo perfInfo; /* The stage performance information */
123: EventPerfLog eventLog; /* The event information for this stage */
124: ClassPerfLog classLog; /* The class information for this stage */
125: } StageInfo;
127: struct _n_StageLog {
128: /* Size information */
129: int numStages; /* The number of registered stages */
130: int maxStages; /* The maximum number of stages */
131: /* Runtime information */
132: IntStack stack; /* The stack for active stages */
133: int curStage; /* The current stage (only used in macros so we don't call StackTop) */
134: /* Stage specific information */
135: StageInfo *stageInfo; /* The information for each stage */
136: EventRegLog eventLog; /* The registered events */
137: ClassRegLog classLog; /* The registered classes */
138: };
140: #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/
142: /*
143: Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately.
145: For the complex numbers version, note that
146: 1 complex addition = 2 flops
147: 1 complex multiplication = 6 flops,
148: where we define 1 flop as that for a double precision scalar. We roughly approximate
149: flop counting for complex numbers by multiplying the total flops by 4; this corresponds
150: to the assumption that we're counting mostly additions and multiplications -- and
151: roughly the same number of each. More accurate counting could be done by distinguishing
152: among the various arithmetic operations.
153: */
155: #if defined(PETSC_USE_COMPLEX)
156: #define PetscLogFlops(n) (_TotalFlops += (4*n),0)
157: #else
158: #define PetscLogFlops(n) (_TotalFlops += (n),0)
159: #endif
161: #if defined (PETSC_HAVE_MPE)
162: #include "mpe.h"
163: EXTERN PetscErrorCode PetscLogMPEBegin(void);
164: EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
166: #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
167: ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
168: MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)
170: #define PETSC_LOG_EVENT_MPE_END(e) \
171: ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
172: MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0)
174: #else
175: #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0
176: #define PETSC_LOG_EVENT_MPE_END(e) 0
177: #endif
179: EXTERN PetscErrorCode (*_PetscLogPLB)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
180: EXTERN PetscErrorCode (*_PetscLogPLE)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
181: EXTERN PetscErrorCode (*_PetscLogPHC)(PetscObject);
182: EXTERN PetscErrorCode (*_PetscLogPHD)(PetscObject);
184: #define PetscLogObjectParent(p,c) \
185: ((c && p) ? ((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id : 0, 0)
187: #define PetscLogObjectParents(p,n,d) 0;{int _i; for (_i=0; _i<n; _i++) {PetscLogObjectParent(p,(d)[_i]);}}
188: #define PetscLogObjectCreate(h) ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0)
189: #define PetscLogObjectDestroy(h) ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0)
190: #define PetscLogObjectMemory(p,m) (((PetscObject)(p))->mem += (m),0)
191: /* Initialization functions */
192: EXTERN PetscErrorCode PetscLogBegin(void);
193: EXTERN PetscErrorCode PetscLogAllBegin(void);
194: EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
195: EXTERN PetscErrorCode PetscLogActions(PetscTruth);
196: EXTERN PetscErrorCode PetscLogObjects(PetscTruth);
197: /* General functions */
198: EXTERN PetscErrorCode PetscLogGetRGBColor(const char*[]);
199: EXTERN PetscErrorCode PetscLogDestroy(void);
200: EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
201: PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
202: EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_PRINTF_FORMAT_CHECK(2,3);
203: /* Output functions */
204: EXTERN PetscErrorCode PetscLogPrintSummary(MPI_Comm, const char[]);
205: EXTERN PetscErrorCode PetscLogPrintDetailed(MPI_Comm, const char[]);
206: EXTERN PetscErrorCode PetscLogDump(const char[]);
207: /* Counter functions */
208: EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
209: /* Stage functions */
210: EXTERN PetscErrorCode PetscLogStageRegister(int*, const char[]);
211: EXTERN PetscErrorCode PetscLogStagePush(int);
212: EXTERN PetscErrorCode PetscLogStagePop(void);
213: EXTERN PetscErrorCode PetscLogStageSetActive(int, PetscTruth);
214: EXTERN PetscErrorCode PetscLogStageGetActive(int, PetscTruth *);
215: EXTERN PetscErrorCode PetscLogStageSetVisible(int, PetscTruth);
216: EXTERN PetscErrorCode PetscLogStageGetVisible(int, PetscTruth *);
217: EXTERN PetscErrorCode PetscLogStageGetId(const char [], int *);
218: /* Event functions */
225: /* Class functions */
226: EXTERN PetscErrorCode PetscLogClassRegister(PetscCookie*, const char []);
228: /* Global counters */
246: (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
251: (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
252: (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
253: PETSC_LOG_EVENT_MPE_BEGIN(e))
258: (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
259: (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
260: PETSC_LOG_EVENT_MPE_END(e))
262: /* Creation and destruction functions */
263: EXTERN PetscErrorCode StageLogCreate(StageLog *);
264: EXTERN PetscErrorCode StageLogDestroy(StageLog);
265: /* Registration functions */
266: EXTERN PetscErrorCode StageLogRegister(StageLog, const char [], int *);
267: /* Runtime functions */
268: EXTERN PetscErrorCode PetscLogGetStageLog(StageLog *);
269: EXTERN PetscErrorCode StageLogPush(StageLog, int);
270: EXTERN PetscErrorCode StageLogPop(StageLog);
271: EXTERN PetscErrorCode StageLogGetCurrent(StageLog, int *);
272: EXTERN PetscErrorCode StageLogSetActive(StageLog, int, PetscTruth);
273: EXTERN PetscErrorCode StageLogGetActive(StageLog, int, PetscTruth *);
274: EXTERN PetscErrorCode StageLogSetVisible(StageLog, int, PetscTruth);
275: EXTERN PetscErrorCode StageLogGetVisible(StageLog, int, PetscTruth *);
276: EXTERN PetscErrorCode StageLogGetStage(StageLog, const char [], int *);
277: EXTERN PetscErrorCode StageLogGetClassRegLog(StageLog, ClassRegLog *);
278: EXTERN PetscErrorCode StageLogGetEventRegLog(StageLog, EventRegLog *);
279: EXTERN PetscErrorCode StageLogGetClassPerfLog(StageLog, int, ClassPerfLog *);
280: EXTERN PetscErrorCode StageLogGetEventPerfLog(StageLog, int, EventPerfLog *);
282: /*
283: These are used internally in the PETSc routines to keep a count of MPI messages and
284: their sizes.
286: This does not work for MPI-Uni because our include/mpiuni/mpi.h file
287: uses macros to defined the MPI operations.
289: It does not work correctly from HP-UX because it processes the
290: macros in a way that sometimes it double counts, hence
291: PETSC_HAVE_BROKEN_RECURSIVE_MACRO
293: It does not work with Windows because winmpich lacks MPI_Type_size()
294: */
295: #if !defined(_petsc_mpi_uni) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
296: /*
297: Logging of MPI activities
298: */
299: #define TypeSize(buff,count,type) \
300: (MPI_Type_size(type,&PETSC_DUMMY_SIZE) || (buff += (PetscLogDouble) ((count)*PETSC_DUMMY_SIZE),0))
302: #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
303: ((PETSC_DUMMY_COUNT = count,irecv_ct++,0) || TypeSize(irecv_len,PETSC_DUMMY_COUNT,datatype) || MPI_Irecv(buf,PETSC_DUMMY_COUNT,datatype,source,tag,comm,request))
305: #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
306: ((PETSC_DUMMY_COUNT = count,isend_ct++,0) || TypeSize(isend_len,PETSC_DUMMY_COUNT,datatype) || MPI_Isend(buf,PETSC_DUMMY_COUNT,datatype,dest,tag,comm,request))
308: #define MPI_Startall_irecv(count,number,requests) \
309: ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
311: #define MPI_Startall_isend(count,number,requests) \
312: ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
314: #define MPI_Start_isend(count,requests) \
315: ((isend_ct++,0) || TypeSize(isend_len,count,MPIU_SCALAR) || MPI_Start(requests))
317: #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
318: ((PETSC_DUMMY_COUNT = count,recv_ct++,0) || TypeSize(recv_len,PETSC_DUMMY_COUNT,datatype) || MPI_Recv(buf,PETSC_DUMMY_COUNT,datatype,source,tag,comm,status))
320: #define MPI_Send(buf,count,datatype,dest,tag,comm) \
321: ((PETSC_DUMMY_COUNT = count,send_ct++,0) || TypeSize(send_len,PETSC_DUMMY_COUNT,datatype) || MPI_Send(buf,PETSC_DUMMY_COUNT,datatype,dest,tag,comm))
323: #define MPI_Wait(request,status) \
324: ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status))
325:
326: #define MPI_Waitany(a,b,c,d) \
327: ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))
329: #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
330: ((PETSC_DUMMY_COUNT = count,wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (PETSC_DUMMY_COUNT),0) || MPI_Waitall(PETSC_DUMMY_COUNT,array_of_requests,array_of_statuses))
331:
332: #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
333: ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))
335: #else
337: #define MPI_Startall_irecv(count,number,requests) \
338: (MPI_Startall(number,requests))
340: #define MPI_Startall_isend(count,number,requests) \
341: (MPI_Startall(number,requests))
343: #define MPI_Start_isend(count,requests) \
344: (MPI_Start(requests))
346: #endif /* !_petsc_mpi_uni && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
348: #else /* ---Logging is turned off --------------------------------------------*/
350: #define PetscLogFlops(n) 0
352: /*
353: With logging turned off, then MPE has to be turned off
354: */
355: #define PetscLogMPEBegin() 0
356: #define PetscLogMPEDump(a) 0
363: #define PetscLogClassRegister(a,b) PetscCookieRegister(a)
366: #define _PetscLogPLB 0
367: #define _PetscLogPLE 0
368: #define _PetscLogPHC 0
369: #define _PetscLogPHD 0
370: #define PetscGetFlops(a) (*(a) = 0.0,0)
375: #define PetscLogObjectParent(p,c) 0
376: #define PetscLogObjectParents(p,n,c) 0
377: #define PetscLogObjectCreate(h) 0
378: #define PetscLogObjectDestroy(h) 0
379: #define PetscLogObjectMemory(p,m) 0
380: #define PetscLogDestroy() 0
381: #define PetscLogStagePush(a) 0
382: #define PetscLogStagePop() 0
383: #define PetscLogStageRegister(a,b) 0
384: #define PetscLogStagePrint(a,flg) 0
385: #define PetscLogPrintSummary(comm,file) 0
386: #define PetscLogPrintDetailed(comm,file) 0
387: #define PetscLogBegin() 0
388: #define PetscLogTraceBegin(file) 0
389: #define PetscLogSet(lb,le) 0
390: #define PetscLogAllBegin() 0
391: #define PetscLogDump(c) 0
393: #define PetscLogObjects(a) 0
394: #define PetscLogActions(a) 0
395: EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
397: /* If PETSC_USE_LOG is NOT defined, these still need to be! */
398: #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
399: #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
400: #define MPI_Start_isend(count,requests) MPI_Start(requests)
402: /* Creation and destruction functions */
403: #define StageLogCreate(stageLog) 0
404: #define StageLogDestroy(stageLog) 0
405: /* Registration functions */
406: #define StageLogRegister(stageLog, name, stage) 0
407: /* Runtime functions */
408: #define PetscLogGetStageLog(stageLog) 0
409: #define StageLogPush(stageLog, stage) 0
410: #define StageLogPop(stageLog) 0
411: #define StageLogGetCurrent(stageLog, stage) 0
412: #define StageLogSetActive(stageLog, stage, active) 0
413: #define StageLogGetActive(stageLog, stage, active) 0
414: #define StageLogSetVisible(stageLog, stage, visible) 0
415: #define StageLogGetVisible(stageLog, stage, visible) 0
416: #define StageLogGetStage(stageLog, name, stage) 0
417: #define PetscLogStageGetId(a,b) (*(b)=0,0)
418: #define PetscLogStageSetActive(a,b) 0
419: #define PetscLogStageGetActive(a,b) 0
420: #define PetscLogStageGetVisible(a,b) 0
421: #define PetscLogStageSetVisible(a,b) 0
423: #endif /* PETSC_USE_LOG */
425: #define PreLoadBegin(flag,name) \
426: {\
427: PetscTruth PreLoading = flag;\
428: int PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
429: _3_PetscOptionsGetTruth(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
430: PreLoadMax = (int)(PreLoading);\
431: PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
432: for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
433: PetscPreLoadingOn = PreLoading;\
434: _3_PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
435: if (PreLoadIt>0) {\
436: _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
437: } else {\
438: _3_PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
439: }\
440: _3_PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
441: _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
443: #define PreLoadEnd() \
444: _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
445: PreLoading = PETSC_FALSE;\
446: }\
447: }
449: #define PreLoadStage(name) \
450: _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
451: if (PreLoadIt>0) {\
452: _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
453: } else {\
454: _3_PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
455: }\
456: _3_PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
457: _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
460: #endif