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: #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/

 43: /* 
 44:    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.

 46:    For the complex numbers version, note that
 47:        1 complex addition = 2 flops
 48:        1 complex multiplication = 6 flops,
 49:    where we define 1 flop as that for a double precision scalar.  We roughly approximate
 50:    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
 51:    to the assumption that we're counting mostly additions and multiplications -- and
 52:    roughly the same number of each.  More accurate counting could be done by distinguishing
 53:    among the various arithmetic operations.
 54:  */

 56: #if defined(PETSC_USE_COMPLEX)
 57: #define PetscLogFlops(n) (_TotalFlops += (4*n),0)
 58: #else
 59: #define PetscLogFlops(n) (_TotalFlops += (n),0)
 60: #endif

 62: #if defined (PETSC_HAVE_MPE)
 63: #include "mpe.h"
 64: EXTERN PetscErrorCode         PetscLogMPEBegin(void);
 65: EXTERN PetscErrorCode         PetscLogMPEDump(const char[]);
 67: #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
 68:   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
 69:    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)

 71: #define PETSC_LOG_EVENT_MPE_END(e) \
 72:   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
 73:    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0)

 75: #else 
 76: #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0 
 77: #define PETSC_LOG_EVENT_MPE_END(e)   0
 78: #endif

 80: EXTERN  PetscErrorCode (*_PetscLogPLB)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
 81: EXTERN  PetscErrorCode (*_PetscLogPLE)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
 82: EXTERN  PetscErrorCode (*_PetscLogPHC)(PetscObject);
 83: EXTERN  PetscErrorCode (*_PetscLogPHD)(PetscObject);

 85: #define PetscLogObjectParent(p,c) \
 86:   ((c && p) ? ((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id : 0, 0)

 88: #define PetscLogObjectParents(p,n,d)  0;{int _i; for (_i=0; _i<n; _i++) {PetscLogObjectParent(p,(d)[_i]);}}
 89: #define PetscLogObjectCreate(h)      ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0)
 90: #define PetscLogObjectDestroy(h)     ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0)
 91: #define PetscLogObjectMemory(p,m)    (((PetscObject)(p))->mem += (m),0)
 92: /* Initialization functions */
 93: EXTERN PetscErrorCode  PetscLogBegin(void);
 94: EXTERN PetscErrorCode  PetscLogAllBegin(void);
 95: EXTERN PetscErrorCode  PetscLogTraceBegin(FILE *);
 96: EXTERN PetscErrorCode  PetscLogActions(PetscTruth);
 97: EXTERN PetscErrorCode  PetscLogObjects(PetscTruth);
 98: /* General functions */
 99: EXTERN PetscErrorCode  PetscLogGetRGBColor(const char*[]);
100: EXTERN PetscErrorCode  PetscLogDestroy(void);
101: EXTERN PetscErrorCode  PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
102:                    PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
103: EXTERN PetscErrorCode  PetscLogObjectState(PetscObject, const char[], ...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
104: /* Output functions */
105: EXTERN PetscErrorCode  PetscLogPrintSummary(MPI_Comm, const char[]);
106: EXTERN PetscErrorCode  PetscLogDump(const char[]);
107: /* Counter functions */
108: EXTERN PetscErrorCode  PetscGetFlops(PetscLogDouble *);
109: /* Stage functions */
110: EXTERN PetscErrorCode  PetscLogStageRegister(int*, const char[]);
111: EXTERN PetscErrorCode  PetscLogStagePush(int);
112: EXTERN PetscErrorCode  PetscLogStagePop(void);
113: EXTERN PetscErrorCode  PetscLogStageSetActive(int, PetscTruth);
114: EXTERN PetscErrorCode  PetscLogStageGetActive(int, PetscTruth *);
115: EXTERN PetscErrorCode  PetscLogStageSetVisible(int, PetscTruth);
116: EXTERN PetscErrorCode  PetscLogStageGetVisible(int, PetscTruth *);
117: EXTERN PetscErrorCode  PetscLogStageGetId(const char [], int *);
118: /* Event functions */
125: /* Class functions */
126: EXTERN PetscErrorCode  PetscLogClassRegister(PetscCookie*, const char []);

128: /* Global counters */

145: /* We must make these structures available if we are to access the event
147:    function call each time, we could make these private.
148: */
149: /* Default log */
150: typedef struct _n_StageLog *StageLog;

153: /* A simple stack (should replace) */
154: typedef struct _n_IntStack *IntStack;

156: /* The structures for logging performance */
157: typedef struct _EventPerfInfo {
158:   int            id;            /* The integer identifying this section */
159:   PetscTruth     active;        /* The flag to activate logging */
160:   PetscTruth     visible;       /* The flag to print info in summary */
161:   int            depth;         /* The nesting depth of the event call */
162:   int            count;         /* The number of times this section was executed */
163:   PetscLogDouble flops;         /* The flops used in this section */
164:   PetscLogDouble time;          /* The time taken for this section */
165:   PetscLogDouble numMessages;   /* The number of messages in this section */
166:   PetscLogDouble messageLength; /* The total message lengths in this section */
167:   PetscLogDouble numReductions; /* The number of reductions in this section */
168: } EventPerfInfo;

170: typedef struct _ClassPerfInfo {
171:   int            id;           /* The integer identifying this class */
172:   int            creations;    /* The number of objects of this class created */
173:   int            destructions; /* The number of objects of this class destroyed */
174:   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
175:   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
176: } ClassPerfInfo;

178: /* The structures for logging registration */
179: typedef struct _ClassRegInfo {
180:   char            *name;   /* The class name */
181:   PetscCookie cookie; /* The integer identifying this class */
182: } ClassRegInfo;

184: typedef struct _EventRegInfo {
185:   char            *name;   /* The name of this event */
186:   PetscCookie cookie; /* The class id for this event (should maybe give class ID instead) */
187: #if defined (PETSC_HAVE_MPE)
188:   int             mpe_id_begin; /* MPE IDs that define the event */
189:   int             mpe_id_end;
190: #endif
191: } EventRegInfo;

193: typedef struct _n_EventRegLog *EventRegLog;
194: struct _n_EventRegLog {
195:   int           numEvents; /* The number of registered events */
196:   int           maxEvents; /* The maximum number of events */
197:   EventRegInfo *eventInfo; /* The registration information for each event */
198: };

200: typedef struct _n_EventPerfLog *EventPerfLog;
201: struct _n_EventPerfLog {
202:   int            numEvents; /* The number of logging events */
203:   int            maxEvents; /* The maximum number of events */
204:   EventPerfInfo *eventInfo; /* The performance information for each event */
205: };

207: /* The structure for logging class information */
208: typedef struct _n_ClassRegLog *ClassRegLog;
209: struct _n_ClassRegLog {
210:   int           numClasses; /* The number of classes registered */
211:   int           maxClasses; /* The maximum number of classes */
212:   ClassRegInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
213: };

215: typedef struct _n_ClassPerfLog *ClassPerfLog;
216: struct _n_ClassPerfLog {
217:   int            numClasses; /* The number of logging classes */
218:   int            maxClasses; /* The maximum number of classes */
219:   ClassPerfInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
220: };

222: /* The structures for logging in stages */
223: typedef struct _StageInfo {
224:   char         *name;     /* The stage name */
225:   PetscTruth    used;     /* The stage was pushed on this processor */
226:   EventPerfInfo perfInfo; /* The stage performance information */
227:   EventPerfLog  eventLog; /* The event information for this stage */
228:   ClassPerfLog  classLog; /* The class information for this stage */
229: } StageInfo;

231: struct _n_StageLog {
232:   /* Size information */
233:   int         numStages; /* The number of registered stages */
234:   int         maxStages; /* The maximum number of stages */
235:   /* Runtime information */
236:   IntStack    stack;     /* The stack for active stages */
237:   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
238:   /* Stage specific information */
239:   StageInfo  *stageInfo; /* The information for each stage */
240:   EventRegLog eventLog;  /* The registered events */
241:   ClassRegLog classLog;  /* The registered classes */
242: };

245:   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active &&  _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \

250:   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
251:     (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
252:   PETSC_LOG_EVENT_MPE_BEGIN(e))


257:   (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
258:     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
259:   PETSC_LOG_EVENT_MPE_END(e))

261: /* Creation and destruction functions */
262: EXTERN PetscErrorCode  StageLogCreate(StageLog *);
263: EXTERN PetscErrorCode  StageLogDestroy(StageLog);
264: /* Registration functions */
265: EXTERN PetscErrorCode  StageLogRegister(StageLog, const char [], int *);
266: /* Runtime functions */
267: EXTERN PetscErrorCode  PetscLogGetStageLog(StageLog *);
268: EXTERN PetscErrorCode  StageLogPush(StageLog, int);
269: EXTERN PetscErrorCode  StageLogPop(StageLog);
270: EXTERN PetscErrorCode  StageLogGetCurrent(StageLog, int *);
271: EXTERN PetscErrorCode  StageLogSetActive(StageLog, int, PetscTruth);
272: EXTERN PetscErrorCode  StageLogGetActive(StageLog, int, PetscTruth *);
273: EXTERN PetscErrorCode  StageLogSetVisible(StageLog, int, PetscTruth);
274: EXTERN PetscErrorCode  StageLogGetVisible(StageLog, int, PetscTruth *);
275: EXTERN PetscErrorCode  StageLogGetStage(StageLog, const char [], int *);
276: EXTERN PetscErrorCode  StageLogGetClassRegLog(StageLog, ClassRegLog *);
277: EXTERN PetscErrorCode  StageLogGetEventRegLog(StageLog, EventRegLog *);
278: EXTERN PetscErrorCode  StageLogGetClassPerfLog(StageLog, int, ClassPerfLog *);
279: EXTERN PetscErrorCode  StageLogGetEventPerfLog(StageLog, int, EventPerfLog *);

281: /*
282:      These are used internally in the PETSc routines to keep a count of MPI messages and 
283:    their sizes.

285:      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
286:    uses macros to defined the MPI operations. 

288:      It does not work correctly from HP-UX because it processes the 
289:    macros in a way that sometimes it double counts, hence 
290:    PETSC_HAVE_BROKEN_RECURSIVE_MACRO

292:      It does not work with Windows because winmpich lacks MPI_Type_size()
293: */
294: #if !defined(_petsc_mpi_uni) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
295: /*
296:    Logging of MPI activities
297: */
298: #define TypeSize(buff,count,type) \
299:  (MPI_Type_size(type,&PETSC_DUMMY_SIZE) || (buff += (PetscLogDouble) ((count)*PETSC_DUMMY_SIZE),0))

301: #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
302:  ((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))

304: #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
305:  ((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))

307: #define MPI_Startall_irecv(count,number,requests) \
308:  ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))

310: #define MPI_Startall_isend(count,number,requests) \
311:  ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))

