Actual source code: petsclog.h

petsc-3.13.6 2020-09-29
Report Typos and Errors
  1: /*
  2:     Defines profile/logging in PETSc.
  3: */

  5: #if !defined(PETSCLOG_H)
  6: #define PETSCLOG_H
  7:  #include <petscsys.h>
  8:  #include <petsctime.h>

 10: /* General logging of information; different from event logging */
 11: PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],PetscObject,const char[],...);
 12: #if defined(PETSC_USE_INFO)
 13: #define PetscInfo(A,S)                       PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S)
 14: #define PetscInfo1(A,S,a1)                   PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1)
 15: #define PetscInfo2(A,S,a1,a2)                PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2)
 16: #define PetscInfo3(A,S,a1,a2,a3)             PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3)
 17: #define PetscInfo4(A,S,a1,a2,a3,a4)          PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4)
 18: #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5)
 19: #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5,a6)
 20: #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5,a6,a7)
 21: #else
 22: #define PetscInfo(A,S)                       0
 23: #define PetscInfo1(A,S,a1)                   0
 24: #define PetscInfo2(A,S,a1,a2)                0
 25: #define PetscInfo3(A,S,a1,a2,a3)             0
 26: #define PetscInfo4(A,S,a1,a2,a3,a4)          0
 27: #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       0
 28: #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    0
 29: #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
 30: #endif

 32: /*E
 33:     PetscInfoCommFlag - Describes the method by which to filter PetscInfo() by communicator size

 35:     Used as an input for PetscInfoSetFilterCommSelf()

 37: $   PETSC_INFO_COMM_ALL - Default uninitialized value. PetscInfo() will not filter based on communicator size (i.e. will
 38: print for all communicators)
 39: $   PETSC_INFO_COMM_NO_SELF - PetscInfo() will NOT print for communicators with size = 1 (i.e. *_COMM_SELF)
 40: $   PETSC_INFO_COMM_ONLY_SELF - PetscInfo will ONLY print for communicators with size = 1

 42:     Level: intermediate

 44: .seealso: PetscInfo(), PetscInfoSetFromOptions(), PetscInfoSetFilterCommSelf()
 45: E*/
 46: typedef enum {
 47:   PETSC_INFO_COMM_ALL = -1,
 48:   PETSC_INFO_COMM_NO_SELF = 0,
 49:   PETSC_INFO_COMM_ONLY_SELF = 1
 50: } PetscInfoCommFlag;

 52: PETSC_EXTERN const char * const PetscInfoCommFlags[];
 53: PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId);
 54: PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId);
 55: PETSC_EXTERN PetscErrorCode PetscInfoEnabled(PetscClassId, PetscBool *);
 56: PETSC_EXTERN PetscErrorCode PetscInfoAllow(PetscBool);
 57: PETSC_EXTERN PetscErrorCode PetscInfoSetFile(const char[],const char[]);
 58: PETSC_EXTERN PetscErrorCode PetscInfoGetFile(char **,FILE **);
 59: PETSC_EXTERN PetscErrorCode PetscInfoSetClasses(PetscBool,PetscInt,const char *const *);
 60: PETSC_EXTERN PetscErrorCode PetscInfoGetClass(const char *, PetscBool *);
 61: PETSC_EXTERN PetscErrorCode PetscInfoGetInfo(PetscBool *,PetscBool *,PetscBool *,PetscBool *,PetscInfoCommFlag *);
 62: PETSC_EXTERN PetscErrorCode PetscInfoProcessClass(const char[],PetscInt,PetscClassId[]);
 63: PETSC_EXTERN PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag);
 64: PETSC_EXTERN PetscErrorCode PetscInfoSetFromOptions(PetscOptions);
 65: PETSC_EXTERN PetscErrorCode PetscInfoDestroy(void);
 66: PETSC_EXTERN PetscBool      PetscLogPrintInfo;  /* if true, indicates PetscInfo() is turned on */

 68: /*MC
 69:     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
 70:      code.

 72:     Level: intermediate

 74: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
 75: M*/
 76: typedef int PetscLogEvent;

 78: /*MC
 79:     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging

 81:     Level: intermediate

 83: .seealso: PetscLogStageRegister(), PetscLogStagePush(), PetscLogStagePop(), PetscLogEvent
 84: M*/
 85: typedef int PetscLogStage;

 87: #define PETSC_EVENT  1311311
 88: PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT;

 90: /* Global flop counter */
 91: PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
 92: PETSC_EXTERN PetscLogDouble petsc_tmp_flops;

 94: /* Global GPU counters */
 95: #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA)
 96: PETSC_EXTERN PetscLogDouble petsc_ctog_ct;
 97: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct;
 98: PETSC_EXTERN PetscLogDouble petsc_ctog_sz;
 99: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz;
