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