313: #define MPI_Start_isend(count,requests) \
314:  ((isend_ct++,0) || TypeSize(isend_len,count,MPIU_SCALAR) || MPI_Start(requests))

316: #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
317:  ((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))

319: #define MPI_Send(buf,count,datatype,dest,tag,comm) \
320:  ((PETSC_DUMMY_COUNT = count,send_ct++,0) || TypeSize(send_len,PETSC_DUMMY_COUNT,datatype) || MPI_Send(buf,PETSC_DUMMY_COUNT,datatype,dest,tag,comm))

322: #define MPI_Wait(request,status) \
323:  ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status))
324: 
325: #define MPI_Waitany(a,b,c,d) \
326:  ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))

328: #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
329:  ((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))
330: 
331: #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
332:  ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))

334: #else

336: #define MPI_Startall_irecv(count,number,requests) \
337:  (MPI_Startall(number,requests))

339: #define MPI_Startall_isend(count,number,requests) \
340:  (MPI_Startall(number,requests))

342: #define MPI_Start_isend(count,requests) \
343:  (MPI_Start(requests))

345: #endif /* !_petsc_mpi_uni && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */

347: #else  /* ---Logging is turned off --------------------------------------------*/

349: #define PetscLogFlops(n) 0

351: /*
352:      With logging turned off, then MPE has to be turned off
353: */
354: #define PetscLogMPEBegin()         0
355: #define PetscLogMPEDump(a)         0