100: PETSC_EXTERN PetscLogDouble petsc_gflops;
101: PETSC_EXTERN PetscLogDouble petsc_gtime;
102: #endif

104: /* We must make the following structures available to access the event
105:      activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public
106:      API and are not intended to be used by other parts of PETSc or by users.

108:      The code that manipulates these structures is in src/sys/logging/utils.
109: */
110: typedef struct _n_PetscIntStack *PetscIntStack;

112: /* -----------------------------------------------------------------------------------------------------*/
113: /*
114:     PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has
115:        static information about it, the second collects statistics on how many objects of the class are created,
116:        how much memory they use, etc.

118:     PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes.
119: */
120: typedef struct  {
121:   char           *name;   /* The class name */
122:   PetscClassId   classid; /* The integer identifying this class */
123: } PetscClassRegInfo;

125: typedef struct {
126:   PetscClassId   id;           /* The integer identifying this class */
127:   int            creations;    /* The number of objects of this class created */
128:   int            destructions; /* The number of objects of this class destroyed */
129:   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
130:   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
131: } PetscClassPerfInfo;

133: typedef struct _n_PetscClassRegLog *PetscClassRegLog;
134: struct _n_PetscClassRegLog {
135:   int               numClasses; /* The number of classes registered */
136:   int               maxClasses; /* The maximum number of classes */
137:   PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
138: };

140: typedef struct _n_PetscClassPerfLog *PetscClassPerfLog;
141: struct _n_PetscClassPerfLog {
142:   int                numClasses; /* The number of logging classes */
143:   int                maxClasses; /* The maximum number of classes */
144:   PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
145: };
146: /* -----------------------------------------------------------------------------------------------------*/
147: /*
148:     PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has
149:        static information about it, the second collects statistics on how many times the event is used, how
150:        much time it takes, etc.

152:     PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one
153:       of these for each stage.

155: */
156: typedef struct {
157:   char         *name;         /* The name of this event */
158:   PetscClassId classid;       /* The class the event is associated with */
159:   PetscBool    collective;    /* Flag this event as collective */
160: #if defined (PETSC_HAVE_MPE)
161:   int          mpe_id_begin;  /* MPE IDs that define the event */
162:   int          mpe_id_end;
163: #endif
164: } PetscEventRegInfo;

