xref: /petsc/include/petsclog.h (revision aa17faf33f543cd5d7c84dc9722c376c3b4f0985)
1 /*
2     Defines profile/logging in PETSc.
3 */
4 
5 #if !defined(__PetscLog_H)
6 #define __PetscLog_H
7 #include "petsc.h"
8 PETSC_EXTERN_CXX_BEGIN
9 /*
10   Each PETSc object class has it's own cookie (internal integer in the
11   data structure used for error checking). These are all defined by an offset
12   from the lowest one, PETSC_COOKIE.
13 */
14 #define PETSC_COOKIE 1211211
15 extern int PETSC_LARGEST_COOKIE;
16 #define PETSC_EVENT  1311311
17 extern int PETSC_LARGEST_EVENT;
18 
19 /* Events for the Petsc standard library */
20 extern int PETSC_Barrier;
21 
22 /* Global flop counter */
23 extern PetscLogDouble _TotalFlops;
24 
25 /* General logging of information; different from event logging */
26 EXTERN PetscErrorCode        PetscLogInfo(void*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
27 EXTERN PetscErrorCode        PetscLogInfoDeactivateClass(int);
28 EXTERN PetscErrorCode        PetscLogInfoActivateClass(int);
29 extern PetscTruth PetscLogPrintInfo;  /* if true, indicates PetscLogInfo() is turned on */
30 
31 #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
32 
33 /*
34    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
35 
36    For the complex numbers version, note that
37        1 complex addition = 2 flops
38        1 complex multiplication = 6 flops,
39    where we define 1 flop as that for a double precision scalar.  We roughly approximate
40    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
41    to the assumption that we're counting mostly additions and multiplications -- and
42    roughly the same number of each.  More accurate counting could be done by distinguishing
43    among the various arithmetic operations.
44  */
45 
46 #if defined(PETSC_USE_COMPLEX)
47 #define PetscLogFlops(n) (_TotalFlops += (4*n),0)
48 #else
49 #define PetscLogFlops(n) (_TotalFlops += (n),0)
50 #endif
51 
52 #if defined (PETSC_HAVE_MPE)
53 #include "mpe.h"
54 EXTERN PetscErrorCode        PetscLogMPEBegin(void);
55 EXTERN PetscErrorCode        PetscLogMPEDump(const char[]);
56 extern PetscTruth UseMPE;
57 #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
58   if(UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) \
59     MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,(char*)"");
60 
61 #define PETSC_LOG_EVENT_MPE_END(e) \
62   if(UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) \
63     MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,(char*)"");
64 
65 #else
66 #define PETSC_LOG_EVENT_MPE_BEGIN(e)
67 #define PETSC_LOG_EVENT_MPE_END(e)
68 #endif
69 
70 EXTERN PetscErrorCode (*_PetscLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
71 EXTERN PetscErrorCode (*_PetscLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
72 EXTERN PetscErrorCode (*_PetscLogPHC)(PetscObject);
73 EXTERN PetscErrorCode (*_PetscLogPHD)(PetscObject);
74 
75 #define PetscLogObjectParent(p,c) \
76   if (c) {\
77     PetscValidHeader((PetscObject)(c),2);\
78     PetscValidHeader((PetscObject)(p),1);\
79     ((PetscObject)(c))->parent = (PetscObject)(p);\
80     ((PetscObject)(c))->parentid = ((PetscObject)p)->id;\
81   }
82 #define PetscLogObjectParents(p,n,d) {int _i; for (_i=0; _i<n; _i++) PetscLogObjectParent(p,(d)[_i]);}
83 #define PetscLogObjectCreate(h)      {if (_PetscLogPHC) (*_PetscLogPHC)((PetscObject)h);}
84 #define PetscLogObjectDestroy(h)     {if (_PetscLogPHD) (*_PetscLogPHD)((PetscObject)h);}
85 #define PetscLogObjectMemory(p,m)    {PetscValidHeader((PetscObject)p,1);((PetscObject)(p))->mem += (m);}
86 /* Initialization functions */
87 EXTERN PetscErrorCode PetscLogBegin(void);
88 EXTERN PetscErrorCode PetscLogAllBegin(void);
89 EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
90 EXTERN PetscErrorCode PetscLogActions(PetscTruth);
91 EXTERN PetscErrorCode PetscLogObjects(PetscTruth);
92 /* General functions */
93 EXTERN PetscErrorCode PetscLogGetRGBColor(const char*[]);
94 EXTERN PetscErrorCode PetscLogDestroy(void);
95 EXTERN PetscErrorCode PetscLogSet(int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
96                    int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
97 EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
98 /* Output functions */
99 EXTERN PetscErrorCode PetscLogPrintSummary(MPI_Comm, const char[]);
100 EXTERN PetscErrorCode PetscLogDump(const char[]);
101 /* Counter functions */
102 EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
103 /* Stage functions */
104 EXTERN PetscErrorCode PetscLogStageRegister(int*, const char[]);
105 EXTERN PetscErrorCode PetscLogStagePush(int);
106 EXTERN PetscErrorCode PetscLogStagePop(void);
107 EXTERN PetscErrorCode PetscLogStageSetActive(int, PetscTruth);
108 EXTERN PetscErrorCode PetscLogStageGetActive(int, PetscTruth *);
109 EXTERN PetscErrorCode PetscLogStageSetVisible(int, PetscTruth);
110 EXTERN PetscErrorCode PetscLogStageGetVisible(int, PetscTruth *);
111 EXTERN PetscErrorCode PetscLogStageGetId(const char [], int *);
112 /* Event functions */
113 EXTERN PetscErrorCode PetscLogEventRegister(int*, const char[], int);
114 EXTERN PetscErrorCode PetscLogEventActivate(int);
115 EXTERN PetscErrorCode PetscLogEventDeactivate(int);
116 EXTERN PetscErrorCode PetscLogEventSetActiveAll(int, PetscTruth);
117 EXTERN PetscErrorCode PetscLogEventActivateClass(int);
118 EXTERN PetscErrorCode PetscLogEventDeactivateClass(int);
119 /* Class functions */
120 EXTERN PetscErrorCode PetscLogClassRegister(int*, const char []);
121 
122 /* Global counters */
123 extern PetscLogDouble irecv_ct,  isend_ct,  recv_ct,  send_ct;
124 extern PetscLogDouble irecv_len, isend_len, recv_len, send_len;
125 extern PetscLogDouble allreduce_ct;
126 extern PetscLogDouble wait_ct, wait_any_ct, wait_all_ct, sum_of_waits_ct;
127 extern int            PETSC_DUMMY, PETSC_DUMMY_SIZE;
128 
129 /* We must make these structures available if we are to access the event
130    activation flags in the PetscLogEventBegin/End() macros. If we forced a
131    function call each time, we could leave these structures in plog.h
132 */
133 /* Default log */
134 typedef struct _StageLog *StageLog;
135 extern StageLog _stageLog;
136 
137 /* A simple stack (should replace) */
138 typedef struct _IntStack *IntStack;
139 
140 /* The structures for logging performance */
141 typedef struct _EventPerfInfo {
142   int            id;            /* The integer identifying this section */
143   PetscTruth     active;        /* The flag to activate logging */
144   PetscTruth     visible;       /* The flag to print info in summary */
145   int            depth;         /* The nesting depth of the event call */
146   int            count;         /* The number of times this section was executed */
147   PetscLogDouble flops;         /* The flops used in this section */
148   PetscLogDouble time;          /* The time taken for this section */
149   PetscLogDouble numMessages;   /* The number of messages in this section */
150   PetscLogDouble messageLength; /* The total message lengths in this section */
151   PetscLogDouble numReductions; /* The number of reductions in this section */
152 } EventPerfInfo;
153 
154 typedef struct _ClassPerfInfo {
155   int            id;           /* The integer identifying this class */
156   int            creations;    /* The number of objects of this class created */
157   int            destructions; /* The number of objects of this class destroyed */
158   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
159   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
160 } ClassPerfInfo;
161 
162 /* The structures for logging registration */
163 typedef struct _ClassRegInfo {
164   char            *name;   /* The class name */
165   PetscCookieCode cookie; /* The integer identifying this class */
166 } ClassRegInfo;
167 
168 typedef struct _EventRegInfo {
169   char            *name;   /* The name of this event */
170   PetscCookieCode cookie; /* The class id for this event (should maybe give class ID instead) */
171 #if defined (PETSC_HAVE_MPE)
172   int             mpe_id_begin; /* MPE IDs that define the event */
173   int             mpe_id_end;
174 #endif
175 } EventRegInfo;
176 
177 /* The structure for logging events */
178 typedef int PetscEvent;
179 
180 typedef struct _EventRegLog *EventRegLog;
181 struct _EventRegLog {
182   int           numEvents; /* The number of registered events */
183   int           maxEvents; /* The maximum number of events */
184   EventRegInfo *eventInfo; /* The registration information for each event */
185 };
186 
187 typedef struct _EventPerfLog *EventPerfLog;
188 struct _EventPerfLog {
189   int            numEvents; /* The number of logging events */
190   int            maxEvents; /* The maximum number of events */
191   EventPerfInfo *eventInfo; /* The performance information for each event */
192 };
193 
194 /* The structure for logging class information */
195 typedef struct _ClassRegLog *ClassRegLog;
196 struct _ClassRegLog {
197   int           numClasses; /* The number of classes registered */
198   int           maxClasses; /* The maximum number of classes */
199   ClassRegInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
200 };
201 
202 typedef struct _ClassPerfLog *ClassPerfLog;
203 struct _ClassPerfLog {
204   int            numClasses; /* The number of logging classes */
205   int            maxClasses; /* The maximum number of classes */
206   ClassPerfInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
207 };
208 
209 /* The structures for logging in stages */
210 typedef struct _StageInfo {
211   char         *name;     /* The stage name */
212   PetscTruth    used;     /* The stage was pushed on this processor */
213   EventPerfInfo perfInfo; /* The stage performance information */
214   EventPerfLog  eventLog; /* The event information for this stage */
215   ClassPerfLog  classLog; /* The class information for this stage */
216 } StageInfo;
217 
218 struct _StageLog {
219   /* Size information */
220   int         numStages; /* The number of registered stages */
221   int         maxStages; /* The maximum number of stages */
222   /* Runtime information */
223   IntStack    stack;     /* The stack for active stages */
224   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
225   /* Stage specific information */
226   StageInfo  *stageInfo; /* The information for each stage */
227   EventRegLog eventLog;  /* The registered events */
228   ClassRegLog classLog;  /* The registered classes */
229 };
230 
231 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0; \
232 {\
233   int _2_ierr;\
234   if (_PetscLogPLB && \
235       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
236       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
237     _2_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);\
238     _2_ierr = MPI_Barrier(cm);CHKERRQ(_2_ierr);\
239     _2_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);\
240   }\
241   _2_ierr = PetscLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(_2_ierr);\
242 }
243 
244 #define PetscLogEventBegin(e,o1,o2,o3,o4) 0; \
245 {\
246   if (_PetscLogPLB && \
247       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
248       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
249     (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
250   }\
251   PETSC_LOG_EVENT_MPE_BEGIN(e); \
252 }
253 
254 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
255 
256 #define PetscLogEventEnd(e,o1,o2,o3,o4) 0; \
257 {\
258   if (_PetscLogPLE && \
259       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
260       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
261     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
262   }\
263   PETSC_LOG_EVENT_MPE_END(e); \
264 }
265 
266 /* Creation and destruction functions */
267 EXTERN PetscErrorCode StageLogCreate(StageLog *);
268 EXTERN PetscErrorCode StageLogDestroy(StageLog);
269 /* Registration functions */
270 EXTERN PetscErrorCode StageLogRegister(StageLog, const char [], int *);
271 /* Runtime functions */
272 EXTERN PetscErrorCode PetscLogGetStageLog(StageLog *);
273 EXTERN PetscErrorCode StageLogPush(StageLog, int);
274 EXTERN PetscErrorCode StageLogPop(StageLog);
275 EXTERN PetscErrorCode StageLogGetCurrent(StageLog, int *);
276 EXTERN PetscErrorCode StageLogSetActive(StageLog, int, PetscTruth);
277 EXTERN PetscErrorCode StageLogGetActive(StageLog, int, PetscTruth *);
278 EXTERN PetscErrorCode StageLogSetVisible(StageLog, int, PetscTruth);
279 EXTERN PetscErrorCode StageLogGetVisible(StageLog, int, PetscTruth *);
280 EXTERN PetscErrorCode StageLogGetStage(StageLog, const char [], int *);
281 EXTERN PetscErrorCode StageLogGetClassRegLog(StageLog, ClassRegLog *);
282 EXTERN PetscErrorCode StageLogGetEventRegLog(StageLog, EventRegLog *);
283 EXTERN PetscErrorCode StageLogGetClassPerfLog(StageLog, int, ClassPerfLog *);
284 EXTERN PetscErrorCode StageLogGetEventPerfLog(StageLog, int, EventPerfLog *);
285 
286 /*
287      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
288    uses macros to defined the MPI operations.
289 
290      It does not work correctly from HP-UX because it processes the
291    macros in a way that sometimes it double counts, hence
292    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
293 
294      It does not work with Windows because winmpich lacks MPI_Type_size()
295 */
296 #if !defined(_petsc_mpi_uni) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
297 /*
298    Logging of MPI activities
299 */
300 
301 #define TypeSize(buff,count,type) \
302 (\
303   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PetscLogDouble) ((count)*PETSC_DUMMY_SIZE))\
304 )
305 
306 #define MPI_Irecv(buf,count, datatype,source,tag,comm,request) \
307 (\
308   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),\
309   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY\
310 )
311 
312 #define MPI_Isend(buf,count, datatype,dest,tag,comm,request) \
313 (\
314   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),\
315   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY\
316 )
317 
318 #define MPI_Startall_irecv(count,number,requests) \
319 (\
320   PETSC_DUMMY = MPI_Startall(number,requests),\
321   irecv_ct += (PetscLogDouble)(number),irecv_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
322 )
323 
324 #define MPI_Startall_isend(count,number,requests) \
325 (\
326   PETSC_DUMMY = MPI_Startall(number,requests),\
327   isend_ct += (PetscLogDouble)(number),isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
328 )
329 
330 #define MPI_Start_isend(count, requests) \
331 (\
332   PETSC_DUMMY = MPI_Start(requests),\
333   isend_ct++,isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
334 )
335 
336 #define MPI_Recv(buf,count, datatype,source,tag,comm,status) \
337 (\
338   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),\
339   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY\
340 )
341 
342 #define MPI_Send(buf,count, datatype,dest,tag,comm) \
343 (\
344   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),\
345   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY\
346 )
347 
348 #define MPI_Wait(request,status) \
349 (\
350   wait_ct++,sum_of_waits_ct++,\
351   MPI_Wait(request,status)\
352 )
353 
354 #define MPI_Waitany(a,b,c,d) \
355 (\
356   wait_any_ct++,sum_of_waits_ct++,\
357   MPI_Waitany(a,b,c,d)\
358 )
359 
360 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
361 (\
362   wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),\
363   MPI_Waitall(count,array_of_requests,array_of_statuses)\
364 )
365 
366 #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
367 (\
368   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
369 )
370 
371 #else
372 
373 #define MPI_Startall_irecv(count,number,requests) \
374 (\
375   MPI_Startall(number,requests)\
376 )
377 
378 #define MPI_Startall_isend(count,number,requests) \
379 (\
380   MPI_Startall(number,requests)\
381 )
382 
383 #define MPI_Start_isend(count, requests) \
384 (\
385   MPI_Start(requests)\
386 )
387 
388 #endif /* !_petsc_mpi_uni && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
389 
390 #else  /* ---Logging is turned off --------------------------------------------*/
391 
392 #define PetscLogFlops(n) 0
393 
394 /*
395      With logging turned off, then MPE has to be turned off
396 */
397 #define PetscLogMPEBegin()         0
398 #define PetscLogMPEDump(a)         0
399 
400 #define PetscLogEventActivate(a)   0
401 #define PetscLogEventDeactivate(a) 0
402 
403 #define PetscLogEventActivateClass(a)   0
404 #define PetscLogEventDeactivateClass(a) 0
405 
406 #define _PetscLogPLB                        0
407 #define _PetscLogPLE                        0
408 #define _PetscLogPHC                        0
409 #define _PetscLogPHD                        0
410 #define PetscGetFlops(a)                (*(a) = 0.0,0)
411 #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
412 #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
413 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
414 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
415 #define PetscLogObjectParent(p,c)
416 #define PetscLogObjectParents(p,n,c)
417 #define PetscLogObjectCreate(h)
418 #define PetscLogObjectDestroy(h)
419 #define PetscLogObjectMemory(p,m)
420 #define PetscLogDestroy()                   0
421 #define PetscLogStagePush(a)                0
422 #define PetscLogStagePop()                  0
423 #define PetscLogStageRegister(a,b)          0
424 #define PetscLogStagePrint(a,flg)           0
425 #define PetscLogPrintSummary(comm,file)     0
426 #define PetscLogBegin()                     0
427 #define PetscLogTraceBegin(file)            0
428 #define PetscLogSet(lb,le)                  0
429 #define PetscLogAllBegin()                  0
430 #define PetscLogDump(c)                     0
431 #define PetscLogEventRegister(a,b,c)        0
432 #define PetscLogObjects(a)                  0
433 #define PetscLogActions(a)                  0
434 EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
435 
436 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
437 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
438 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
439 #define MPI_Start_isend(count,requests) MPI_Start(requests)
440 
441 /* Creation and destruction functions */
442 #define StageLogCreate(stageLog)                     0
443 #define StageLogDestroy(stageLog)                    0
444 /* Registration functions */
445 #define StageLogRegister(stageLog, name, stage)      0
446 /* Runtime functions */
447 #define PetscLogGetStageLog(stageLog)                0
448 #define StageLogPush(stageLog, stage)                0
449 #define StageLogPop(stageLog)                        0
450 #define StageLogGetCurrent(stageLog, stage)          0
451 #define StageLogSetActive(stageLog, stage, active)   0
452 #define StageLogGetActive(stageLog, stage, active)   0
453 #define StageLogSetVisible(stageLog, stage, visible) 0
454 #define StageLogGetVisible(stageLog, stage, visible) 0
455 #define StageLogGetStage(stageLog, name, stage)      0
456 
457 #endif   /* PETSC_USE_LOG */
458 
459 extern PetscTruth PetscPreLoadingUsed;       /* true if we are or have done preloading */
460 extern PetscTruth PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
461 
462 #define PreLoadBegin(flag,name) \
463 {\
464   PetscTruth PreLoading = flag;\
465   int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
466   _3_ierr = PetscOptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
467   PreLoadMax = (int)(PreLoading);\
468   PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
469   for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
470     PetscPreLoadingOn = PreLoading;\
471     _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
472     if (PreLoadIt>0) {\
473       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
474     } else {\
475       _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
476     }\
477     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
478     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
479 
480 #define PreLoadEnd() \
481     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
482     PreLoading = PETSC_FALSE;\
483   }\
484 }
485 
486 #define PreLoadStage(name) \
487   _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
488   if (PreLoadIt>0) {\
489     _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
490   } else {\
491     _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
492   }\
493   _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
494   _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
495 
496 PETSC_EXTERN_CXX_END
497 #endif
498