xref: /petsc/include/petsclog.h (revision e47d2de249347d92e0688f202bcd23c68c46d7c3)
197bb86f7SLois Curfman McInnes /*
27588ac45SBarry Smith     Defines profile/logging in PETSc.
397bb86f7SLois Curfman McInnes */
497bb86f7SLois Curfman McInnes 
5b0a32e0cSBarry Smith #if !defined(__PetscLog_H)
6b0a32e0cSBarry Smith #define __PetscLog_H
7d382aafbSBarry Smith #include "petscsys.h"
8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
9c8d78d4dSSatish Balay 
10b859824cSBarry Smith /*MC
11b859824cSBarry Smith     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
12b859824cSBarry Smith      code.
13b859824cSBarry Smith 
14b859824cSBarry Smith     Level: intermediate
15b859824cSBarry Smith 
16b859824cSBarry Smith .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
17b859824cSBarry Smith M*/
18b859824cSBarry Smith typedef int PetscLogEvent;
19b859824cSBarry Smith 
20b859824cSBarry Smith /*MC
21b859824cSBarry Smith     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
22b859824cSBarry Smith 
23b859824cSBarry Smith     Level: intermediate
24b859824cSBarry Smith 
25b859824cSBarry Smith .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent
26b859824cSBarry Smith M*/
27b859824cSBarry Smith typedef int PetscLogStage;
28b859824cSBarry Smith 
298ba1e511SMatthew Knepley #define PETSC_EVENT  1311311
30166c7f25SBarry Smith extern PetscLogEvent PETSC_LARGEST_EVENT;
3197bb86f7SLois Curfman McInnes 
3219b02663SBarry Smith /* Global flop counter */
33205a32c2SJed Brown extern PetscLogDouble  petsc_TotalFlops;
3490fdf44cSMatthew Knepley extern PetscLogDouble petsc_tmp_flops;
3519b02663SBarry Smith 
36edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */
377087cfbeSBarry Smith extern PetscErrorCode  PetscInfo_Private(const char[],void*,const char[],...);
386cf91177SBarry Smith #if defined(PETSC_USE_INFO)
392714b66aSJed Brown #define PetscInfo(A,S)                       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S)
402714b66aSJed Brown #define PetscInfo1(A,S,a1)                   PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1)
412714b66aSJed Brown #define PetscInfo2(A,S,a1,a2)                PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2)
422714b66aSJed Brown #define PetscInfo3(A,S,a1,a2,a3)             PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3)
432714b66aSJed Brown #define PetscInfo4(A,S,a1,a2,a3,a4)          PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4)
442714b66aSJed Brown #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5)
452714b66aSJed Brown #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6)
462714b66aSJed Brown #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)
4763ba0a88SBarry Smith #else
48ae15b995SBarry Smith #define PetscInfo(A,S)                       0
49ae15b995SBarry Smith #define PetscInfo1(A,S,a1)                   0
50ae15b995SBarry Smith #define PetscInfo2(A,S,a1,a2)                0
51ae15b995SBarry Smith #define PetscInfo3(A,S,a1,a2,a3)             0
52ae15b995SBarry Smith #define PetscInfo4(A,S,a1,a2,a3,a4)          0
53ae15b995SBarry Smith #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       0
54ae15b995SBarry Smith #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    0
55ae15b995SBarry Smith #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
5663ba0a88SBarry Smith #endif
577087cfbeSBarry Smith extern PetscErrorCode  PetscInfoDeactivateClass(PetscClassId);
587087cfbeSBarry Smith extern PetscErrorCode  PetscInfoActivateClass(PetscClassId);
597087cfbeSBarry Smith extern PetscBool       PetscLogPrintInfo;  /* if true, indicates PetscInfo() is turned on */
60614700edSBarry Smith 
6131d06abdSBarry Smith /* We must make the following structures available to access the event
6231d06abdSBarry Smith      activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public
6331d06abdSBarry Smith      API and are not intended to be used by other parts of PETSc or by users.
64d49d4b11SBarry Smith 
6531d06abdSBarry Smith      The code that manipulates these structures is in src/sys/plog/utils.
6631d06abdSBarry Smith */
67aa213bdcSJed Brown typedef struct _n_PetscIntStack *PetscIntStack;
686a6a9b46SSatish Balay 
69c60ec953SBarry Smith /*
70aa213bdcSJed Brown     PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has
71c60ec953SBarry Smith        static information about it, the second collects statistics on how many objects of the class are created,
72c60ec953SBarry Smith        how much memory they use, etc.
73c60ec953SBarry Smith 
74aa213bdcSJed Brown     PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes.
75c60ec953SBarry Smith */
766a6a9b46SSatish Balay typedef struct  {
77c60ec953SBarry Smith   char           *name;   /* The class name */
78c60ec953SBarry Smith   PetscClassId   classid; /* The integer identifying this class */
79aa213bdcSJed Brown } PetscClassRegInfo;
806a6a9b46SSatish Balay 
816a6a9b46SSatish Balay typedef struct {
820700a824SBarry Smith   PetscClassId   id;           /* The integer identifying this class */
836a6a9b46SSatish Balay   int            creations;    /* The number of objects of this class created */
846a6a9b46SSatish Balay   int            destructions; /* The number of objects of this class destroyed */
856a6a9b46SSatish Balay   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
866a6a9b46SSatish Balay   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
87aa213bdcSJed Brown } PetscClassPerfInfo;
886a6a9b46SSatish Balay 
89aa213bdcSJed Brown typedef struct _n_PetscClassRegLog *PetscClassRegLog;
90aa213bdcSJed Brown struct _n_PetscClassRegLog {
91c60ec953SBarry Smith   int               numClasses; /* The number of classes registered */
92c60ec953SBarry Smith   int               maxClasses; /* The maximum number of classes */
93aa213bdcSJed Brown   PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
94c60ec953SBarry Smith };
956a6a9b46SSatish Balay 
96aa213bdcSJed Brown typedef struct _n_PetscClassPerfLog *PetscClassPerfLog;
97aa213bdcSJed Brown struct _n_PetscClassPerfLog {
98c60ec953SBarry Smith   int                numClasses; /* The number of logging classes */
99c60ec953SBarry Smith   int                maxClasses; /* The maximum number of classes */
100aa213bdcSJed Brown   PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
101c60ec953SBarry Smith };
102c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/
103c60ec953SBarry Smith /*
104aa213bdcSJed Brown     PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has
105c60ec953SBarry Smith        static information about it, the second collects statistics on how many times the event is used, how
106c60ec953SBarry Smith        much time it takes, etc.
107c60ec953SBarry Smith 
108aa213bdcSJed Brown     PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one
109c60ec953SBarry Smith       of these for each stage.
110c60ec953SBarry Smith 
111c60ec953SBarry Smith */
1126a6a9b46SSatish Balay typedef struct {
1136a6a9b46SSatish Balay   char         *name;         /* The name of this event */
114c60ec953SBarry Smith   PetscClassId classid;       /* The class the event is associated with */
1156a6a9b46SSatish Balay #if defined (PETSC_HAVE_MPE)
1166a6a9b46SSatish Balay   int          mpe_id_begin; /* MPE IDs that define the event */
1176a6a9b46SSatish Balay   int          mpe_id_end;
1186a6a9b46SSatish Balay #endif
119aa213bdcSJed Brown } PetscEventRegInfo;
1206a6a9b46SSatish Balay 
121c60ec953SBarry Smith typedef struct {
122c60ec953SBarry Smith   int            id;            /* The integer identifying this event */
123ace3abfcSBarry Smith   PetscBool      active;        /* The flag to activate logging */
124ace3abfcSBarry Smith   PetscBool      visible;       /* The flag to print info in summary */
125c60ec953SBarry Smith   int            depth;         /* The nesting depth of the event call */
126c60ec953SBarry Smith   int            count;         /* The number of times this event was executed */
127c60ec953SBarry Smith   PetscLogDouble flops;         /* The flops used in this event */
128c60ec953SBarry Smith   PetscLogDouble time;          /* The time taken for this event */
129c60ec953SBarry Smith   PetscLogDouble numMessages;   /* The number of messages in this event */
130c60ec953SBarry Smith   PetscLogDouble messageLength; /* The total message lengths in this event */
131c60ec953SBarry Smith   PetscLogDouble numReductions; /* The number of reductions in this event */
132aa213bdcSJed Brown } PetscEventPerfInfo;
133c60ec953SBarry Smith 
134aa213bdcSJed Brown typedef struct _n_PetscEventRegLog *PetscEventRegLog;
135aa213bdcSJed Brown struct _n_PetscEventRegLog {
1366a6a9b46SSatish Balay   int               numEvents;  /* The number of registered events */
1376a6a9b46SSatish Balay   int               maxEvents;  /* The maximum number of events */
138aa213bdcSJed Brown   PetscEventRegInfo *eventInfo; /* The registration information for each event */
1396a6a9b46SSatish Balay };
1406a6a9b46SSatish Balay 
141aa213bdcSJed Brown typedef struct _n_PetscEventPerfLog *PetscEventPerfLog;
142aa213bdcSJed Brown struct _n_PetscEventPerfLog {
1436a6a9b46SSatish Balay   int                numEvents;  /* The number of logging events */
1446a6a9b46SSatish Balay   int                maxEvents;  /* The maximum number of events */
145aa213bdcSJed Brown   PetscEventPerfInfo *eventInfo; /* The performance information for each event */
1466a6a9b46SSatish Balay };
147c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/
148c60ec953SBarry Smith /*
149aa213bdcSJed Brown    PetscStageInfo - Contains all the information about a particular stage.
1506a6a9b46SSatish Balay 
151aa213bdcSJed Brown    PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code.
152c60ec953SBarry Smith */
153aa213bdcSJed Brown typedef struct _PetscStageInfo {
1546a6a9b46SSatish Balay   char               *name;     /* The stage name */
155ace3abfcSBarry Smith   PetscBool          used;      /* The stage was pushed on this processor */
156aa213bdcSJed Brown   PetscEventPerfInfo perfInfo;  /* The stage performance information */
157aa213bdcSJed Brown   PetscEventPerfLog  eventLog;  /* The event information for this stage */
158aa213bdcSJed Brown   PetscClassPerfLog  classLog;  /* The class information for this stage */
159aa213bdcSJed Brown } PetscStageInfo;
1606a6a9b46SSatish Balay 
161aa213bdcSJed Brown typedef struct _n_PetscStageLog *PetscStageLog;
162205a32c2SJed Brown extern  PetscStageLog petsc_stageLog;
163aa213bdcSJed Brown struct _n_PetscStageLog {
1646a6a9b46SSatish Balay   int              numStages;   /* The number of registered stages */
1656a6a9b46SSatish Balay   int              maxStages;   /* The maximum number of stages */
166aa213bdcSJed Brown   PetscIntStack    stack;       /* The stack for active stages */
167aa213bdcSJed Brown   int              curStage;    /* The current stage (only used in macros so we don't call PetscIntStackTop) */
168aa213bdcSJed Brown   PetscStageInfo   *stageInfo;  /* The information for each stage */
169aa213bdcSJed Brown   PetscEventRegLog eventLog;    /* The registered events */
170aa213bdcSJed Brown   PetscClassRegLog classLog;    /* The registered classes */
1716a6a9b46SSatish Balay };
1726a6a9b46SSatish Balay 
173aa482453SBarry Smith #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
174614700edSBarry Smith 
175da63de55SLois Curfman McInnes /*
176da63de55SLois Curfman McInnes    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
177da63de55SLois Curfman McInnes 
178da63de55SLois Curfman McInnes    For the complex numbers version, note that
179da63de55SLois Curfman McInnes        1 complex addition = 2 flops
180da63de55SLois Curfman McInnes        1 complex multiplication = 6 flops,
181da63de55SLois Curfman McInnes    where we define 1 flop as that for a double precision scalar.  We roughly approximate
182da63de55SLois Curfman McInnes    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
183da63de55SLois Curfman McInnes    to the assumption that we're counting mostly additions and multiplications -- and
184da63de55SLois Curfman McInnes    roughly the same number of each.  More accurate counting could be done by distinguishing
185da63de55SLois Curfman McInnes    among the various arithmetic operations.
186da63de55SLois Curfman McInnes  */
187da63de55SLois Curfman McInnes 
188aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
189542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0
190da63de55SLois Curfman McInnes #else
191542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0
192bf3909cdSBarry Smith #endif
193bf3909cdSBarry Smith 
194bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG)
195205a32c2SJed Brown #define PetscLogFlops(n) (petsc_tmp_flops = (PETSC_FLOPS_PER_OP*((PetscLogDouble)n)), ((petsc_tmp_flops < 0) ? PETSC_ERR_FLOP_COUNT : (petsc_TotalFlops += petsc_tmp_flops,0)))
196205a32c2SJed Brown #define PetscLogFlopsNoError(n) (petsc_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
197bf3909cdSBarry Smith #else
198205a32c2SJed Brown #define PetscLogFlops(n) (petsc_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n),0)
199205a32c2SJed Brown #define PetscLogFlopsNoError(n) (petsc_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
200da63de55SLois Curfman McInnes #endif
20177c4ece6SBarry Smith 
202aa482453SBarry Smith #if defined (PETSC_HAVE_MPE)
20377c4ece6SBarry Smith #include "mpe.h"
2047087cfbeSBarry Smith extern PetscErrorCode         PetscLogMPEBegin(void);
2057087cfbeSBarry Smith extern PetscErrorCode         PetscLogMPEDump(const char[]);
206ace3abfcSBarry Smith extern PetscBool  UseMPE;
207043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
208205a32c2SJed Brown   ((UseMPE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
209205a32c2SJed Brown    MPE_Log_event(petsc_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)
210043328b6SSatish Balay 
211043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e) \
212205a32c2SJed Brown   ((UseMPE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
213205a32c2SJed Brown    MPE_Log_event(petsc_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0)
214043328b6SSatish Balay 
215614700edSBarry Smith #else
21652e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0
21752e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_END(e)   0
21877c4ece6SBarry Smith #endif
21977c4ece6SBarry Smith 
2208b5db460SBarry Smith extern  PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
2218b5db460SBarry Smith extern  PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
2228b5db460SBarry Smith extern  PetscErrorCode (*PetscLogPHC)(PetscObject);
2238b5db460SBarry Smith extern  PetscErrorCode (*PetscLogPHD)(PetscObject);
22477c4ece6SBarry Smith 
225043328b6SSatish Balay #define PetscLogObjectParent(p,c) \
226e0f8cd26SJed Brown   (c && p && (((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id,0))
22752e6d16bSBarry Smith 
228efee365bSSatish Balay #define PetscLogObjectParents(p,n,d)  0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}}
2298b5db460SBarry Smith #define PetscLogObjectCreate(h)      ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)h) : 0)
2308b5db460SBarry Smith #define PetscLogObjectDestroy(h)     ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)h) : 0)
23152e6d16bSBarry Smith #define PetscLogObjectMemory(p,m)    (((PetscObject)(p))->mem += (m),0)
2328ba1e511SMatthew Knepley /* Initialization functions */
2337087cfbeSBarry Smith extern PetscErrorCode  PetscLogBegin(void);
2347087cfbeSBarry Smith extern PetscErrorCode  PetscLogAllBegin(void);
2357087cfbeSBarry Smith extern PetscErrorCode  PetscLogTraceBegin(FILE *);
2367087cfbeSBarry Smith extern PetscErrorCode  PetscLogActions(PetscBool);
2377087cfbeSBarry Smith extern PetscErrorCode  PetscLogObjects(PetscBool);
2388ba1e511SMatthew Knepley /* General functions */
2397087cfbeSBarry Smith extern PetscErrorCode  PetscLogGetRGBColor(const char*[]);
2407087cfbeSBarry Smith extern PetscErrorCode  PetscLogDestroy(void);
2417087cfbeSBarry Smith extern PetscErrorCode  PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
2426849ba73SBarry Smith                    PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
2437087cfbeSBarry Smith extern PetscErrorCode  PetscLogObjectState(PetscObject, const char[], ...);
2448ba1e511SMatthew Knepley /* Output functions */
24591eabc43SBarry Smith extern PetscErrorCode  PetscLogView(PetscViewer);
24691eabc43SBarry Smith extern PetscErrorCode  PetscLogViewPython(PetscViewer);
2477087cfbeSBarry Smith extern PetscErrorCode  PetscLogPrintDetailed(MPI_Comm, const char[]);
2487087cfbeSBarry Smith extern PetscErrorCode  PetscLogDump(const char[]);
24931d06abdSBarry Smith 
2507087cfbeSBarry Smith extern PetscErrorCode  PetscGetFlops(PetscLogDouble *);
25131d06abdSBarry Smith 
2527087cfbeSBarry Smith extern PetscErrorCode  PetscLogStageRegister(const char[],PetscLogStage*);
2537087cfbeSBarry Smith extern PetscErrorCode  PetscLogStagePush(PetscLogStage);
2547087cfbeSBarry Smith extern PetscErrorCode  PetscLogStagePop(void);
2557087cfbeSBarry Smith extern PetscErrorCode  PetscLogStageSetActive(PetscLogStage, PetscBool );
2567087cfbeSBarry Smith extern PetscErrorCode  PetscLogStageGetActive(PetscLogStage, PetscBool  *);
2577087cfbeSBarry Smith extern PetscErrorCode  PetscLogStageSetVisible(PetscLogStage, PetscBool );
2587087cfbeSBarry Smith extern PetscErrorCode  PetscLogStageGetVisible(PetscLogStage, PetscBool  *);
2597087cfbeSBarry Smith extern PetscErrorCode  PetscLogStageGetId(const char [], PetscLogStage *);
2608ba1e511SMatthew Knepley /* Event functions */
2617087cfbeSBarry Smith extern PetscErrorCode  PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*);
2627087cfbeSBarry Smith extern PetscErrorCode  PetscLogEventActivate(PetscLogEvent);
2637087cfbeSBarry Smith extern PetscErrorCode  PetscLogEventDeactivate(PetscLogEvent);
2647087cfbeSBarry Smith extern PetscErrorCode  PetscLogEventSetActiveAll(PetscLogEvent, PetscBool );
2657087cfbeSBarry Smith extern PetscErrorCode  PetscLogEventActivateClass(PetscClassId);
2667087cfbeSBarry Smith extern PetscErrorCode  PetscLogEventDeactivateClass(PetscClassId);
2679afaeae2SBarry Smith 
2688ba1e511SMatthew Knepley 
2698ba1e511SMatthew Knepley /* Global counters */
270ad39c06fSJed Brown extern  PetscLogDouble petsc_irecv_ct;
271ad39c06fSJed Brown extern  PetscLogDouble petsc_isend_ct;
272ad39c06fSJed Brown extern  PetscLogDouble petsc_recv_ct;
273ad39c06fSJed Brown extern  PetscLogDouble petsc_send_ct;
274ad39c06fSJed Brown extern  PetscLogDouble petsc_irecv_len;
275ad39c06fSJed Brown extern  PetscLogDouble petsc_isend_len;
276ad39c06fSJed Brown extern  PetscLogDouble petsc_recv_len;
277ad39c06fSJed Brown extern  PetscLogDouble petsc_send_len;
278ad39c06fSJed Brown extern  PetscLogDouble petsc_allreduce_ct;
279ad39c06fSJed Brown extern  PetscLogDouble petsc_gather_ct;
280ad39c06fSJed Brown extern  PetscLogDouble petsc_scatter_ct;
281ad39c06fSJed Brown extern  PetscLogDouble petsc_wait_ct;
282ad39c06fSJed Brown extern  PetscLogDouble petsc_wait_any_ct;
283ad39c06fSJed Brown extern  PetscLogDouble petsc_wait_all_ct;
284ad39c06fSJed Brown extern  PetscLogDouble petsc_sum_of_waits_ct;
2858ba1e511SMatthew Knepley 
28652e6d16bSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
2878b5db460SBarry Smith   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active &&  petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
28852e6d16bSBarry Smith     (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \
28952e6d16bSBarry Smith    PetscLogEventBegin((e)+1,o1,o2,o3,o4))
29077c4ece6SBarry Smith 
29152e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \
2928b5db460SBarry Smith   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
2938b5db460SBarry Smith     (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
29452e6d16bSBarry Smith   PETSC_LOG_EVENT_MPE_BEGIN(e))
295043328b6SSatish Balay 
296b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
297043328b6SSatish Balay 
29852e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2998b5db460SBarry Smith   (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
3008b5db460SBarry Smith     (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
30152e6d16bSBarry Smith   PETSC_LOG_EVENT_MPE_END(e))
30277c4ece6SBarry Smith 
30309573ac7SBarry Smith extern PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*);
30409573ac7SBarry Smith extern PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent);
305003131ecSBarry Smith 
306ce85283eSBarry Smith /*
307f621e05eSBarry Smith      These are used internally in the PETSc routines to keep a count of MPI messages and
308f621e05eSBarry Smith    their sizes.
309f621e05eSBarry Smith 
3103c94ec11SBarry Smith      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
311ce85283eSBarry Smith    uses macros to defined the MPI operations.
31215308354SBarry Smith 
31315308354SBarry Smith      It does not work correctly from HP-UX because it processes the
314bb4af37aSBarry Smith    macros in a way that sometimes it double counts, hence
315b6410449SSatish Balay    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
3167c1e34a4SSatish Balay 
317f569fd43SBarry Smith      It does not work with Windows because winmpich lacks MPI_Type_size()
318ce85283eSBarry Smith */
319c8217ed5SSatish Balay #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
32077a39924SBarry Smith /*
32177a39924SBarry Smith    Logging of MPI activities
32277a39924SBarry Smith */
323ad39c06fSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type)
324f95db71bSBarry Smith {
325618e35e3SBarry Smith   PetscMPIInt mysize; return  (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0));
326f95db71bSBarry Smith }
32777a39924SBarry Smith 
328ad39c06fSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, PetscLogDouble *buff,PetscMPIInt *counts,MPI_Datatype type)
3293b9284c0SMatthew G Knepley {
3303b9284c0SMatthew G Knepley   PetscMPIInt mysize, commsize, p;
3313b9284c0SMatthew G Knepley   PetscErrorCode _myierr;
3323b9284c0SMatthew G Knepley 
3333b9284c0SMatthew G Knepley   _myierr = MPI_Comm_size(comm,&commsize);CHKERRQ(_myierr);
3343b9284c0SMatthew G Knepley   _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr);
3353b9284c0SMatthew G Knepley   for(p = 0; p < commsize; ++p) {
3363b9284c0SMatthew G Knepley     *buff += (PetscLogDouble) (counts[p]*mysize);
3373b9284c0SMatthew G Knepley   }
3383b9284c0SMatthew G Knepley   return 0;
3393b9284c0SMatthew G Knepley }
3403b9284c0SMatthew G Knepley 
34177a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
342ad39c06fSJed Brown  ((petsc_irecv_ct++,0) || PetscMPITypeSize(&petsc_irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request))
34315308354SBarry Smith 
34477a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
345ad39c06fSJed Brown  ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request))
34615308354SBarry Smith 
3470d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
348ad39c06fSJed Brown  ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
3490d4b0b6cSBarry Smith 
3500d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
351ad39c06fSJed Brown  ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
3520d4b0b6cSBarry Smith 
3530d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \
354ad39c06fSJed Brown  ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Start(requests))
3550d4b0b6cSBarry Smith 
356ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
357ad39c06fSJed Brown  ((petsc_recv_ct++,0) || PetscMPITypeSize(&petsc_recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status))
35815308354SBarry Smith 
35977a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \
360ad39c06fSJed Brown  ((petsc_send_ct++,0) || PetscMPITypeSize(&petsc_send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm))
36177a39924SBarry Smith 
36277a39924SBarry Smith #define MPI_Wait(request,status) \
363ad39c06fSJed Brown  ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait(request,status))
36477a39924SBarry Smith 
36577a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \
366ad39c06fSJed Brown  ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))
36777a39924SBarry Smith 
36877a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
369ad39c06fSJed Brown  ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses))
37077a39924SBarry Smith 
37177a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
372ad39c06fSJed Brown  ((petsc_allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))
3733914022bSBarry Smith 
3743b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
375ad39c06fSJed Brown  ((petsc_allreduce_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm))
3763b9284c0SMatthew G Knepley 
3773b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
378ad39c06fSJed Brown  ((petsc_allreduce_ct++,0) || PetscMPITypeSizeComm(comm,&petsc_send_len,sendcnts,sendtype) || MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm))
3793b9284c0SMatthew G Knepley 
38001faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
381ad39c06fSJed Brown  ((petsc_gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm))
38201faf4e4SMatthew Knepley 
38301faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
384ad39c06fSJed Brown  ((petsc_gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm))
38501faf4e4SMatthew Knepley 
38601faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
387ad39c06fSJed Brown  ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
38801faf4e4SMatthew Knepley 
38901faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
390ad39c06fSJed Brown  ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm))
39101faf4e4SMatthew Knepley 
39201faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
393ad39c06fSJed Brown  ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
39401faf4e4SMatthew Knepley 
39501faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
396ad39c06fSJed Brown   ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm))
39701faf4e4SMatthew Knepley 
3980d4b0b6cSBarry Smith #else
3990d4b0b6cSBarry Smith 
4000d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
4015e3723c6SSatish Balay  (MPI_Startall(number,requests))
4020d4b0b6cSBarry Smith 
4030d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
4045e3723c6SSatish Balay  (MPI_Startall(number,requests))
4050d4b0b6cSBarry Smith 
4060d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \
4075e3723c6SSatish Balay  (MPI_Start(requests))
4080d4b0b6cSBarry Smith 
409c8217ed5SSatish Balay #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
410614700edSBarry Smith 
411df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
412614700edSBarry Smith 
413b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
414d854a674SSatish Balay #define PetscLogFlopsNoError(n)
415614700edSBarry Smith 
416df8cf0b5SBarry Smith /*
417df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
418df8cf0b5SBarry Smith */
419b0a32e0cSBarry Smith #define PetscLogMPEBegin()         0
420b0a32e0cSBarry Smith #define PetscLogMPEDump(a)         0
421614700edSBarry Smith 
422b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
423b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
424614700edSBarry Smith 
425b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
426b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
427e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b)  0
42877c4ece6SBarry Smith 
4298b5db460SBarry Smith #define PetscLogPLB                        0
4308b5db460SBarry Smith #define PetscLogPLE                        0
4318b5db460SBarry Smith #define PetscLogPHC                        0
4328b5db460SBarry Smith #define PetscLogPHD                        0
43399de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
434b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
435b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
436b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
437b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
43852e6d16bSBarry Smith #define PetscLogObjectParent(p,c)           0
439efee365bSSatish Balay #define PetscLogObjectParents(p,n,c)        0
44052e6d16bSBarry Smith #define PetscLogObjectCreate(h)             0
44152e6d16bSBarry Smith #define PetscLogObjectDestroy(h)            0
44252e6d16bSBarry Smith #define PetscLogObjectMemory(p,m)           0
443b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
444b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
445b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
446b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
447b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
44891eabc43SBarry Smith #define PetscLogView(viewer)                0
44991eabc43SBarry Smith #define PetscLogViewPython(viewer)          0
45078392ef1SBarry Smith #define PetscLogPrintDetailed(comm,file)    0
451b0a32e0cSBarry Smith #define PetscLogBegin()                     0
452b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
453b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
454b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
455b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
456043328b6SSatish Balay #define PetscLogEventRegister(a,b,c)        0
45773fda44aSBarry Smith #define PetscLogObjects(a)                  0
45873fda44aSBarry Smith #define PetscLogActions(a)                  0
4597087cfbeSBarry Smith extern PetscErrorCode  PetscLogObjectState(PetscObject,const char[],...);
460ce6058e1SBarry Smith 
461aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
462ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
463ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
464ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
465fad68dfaSSatish Balay #define PetscLogStageGetId(a,b)                      (*(b)=0,0)
466fad68dfaSSatish Balay #define PetscLogStageSetActive(a,b)                  0
4676a6a9b46SSatish Balay #define PetscLogStageGetActive(a,b)                  0
4686a6a9b46SSatish Balay #define PetscLogStageGetVisible(a,b)                 0
4696a6a9b46SSatish Balay #define PetscLogStageSetVisible(a,b)                 0
470f141ce34SMatthew Knepley 
471aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4726daaf66cSBarry Smith 
473aa213bdcSJed Brown extern PetscErrorCode PetscIntStackCreate(PetscIntStack *);
474aa213bdcSJed Brown extern PetscErrorCode PetscIntStackDestroy(PetscIntStack);
475aa213bdcSJed Brown extern PetscErrorCode PetscIntStackPush(PetscIntStack, int);
476aa213bdcSJed Brown extern PetscErrorCode PetscIntStackPop(PetscIntStack, int *);
477aa213bdcSJed Brown extern PetscErrorCode PetscIntStackTop(PetscIntStack, int *);
478aa213bdcSJed Brown extern PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool  *);
479fcfd50ebSBarry Smith 
480fcfd50ebSBarry Smith #undef __FUNCT__
481fcfd50ebSBarry Smith #define __FUNCT__ "PetscLogGetStageLog"
482fcfd50ebSBarry Smith /*@C
483fcfd50ebSBarry Smith   PetscLogGetStageLog - This function returns the default stage logging object.
484fcfd50ebSBarry Smith 
485fcfd50ebSBarry Smith   Not collective
486fcfd50ebSBarry Smith 
487fcfd50ebSBarry Smith   Output Parameter:
488aa213bdcSJed Brown . stageLog - The default PetscStageLog
489fcfd50ebSBarry Smith 
490fcfd50ebSBarry Smith   Level: developer
491fcfd50ebSBarry Smith 
492fcfd50ebSBarry Smith   Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault()
493fcfd50ebSBarry Smith 
494fcfd50ebSBarry Smith .keywords: log, stage
495aa213bdcSJed Brown .seealso: PetscStageLogCreate()
496fcfd50ebSBarry Smith @*/
497aa213bdcSJed Brown PETSC_STATIC_INLINE PetscErrorCode  PetscLogGetStageLog(PetscStageLog *stageLog)
498fcfd50ebSBarry Smith {
499fcfd50ebSBarry Smith   PetscFunctionBegin;
500fcfd50ebSBarry Smith   PetscValidPointer(stageLog,1);
501205a32c2SJed Brown   if (!petsc_stageLog) {
502fcfd50ebSBarry Smith     fprintf(stderr, "PETSC ERROR: Logging has not been enabled.\nYou might have forgotten to call PetscInitialize().\n");
503fcfd50ebSBarry Smith     MPI_Abort(MPI_COMM_WORLD, PETSC_ERR_SUP);
504fcfd50ebSBarry Smith   }
505205a32c2SJed Brown   *stageLog = petsc_stageLog;
506fcfd50ebSBarry Smith   PetscFunctionReturn(0);
507fcfd50ebSBarry Smith }
508fcfd50ebSBarry Smith 
509fcfd50ebSBarry Smith #undef __FUNCT__
510aa213bdcSJed Brown #define __FUNCT__ "PetscStageLogGetCurrent"
511fcfd50ebSBarry Smith /*@C
512aa213bdcSJed Brown   PetscStageLogGetCurrent - This function returns the stage from the top of the stack.
513fcfd50ebSBarry Smith 
514fcfd50ebSBarry Smith   Not Collective
515fcfd50ebSBarry Smith 
516fcfd50ebSBarry Smith   Input Parameter:
517aa213bdcSJed Brown . stageLog - The PetscStageLog
518fcfd50ebSBarry Smith 
519fcfd50ebSBarry Smith   Output Parameter:
520fcfd50ebSBarry Smith . stage    - The current stage
521fcfd50ebSBarry Smith 
522fcfd50ebSBarry Smith   Notes:
523fcfd50ebSBarry Smith   If no stage is currently active, stage is set to -1.
524fcfd50ebSBarry Smith 
525fcfd50ebSBarry Smith   Level: developer
526fcfd50ebSBarry Smith 
527fcfd50ebSBarry Smith   Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault()
528fcfd50ebSBarry Smith 
529fcfd50ebSBarry Smith .keywords: log, stage
530aa213bdcSJed Brown .seealso: PetscStageLogPush(), PetscStageLogPop(), PetscLogGetStageLog()
531fcfd50ebSBarry Smith @*/
532aa213bdcSJed Brown PETSC_STATIC_INLINE PetscErrorCode  PetscStageLogGetCurrent(PetscStageLog stageLog, int *stage)
533fcfd50ebSBarry Smith {
534fcfd50ebSBarry Smith   PetscBool      empty;
535fcfd50ebSBarry Smith   PetscErrorCode ierr;
536fcfd50ebSBarry Smith 
537fcfd50ebSBarry Smith   PetscFunctionBegin;
538aa213bdcSJed Brown   ierr = PetscIntStackEmpty(stageLog->stack, &empty);CHKERRQ(ierr);
539fcfd50ebSBarry Smith   if (empty) {
540fcfd50ebSBarry Smith     *stage = -1;
541fcfd50ebSBarry Smith   } else {
542aa213bdcSJed Brown     ierr = PetscIntStackTop(stageLog->stack, stage);CHKERRQ(ierr);
543fcfd50ebSBarry Smith   }
544fcfd50ebSBarry Smith #ifdef PETSC_USE_DEBUG
545*e47d2de2SBarry Smith   if (*stage != stageLog->curStage) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB, "Inconsistency in stage log: stage %d should be %d", *stage, stageLog->curStage);
546fcfd50ebSBarry Smith #endif
547fcfd50ebSBarry Smith   PetscFunctionReturn(0);
548fcfd50ebSBarry Smith }
549fcfd50ebSBarry Smith 
550fcfd50ebSBarry Smith #undef __FUNCT__
551aa213bdcSJed Brown #define __FUNCT__ "PetscStageLogGetEventPerfLog"
552fcfd50ebSBarry Smith /*@C
553aa213bdcSJed Brown   PetscStageLogGetEventPerfLog - This function returns the PetscEventPerfLog for the given stage.
554fcfd50ebSBarry Smith 
555fcfd50ebSBarry Smith   Not Collective
556fcfd50ebSBarry Smith 
557fcfd50ebSBarry Smith   Input Parameters:
558aa213bdcSJed Brown + stageLog - The PetscStageLog
559fcfd50ebSBarry Smith - stage    - The stage
560fcfd50ebSBarry Smith 
561fcfd50ebSBarry Smith   Output Parameter:
562aa213bdcSJed Brown . eventLog - The PetscEventPerfLog
563fcfd50ebSBarry Smith 
564fcfd50ebSBarry Smith   Level: developer
565fcfd50ebSBarry Smith 
566fcfd50ebSBarry Smith   Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault()
567fcfd50ebSBarry Smith 
568fcfd50ebSBarry Smith .keywords: log, stage
569aa213bdcSJed Brown .seealso: PetscStageLogPush(), PetscStageLogPop(), PetscLogGetStageLog()
570fcfd50ebSBarry Smith @*/
571aa213bdcSJed Brown PETSC_STATIC_INLINE PetscErrorCode  PetscStageLogGetEventPerfLog(PetscStageLog stageLog, int stage, PetscEventPerfLog *eventLog)
572fcfd50ebSBarry Smith {
573fcfd50ebSBarry Smith   PetscFunctionBegin;
574fcfd50ebSBarry Smith   PetscValidPointer(eventLog,3);
575*e47d2de2SBarry Smith   if ((stage < 0) || (stage >= stageLog->numStages)) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d should be in [0,%d)", stage, stageLog->numStages);
576fcfd50ebSBarry Smith   *eventLog = stageLog->stageInfo[stage].eventLog;
577fcfd50ebSBarry Smith   PetscFunctionReturn(0);
578fcfd50ebSBarry Smith }
579fcfd50ebSBarry Smith 
580bf5c43c7SMatthew Knepley /* Special support for C++ */
581bf5c43c7SMatthew Knepley #include "petsclog.hh"
582bf5c43c7SMatthew Knepley 
583204a6943SJed Brown #define PetscPreLoadBegin(flag,name) \
584204a6943SJed Brown do {\
585204a6943SJed Brown   PetscBool      PetscPreLoading = flag;\
586204a6943SJed Brown   int            PetscPreLoadMax,PetscPreLoadIt;\
587166c7f25SBarry Smith   PetscLogStage  _stageNum;\
5888cbcd9ccSBarry Smith   PetscErrorCode _3_ierr;	\
589204a6943SJed Brown   _3_ierr = PetscOptionsGetBool(PETSC_NULL,"-preload",&PetscPreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
590204a6943SJed Brown   PetscPreLoadMax = (int)(PetscPreLoading);\
591204a6943SJed Brown   PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
592204a6943SJed Brown   for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\
593204a6943SJed Brown     PetscPreLoadingOn = PetscPreLoading;\
5946e491fe6SBarry Smith     _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
595204a6943SJed Brown     if (PetscPreLoadIt>0) {\
5968e58c17dSMatthew Knepley       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
5978e58c17dSMatthew Knepley     } else {\
598a3bc4eb9SBarry Smith       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
5998e58c17dSMatthew Knepley     }\
600204a6943SJed Brown     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\
6018e58c17dSMatthew Knepley     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
6028e58c17dSMatthew Knepley 
603204a6943SJed Brown #define PetscPreLoadEnd() \
604043328b6SSatish Balay     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
605204a6943SJed Brown     PetscPreLoading = PETSC_FALSE;\
606043328b6SSatish Balay   }\
607204a6943SJed Brown } while (0)
6088e58c17dSMatthew Knepley 
609204a6943SJed Brown #define PetscPreLoadStage(name) do {                                         \
610043328b6SSatish Balay     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);                      \
611204a6943SJed Brown     if (PetscPreLoadIt>0) {                                                  \
6128e58c17dSMatthew Knepley       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);   \
6138e58c17dSMatthew Knepley     } else {                                                            \
614a3bc4eb9SBarry Smith       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
6158e58c17dSMatthew Knepley     }                                                                   \
616204a6943SJed Brown     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \
617204a6943SJed Brown     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);            \
618204a6943SJed Brown   } while (0)
619e9fa29b7SSatish Balay 
620e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
62197bb86f7SLois Curfman McInnes #endif
622