166: typedef struct {
167:   int            id;            /* The integer identifying this event */
168:   PetscBool      active;        /* The flag to activate logging */
169:   PetscBool      visible;       /* The flag to print info in summary */
170:   int            depth;         /* The nesting depth of the event call */
171:   int            count;         /* The number of times this event was executed */
172:   PetscLogDouble flops, flops2, flopsTmp; /* The flops and flops^2 used in this event */
173:   PetscLogDouble time, time2, timeTmp;    /* The time and time^2 taken for this event */
174:   PetscLogDouble syncTime;                /* The synchronization barrier time */
175:   PetscLogDouble dof[8];        /* The number of degrees of freedom associated with this event */
176:   PetscLogDouble errors[8];     /* The errors (user-defined) associated with this event */
177:   PetscLogDouble numMessages;   /* The number of messages in this event */
178:   PetscLogDouble messageLength; /* The total message lengths in this event */
179:   PetscLogDouble numReductions; /* The number of reductions in this event */
180:   PetscLogDouble memIncrease;   /* How much the resident memory has increased in this event */
181:   PetscLogDouble mallocIncrease;/* How much the maximum malloced space has increased in this event */
182:   PetscLogDouble mallocSpace;   /* How much the space was malloced and kept during this event */
183:   PetscLogDouble mallocIncreaseEvent;  /* Maximum of the high water mark with in event minus memory available at the end of the event */
184:   #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA)
185:   PetscLogDouble CpuToGpuCount; /* The total number of CPU to GPU copies */
186:   PetscLogDouble GpuToCpuCount; /* The total number of GPU to CPU copies */
187:   PetscLogDouble CpuToGpuSize;  /* The total size of CPU to GPU copies */
188:   PetscLogDouble GpuToCpuSize;  /* The total size of GPU to CPU copies */
189:   PetscLogDouble GpuFlops;      /* The flops done on a GPU in this event */
190:   PetscLogDouble GpuTime;       /* The time spent on a GPU in this event */
191:   #endif
192: } PetscEventPerfInfo;

194: typedef struct _n_PetscEventRegLog *PetscEventRegLog;
195: struct _n_PetscEventRegLog {
196:   int               numEvents;  /* The number of registered events */
197:   int               maxEvents;  /* The maximum number of events */
198:   PetscEventRegInfo *eventInfo; /* The registration information for each event */
199: };

201: typedef struct _n_PetscEventPerfLog *PetscEventPerfLog;
202: struct _n_PetscEventPerfLog {
203:   int                numEvents;  /* The number of logging events */
204:   int                maxEvents;  /* The maximum number of events */
205:   PetscEventPerfInfo *eventInfo; /* The performance information for each event */
206: };
207: /* ------------------------------------------------------------------------------------------------------------*/
208: /*
209:    PetscStageInfo - Contains all the information about a particular stage.

211:    PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code.
212: */
213: typedef struct _PetscStageInfo {
214:   char               *name;     /* The stage name */
215:   PetscBool          used;      /* The stage was pushed on this processor */
216:   PetscEventPerfInfo perfInfo;  /* The stage performance information */
217:   PetscEventPerfLog  eventLog;  /* The event information for this stage */
218:   PetscClassPerfLog  classLog;  /* The class information for this stage */
219: } PetscStageInfo;

221: typedef struct _n_PetscStageLog *PetscStageLog;
222: struct _n_PetscStageLog {
223:   int              numStages;   /* The number of registered stages */
224:   int              maxStages;   /* The maximum number of stages */
225:   PetscIntStack    stack;       /* The stack for active stages */
226:   int              curStage;    /* The current stage (only used in macros so we don't call PetscIntStackTop) */
227:   PetscStageInfo   *stageInfo;  /* The information for each stage */
228:   PetscEventRegLog eventLog;    /* The registered events */
229:   PetscClassRegLog classLog;    /* The registered classes */
230: };
231: /* -----------------------------------------------------------------------------------------------------*/

233: PETSC_EXTERN PetscErrorCode PetscLogObjectParent(PetscObject,PetscObject);
234: PETSC_EXTERN PetscErrorCode PetscLogObjectMemory(PetscObject,PetscLogDouble);

236: #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
237: PETSC_EXTERN PetscStageLog petsc_stageLog;
238: PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog*);
239: PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog,int*);
240: PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog,int,PetscEventPerfLog*);

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

245:    For the complex numbers version, note that
246:        1 complex addition = 2 flops
247:        1 complex multiplication = 6 flops,
248:    where we define 1 flop as that for a double precision scalar.  We roughly approximate
249:    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
250:    to the assumption that we're counting mostly additions and multiplications -- and
251:    roughly the same number of each.  More accurate counting could be done by distinguishing
252:    among the various arithmetic operations.
253:  */

