xref: /petsc/include/petsclog.h (revision 09573ac72a50d3e7ecd55a2b7f0ef28450cd0a8b)
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 */
338738c821SJed Brown extern PetscLogDouble PETSCSYS_DLLEXPORT _TotalFlops;
3490fdf44cSMatthew Knepley extern PetscLogDouble petsc_tmp_flops;
3519b02663SBarry Smith 
36edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */
37*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT 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
57*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscInfoDeactivateClass(PetscClassId);
58*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscInfoActivateClass(PetscClassId);
59ace3abfcSBarry Smith extern PetscBool      PETSCSYS_DLLEXPORT 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 */
676a6a9b46SSatish Balay typedef struct _n_IntStack *IntStack;
686a6a9b46SSatish Balay 
69c60ec953SBarry Smith /*
70c60ec953SBarry Smith     ClassRegInfo, ClassPerfInfo - 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 
74c60ec953SBarry Smith     ClassRegLog, ClassPerfLog - arrays of the ClassRegInfo and ClassPerfInfo 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 */
79c60ec953SBarry Smith } ClassRegInfo;
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 */
876a6a9b46SSatish Balay } ClassPerfInfo;
886a6a9b46SSatish Balay 
89c60ec953SBarry Smith typedef struct _n_ClassRegLog *ClassRegLog;
90c60ec953SBarry Smith struct _n_ClassRegLog {
91c60ec953SBarry Smith   int            numClasses; /* The number of classes registered */
92c60ec953SBarry Smith   int            maxClasses; /* The maximum number of classes */
93c60ec953SBarry Smith   ClassRegInfo * classInfo;  /* The structure for class information (classids are monotonicly increasing) */
94c60ec953SBarry Smith };
956a6a9b46SSatish Balay 
96c60ec953SBarry Smith typedef struct _n_ClassPerfLog *ClassPerfLog;
97c60ec953SBarry Smith struct _n_ClassPerfLog {
98c60ec953SBarry Smith   int            numClasses; /* The number of logging classes */
99c60ec953SBarry Smith   int            maxClasses; /* The maximum number of classes */
100c60ec953SBarry Smith   ClassPerfInfo *classInfo;  /* The structure for class information (classids are monotonicly increasing) */
101c60ec953SBarry Smith };
102c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/
103c60ec953SBarry Smith /*
104c60ec953SBarry Smith     EventRegInfo, EventPerfInfo - 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 
108c60ec953SBarry Smith     EventRegLog, EventPerfLog - an array of all EventRegInfo and EventPerfInfo 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
1196a6a9b46SSatish Balay } EventRegInfo;
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 */
132c60ec953SBarry Smith } EventPerfInfo;
133c60ec953SBarry Smith 
1346a6a9b46SSatish Balay typedef struct _n_EventRegLog *EventRegLog;
1356a6a9b46SSatish Balay struct _n_EventRegLog {
1366a6a9b46SSatish Balay   int           numEvents; /* The number of registered events */
1376a6a9b46SSatish Balay   int           maxEvents; /* The maximum number of events */
1386a6a9b46SSatish Balay   EventRegInfo *eventInfo; /* The registration information for each event */
1396a6a9b46SSatish Balay };
1406a6a9b46SSatish Balay 
1416a6a9b46SSatish Balay typedef struct _n_EventPerfLog *EventPerfLog;
1426a6a9b46SSatish Balay struct _n_EventPerfLog {
1436a6a9b46SSatish Balay   int            numEvents; /* The number of logging events */
1446a6a9b46SSatish Balay   int            maxEvents; /* The maximum number of events */
1456a6a9b46SSatish Balay   EventPerfInfo *eventInfo; /* The performance information for each event */
1466a6a9b46SSatish Balay };
147c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/
148c60ec953SBarry Smith /*
149c60ec953SBarry Smith    StageInfo - Contains all the information about a particular stage.
1506a6a9b46SSatish Balay 
151c60ec953SBarry Smith    StageLog - An array of StageInfo for each registered stage. There is a single one of these in the code.
152c60ec953SBarry Smith */
1536a6a9b46SSatish Balay typedef struct _StageInfo {
1546a6a9b46SSatish Balay   char         *name;     /* The stage name */
155ace3abfcSBarry Smith   PetscBool     used;     /* The stage was pushed on this processor */
1566a6a9b46SSatish Balay   EventPerfInfo perfInfo; /* The stage performance information */
1576a6a9b46SSatish Balay   EventPerfLog  eventLog; /* The event information for this stage */
1586a6a9b46SSatish Balay   ClassPerfLog  classLog; /* The class information for this stage */
1596a6a9b46SSatish Balay } StageInfo;
1606a6a9b46SSatish Balay 
161c60ec953SBarry Smith typedef struct _n_StageLog *StageLog;
1628738c821SJed Brown extern PETSCSYS_DLLEXPORT StageLog _stageLog;
1636a6a9b46SSatish Balay struct _n_StageLog {
1646a6a9b46SSatish Balay   int         numStages; /* The number of registered stages */
1656a6a9b46SSatish Balay   int         maxStages; /* The maximum number of stages */
1666a6a9b46SSatish Balay   IntStack    stack;     /* The stack for active stages */
1676a6a9b46SSatish Balay   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
1686a6a9b46SSatish Balay   StageInfo  *stageInfo; /* The information for each stage */
1696a6a9b46SSatish Balay   EventRegLog eventLog;  /* The registered events */
1706a6a9b46SSatish Balay   ClassRegLog 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)
195542d4b3fSSatish Balay #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)))
196542d4b3fSSatish Balay #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
197bf3909cdSBarry Smith #else
198542d4b3fSSatish Balay #define PetscLogFlops(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n),0)
199542d4b3fSSatish Balay #define PetscLogFlopsNoError(n) (_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"
204*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT        PetscLogMPEBegin(void);
205*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT        PetscLogMPEDump(const char[]);
206ace3abfcSBarry Smith extern PetscBool  UseMPE;
207043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
208335e4f37SSatish Balay   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
209a1b71033SSatish Balay    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)
210043328b6SSatish Balay 
211043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e) \
212335e4f37SSatish Balay   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
213a1b71033SSatish Balay    MPE_Log_event(_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 
220*09573ac7SBarry Smith extern PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
221*09573ac7SBarry Smith extern PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
222*09573ac7SBarry Smith extern PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPHC)(PetscObject);
223*09573ac7SBarry Smith extern PETSCSYS_DLLEXPORT 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);}}
229d38fa0fbSBarry Smith #define PetscLogObjectCreate(h)      ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0)
230d38fa0fbSBarry Smith #define PetscLogObjectDestroy(h)     ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0)
23152e6d16bSBarry Smith #define PetscLogObjectMemory(p,m)    (((PetscObject)(p))->mem += (m),0)
2328ba1e511SMatthew Knepley /* Initialization functions */
233*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogBegin(void);
234*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogAllBegin(void);
235*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogTraceBegin(FILE *);
236*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogActions(PetscBool);
237*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogObjects(PetscBool);
2388ba1e511SMatthew Knepley /* General functions */
239*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogGetRGBColor(const char*[]);
240*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogDestroy(void);
241*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
2426849ba73SBarry Smith                    PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
243*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogObjectState(PetscObject, const char[], ...);
2448ba1e511SMatthew Knepley /* Output functions */
245*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogPrintSummary(MPI_Comm, const char[]);
246*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogPrintSummaryPython(PetscViewer);
247*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogPrintDetailed(MPI_Comm, const char[]);
248*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogDump(const char[]);
24931d06abdSBarry Smith 
250*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscGetFlops(PetscLogDouble *);
25131d06abdSBarry Smith 
252*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageRegister(const char[],PetscLogStage*);
253*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStagePush(PetscLogStage);
254*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStagePop(void);
255*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageSetActive(PetscLogStage, PetscBool );
256*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageGetActive(PetscLogStage, PetscBool  *);
257*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageSetVisible(PetscLogStage, PetscBool );
258*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageGetVisible(PetscLogStage, PetscBool  *);
259*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageGetId(const char [], PetscLogStage *);
2608ba1e511SMatthew Knepley /* Event functions */
261*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*);
262*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventActivate(PetscLogEvent);
263*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventDeactivate(PetscLogEvent);
264*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventSetActiveAll(PetscLogEvent, PetscBool );
265*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventActivateClass(PetscClassId);
266*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventDeactivateClass(PetscClassId);
2679afaeae2SBarry Smith 
2688ba1e511SMatthew Knepley 
2698ba1e511SMatthew Knepley /* Global counters */
2708738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble irecv_ct;
2718738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble isend_ct;
2728738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble recv_ct;
2738738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble send_ct;
2748738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble irecv_len;
2758738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble isend_len;
2768738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble recv_len;
2778738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble send_len;
2788738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble allreduce_ct;
2798738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble gather_ct;
2808738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble scatter_ct;
2818738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble wait_ct;
2828738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble wait_any_ct;
2838738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble wait_all_ct;
2848738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble sum_of_waits_ct;
2858ba1e511SMatthew Knepley 
28652e6d16bSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
28752e6d16bSBarry Smith   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active &&  _stageLog->stageInfo[_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) \
29252e6d16bSBarry Smith   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
29352e6d16bSBarry 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) \
29952e6d16bSBarry Smith   (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
30052e6d16bSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
30152e6d16bSBarry Smith   PETSC_LOG_EVENT_MPE_END(e))
30277c4ece6SBarry Smith 
303*09573ac7SBarry Smith extern PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*);
304*09573ac7SBarry 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 */
323f95db71bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode TypeSize(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 
32877a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
329f95db71bSBarry Smith  ((irecv_ct++,0) || TypeSize(&irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request))
33015308354SBarry Smith 
33177a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
332f95db71bSBarry Smith  ((isend_ct++,0) || TypeSize(&isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request))
33315308354SBarry Smith 
3340d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
335f95db71bSBarry Smith  ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(&irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
3360d4b0b6cSBarry Smith 
3370d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
338f95db71bSBarry Smith  ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
3390d4b0b6cSBarry Smith 
3400d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \
341f95db71bSBarry Smith  ((isend_ct++,0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Start(requests))
3420d4b0b6cSBarry Smith 
343ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
344f95db71bSBarry Smith  ((recv_ct++,0) || TypeSize(&recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status))
34515308354SBarry Smith 
34677a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \
347f95db71bSBarry Smith  ((send_ct++,0) || TypeSize(&send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm))
34877a39924SBarry Smith 
34977a39924SBarry Smith #define MPI_Wait(request,status) \
3505e3723c6SSatish Balay  ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status))
35177a39924SBarry Smith 
35277a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \
3535e3723c6SSatish Balay  ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))
35477a39924SBarry Smith 
35577a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
356f95db71bSBarry Smith  ((wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses))
35777a39924SBarry Smith 
35877a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
3595e3723c6SSatish Balay  ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))
3603914022bSBarry Smith 
36101faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
36201faf4e4SMatthew Knepley  ((gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm))
36301faf4e4SMatthew Knepley 
36401faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
36501faf4e4SMatthew Knepley  ((gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm))
36601faf4e4SMatthew Knepley 
36701faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
368f95db71bSBarry Smith  ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
36901faf4e4SMatthew Knepley 
37001faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
371f95db71bSBarry Smith  ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm))
37201faf4e4SMatthew Knepley 
37301faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
374f95db71bSBarry Smith   ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
37501faf4e4SMatthew Knepley 
37601faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
377f95db71bSBarry Smith   ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm))
37801faf4e4SMatthew Knepley 
3790d4b0b6cSBarry Smith #else
3800d4b0b6cSBarry Smith 
3810d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
3825e3723c6SSatish Balay  (MPI_Startall(number,requests))
3830d4b0b6cSBarry Smith 
3840d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
3855e3723c6SSatish Balay  (MPI_Startall(number,requests))
3860d4b0b6cSBarry Smith 
3870d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \
3885e3723c6SSatish Balay  (MPI_Start(requests))
3890d4b0b6cSBarry Smith 
390c8217ed5SSatish Balay #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
391614700edSBarry Smith 
392df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
393614700edSBarry Smith 
394b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
395d854a674SSatish Balay #define PetscLogFlopsNoError(n)
396614700edSBarry Smith 
397df8cf0b5SBarry Smith /*
398df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
399df8cf0b5SBarry Smith */
400b0a32e0cSBarry Smith #define PetscLogMPEBegin()         0
401b0a32e0cSBarry Smith #define PetscLogMPEDump(a)         0
402614700edSBarry Smith 
403b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
404b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
405614700edSBarry Smith 
406b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
407b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
408e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b)  0
40977c4ece6SBarry Smith 
410b0a32e0cSBarry Smith #define _PetscLogPLB                        0
411b0a32e0cSBarry Smith #define _PetscLogPLE                        0
412b0a32e0cSBarry Smith #define _PetscLogPHC                        0
413b0a32e0cSBarry Smith #define _PetscLogPHD                        0
41499de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
415b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
416b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
417b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
418b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
41952e6d16bSBarry Smith #define PetscLogObjectParent(p,c)           0
420efee365bSSatish Balay #define PetscLogObjectParents(p,n,c)        0
42152e6d16bSBarry Smith #define PetscLogObjectCreate(h)             0
42252e6d16bSBarry Smith #define PetscLogObjectDestroy(h)            0
42352e6d16bSBarry Smith #define PetscLogObjectMemory(p,m)           0
424b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
425b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
426b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
427b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
428b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
429b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file)     0
43099e523acSBarry Smith #define PetscLogPrintSummaryPy(file)        0
43178392ef1SBarry Smith #define PetscLogPrintDetailed(comm,file)    0
432b0a32e0cSBarry Smith #define PetscLogBegin()                     0
433b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
434b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
435b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
436b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
437043328b6SSatish Balay #define PetscLogEventRegister(a,b,c)        0
43873fda44aSBarry Smith #define PetscLogObjects(a)                  0
43973fda44aSBarry Smith #define PetscLogActions(a)                  0
440*09573ac7SBarry Smith extern PetscErrorCode PETSCSYS_DLLEXPORT PetscLogObjectState(PetscObject,const char[],...);
441ce6058e1SBarry Smith 
442aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
443ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
444ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
445ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
446fad68dfaSSatish Balay #define PetscLogStageGetId(a,b)                      (*(b)=0,0)
447fad68dfaSSatish Balay #define PetscLogStageSetActive(a,b)                  0
4486a6a9b46SSatish Balay #define PetscLogStageGetActive(a,b)                  0
4496a6a9b46SSatish Balay #define PetscLogStageGetVisible(a,b)                 0
4506a6a9b46SSatish Balay #define PetscLogStageSetVisible(a,b)                 0
451f141ce34SMatthew Knepley 
452aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4536daaf66cSBarry Smith 
454bf5c43c7SMatthew Knepley /* Special support for C++ */
455bf5c43c7SMatthew Knepley #include "petsclog.hh"
456bf5c43c7SMatthew Knepley 
457043328b6SSatish Balay #define PreLoadBegin(flag,name) \
458043328b6SSatish Balay {\
459ace3abfcSBarry Smith   PetscBool      PreLoading = flag;\
4608cbcd9ccSBarry Smith   int            PreLoadMax,PreLoadIt;\
461166c7f25SBarry Smith   PetscLogStage  _stageNum;\
4628cbcd9ccSBarry Smith   PetscErrorCode _3_ierr;	\
463acfcf0e5SJed Brown   _3_ierr = PetscOptionsGetBool(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
464043328b6SSatish Balay   PreLoadMax = (int)(PreLoading);\
465043328b6SSatish Balay   PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
466e7592fafSBarry Smith   for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
467435da068SBarry Smith     PetscPreLoadingOn = PreLoading;\
4686e491fe6SBarry Smith     _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
4698e58c17dSMatthew Knepley     if (PreLoadIt>0) {\
4708e58c17dSMatthew Knepley       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4718e58c17dSMatthew Knepley     } else {\
472a3bc4eb9SBarry Smith       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
4738e58c17dSMatthew Knepley     }\
474ace3abfcSBarry Smith     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PreLoadMax || PreLoadIt));\
4758e58c17dSMatthew Knepley     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
4768e58c17dSMatthew Knepley 
477043328b6SSatish Balay #define PreLoadEnd() \
478043328b6SSatish Balay     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
479043328b6SSatish Balay     PreLoading = PETSC_FALSE;\
480043328b6SSatish Balay   }\
481043328b6SSatish Balay }
4828e58c17dSMatthew Knepley 
483043328b6SSatish Balay #define PreLoadStage(name) \
484043328b6SSatish Balay   _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
4858e58c17dSMatthew Knepley   if (PreLoadIt>0) {\
4868e58c17dSMatthew Knepley     _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4878e58c17dSMatthew Knepley   } else {\
488a3bc4eb9SBarry Smith     _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr);	\
4898e58c17dSMatthew Knepley   }\
490ace3abfcSBarry Smith   _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PreLoadMax || PreLoadIt));\
4918e58c17dSMatthew Knepley   _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
492e9fa29b7SSatish Balay 
493e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
49497bb86f7SLois Curfman McInnes #endif
495