xref: /petsc/include/petsclog.h (revision bfcb38ea38335faa6e7f8d97f6bc6ce9aa2a1dd1)
1 /*
2     Defines profile/logging in PETSc.
3 */
4 
5 #if !defined(__PetscLog_H)
6 #define __PetscLog_H
7 #include <petscsys.h>
8 
9 /* General logging of information; different from event logging */
10 PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],void*,const char[],...);
11 #if defined(PETSC_USE_INFO)
12 #define PetscInfo(A,S)                       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S)
13 #define PetscInfo1(A,S,a1)                   PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1)
14 #define PetscInfo2(A,S,a1,a2)                PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2)
15 #define PetscInfo3(A,S,a1,a2,a3)             PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3)
16 #define PetscInfo4(A,S,a1,a2,a3,a4)          PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4)
17 #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5)
18 #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6)
19 #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6,a7)
20 #else
21 #define PetscInfo(A,S)                       0
22 #define PetscInfo1(A,S,a1)                   0
23 #define PetscInfo2(A,S,a1,a2)                0
24 #define PetscInfo3(A,S,a1,a2,a3)             0
25 #define PetscInfo4(A,S,a1,a2,a3,a4)          0
26 #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       0
27 #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    0
28 #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
29 #endif
30 PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId);
31 PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId);
32 PETSC_EXTERN PetscBool PetscLogPrintInfo;  /* if true, indicates PetscInfo() is turned on */
33 
34 /*MC
35     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
36      code.
37 
38     Level: intermediate
39 
40 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
41 M*/
42 typedef int PetscLogEvent;
43 
44 /*MC
45     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
46 
47     Level: intermediate
48 
49 .seealso: PetscLogStageRegister(), PetscLogStagePush(), PetscLogStagePop(), PetscLogEvent
50 M*/
51 typedef int PetscLogStage;
52 
53 #define PETSC_EVENT  1311311
54 PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT;
55 
56 /* Global flop counter */
57 PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
58 PETSC_EXTERN PetscLogDouble petsc_tmp_flops;
59 
60 /* We must make the following structures available to access the event
61      activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public
62      API and are not intended to be used by other parts of PETSc or by users.
63 
64      The code that manipulates these structures is in src/sys/logging/utils.
65 */
66 typedef struct _n_PetscIntStack *PetscIntStack;
67 
68 /* -----------------------------------------------------------------------------------------------------*/
69 /*
70     PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has
71        static information about it, the second collects statistics on how many objects of the class are created,
72        how much memory they use, etc.
73 
74     PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes.
75 */
76 typedef struct  {
77   char           *name;   /* The class name */
78   PetscClassId   classid; /* The integer identifying this class */
79 } PetscClassRegInfo;
80 
81 typedef struct {
82   PetscClassId   id;           /* The integer identifying this class */
83   int            creations;    /* The number of objects of this class created */
84   int            destructions; /* The number of objects of this class destroyed */
85   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
86   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
87 } PetscClassPerfInfo;
88 
89 typedef struct _n_PetscClassRegLog *PetscClassRegLog;
90 struct _n_PetscClassRegLog {
91   int               numClasses; /* The number of classes registered */
92   int               maxClasses; /* The maximum number of classes */
93   PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
94 };
95 
96 typedef struct _n_PetscClassPerfLog *PetscClassPerfLog;
97 struct _n_PetscClassPerfLog {
98   int                numClasses; /* The number of logging classes */
99   int                maxClasses; /* The maximum number of classes */
100   PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
101 };
102 /* -----------------------------------------------------------------------------------------------------*/
103 /*
104     PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has
105        static information about it, the second collects statistics on how many times the event is used, how
106        much time it takes, etc.
107 
108     PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one
109       of these for each stage.
110 
111 */
112 typedef struct {
113   char         *name;         /* The name of this event */
114   PetscClassId classid;       /* The class the event is associated with */
115   PetscBool    collective;    /* Flag this event as collective */
116 #if defined (PETSC_HAVE_MPE)
117   int          mpe_id_begin;  /* MPE IDs that define the event */
118   int          mpe_id_end;
119 #endif
120 } PetscEventRegInfo;
121 
122 typedef struct {
123   int            id;            /* The integer identifying this event */
124   PetscBool      active;        /* The flag to activate logging */
125   PetscBool      visible;       /* The flag to print info in summary */
126   int            depth;         /* The nesting depth of the event call */
127   int            count;         /* The number of times this event was executed */
128   PetscLogDouble flops, flops2, flopsTmp; /* The flops and flops^2 used in this event */
129   PetscLogDouble time, time2, timeTmp;    /* The time and time^2 taken for this event */
130   PetscLogDouble syncTime;                /* The synchronization barrier time */
131   PetscLogDouble dof[8];        /* The number of degrees of freedom associated with this event */
132   PetscLogDouble errors[8];     /* The errors (user-defined) associated with this event */
133   PetscLogDouble numMessages;   /* The number of messages in this event */
134   PetscLogDouble messageLength; /* The total message lengths in this event */
135   PetscLogDouble numReductions; /* The number of reductions in this event */
136   PetscLogDouble memIncrease;   /* How much the resident memory has increased in this event */
137   PetscLogDouble mallocIncrease;/* How much the maximum malloced space has increased in this event */
138   PetscLogDouble mallocSpace;   /* How much the space was malloced and kept during this event */
139   PetscLogDouble mallocIncreaseEvent;  /* Maximum of the high water mark with in event minus memory available at the end of the event */
140 } PetscEventPerfInfo;
141 
142 typedef struct _n_PetscEventRegLog *PetscEventRegLog;
143 struct _n_PetscEventRegLog {
144   int               numEvents;  /* The number of registered events */
145   int               maxEvents;  /* The maximum number of events */
146   PetscEventRegInfo *eventInfo; /* The registration information for each event */
147 };
148 
149 typedef struct _n_PetscEventPerfLog *PetscEventPerfLog;
150 struct _n_PetscEventPerfLog {
151   int                numEvents;  /* The number of logging events */
152   int                maxEvents;  /* The maximum number of events */
153   PetscEventPerfInfo *eventInfo; /* The performance information for each event */
154 };
155 /* ------------------------------------------------------------------------------------------------------------*/
156 /*
157    PetscStageInfo - Contains all the information about a particular stage.
158 
159    PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code.
160 */
161 typedef struct _PetscStageInfo {
162   char               *name;     /* The stage name */
163   PetscBool          used;      /* The stage was pushed on this processor */
164   PetscEventPerfInfo perfInfo;  /* The stage performance information */
165   PetscEventPerfLog  eventLog;  /* The event information for this stage */
166   PetscClassPerfLog  classLog;  /* The class information for this stage */
167 } PetscStageInfo;
168 
169 typedef struct _n_PetscStageLog *PetscStageLog;
170 struct _n_PetscStageLog {
171   int              numStages;   /* The number of registered stages */
172   int              maxStages;   /* The maximum number of stages */
173   PetscIntStack    stack;       /* The stack for active stages */
174   int              curStage;    /* The current stage (only used in macros so we don't call PetscIntStackTop) */
175   PetscStageInfo   *stageInfo;  /* The information for each stage */
176   PetscEventRegLog eventLog;    /* The registered events */
177   PetscClassRegLog classLog;    /* The registered classes */
178 };
179 /* -----------------------------------------------------------------------------------------------------*/
180 
181 PETSC_EXTERN PetscErrorCode PetscLogObjectParent(PetscObject,PetscObject);
182 PETSC_EXTERN PetscErrorCode PetscLogObjectMemory(PetscObject,PetscLogDouble);
183 
184 #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
185 PETSC_EXTERN PetscStageLog petsc_stageLog;
186 PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog*);
187 PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog,int*);
188 PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog,int,PetscEventPerfLog*);
189 
190 /*
191    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
192 
193    For the complex numbers version, note that
194        1 complex addition = 2 flops
195        1 complex multiplication = 6 flops,
196    where we define 1 flop as that for a double precision scalar.  We roughly approximate
197    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
198    to the assumption that we're counting mostly additions and multiplications -- and
199    roughly the same number of each.  More accurate counting could be done by distinguishing
200    among the various arithmetic operations.
201  */
202 
203 #if defined(PETSC_USE_COMPLEX)
204 #define PETSC_FLOPS_PER_OP 4.0
205 #else
206 #define PETSC_FLOPS_PER_OP 1.0
207 #endif
208 
209 PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n)
210 {
211   PetscFunctionBegin;
212 #if defined(PETSC_USE_DEBUG)
213   if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops");
214 #endif
215   petsc_TotalFlops += PETSC_FLOPS_PER_OP*n;
216   PetscFunctionReturn(0);
217 }
218 
219 PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
220 
221 #if defined (PETSC_HAVE_MPE)
222 PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
223 PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
224 #endif
225 
226 PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
227 PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
228 PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject);
229 PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject);
230 
231 #define PetscLogObjectParents(p,n,d)  0;do{int _i; for (_i=0; _i<(n); _i++) {ierr = PetscLogObjectParent((PetscObject)(p),(PetscObject)(d)[_i]);CHKERRQ(ierr);}}while(0)
232 #define PetscLogObjectCreate(h)      ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : 0)
233 #define PetscLogObjectDestroy(h)     ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : 0)
234 PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...);
235 
236 /* Initialization functions */
237 PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
238 PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void);
239 PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
240 PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
241 PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
242 PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
243 PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble,PetscLogDouble*);
244 PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
245                                         PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
246 
247 /* Output functions */
248 PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
249 PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
250 PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);
251 
252 /* Stage functions */
253 PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*);
254 PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
255 PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
256 PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage,PetscBool);
257 PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage,PetscBool*);
258 PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage,PetscBool);
259 PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage,PetscBool*);
260 PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[],PetscLogStage*);
261 
262 /* Event functions */
263 PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[],PetscClassId,PetscLogEvent*);
264 PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent,PetscBool);
265 PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
266 PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
267 PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
268 PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
269 PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent,PetscBool);
270 PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
271 PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
272 PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[],PetscLogEvent*);
273 PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int,PetscLogEvent,PetscEventPerfInfo*);
274 PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
275 PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);
276 
277 /* Global counters */
278 PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
279 PETSC_EXTERN PetscLogDouble petsc_isend_ct;
280 PETSC_EXTERN PetscLogDouble petsc_recv_ct;
281 PETSC_EXTERN PetscLogDouble petsc_send_ct;
282 PETSC_EXTERN PetscLogDouble petsc_irecv_len;
283 PETSC_EXTERN PetscLogDouble petsc_isend_len;
284 PETSC_EXTERN PetscLogDouble petsc_recv_len;
285 PETSC_EXTERN PetscLogDouble petsc_send_len;
286 PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
287 PETSC_EXTERN PetscLogDouble petsc_gather_ct;
288 PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
289 PETSC_EXTERN PetscLogDouble petsc_wait_ct;
290 PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
291 PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
292 PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;
293 
294 PETSC_EXTERN PetscBool      PetscLogMemory;
295 
296 PETSC_EXTERN PetscBool PetscLogSyncOn;  /* true if logging synchronization is enabled */
297 PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm);
298 
299 #define PetscLogEventSync(e,comm) \
300   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
301     PetscLogEventSynchronize((e),(comm)) : 0 ))
302 
303 #define PetscLogEventBegin(e,o1,o2,o3,o4) \
304   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
305     (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ))
306 
307 #define PetscLogEventEnd(e,o1,o2,o3,o4) \
308   (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
309     (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ))
310 
311 PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent,PetscLogDouble*);
312 PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent);
313 
314 /*
315      These are used internally in the PETSc routines to keep a count of MPI messages and
316    their sizes.
317 
318      This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file
319    uses macros to defined the MPI operations.
320 
321      It does not work correctly from HP-UX because it processes the
322    macros in a way that sometimes it double counts, hence
323    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
324 
325      It does not work with Windows because winmpich lacks MPI_Type_size()
326 */
327 #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
328 /*
329    Logging of MPI activities
330 */
331 PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type)
332 {
333   PetscMPIInt mysize;
334   PetscErrorCode _myierr;
335   if (type == MPI_DATATYPE_NULL) return 0;
336   _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr);
337   *buff += (PetscLogDouble) (count*mysize);
338   return 0;
339 }
340 
341 PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, PetscLogDouble *buff,PetscMPIInt *counts,MPI_Datatype type)
342 {
343   PetscMPIInt mysize, commsize, p;
344   PetscErrorCode _myierr;
345 
346   if (type == MPI_DATATYPE_NULL) return 0;
347   _myierr = MPI_Comm_size(comm,&commsize);CHKERRQ(_myierr);
348   _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr);
349   for (p = 0; p < commsize; ++p) {
350     *buff += (PetscLogDouble) (counts[p]*mysize);
351   }
352   return 0;
353 }
354 
355 /*
356     Returns 1 if the communicator is parallel else zero
357 */
358 PETSC_STATIC_INLINE int PetscMPIParallelComm(MPI_Comm comm)
359 {
360   PetscMPIInt size; MPI_Comm_size(comm,&size); return size > 1;
361 }
362 
363 #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
364   ((petsc_irecv_ct++,0) || PetscMPITypeSize(&(petsc_irecv_len),(count),(datatype)) || MPI_Irecv((buf),(count),(datatype),(source),(tag),(comm),(request)))
365 
366 #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
367   ((petsc_isend_ct++,0) || PetscMPITypeSize(&(petsc_isend_len),(count),(datatype)) || MPI_Isend((buf),(count),(datatype),(dest),(tag),(comm),(request)))
368 
369 #define MPI_Startall_irecv(count,datatype,number,requests) \
370   ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&(petsc_irecv_len),(count),(datatype)) || ((number) && MPI_Startall((number),(requests))))
371 
372 #define MPI_Startall_isend(count,datatype,number,requests) \
373   ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&(petsc_isend_len),(count),(datatype)) || ((number) && MPI_Startall((number),(requests))))
374 
375 #define MPI_Start_isend(count,datatype,requests) \
376   ((petsc_isend_ct++,0) || PetscMPITypeSize((&petsc_isend_len),(count),(datatype)) || MPI_Start((requests)))
377 
378 #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
379   ((petsc_recv_ct++,0) || PetscMPITypeSize((&petsc_recv_len),(count),(datatype)) || MPI_Recv((buf),(count),(datatype),(source),(tag),(comm),(status)))
380 
381 #define MPI_Send(buf,count,datatype,dest,tag,comm) \
382   ((petsc_send_ct++,0) || PetscMPITypeSize((&petsc_send_len),(count),(datatype)) || MPI_Send((buf),(count),(datatype),(dest),(tag),(comm)))
383 
384 #define MPI_Wait(request,status) \
385   ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait((request),(status)))
386 
387 #define MPI_Waitany(a,b,c,d) \
388   ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany((a),(b),(c),(d)))
389 
390 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
391   ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall((count),(array_of_requests),(array_of_statuses)))
392 
393 #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
394   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Allreduce((sendbuf),(recvbuf),(count),(datatype),(op),(comm)))
395 
396 #define MPI_Bcast(buffer,count,datatype,root,comm) \
397   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Bcast((buffer),(count),(datatype),(root),(comm)))
398 
399 #define MPI_Reduce_scatter_block(sendbuf,recvbuf,recvcount,datatype,op,comm) \
400   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Reduce_scatter_block((sendbuf),(recvbuf),(recvcount),(datatype),(op),(comm)))
401 
402 #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
403   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((&petsc_send_len),(sendcount),(sendtype)) || MPI_Alltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm)))
404 
405 #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
406   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSizeComm((comm),(&petsc_send_len),(sendcnts),(sendtype)) || MPI_Alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm)))
407 
408 #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
409   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm)))
410 
411 #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
412   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm)))
413 
414 #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
415   ((petsc_gather_ct++,0) || PetscMPITypeSize((&petsc_send_len),(sendcount),(sendtype)) || MPI_Gather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))
416 
417 #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
418   ((petsc_gather_ct++,0) || PetscMPITypeSize((&petsc_send_len),(sendcount),(sendtype)) || MPI_Gatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm)))
419 
420 #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
421   ((petsc_scatter_ct++,0) || PetscMPITypeSize((&petsc_recv_len),(recvcount),(recvtype)) || MPI_Scatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))
422 
423 #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
424   ((petsc_scatter_ct++,0) || PetscMPITypeSize((&petsc_recv_len),(recvcount),(recvtype)) || MPI_Scatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))
425 
426 #else
427 
428 #define MPI_Startall_irecv(count,datatype,number,requests) \
429   ((number) && MPI_Startall((number),(requests)))
430 
431 #define MPI_Startall_isend(count,datatype,number,requests) \
432   ((number) && MPI_Startall((number),(requests)))
433 
434 #define MPI_Start_isend(count,datatype,requests) \
435   (MPI_Start((requests)))
436 
437 #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
438 
439 #else  /* ---Logging is turned off --------------------------------------------*/
440 
441 #define PetscLogMemory                     PETSC_FALSE
442 
443 #define PetscLogFlops(n)                   0
444 #define PetscGetFlops(a)                   (*(a) = 0.0,0)
445 
446 #define PetscLogStageRegister(a,b)         0
447 #define PetscLogStagePush(a)               0
448 #define PetscLogStagePop()                 0
449 #define PetscLogStageSetActive(a,b)        0
450 #define PetscLogStageGetActive(a,b)        0
451 #define PetscLogStageGetVisible(a,b)       0
452 #define PetscLogStageSetVisible(a,b)       0
453 #define PetscLogStageGetId(a,b)            (*(b)=0,0)
454 
455 #define PetscLogEventRegister(a,b,c)       0
456 #define PetscLogEventSetCollective(a,b)    0
457 #define PetscLogEventIncludeClass(a)       0
458 #define PetscLogEventExcludeClass(a)       0
459 #define PetscLogEventActivate(a)           0
460 #define PetscLogEventDeactivate(a)         0
461 #define PetscLogEventActivateClass(a)      0
462 #define PetscLogEventDeactivateClass(a)    0
463 #define PetscLogEventSetActiveAll(a,b)     0
464 #define PetscLogEventGetId(a,b)            (*(b)=0,0)
465 #define PetscLogEventGetPerfInfo(a,b,c)    0
466 #define PetscLogEventSetDof(a,b,c)         0
467 #define PetscLogEventSetError(a,b,c)       0
468 
469 #define PetscLogPLB                        0
470 #define PetscLogPLE                        0
471 #define PetscLogPHC                        0
472 #define PetscLogPHD                        0
473 
474 #define PetscLogObjectParents(p,n,c)       0
475 #define PetscLogObjectCreate(h)            0
476 #define PetscLogObjectDestroy(h)           0
477 PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...);
478 
479 #define PetscLogDefaultBegin()             0
480 #define PetscLogAllBegin()                 0
481 #define PetscLogNestedBegin()              0
482 #define PetscLogTraceBegin(file)           0
483 #define PetscLogActions(a)                 0
484 #define PetscLogObjects(a)                 0
485 #define PetscLogSetThreshold(a,b)          0
486 #define PetscLogSet(lb,le)                 0
487 
488 #define PetscLogView(viewer)               0
489 #define PetscLogViewFromOptions()          0
490 #define PetscLogDump(c)                    0
491 
492 #define PetscLogEventSync(e,comm)          0
493 #define PetscLogEventBegin(e,o1,o2,o3,o4)  0
494 #define PetscLogEventEnd(e,o1,o2,o3,o4)    0
495 
496 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
497 #define MPI_Startall_irecv(count,datatype,number,requests) ((number) && MPI_Startall(number,requests))
498 #define MPI_Startall_isend(count,datatype,number,requests) ((number) && MPI_Startall(number,requests))
499 #define MPI_Start_isend(count,datatype,requests)           MPI_Start(requests)
500 
501 #endif   /* PETSC_USE_LOG */
502 
503 #define PetscPreLoadBegin(flag,name) \
504 do {\
505   PetscBool      PetscPreLoading = flag;\
506   int            PetscPreLoadMax,PetscPreLoadIt;\
507   PetscLogStage  _stageNum;\
508   PetscErrorCode _3_ierr; \
509   _3_ierr = PetscOptionsGetBool(NULL,NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr); \
510   PetscPreLoadMax = (int)(PetscPreLoading);\
511   PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
512   for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\
513     PetscPreLoadingOn = PetscPreLoading;\
514     _3_ierr = PetscBarrier(NULL);CHKERRQ(_3_ierr);\
515     if (PetscPreLoadIt>0) {\
516       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
517     } else {\
518       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
519     }\
520     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\
521     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
522 
523 #define PetscPreLoadEnd() \
524     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
525     PetscPreLoading = PETSC_FALSE;\
526   }\
527 } while (0)
528 
529 #define PetscPreLoadStage(name) do {                                         \
530     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);                      \
531     if (PetscPreLoadIt>0) {                                                  \
532       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);   \
533     } else {                                                            \
534       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
535     }                                                                   \
536     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \
537     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);            \
538   } while (0)
539 
540 /* some vars for logging */
541 PETSC_EXTERN PetscBool PetscPreLoadingUsed;       /* true if we are or have done preloading */
542 PETSC_EXTERN PetscBool PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
543 
544 #endif
545