255: #if defined(PETSC_USE_COMPLEX)
256: #define PETSC_FLOPS_PER_OP 4.0
257: #else
258: #define PETSC_FLOPS_PER_OP 1.0
259: #endif

261: /*@
262:        PetscLogFlops - Log how many flops are performed in a calculation

264:    Input Paramters:
265:     flops - the number of flops

267:    Notes:
268:      To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double, 
269:      not an integer. Use PetscLogFlops(4.0*n) not PetscLogFlops(4*n)

271:    Level: intermediate

273: .seealso: PetscLogView()
274: @*/

276: PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n)
277: {
279: #if defined(PETSC_USE_DEBUG)
280:   if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops");
281: #endif
282:   petsc_TotalFlops += PETSC_FLOPS_PER_OP*n;
283:   return(0);
284: }

286: #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA)
287: PETSC_STATIC_INLINE PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size)
288: {
290:   petsc_ctog_ct += 1;
291:   petsc_ctog_sz += size;
292:   return(0);
293: }

295: PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size)
296: {
298:   petsc_gtoc_ct += 1;
299:   petsc_gtoc_sz += size;
300:   return(0);
301: }

303: PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuFlops(PetscLogDouble n)
304: {
306: #if defined(PETSC_USE_DEBUG)
307:   if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops");
308: #endif
309:   petsc_TotalFlops += PETSC_FLOPS_PER_OP*n;
310:   petsc_gflops += PETSC_FLOPS_PER_OP*n;
311:   return(0);
312: }

314: PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeBegin()
315: {
318:   PetscTimeSubtract(&petsc_gtime);
319:   return(0);
320: }

322: PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeEnd()
323: {
326:   PetscTimeAdd(&petsc_gtime);
327:   return(0);
328: }

330: PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t)
331: {
333:   petsc_gtime += t;
334:   return(0);
335: }
336: #endif

338: PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);

340: #if defined (PETSC_HAVE_MPE)
341: PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
342: PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
343: #endif

345: PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
346: PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
347: PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject);
348: PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject);

350: #define PetscLogObjectParents(p,n,d)  0;do{int _i; for (_i=0; _i<(n); _i++) {PetscLogObjectParent((PetscObject)(p),(PetscObject)(d)[_i]);}}while(0)
351: #define PetscLogObjectCreate(h)      ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : 0)
352: #define PetscLogObjectDestroy(h)     ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : 0)
353: PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...);

355: /* Initialization functions */
356: PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
357: PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void);
358: PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
359: PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
360: PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
361: PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
362: PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble,PetscLogDouble*);
363: PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
364:                                         PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));

366: /* Output functions */
367: PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
368: PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
369: PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);

371: /* Stage functions */
372: PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*);
373: PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
374: PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
375: PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage,PetscBool);
376: PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage,PetscBool*);
377: PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage,PetscBool);
378: PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage,PetscBool*);
379: PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[],PetscLogStage*);

381: /* Event functions */
382: PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[],PetscClassId,PetscLogEvent*);
383: PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent,PetscBool);
384: PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
385: PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
386: PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
387: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
388: PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent,PetscBool);
389: PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
390: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
391: PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[],PetscLogEvent*);
392: PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int,PetscLogEvent,PetscEventPerfInfo*);
393: PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
394: PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);

396: /* Global counters */
397: PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
398: PETSC_EXTERN PetscLogDouble petsc_isend_ct;
399: PETSC_EXTERN PetscLogDouble petsc_recv_ct;
400: PETSC_EXTERN PetscLogDouble petsc_send_ct;
401: PETSC_EXTERN PetscLogDouble petsc_irecv_len;
402: PETSC_EXTERN PetscLogDouble petsc_isend_len;
403: PETSC_EXTERN PetscLogDouble petsc_recv_len;
404: PETSC_EXTERN PetscLogDouble petsc_send_len;
405: PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
406: PETSC_EXTERN PetscLogDouble petsc_gather_ct;
407: PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
408: PETSC_EXTERN PetscLogDouble petsc_wait_ct;
409: PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
410: PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
411: PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;

