xref: /petsc/include/petsclog.h (revision 7d0a6c19129e7069c8a40e210b34ed62989173db)
1 /*
2     Defines profile/logging in PETSc.
3 */
4 
5 #if !defined(__PetscLog_H)
6 #define __PetscLog_H
7 #include "petscsys.h"
8 PETSC_EXTERN_CXX_BEGIN
9 
10 /*MC
11     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
12      code.
13 
14     Level: intermediate
15 
16 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
17 M*/
18 typedef int PetscLogEvent;
19 
20 /*MC
21     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
22 
23     Level: intermediate
24 
25 .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent
26 M*/
27 typedef int PetscLogStage;
28 
29 #define PETSC_EVENT  1311311
30 extern PetscLogEvent PETSC_LARGEST_EVENT;
31 
32 /* Global flop counter */
33 extern PetscLogDouble  _TotalFlops;
34 extern PetscLogDouble petsc_tmp_flops;
35 
36 /* General logging of information; different from event logging */
37 extern PetscErrorCode  PetscInfo_Private(const char[],void*,const char[],...);
38 #if defined(PETSC_USE_INFO)
39 #define PetscInfo(A,S)                       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S)
40 #define PetscInfo1(A,S,a1)                   PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1)
41 #define PetscInfo2(A,S,a1,a2)                PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2)
42 #define PetscInfo3(A,S,a1,a2,a3)             PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3)
43 #define PetscInfo4(A,S,a1,a2,a3,a4)          PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4)
44 #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5)
45 #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6)
46 #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)
47 #else
48 #define PetscInfo(A,S)                       0
49 #define PetscInfo1(A,S,a1)                   0
50 #define PetscInfo2(A,S,a1,a2)                0
51 #define PetscInfo3(A,S,a1,a2,a3)             0
52 #define PetscInfo4(A,S,a1,a2,a3,a4)          0
53 #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       0
54 #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    0
55 #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
56 #endif
57 extern PetscErrorCode  PetscInfoDeactivateClass(PetscClassId);
58 extern PetscErrorCode  PetscInfoActivateClass(PetscClassId);
59 extern PetscBool       PetscLogPrintInfo;  /* if true, indicates PetscInfo() is turned on */
60 
61 /* We must make the following structures available to access the event
62      activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public
63      API and are not intended to be used by other parts of PETSc or by users.
64 
65      The code that manipulates these structures is in src/sys/plog/utils.
66 */
67 typedef struct _n_IntStack *IntStack;
68 
69 /*
70     ClassRegInfo, ClassPerfInfo - 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     ClassRegLog, ClassPerfLog - arrays of the ClassRegInfo and ClassPerfInfo for all classes.
75 */
76 typedef struct  {
77   char           *name;   /* The class name */
78   PetscClassId   classid; /* The integer identifying this class */
79 } ClassRegInfo;
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 } ClassPerfInfo;
88 
89 typedef struct _n_ClassRegLog *ClassRegLog;
90 struct _n_ClassRegLog {
91   int            numClasses; /* The number of classes registered */
92   int            maxClasses; /* The maximum number of classes */
93   ClassRegInfo * classInfo;  /* The structure for class information (classids are monotonicly increasing) */
94 };
95 
96 typedef struct _n_ClassPerfLog *ClassPerfLog;
97 struct _n_ClassPerfLog {
98   int            numClasses; /* The number of logging classes */
99   int            maxClasses; /* The maximum number of classes */
100   ClassPerfInfo *classInfo;  /* The structure for class information (classids are monotonicly increasing) */
101 };
102 /* -----------------------------------------------------------------------------------------------------*/
103 /*
104     EventRegInfo, EventPerfInfo - 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     EventRegLog, EventPerfLog - an array of all EventRegInfo and EventPerfInfo 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 #if defined (PETSC_HAVE_MPE)
116   int          mpe_id_begin; /* MPE IDs that define the event */
117   int          mpe_id_end;
118 #endif
119 } EventRegInfo;
120 
121 typedef struct {
122   int            id;            /* The integer identifying this event */
123   PetscBool      active;        /* The flag to activate logging */
124   PetscBool      visible;       /* The flag to print info in summary */
125   int            depth;         /* The nesting depth of the event call */
126   int            count;         /* The number of times this event was executed */
127   PetscLogDouble flops;         /* The flops used in this event */
128   PetscLogDouble time;          /* The time taken for this event */
129   PetscLogDouble numMessages;   /* The number of messages in this event */
130   PetscLogDouble messageLength; /* The total message lengths in this event */
131   PetscLogDouble numReductions; /* The number of reductions in this event */
132 } EventPerfInfo;
133 
134 typedef struct _n_EventRegLog *EventRegLog;
135 struct _n_EventRegLog {
136   int           numEvents; /* The number of registered events */
137   int           maxEvents; /* The maximum number of events */
138   EventRegInfo *eventInfo; /* The registration information for each event */
139 };
140 
141 typedef struct _n_EventPerfLog *EventPerfLog;
142 struct _n_EventPerfLog {
143   int            numEvents; /* The number of logging events */
144   int            maxEvents; /* The maximum number of events */
145   EventPerfInfo *eventInfo; /* The performance information for each event */
146 };
147 /* ------------------------------------------------------------------------------------------------------------*/
148 /*
149    StageInfo - Contains all the information about a particular stage.
150 
151    StageLog - An array of StageInfo for each registered stage. There is a single one of these in the code.
152 */
153 typedef struct _StageInfo {
154   char         *name;     /* The stage name */
155   PetscBool     used;     /* The stage was pushed on this processor */
156   EventPerfInfo perfInfo; /* The stage performance information */
157   EventPerfLog  eventLog; /* The event information for this stage */
158   ClassPerfLog  classLog; /* The class information for this stage */
159 } StageInfo;
160 
161 typedef struct _n_StageLog *StageLog;
162 extern  StageLog _stageLog;
163 struct _n_StageLog {
164   int         numStages; /* The number of registered stages */
165   int         maxStages; /* The maximum number of stages */
166   IntStack    stack;     /* The stack for active stages */
167   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
168   StageInfo  *stageInfo; /* The information for each stage */
169   EventRegLog eventLog;  /* The registered events */
170   ClassRegLog classLog;  /* The registered classes */
171 };
172 
173 #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
174 
175 /*
176    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
177 
178    For the complex numbers version, note that
179        1 complex addition = 2 flops
180        1 complex multiplication = 6 flops,
181    where we define 1 flop as that for a double precision scalar.  We roughly approximate
182    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
183    to the assumption that we're counting mostly additions and multiplications -- and
184    roughly the same number of each.  More accurate counting could be done by distinguishing
185    among the various arithmetic operations.
186  */
187 
188 #if defined(PETSC_USE_COMPLEX)
189 #define PETSC_FLOPS_PER_OP 4.0
190 #else
191 #define PETSC_FLOPS_PER_OP 1.0
192 #endif
193 
194 #if defined(PETSC_USE_DEBUG)
195 #define PetscLogFlops(n) (petsc_tmp_flops = (PETSC_FLOPS_PER_OP*((PetscLogDouble)n)), ((petsc_tmp_flops < 0) ? PETSC_ERR_FLOP_COUNT : (_TotalFlops += petsc_tmp_flops,0)))
196 #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
197 #else
198 #define PetscLogFlops(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n),0)
199 #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
200 #endif
201 
202 #if defined (PETSC_HAVE_MPE)
203 #include "mpe.h"
204 extern PetscErrorCode         PetscLogMPEBegin(void);
205 extern PetscErrorCode         PetscLogMPEDump(const char[]);
206 extern PetscBool  UseMPE;
207 #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
208   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
209    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)
210 
211 #define PETSC_LOG_EVENT_MPE_END(e) \
212   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
213    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0)
214 
215 #else
216 #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0
217 #define PETSC_LOG_EVENT_MPE_END(e)   0
218 #endif
219 
220 extern  PetscErrorCode (*_PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
221 extern  PetscErrorCode (*_PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
222 extern  PetscErrorCode (*_PetscLogPHC)(PetscObject);
223 extern  PetscErrorCode (*_PetscLogPHD)(PetscObject);
224 
225 #define PetscLogObjectParent(p,c) \
226   (c && p && (((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id,0))
227 
228 #define PetscLogObjectParents(p,n,d)  0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}}
229 #define PetscLogObjectCreate(h)      ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0)
230 #define PetscLogObjectDestroy(h)     ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0)
231 #define PetscLogObjectMemory(p,m)    (((PetscObject)(p))->mem += (m),0)
232 /* Initialization functions */
233 extern PetscErrorCode  PetscLogBegin(void);
234 extern PetscErrorCode  PetscLogAllBegin(void);
235 extern PetscErrorCode  PetscLogTraceBegin(FILE *);
236 extern PetscErrorCode  PetscLogActions(PetscBool);
237 extern PetscErrorCode  PetscLogObjects(PetscBool);
238 /* General functions */
239 extern PetscErrorCode  PetscLogGetRGBColor(const char*[]);
240 extern PetscErrorCode  PetscLogDestroy(void);
241 extern PetscErrorCode  PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
242                    PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
243 extern PetscErrorCode  PetscLogObjectState(PetscObject, const char[], ...);
244 /* Output functions */
245 extern PetscErrorCode  PetscLogView(PetscViewer);
246 extern PetscErrorCode  PetscLogViewPython(PetscViewer);
247 extern PetscErrorCode  PetscLogPrintDetailed(MPI_Comm, const char[]);
248 extern PetscErrorCode  PetscLogDump(const char[]);
249 
250 extern PetscErrorCode  PetscGetFlops(PetscLogDouble *);
251 
252 extern PetscErrorCode  PetscLogStageRegister(const char[],PetscLogStage*);
253 extern PetscErrorCode  PetscLogStagePush(PetscLogStage);
254 extern PetscErrorCode  PetscLogStagePop(void);
255 extern PetscErrorCode  PetscLogStageSetActive(PetscLogStage, PetscBool );
256 extern PetscErrorCode  PetscLogStageGetActive(PetscLogStage, PetscBool  *);
257 extern PetscErrorCode  PetscLogStageSetVisible(PetscLogStage, PetscBool );
258 extern PetscErrorCode  PetscLogStageGetVisible(PetscLogStage, PetscBool  *);
259 extern PetscErrorCode  PetscLogStageGetId(const char [], PetscLogStage *);
260 /* Event functions */
261 extern PetscErrorCode  PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*);
262 extern PetscErrorCode  PetscLogEventActivate(PetscLogEvent);
263 extern PetscErrorCode  PetscLogEventDeactivate(PetscLogEvent);
264 extern PetscErrorCode  PetscLogEventSetActiveAll(PetscLogEvent, PetscBool );
265 extern PetscErrorCode  PetscLogEventActivateClass(PetscClassId);
266 extern PetscErrorCode  PetscLogEventDeactivateClass(PetscClassId);
267 
268 
269 /* Global counters */
270 extern  PetscLogDouble irecv_ct;
271 extern  PetscLogDouble isend_ct;
272 extern  PetscLogDouble recv_ct;
273 extern  PetscLogDouble send_ct;
274 extern  PetscLogDouble irecv_len;
275 extern  PetscLogDouble isend_len;
276 extern  PetscLogDouble recv_len;
277 extern  PetscLogDouble send_len;
278 extern  PetscLogDouble allreduce_ct;
279 extern  PetscLogDouble gather_ct;
280 extern  PetscLogDouble scatter_ct;
281 extern  PetscLogDouble wait_ct;
282 extern  PetscLogDouble wait_any_ct;
283 extern  PetscLogDouble wait_all_ct;
284 extern  PetscLogDouble sum_of_waits_ct;
285 
286 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
287   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active &&  _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
288     (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \
289    PetscLogEventBegin((e)+1,o1,o2,o3,o4))
290 
291 #define PetscLogEventBegin(e,o1,o2,o3,o4) \
292   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
293     (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
294   PETSC_LOG_EVENT_MPE_BEGIN(e))
295 
296 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
297 
298 #define PetscLogEventEnd(e,o1,o2,o3,o4) \
299   (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
300     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
301   PETSC_LOG_EVENT_MPE_END(e))
302 
303 extern PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*);
304 extern PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent);
305 
306 /*
307      These are used internally in the PETSc routines to keep a count of MPI messages and
308    their sizes.
309 
310      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
311    uses macros to defined the MPI operations.
312 
313      It does not work correctly from HP-UX because it processes the
314    macros in a way that sometimes it double counts, hence
315    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
316 
317      It does not work with Windows because winmpich lacks MPI_Type_size()
318 */
319 #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
320 /*
321    Logging of MPI activities
322 */
323 PETSC_STATIC_INLINE PetscErrorCode TypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type)
324 {
325   PetscMPIInt mysize; return  (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0));
326 }
327 
328 #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
329  ((irecv_ct++,0) || TypeSize(&irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request))
330 
331 #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
332  ((isend_ct++,0) || TypeSize(&isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request))
333 
334 #define MPI_Startall_irecv(count,number,requests) \
335  ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(&irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
336 
337 #define MPI_Startall_isend(count,number,requests) \
338  ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
339 
340 #define MPI_Start_isend(count,requests) \
341  ((isend_ct++,0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Start(requests))
342 
343 #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
344  ((recv_ct++,0) || TypeSize(&recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status))
345 
346 #define MPI_Send(buf,count,datatype,dest,tag,comm) \
347  ((send_ct++,0) || TypeSize(&send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm))
348 
349 #define MPI_Wait(request,status) \
350  ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status))
351 
352 #define MPI_Waitany(a,b,c,d) \
353  ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))
354 
355 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
356  ((wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses))
357 
358 #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
359  ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))
360 
361 #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
362  ((gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm))
363 
364 #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
365  ((gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm))
366 
367 #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
368  ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
369 
370 #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
371  ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm))
372 
373 #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
374   ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
375 
376 #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
377   ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm))
378 
379 #else
380 
381 #define MPI_Startall_irecv(count,number,requests) \
382  (MPI_Startall(number,requests))
383 
384 #define MPI_Startall_isend(count,number,requests) \
385  (MPI_Startall(number,requests))
386 
387 #define MPI_Start_isend(count,requests) \
388  (MPI_Start(requests))
389 
390 #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
391 
392 #else  /* ---Logging is turned off --------------------------------------------*/
393 
394 #define PetscLogFlops(n) 0
395 #define PetscLogFlopsNoError(n)
396 
397 /*
398      With logging turned off, then MPE has to be turned off
399 */
400 #define PetscLogMPEBegin()         0
401 #define PetscLogMPEDump(a)         0
402 
403 #define PetscLogEventActivate(a)   0
404 #define PetscLogEventDeactivate(a) 0
405 
406 #define PetscLogEventActivateClass(a)   0
407 #define PetscLogEventDeactivateClass(a) 0
408 #define PetscLogEventSetActiveAll(a,b)  0
409 
410 #define _PetscLogPLB                        0
411 #define _PetscLogPLE                        0
412 #define _PetscLogPHC                        0
413 #define _PetscLogPHD                        0
414 #define PetscGetFlops(a)                (*(a) = 0.0,0)
415 #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
416 #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
417 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
418 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
419 #define PetscLogObjectParent(p,c)           0
420 #define PetscLogObjectParents(p,n,c)        0
421 #define PetscLogObjectCreate(h)             0
422 #define PetscLogObjectDestroy(h)            0
423 #define PetscLogObjectMemory(p,m)           0
424 #define PetscLogDestroy()                   0
425 #define PetscLogStagePush(a)                0
426 #define PetscLogStagePop()                  0
427 #define PetscLogStageRegister(a,b)          0
428 #define PetscLogStagePrint(a,flg)           0
429 #define PetscLogView(viewer)                0
430 #define PetscLogViewPython(viewer)          0
431 #define PetscLogPrintDetailed(comm,file)    0
432 #define PetscLogBegin()                     0
433 #define PetscLogTraceBegin(file)            0
434 #define PetscLogSet(lb,le)                  0
435 #define PetscLogAllBegin()                  0
436 #define PetscLogDump(c)                     0
437 #define PetscLogEventRegister(a,b,c)        0
438 #define PetscLogObjects(a)                  0
439 #define PetscLogActions(a)                  0
440 extern PetscErrorCode  PetscLogObjectState(PetscObject,const char[],...);
441 
442 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
443 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
444 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
445 #define MPI_Start_isend(count,requests) MPI_Start(requests)
446 #define PetscLogStageGetId(a,b)                      (*(b)=0,0)
447 #define PetscLogStageSetActive(a,b)                  0
448 #define PetscLogStageGetActive(a,b)                  0
449 #define PetscLogStageGetVisible(a,b)                 0
450 #define PetscLogStageSetVisible(a,b)                 0
451 
452 #endif   /* PETSC_USE_LOG */
453 
454 /* Special support for C++ */
455 #include "petsclog.hh"
456 
457 #define PreLoadBegin(flag,name) \
458 {\
459   PetscBool      PreLoading = flag;\
460   int            PreLoadMax,PreLoadIt;\
461   PetscLogStage  _stageNum;\
462   PetscErrorCode _3_ierr;	\
463   _3_ierr = PetscOptionsGetBool(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
464   PreLoadMax = (int)(PreLoading);\
465   PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
466   for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
467     PetscPreLoadingOn = PreLoading;\
468     _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
469     if (PreLoadIt>0) {\
470       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
471     } else {\
472       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
473     }\
474     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PreLoadMax || PreLoadIt));\
475     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
476 
477 #define PreLoadEnd() \
478     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
479     PreLoading = PETSC_FALSE;\
480   }\
481 }
482 
483 #define PreLoadStage(name) \
484   _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
485   if (PreLoadIt>0) {\
486     _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
487   } else {\
488     _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr);	\
489   }\
490   _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PreLoadMax || PreLoadIt));\
491   _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
492 
493 PETSC_EXTERN_CXX_END
494 #endif
495