xref: /petsc/include/petsclog.h (revision 9cc1f4e33c149b29186aeebaa37298fc478f8043)
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 PetscCookie PETSC_LARGEST_COOKIE;
16 #define PETSC_EVENT  1311311
17 extern PetscEvent PETSC_LARGEST_EVENT;
18 
19 /* Events for the Petsc standard library */
20 extern PetscEvent 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(PetscCookie);
28 EXTERN PetscErrorCode        PetscLogInfoActivateClass(PetscCookie);
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)(PetscEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
71 EXTERN PetscErrorCode (*_PetscLogPLE)(PetscEvent,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(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
96                    PetscErrorCode (*)(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(PetscEvent*, const char[], PetscCookie);
114 EXTERN PetscErrorCode PetscLogEventActivate(PetscEvent);
115 EXTERN PetscErrorCode PetscLogEventDeactivate(PetscEvent);
116 EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscEvent, PetscTruth);
117 EXTERN PetscErrorCode PetscLogEventActivateClass(PetscCookie);
118 EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscCookie);
119 /* Class functions */
120 EXTERN PetscErrorCode PetscLogClassRegister(PetscCookie*, 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   PetscCookie cookie; /* The integer identifying this class */
166 } ClassRegInfo;
167 
168 typedef struct _EventRegInfo {
169   char            *name;   /* The name of this event */
170   PetscCookie 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 typedef struct _EventRegLog *EventRegLog;
178 struct _EventRegLog {
179   int           numEvents; /* The number of registered events */
180   int           maxEvents; /* The maximum number of events */
181   EventRegInfo *eventInfo; /* The registration information for each event */
182 };
183 
184 typedef struct _EventPerfLog *EventPerfLog;
185 struct _EventPerfLog {
186   int            numEvents; /* The number of logging events */
187   int            maxEvents; /* The maximum number of events */
188   EventPerfInfo *eventInfo; /* The performance information for each event */
189 };
190 
191 /* The structure for logging class information */
192 typedef struct _ClassRegLog *ClassRegLog;
193 struct _ClassRegLog {
194   int           numClasses; /* The number of classes registered */
195   int           maxClasses; /* The maximum number of classes */
196   ClassRegInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
197 };
198 
199 typedef struct _ClassPerfLog *ClassPerfLog;
200 struct _ClassPerfLog {
201   int            numClasses; /* The number of logging classes */
202   int            maxClasses; /* The maximum number of classes */
203   ClassPerfInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
204 };
205 
206 /* The structures for logging in stages */
207 typedef struct _StageInfo {
208   char         *name;     /* The stage name */
209   PetscTruth    used;     /* The stage was pushed on this processor */
210   EventPerfInfo perfInfo; /* The stage performance information */
211   EventPerfLog  eventLog; /* The event information for this stage */
212   ClassPerfLog  classLog; /* The class information for this stage */
213 } StageInfo;
214 
215 struct _StageLog {
216   /* Size information */
217   int         numStages; /* The number of registered stages */
218   int         maxStages; /* The maximum number of stages */
219   /* Runtime information */
220   IntStack    stack;     /* The stack for active stages */
221   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
222   /* Stage specific information */
223   StageInfo  *stageInfo; /* The information for each stage */
224   EventRegLog eventLog;  /* The registered events */
225   ClassRegLog classLog;  /* The registered classes */
226 };
227 
228 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0; \
229 {\
230   int _2_ierr;\
231   if (_PetscLogPLB && \
232       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
233       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
234     _2_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);\
235     _2_ierr = MPI_Barrier(cm);CHKERRQ(_2_ierr);\
236     _2_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);\
237   }\
238   _2_ierr = PetscLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(_2_ierr);\
239 }
240 
241 #define PetscLogEventBegin(e,o1,o2,o3,o4) 0; \
242 {\
243   if (_PetscLogPLB && \
244       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
245       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
246     (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
247   }\
248   PETSC_LOG_EVENT_MPE_BEGIN(e); \
249 }
250 
251 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
252 
253 #define PetscLogEventEnd(e,o1,o2,o3,o4) 0; \
254 {\
255   if (_PetscLogPLE && \
256       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
257       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
258     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
259   }\
260   PETSC_LOG_EVENT_MPE_END(e); \
261 }
262 
263 /* Creation and destruction functions */
264 EXTERN PetscErrorCode StageLogCreate(StageLog *);
265 EXTERN PetscErrorCode StageLogDestroy(StageLog);
266 /* Registration functions */
267 EXTERN PetscErrorCode StageLogRegister(StageLog, const char [], int *);
268 /* Runtime functions */
269 EXTERN PetscErrorCode PetscLogGetStageLog(StageLog *);
270 EXTERN PetscErrorCode StageLogPush(StageLog, int);
271 EXTERN PetscErrorCode StageLogPop(StageLog);
272 EXTERN PetscErrorCode StageLogGetCurrent(StageLog, int *);
273 EXTERN PetscErrorCode StageLogSetActive(StageLog, int, PetscTruth);
274 EXTERN PetscErrorCode StageLogGetActive(StageLog, int, PetscTruth *);
275 EXTERN PetscErrorCode StageLogSetVisible(StageLog, int, PetscTruth);
276 EXTERN PetscErrorCode StageLogGetVisible(StageLog, int, PetscTruth *);
277 EXTERN PetscErrorCode StageLogGetStage(StageLog, const char [], int *);
278 EXTERN PetscErrorCode StageLogGetClassRegLog(StageLog, ClassRegLog *);
279 EXTERN PetscErrorCode StageLogGetEventRegLog(StageLog, EventRegLog *);
280 EXTERN PetscErrorCode StageLogGetClassPerfLog(StageLog, int, ClassPerfLog *);
281 EXTERN PetscErrorCode StageLogGetEventPerfLog(StageLog, int, EventPerfLog *);
282 
283 /*
284      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
285    uses macros to defined the MPI operations.
286 
287      It does not work correctly from HP-UX because it processes the
288    macros in a way that sometimes it double counts, hence
289    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
290 
291      It does not work with Windows because winmpich lacks MPI_Type_size()
292 */
293 #if !defined(_petsc_mpi_uni) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
294 /*
295    Logging of MPI activities
296 */
297 
298 #define TypeSize(buff,count,type) \
299 (\
300   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PetscLogDouble) ((count)*PETSC_DUMMY_SIZE))\
301 )
302 
303 #define MPI_Irecv(buf,count, datatype,source,tag,comm,request) \
304 (\
305   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),\
306   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY\
307 )
308 
309 #define MPI_Isend(buf,count, datatype,dest,tag,comm,request) \
310 (\
311   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),\
312   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY\
313 )
314 
315 #define MPI_Startall_irecv(count,number,requests) \
316 (\
317   PETSC_DUMMY = MPI_Startall(number,requests),\
318   irecv_ct += (PetscLogDouble)(number),irecv_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
319 )
320 
321 #define MPI_Startall_isend(count,number,requests) \
322 (\
323   PETSC_DUMMY = MPI_Startall(number,requests),\
324   isend_ct += (PetscLogDouble)(number),isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
325 )
326 
327 #define MPI_Start_isend(count, requests) \
328 (\
329   PETSC_DUMMY = MPI_Start(requests),\
330   isend_ct++,isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
331 )
332 
333 #define MPI_Recv(buf,count, datatype,source,tag,comm,status) \
334 (\
335   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),\
336   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY\
337 )
338 
339 #define MPI_Send(buf,count, datatype,dest,tag,comm) \
340 (\
341   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),\
342   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY\
343 )
344 
345 #define MPI_Wait(request,status) \
346 (\
347   wait_ct++,sum_of_waits_ct++,\
348   MPI_Wait(request,status)\
349 )
350 
351 #define MPI_Waitany(a,b,c,d) \
352 (\
353   wait_any_ct++,sum_of_waits_ct++,\
354   MPI_Waitany(a,b,c,d)\
355 )
356 
357 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
358 (\
359   wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),\
360   MPI_Waitall(count,array_of_requests,array_of_statuses)\
361 )
362 
363 #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
364 (\
365   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
366 )
367 
368 #else
369 
370 #define MPI_Startall_irecv(count,number,requests) \
371 (\
372   MPI_Startall(number,requests)\
373 )
374 
375 #define MPI_Startall_isend(count,number,requests) \
376 (\
377   MPI_Startall(number,requests)\
378 )
379 
380 #define MPI_Start_isend(count, requests) \
381 (\
382   MPI_Start(requests)\
383 )
384 
385 #endif /* !_petsc_mpi_uni && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
386 
387 #else  /* ---Logging is turned off --------------------------------------------*/
388 
389 #define PetscLogFlops(n) 0
390 
391 /*
392      With logging turned off, then MPE has to be turned off
393 */
394 #define PetscLogMPEBegin()         0
395 #define PetscLogMPEDump(a)         0
396 
397 #define PetscLogEventActivate(a)   0
398 #define PetscLogEventDeactivate(a) 0
399 
400 #define PetscLogEventActivateClass(a)   0
401 #define PetscLogEventDeactivateClass(a) 0
402 
403 #define _PetscLogPLB                        0
404 #define _PetscLogPLE                        0
405 #define _PetscLogPHC                        0
406 #define _PetscLogPHD                        0
407 #define PetscGetFlops(a)                (*(a) = 0.0,0)
408 #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
409 #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
410 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
411 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
412 #define PetscLogObjectParent(p,c)
413 #define PetscLogObjectParents(p,n,c)
414 #define PetscLogObjectCreate(h)
415 #define PetscLogObjectDestroy(h)
416 #define PetscLogObjectMemory(p,m)
417 #define PetscLogDestroy()                   0
418 #define PetscLogStagePush(a)                0
419 #define PetscLogStagePop()                  0
420 #define PetscLogStageRegister(a,b)          0
421 #define PetscLogStagePrint(a,flg)           0
422 #define PetscLogPrintSummary(comm,file)     0
423 #define PetscLogBegin()                     0
424 #define PetscLogTraceBegin(file)            0
425 #define PetscLogSet(lb,le)                  0
426 #define PetscLogAllBegin()                  0
427 #define PetscLogDump(c)                     0
428 #define PetscLogEventRegister(a,b,c)        0
429 #define PetscLogObjects(a)                  0
430 #define PetscLogActions(a)                  0
431 EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
432 
433 /* If PETSC_USE_LOG is NOT defined, these still need to be! */
434 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
435 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
436 #define MPI_Start_isend(count,requests) MPI_Start(requests)
437 
438 /* Creation and destruction functions */
439 #define StageLogCreate(stageLog)                     0
440 #define StageLogDestroy(stageLog)                    0
441 /* Registration functions */
442 #define StageLogRegister(stageLog, name, stage)      0
443 /* Runtime functions */
444 #define PetscLogGetStageLog(stageLog)                0
445 #define StageLogPush(stageLog, stage)                0
446 #define StageLogPop(stageLog)                        0
447 #define StageLogGetCurrent(stageLog, stage)          0
448 #define StageLogSetActive(stageLog, stage, active)   0
449 #define StageLogGetActive(stageLog, stage, active)   0
450 #define StageLogSetVisible(stageLog, stage, visible) 0
451 #define StageLogGetVisible(stageLog, stage, visible) 0
452 #define StageLogGetStage(stageLog, name, stage)      0
453 
454 #endif   /* PETSC_USE_LOG */
455 
456 extern PetscTruth PetscPreLoadingUsed;       /* true if we are or have done preloading */
457 extern PetscTruth PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
458 
459 #define PreLoadBegin(flag,name) \
460 {\
461   PetscTruth PreLoading = flag;\
462   int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
463   _3_ierr = PetscOptionsGetLogical(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(&_stageNum,name);CHKERRQ(_3_ierr);\
473     }\
474     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!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(&_stageNum,name);CHKERRQ(_3_ierr);\
489   }\
490   _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
491   _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
492 
493 PETSC_EXTERN_CXX_END
494 #endif
495