413: PETSC_EXTERN PetscBool      PetscLogMemory;

415: PETSC_EXTERN PetscBool PetscLogSyncOn;  /* true if logging synchronization is enabled */
416: PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm);

418: #define PetscLogEventSync(e,comm) \
419:   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
420:     PetscLogEventSynchronize((e),(comm)) : 0 ))

422: #define PetscLogEventBegin(e,o1,o2,o3,o4) \
423:   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
424:     (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ))

426: #define PetscLogEventEnd(e,o1,o2,o3,o4) \
427:   (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
428:     (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ))

430: PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent,PetscLogDouble*);
431: PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent);

433: /*
434:      These are used internally in the PETSc routines to keep a count of MPI messages and
435:    their sizes.

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

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

444:      It does not work with Windows because winmpich lacks MPI_Type_size()
445: */
446: #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
447: /*
448:    Logging of MPI activities
449: */
450: PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscInt count,MPI_Datatype type,PetscLogDouble *length)
451: {
452:   PetscMPIInt    typesize;
454:   if (type == MPI_DATATYPE_NULL) return 0;
455:   MPI_Type_size(type,&typesize);
456:   *length += (PetscLogDouble) (count*typesize);
457:   return 0;
458: }

460: PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length)
461: {
462:   PetscMPIInt    typesize,size,p;

465:   if (type == MPI_DATATYPE_NULL) return 0;
466:   MPI_Comm_size(comm,&size);
467:   MPI_Type_size(type,&typesize);
468:   for (p=0; p<size; ++p) {
469:     *length += (PetscLogDouble) (counts[p]*typesize);
470:   }
471:   return 0;
472: }

474: PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeCount(PetscInt n,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length)
475: {
476:   PetscMPIInt    typesize,p;

479:   if (type == MPI_DATATYPE_NULL) return 0;
480:   MPI_Type_size(type,&typesize);
481:   for (p=0; p<n; ++p) {
482:     *length += (PetscLogDouble) (counts[p]*typesize);
483:   }
484:   return 0;
485: }

487: /*
488:     Returns 1 if the communicator is parallel else zero
489: */
490: PETSC_STATIC_INLINE int PetscMPIParallelComm(MPI_Comm comm)
491: {
492:   PetscMPIInt size; MPI_Comm_size(comm,&size); return size > 1;
493: }

495: #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
496:   ((petsc_irecv_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || MPI_Irecv((buf),(count),(datatype),(source),(tag),(comm),(request)))

498: #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
499:   ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || MPI_Isend((buf),(count),(datatype),(dest),(tag),(comm),(request)))

501: #define MPI_Startall_irecv(count,datatype,number,requests) \
502:   ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || ((number) && MPI_Startall((number),(requests))))

504: #define MPI_Startall_isend(count,datatype,number,requests) \
505:   ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || ((number) && MPI_Startall((number),(requests))))

507: #define MPI_Start_isend(count,datatype,requests) \
508:   ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_isend_len)) || MPI_Start((requests)))

510: #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
511:   ((petsc_recv_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_recv_len)) || MPI_Recv((buf),(count),(datatype),(source),(tag),(comm),(status)))

513: #define MPI_Send(buf,count,datatype,dest,tag,comm) \
514:   ((petsc_send_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_send_len)) || MPI_Send((buf),(count),(datatype),(dest),(tag),(comm)))

516: #define MPI_Wait(request,status) \
517:   ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait((request),(status)))

519: #define MPI_Waitany(a,b,c,d) \
520:   ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany((a),(b),(c),(d)))

522: #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
523:   ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall((count),(array_of_requests),(array_of_statuses)))

525: #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
526:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Allreduce((sendbuf),(recvbuf),(count),(datatype),(op),(comm)))

528: #define MPI_Bcast(buffer,count,datatype,root,comm) \
529:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Bcast((buffer),(count),(datatype),(root),(comm)))