362: #define PetscLogClassRegister(a,b)      PetscCookieRegister(a)

365: #define _PetscLogPLB                        0
366: #define _PetscLogPLE                        0
367: #define _PetscLogPHC                        0
368: #define _PetscLogPHD                        0
369: #define PetscGetFlops(a)                (*(a) = 0.0,0)
374: #define PetscLogObjectParent(p,c)           0
375: #define PetscLogObjectParents(p,n,c)        0
376: #define PetscLogObjectCreate(h)             0
377: #define PetscLogObjectDestroy(h)            0
378: #define PetscLogObjectMemory(p,m)           0
379: #define PetscLogDestroy()                   0
380: #define PetscLogStagePush(a)                0
381: #define PetscLogStagePop()                  0
382: #define PetscLogStageRegister(a,b)          0
383: #define PetscLogStagePrint(a,flg)           0
384: #define PetscLogPrintSummary(comm,file)     0
385: #define PetscLogBegin()                     0
386: #define PetscLogTraceBegin(file)            0
387: #define PetscLogSet(lb,le)                  0
388: #define PetscLogAllBegin()                  0
389: #define PetscLogDump(c)                     0
391: #define PetscLogObjects(a)                  0
392: #define PetscLogActions(a)                  0
393: EXTERN PetscErrorCode  PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);

