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 PetscLogFlopsNoCheck(n) (_TotalFlops += (4*n),0)
157: #define PetscLogFlops(n) 0; \
158: {\
159: PetscLogDouble _tmp_flops = (n); \
160: if (_tmp_flops < 0) { SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"PetscLogFlops: flop-count given is negative: %5.2f", _tmp_flops); } \
161: _TotalFlops += 4*_tmp_flops; \
162: }
163: #else
164: #define PetscLogFlopsNoCheck(n) (_TotalFlops += (n),0)
165: #define PetscLogFlops(n) 0; \
166: {\
167: PetscLogDouble _tmp_flops = (n); \
168: if (_tmp_flops < 0) { SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE,"PetscLogFlops: flop-count given is negative: %5.2f", _tmp_flops); } \
169: _TotalFlops += _tmp_flops; \
170: }
171: #endif
173: #if defined (PETSC_HAVE_MPE)
174: #include "mpe.h"
175: EXTERN PetscErrorCode PetscLogMPEBegin(void);
176: EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
178: #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
179: ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
180: MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)
182: #define PETSC_LOG_EVENT_MPE_END(e) \
183: ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
184: MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0)
186: #else
187: #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0
188: #define PETSC_LOG_EVENT_MPE_END(e) 0
189: #endif
191: EXTERN PetscErrorCode (*_PetscLogPLB)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
192: EXTERN PetscErrorCode (*_PetscLogPLE)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
193: EXTERN PetscErrorCode (*_PetscLogPHC)(PetscObject);
194: EXTERN PetscErrorCode (*_PetscLogPHD)(PetscObject);
196: #define PetscLogObjectParent(p,c) \
197: ((c && p) ? ((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id : 0, 0)
199: #define PetscLogObjectParents(p,n,d) 0;{int _i; for (_i=0; _i<n; _i++) {PetscLogObjectParent(p,(d)[_i]);}}
200: #define PetscLogObjectCreate(h) ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0)
201: #define PetscLogObjectDestroy(h) ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0)
202: #define PetscLogObjectMemory(p,m) (((PetscObject)(p))->mem += (m),0)
203: /* Initialization functions */
204: EXTERN PetscErrorCode PetscLogBegin(void);
205: EXTERN PetscErrorCode PetscLogAllBegin(void);
206: EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
207: EXTERN PetscErrorCode PetscLogActions(PetscTruth);
208: EXTERN PetscErrorCode PetscLogObjects(PetscTruth);
209: /* General functions */
210: EXTERN PetscErrorCode PetscLogGetRGBColor(const char*[]);
211: EXTERN PetscErrorCode PetscLogDestroy(void);
212: EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
213: PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
214: EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_PRINTF_FORMAT_CHECK(2,3);
215: /* Output functions */
216: EXTERN PetscErrorCode PetscLogPrintSummary(MPI_Comm, const char[]);
217: EXTERN PetscErrorCode PetscLogPrintDetailed(MPI_Comm, const char[]);
218: EXTERN PetscErrorCode PetscLogDump(const char[]);
219: /* Counter functions */
220: EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
221: /* Stage functions */
222: EXTERN PetscErrorCode PetscLogStageRegister(int*, const char[]);
223: EXTERN PetscErrorCode PetscLogStagePush(int);
224: EXTERN PetscErrorCode PetscLogStagePop(void);
225: EXTERN PetscErrorCode PetscLogStageSetActive(int, PetscTruth);
226: EXTERN PetscErrorCode PetscLogStageGetActive(int, PetscTruth *);
227: EXTERN PetscErrorCode PetscLogStageSetVisible(int, PetscTruth);
228: EXTERN PetscErrorCode PetscLogStageGetVisible(int, PetscTruth *);
229: EXTERN PetscErrorCode PetscLogStageGetId(const char [], int *);
230: /* Event functions */
237: /* Class functions */
238: EXTERN PetscErrorCode PetscLogClassRegister(PetscCookie*, const char []);
240: /* Global counters */
258: (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
263: (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
264: (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
265: PETSC_LOG_EVENT_MPE_BEGIN(e))
270: (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
271: (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
272: PETSC_LOG_EVENT_MPE_END(e))
274: /* Creation and destruction functions */
275: EXTERN PetscErrorCode StageLogCreate(StageLog *);
276: EXTERN PetscErrorCode StageLogDestroy(StageLog);
277: /* Registration functions */
278: EXTERN PetscErrorCode StageLogRegister(StageLog, const char [], int *);
279: /* Runtime functions */
280: EXTERN PetscErrorCode PetscLogGetStageLog(StageLog *);
281: EXTERN PetscErrorCode StageLogPush(StageLog, int);
282: EXTERN PetscErrorCode StageLogPop(StageLog);
283: EXTERN PetscErrorCode StageLogGetCurrent(StageLog, int *);
284: EXTERN PetscErrorCode StageLogSetActive(StageLog, int, PetscTruth);
285: EXTERN PetscErrorCode StageLogGetActive(StageLog, int, PetscTruth *);
286: EXTERN PetscErrorCode StageLogSetVisible(StageLog, int, PetscTruth);
287: EXTERN PetscErrorCode StageLogGetVisible(StageLog, int, PetscTruth *);
288: EXTERN PetscErrorCode StageLogGetStage(StageLog, const char [], int *);
289: EXTERN PetscErrorCode StageLogGetClassRegLog(StageLog, ClassRegLog *);
290: EXTERN PetscErrorCode StageLogGetEventRegLog(StageLog, EventRegLog *);
291: EXTERN PetscErrorCode StageLogGetClassPerfLog(StageLog, int, ClassPerfLog *);
292: EXTERN PetscErrorCode StageLogGetEventPerfLog(StageLog, int, EventPerfLog *);
294: /*
295: These are used internally in the PETSc routines to keep a count of MPI messages and
296: their sizes.
298: This does not work for MPI-Uni because our include/mpiuni/mpi.h file
299: uses macros to defined the MPI operations.
301: It does not work correctly from HP-UX because it processes the
302: macros in a way that sometimes it double counts, hence
303: PETSC_HAVE_BROKEN_RECURSIVE_MACRO
305: It does not work with Windows because winmpich lacks MPI_Type_size()
306: */
307: #if !defined(_petsc_mpi_uni) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
308: /*
309: Logging of MPI activities
310: */
311: #define TypeSize(buff,count,type) \
312: (MPI_Type_size(type,&PETSC_DUMMY_SIZE) || (buff += (PetscLogDouble) ((count)*PETSC_DUMMY_SIZE),0))
314: #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
315: ((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))
317: #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
318: ((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))
320: #define MPI_Startall_irecv(count,number,requests) \
321: ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
323: #define MPI_Startall_isend(count,number,requests) \
324: ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
326: #define MPI_Start_isend(count,requests) \
327: ((isend_ct++,0) || TypeSize(isend_len,count,MPIU_SCALAR) || MPI_Start(requests))
329: #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
330: ((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))
332: #define MPI_Send(buf,count,datatype,dest,tag,comm) \
333: ((PETSC_DUMMY_COUNT = count,send_ct++,0) || TypeSize(send_len,PETSC_DUMMY_COUNT,datatype) || MPI_Send(buf,PETSC_DUMMY_COUNT,datatype,dest,tag,comm))
335: #define MPI_Wait(request,status) \
336: ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status))
337:
338: #define MPI_Waitany(a,b,c,d) \
339: ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))
341: #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
342: ((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))
343:
344: #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
345: ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))
347: #else
349: #define MPI_Startall_irecv(count,number,requests) \
350: (MPI_Startall(number,requests))
352: #define MPI_Startall_isend(count,number,requests) \
353: (MPI_Startall(number,requests))
355: #define MPI_Start_isend(count,requests) \
356: (MPI_Start(requests))
358: #endif /* !_petsc_mpi_uni && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
360: #else /* ---Logging is turned off --------------------------------------------*/
362: #define PetscLogFlops(n) 0
363: #define PetscLogFlopsNoCheck(n)
365: /*
366: With logging turned off, then MPE has to be turned off
367: */
368: #define PetscLogMPEBegin() 0
369: #define PetscLogMPEDump(a) 0
376: #define PetscLogClassRegister(a,b) PetscCookieRegister(a)
379: #define _PetscLogPLB 0
380: #define _PetscLogPLE 0
381: #define _PetscLogPHC 0
382: #define _PetscLogPHD 0
383: #define PetscGetFlops(a) (*(a) = 0.0,0)
388: #define PetscLogObjectParent(p,c) 0
389: #define PetscLogObjectParents(p,n,c) 0
390: #define PetscLogObjectCreate(h) 0
391: #define PetscLogObjectDestroy(h) 0
392: #define PetscLogObjectMemory(p,m) 0
393: #define PetscLogDestroy() 0
394: #define PetscLogStagePush(a) 0
395: #define PetscLogStagePop() 0
396: #define PetscLogStageRegister(a,b) 0
397: #define PetscLogStagePrint(a,flg) 0
398: #define PetscLogPrintSummary(comm,file) 0
399: #define PetscLogPrintDetailed(comm,file) 0
400: #define PetscLogBegin() 0
401: #define PetscLogTraceBegin(file) 0
402: #define PetscLogSet(lb,le) 0
403: #define PetscLogAllBegin() 0
404: #define PetscLogDump(c) 0
406: #define PetscLogObjects(a) 0
407: #define PetscLogActions(a) 0
408: EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
410: /* If PETSC_USE_LOG is NOT defined, these still need to be! */
411: #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
412: #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
413: #define MPI_Start_isend(count,requests) MPI_Start(requests)
415: /* Creation and destruction functions */
416: #define StageLogCreate(stageLog) 0
417: #define StageLogDestroy(stageLog) 0
418: /* Registration functions */
419: #define StageLogRegister(stageLog, name, stage) 0
420: /* Runtime functions */
421: #define PetscLogGetStageLog(stageLog) 0
422: #define StageLogPush(stageLog, stage) 0
423: #define StageLogPop(stageLog) 0
424: #define StageLogGetCurrent(stageLog, stage) 0
425: #define StageLogSetActive(stageLog, stage, active) 0
426: #define StageLogGetActive(stageLog, stage, active) 0
427: #define StageLogSetVisible(stageLog, stage, visible) 0
428: #define StageLogGetVisible(stageLog, stage, visible) 0
429: #define StageLogGetStage(stageLog, name, stage) 0
430: #define PetscLogStageGetId(a,b) (*(b)=0,0)
431: #define PetscLogStageSetActive(a,b) 0
432: #define PetscLogStageGetActive(a,b) 0
433: #define PetscLogStageGetVisible(a,b) 0
434: #define PetscLogStageSetVisible(a,b) 0
436: #endif /* PETSC_USE_LOG */
438: #define PreLoadBegin(flag,name) \
439: {\
440: PetscTruth PreLoading = flag;\
441: int PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
442: _3_PetscOptionsGetTruth(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
443: PreLoadMax = (int)(PreLoading);\
444: PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
445: for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
446: PetscPreLoadingOn = PreLoading;\
447: _3_PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
448: if (PreLoadIt>0) {\
449: _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
450: } else {\
451: _3_PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
452: }\
453: _3_PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
454: _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
456: #define PreLoadEnd() \
457: _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
458: PreLoading = PETSC_FALSE;\
459: }\
460: }
462: #define PreLoadStage(name) \
463: _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
464: if (PreLoadIt>0) {\
465: _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
466: } else {\
467: _3_PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
468: }\
469: _3_PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
470: _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
473: #endif