531: #define MPI_Reduce_scatter_block(sendbuf,recvbuf,recvcount,datatype,op,comm) \
532:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Reduce_scatter_block((sendbuf),(recvbuf),(recvcount),(datatype),(op),(comm)))

534: #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
535:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Alltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm)))

537: #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
538:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSizeComm((comm),(sendcnts),(sendtype),(&petsc_send_len)) || MPI_Alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm)))

540: #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
541:   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm)))

543: #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
544:   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm)))

546: #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
547:   ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))

549: #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
550:   ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm)))

552: #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
553:   ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))

555: #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
556:   ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))

558: #define MPI_Ialltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \
559:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Ialltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request)))

561: #define MPI_Ialltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \
562:   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSizeComm((comm),(sendcnts),(sendtype),(&petsc_send_len)) || MPI_Ialltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request)))

564: #define MPI_Iallgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \
565:   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request)))

567: #define MPI_Iallgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm,request) \
568:   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm),(request)))

570: #define MPI_Igather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \
571:   ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request)))

573: #define MPI_Igatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm,request) \
574:   ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm),(request)))

576: #define MPI_Iscatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \
577:   ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request)))

579: #define MPI_Iscatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \
580:   ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request)))

582: /* We treat MPI_Ineighbor_alltoallv as a set of isend/irecv instead of a traditional MPI collective.
583:    OpenMPI-3.0 ran into error with outdegree = indegree = 0, so we use ((outdegree) || (indegree)) as a workaround.
584:  */
585: #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \
586:   ((petsc_isend_ct += (PetscLogDouble)(outdegree),0) || (petsc_irecv_ct += (PetscLogDouble)(indegree),0) || PetscMPITypeSizeCount((outdegree),(sendcnts),(sendtype),(&petsc_isend_len)) || PetscMPITypeSizeCount((indegree),(recvcnts),(recvtype),(&petsc_irecv_len)) || (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request))))

588: #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
589:   ((petsc_isend_ct += (PetscLogDouble)(outdegree),0) || (petsc_irecv_ct += (PetscLogDouble)(indegree),0) || PetscMPITypeSizeCount((outdegree),(sendcnts),(sendtype),(&petsc_isend_len)) || PetscMPITypeSizeCount((indegree),(recvcnts),(recvtype),(&petsc_irecv_len)) || (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm))))

591: #else

593: #define MPI_Startall_irecv(count,datatype,number,requests) \
594:   ((number) && MPI_Startall((number),(requests)))

596: #define MPI_Startall_isend(count,datatype,number,requests) \
597:   ((number) && MPI_Startall((number),(requests)))

599: #define MPI_Start_isend(count,datatype,requests) \
600:   (MPI_Start((requests)))

602: #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \
603:   (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request)))

605: #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
606:   (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm)))
607: #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */

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

611: #define PetscLogMemory                     PETSC_FALSE

613: #define PetscLogFlops(n)                   0
614: #define PetscGetFlops(a)                   (*(a) = 0.0,0)

616: #define PetscLogStageRegister(a,b)         0
617: #define PetscLogStagePush(a)               0
618: #define PetscLogStagePop()                 0
619: #define PetscLogStageSetActive(a,b)        0
620: #define PetscLogStageGetActive(a,b)        0
621: #define PetscLogStageGetVisible(a,b)       0
622: #define PetscLogStageSetVisible(a,b)       0
623: #define PetscLogStageGetId(a,b)            (*(b)=0,0)

625: #define PetscLogEventRegister(a,b,c)       0
626: #define PetscLogEventSetCollective(a,b)    0
627: #define PetscLogEventIncludeClass(a)       0
628: #define PetscLogEventExcludeClass(a)       0
629: #define PetscLogEventActivate(a)           0
630: #define PetscLogEventDeactivate(a)         0
631: #define PetscLogEventActivateClass(a)      0
632: #define PetscLogEventDeactivateClass(a)    0
633: #define PetscLogEventSetActiveAll(a,b)     0
634: #define PetscLogEventGetId(a,b)            (*(b)=0,0)
635: #define PetscLogEventGetPerfInfo(a,b,c)    0
636: #define PetscLogEventSetDof(a,b,c)         0
637: #define PetscLogEventSetError(a,b,c)       0