395: /* If PETSC_USE_LOG is NOT defined, these still need to be! */
396: #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
397: #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
398: #define MPI_Start_isend(count,requests) MPI_Start(requests)

400: /* Creation and destruction functions */
401: #define StageLogCreate(stageLog)                     0
402: #define StageLogDestroy(stageLog)                    0
403: /* Registration functions */
404: #define StageLogRegister(stageLog, name, stage)      0
405: /* Runtime functions */
406: #define PetscLogGetStageLog(stageLog)                0
407: #define StageLogPush(stageLog, stage)                0
408: #define StageLogPop(stageLog)                        0
409: #define StageLogGetCurrent(stageLog, stage)          0
410: #define StageLogSetActive(stageLog, stage, active)   0
411: #define StageLogGetActive(stageLog, stage, active)   0
412: #define StageLogSetVisible(stageLog, stage, visible) 0
413: #define StageLogGetVisible(stageLog, stage, visible) 0
414: #define StageLogGetStage(stageLog, name, stage)      0
415: #define PetscLogStageGetId(a,b)                      (*(b)=0,0)
416: #define PetscLogStageSetActive(a,b)                  0

418: #endif   /* PETSC_USE_LOG */

420: #define PreLoadBegin(flag,name) \
421: {\
422:   PetscTruth PreLoading = flag;\
423:   int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
424:   _3_PetscOptionsGetTruth(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
425:   PreLoadMax = (int)(PreLoading);\
426:   PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
427:   for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
428:     PetscPreLoadingOn = PreLoading;\
429:     _3_PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
430:     if (PreLoadIt>0) {\
431:       _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
432:     } else {\
433:       _3_PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
434:     }\
435:     _3_PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
436:     _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);

438: #define PreLoadEnd() \
439:     _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
440:     PreLoading = PETSC_FALSE;\
441:   }\
442: }

444: #define PreLoadStage(name) \
445:   _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
446:   if (PreLoadIt>0) {\
447:     _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
448:   } else {\
449:     _3_PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
450:   }\
451:   _3_PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
452:   _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);

455: #endif