639: #define PetscLogPLB                        0
640: #define PetscLogPLE                        0
641: #define PetscLogPHC                        0
642: #define PetscLogPHD                        0

644: #define PetscLogObjectParents(p,n,c)       0
645: #define PetscLogObjectCreate(h)            0
646: #define PetscLogObjectDestroy(h)           0
647: PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...);

649: #define PetscLogDefaultBegin()             0
650: #define PetscLogAllBegin()                 0
651: #define PetscLogNestedBegin()              0
652: #define PetscLogTraceBegin(file)           0
653: #define PetscLogActions(a)                 0
654: #define PetscLogObjects(a)                 0
655: #define PetscLogSetThreshold(a,b)          0
656: #define PetscLogSet(lb,le)                 0

658: #define PetscLogView(viewer)               0
659: #define PetscLogViewFromOptions()          0
660: #define PetscLogDump(c)                    0

662: #define PetscLogEventSync(e,comm)          0
663: #define PetscLogEventBegin(e,o1,o2,o3,o4)  0
664: #define PetscLogEventEnd(e,o1,o2,o3,o4)    0

666: #define PetscLogCpuToGpu(a)                0
667: #define PetscLogGpuToCpu(a)                0
668: #define PetscLogGpuFlops(a)                0
669: #define PetscLogGpuTimeBegin()             0
670: #define PetscLogGpuTimeEnd()               0
671: #define PetscLogGpuTimeAdd(a)              0

673: /* If PETSC_USE_LOG is NOT defined, these still need to be! */
674: #define MPI_Startall_irecv(count,datatype,number,requests) ((number) && MPI_Startall(number,requests))
675: #define MPI_Startall_isend(count,datatype,number,requests) ((number) && MPI_Startall(number,requests))
676: #define MPI_Start_isend(count,datatype,requests)           MPI_Start(requests)
677: #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \
678:   (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request)))
679: #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
680:   (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm)))

682: #endif   /* PETSC_USE_LOG */

684: #define PetscPreLoadBegin(flag,name) \
685: do {\
686:   PetscBool      PetscPreLoading = flag;\
687:   int            PetscPreLoadMax,PetscPreLoadIt;\
688:   PetscLogStage  _stageNum;\
689:   PetscErrorCode _3_ierr; \
690:   _3_PetscOptionsGetBool(NULL,NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr); \
691:   PetscPreLoadMax = (int)(PetscPreLoading);\
692:   PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
693:   for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\
694:     PetscPreLoadingOn = PetscPreLoading;\
695:     _3_PetscBarrier(NULL);CHKERRQ(_3_ierr);\
696:     if (PetscPreLoadIt>0) {\
697:       _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
698:     } else {\
699:       _3_PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
700:     }\
701:     _3_PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\
702:     _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);

704: #define PetscPreLoadEnd() \
705:     _3_PetscLogStagePop();CHKERRQ(_3_ierr);\
706:     PetscPreLoading = PETSC_FALSE;\
707:   }\
708: } while (0)

710: #define PetscPreLoadStage(name) do {                                         \
711:     _3_PetscLogStagePop();CHKERRQ(_3_ierr);                      \
712:     if (PetscPreLoadIt>0) {                                                  \
713:       _3_PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);   \
714:     } else {                                                            \
715:       _3_PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
716:     }                                                                   \
717:     _3_PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \
718:     _3_PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);            \
719:   } while (0)

721: /* some vars for logging */
722: PETSC_EXTERN PetscBool PetscPreLoadingUsed;       /* true if we are or have done preloading */
723: PETSC_EXTERN PetscBool PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */

725: #endif