xref: /petsc/include/petsclog.h (revision e0f8cd26c844241a99d256ca5b6c23d04b9ba606)
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 
108ba1e511SMatthew Knepley #define PETSC_EVENT  1311311
11166c7f25SBarry Smith extern PetscLogEvent PETSC_LARGEST_EVENT;
1297bb86f7SLois Curfman McInnes 
1319b02663SBarry Smith /* Global flop counter */
148738c821SJed Brown extern PetscLogDouble PETSCSYS_DLLEXPORT _TotalFlops;
1590fdf44cSMatthew Knepley extern PetscLogDouble petsc_tmp_flops;
1619b02663SBarry Smith 
17edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */
188738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInfo_Private(const char[],void*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
196cf91177SBarry Smith #if defined(PETSC_USE_INFO)
202714b66aSJed Brown #define PetscInfo(A,S)                       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S)
212714b66aSJed Brown #define PetscInfo1(A,S,a1)                   PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1)
222714b66aSJed Brown #define PetscInfo2(A,S,a1,a2)                PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2)
232714b66aSJed Brown #define PetscInfo3(A,S,a1,a2,a3)             PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3)
242714b66aSJed Brown #define PetscInfo4(A,S,a1,a2,a3,a4)          PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4)
252714b66aSJed Brown #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5)
262714b66aSJed Brown #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6)
272714b66aSJed 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)
2863ba0a88SBarry Smith #else
29ae15b995SBarry Smith #define PetscInfo(A,S)                       0
30ae15b995SBarry Smith #define PetscInfo1(A,S,a1)                   0
31ae15b995SBarry Smith #define PetscInfo2(A,S,a1,a2)                0
32ae15b995SBarry Smith #define PetscInfo3(A,S,a1,a2,a3)             0
33ae15b995SBarry Smith #define PetscInfo4(A,S,a1,a2,a3,a4)          0
34ae15b995SBarry Smith #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       0
35ae15b995SBarry Smith #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    0
36ae15b995SBarry Smith #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
3763ba0a88SBarry Smith #endif
388738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInfoDeactivateClass(PetscClassId);
398738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInfoActivateClass(PetscClassId);
40ace3abfcSBarry Smith extern PetscBool      PETSCSYS_DLLEXPORT PetscLogPrintInfo;  /* if true, indicates PetscInfo() is turned on */
41614700edSBarry Smith 
4231d06abdSBarry Smith /* We must make the following structures available to access the event
4331d06abdSBarry Smith      activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public
4431d06abdSBarry Smith      API and are not intended to be used by other parts of PETSc or by users.
45d49d4b11SBarry Smith 
4631d06abdSBarry Smith      The code that manipulates these structures is in src/sys/plog/utils.
4731d06abdSBarry Smith */
486a6a9b46SSatish Balay typedef struct _n_IntStack *IntStack;
496a6a9b46SSatish Balay 
50c60ec953SBarry Smith /*
51c60ec953SBarry Smith     ClassRegInfo, ClassPerfInfo - Each class has two data structures associated with it. The first has
52c60ec953SBarry Smith        static information about it, the second collects statistics on how many objects of the class are created,
53c60ec953SBarry Smith        how much memory they use, etc.
54c60ec953SBarry Smith 
55c60ec953SBarry Smith     ClassRegLog, ClassPerfLog - arrays of the ClassRegInfo and ClassPerfInfo for all classes.
56c60ec953SBarry Smith */
576a6a9b46SSatish Balay typedef struct  {
58c60ec953SBarry Smith   char           *name;   /* The class name */
59c60ec953SBarry Smith   PetscClassId   classid; /* The integer identifying this class */
60c60ec953SBarry Smith } ClassRegInfo;
616a6a9b46SSatish Balay 
626a6a9b46SSatish Balay typedef struct {
630700a824SBarry Smith   PetscClassId   id;           /* The integer identifying this class */
646a6a9b46SSatish Balay   int            creations;    /* The number of objects of this class created */
656a6a9b46SSatish Balay   int            destructions; /* The number of objects of this class destroyed */
666a6a9b46SSatish Balay   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
676a6a9b46SSatish Balay   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
686a6a9b46SSatish Balay } ClassPerfInfo;
696a6a9b46SSatish Balay 
70c60ec953SBarry Smith typedef struct _n_ClassRegLog *ClassRegLog;
71c60ec953SBarry Smith struct _n_ClassRegLog {
72c60ec953SBarry Smith   int            numClasses; /* The number of classes registered */
73c60ec953SBarry Smith   int            maxClasses; /* The maximum number of classes */
74c60ec953SBarry Smith   ClassRegInfo * classInfo;  /* The structure for class information (classids are monotonicly increasing) */
75c60ec953SBarry Smith };
766a6a9b46SSatish Balay 
77c60ec953SBarry Smith typedef struct _n_ClassPerfLog *ClassPerfLog;
78c60ec953SBarry Smith struct _n_ClassPerfLog {
79c60ec953SBarry Smith   int            numClasses; /* The number of logging classes */
80c60ec953SBarry Smith   int            maxClasses; /* The maximum number of classes */
81c60ec953SBarry Smith   ClassPerfInfo *classInfo;  /* The structure for class information (classids are monotonicly increasing) */
82c60ec953SBarry Smith };
83c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/
84c60ec953SBarry Smith /*
85c60ec953SBarry Smith     EventRegInfo, EventPerfInfo - Each event has two data structures associated with it. The first has
86c60ec953SBarry Smith        static information about it, the second collects statistics on how many times the event is used, how
87c60ec953SBarry Smith        much time it takes, etc.
88c60ec953SBarry Smith 
89c60ec953SBarry Smith     EventRegLog, EventPerfLog - an array of all EventRegInfo and EventPerfInfo for all events. There is one
90c60ec953SBarry Smith       of these for each stage.
91c60ec953SBarry Smith 
92c60ec953SBarry Smith */
936a6a9b46SSatish Balay typedef struct {
946a6a9b46SSatish Balay   char         *name;         /* The name of this event */
95c60ec953SBarry Smith   PetscClassId classid;       /* The class the event is associated with */
966a6a9b46SSatish Balay #if defined (PETSC_HAVE_MPE)
976a6a9b46SSatish Balay   int          mpe_id_begin; /* MPE IDs that define the event */
986a6a9b46SSatish Balay   int          mpe_id_end;
996a6a9b46SSatish Balay #endif
1006a6a9b46SSatish Balay } EventRegInfo;
1016a6a9b46SSatish Balay 
102c60ec953SBarry Smith typedef struct {
103c60ec953SBarry Smith   int            id;            /* The integer identifying this event */
104ace3abfcSBarry Smith   PetscBool      active;        /* The flag to activate logging */
105ace3abfcSBarry Smith   PetscBool      visible;       /* The flag to print info in summary */
106c60ec953SBarry Smith   int            depth;         /* The nesting depth of the event call */
107c60ec953SBarry Smith   int            count;         /* The number of times this event was executed */
108c60ec953SBarry Smith   PetscLogDouble flops;         /* The flops used in this event */
109c60ec953SBarry Smith   PetscLogDouble time;          /* The time taken for this event */
110c60ec953SBarry Smith   PetscLogDouble numMessages;   /* The number of messages in this event */
111c60ec953SBarry Smith   PetscLogDouble messageLength; /* The total message lengths in this event */
112c60ec953SBarry Smith   PetscLogDouble numReductions; /* The number of reductions in this event */
113c60ec953SBarry Smith } EventPerfInfo;
114c60ec953SBarry Smith 
1156a6a9b46SSatish Balay typedef struct _n_EventRegLog *EventRegLog;
1166a6a9b46SSatish Balay struct _n_EventRegLog {
1176a6a9b46SSatish Balay   int           numEvents; /* The number of registered events */
1186a6a9b46SSatish Balay   int           maxEvents; /* The maximum number of events */
1196a6a9b46SSatish Balay   EventRegInfo *eventInfo; /* The registration information for each event */
1206a6a9b46SSatish Balay };
1216a6a9b46SSatish Balay 
1226a6a9b46SSatish Balay typedef struct _n_EventPerfLog *EventPerfLog;
1236a6a9b46SSatish Balay struct _n_EventPerfLog {
1246a6a9b46SSatish Balay   int            numEvents; /* The number of logging events */
1256a6a9b46SSatish Balay   int            maxEvents; /* The maximum number of events */
1266a6a9b46SSatish Balay   EventPerfInfo *eventInfo; /* The performance information for each event */
1276a6a9b46SSatish Balay };
128c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/
129c60ec953SBarry Smith /*
130c60ec953SBarry Smith    StageInfo - Contains all the information about a particular stage.
1316a6a9b46SSatish Balay 
132c60ec953SBarry Smith    StageLog - An array of StageInfo for each registered stage. There is a single one of these in the code.
133c60ec953SBarry Smith */
1346a6a9b46SSatish Balay typedef struct _StageInfo {
1356a6a9b46SSatish Balay   char         *name;     /* The stage name */
136ace3abfcSBarry Smith   PetscBool     used;     /* The stage was pushed on this processor */
1376a6a9b46SSatish Balay   EventPerfInfo perfInfo; /* The stage performance information */
1386a6a9b46SSatish Balay   EventPerfLog  eventLog; /* The event information for this stage */
1396a6a9b46SSatish Balay   ClassPerfLog  classLog; /* The class information for this stage */
1406a6a9b46SSatish Balay } StageInfo;
1416a6a9b46SSatish Balay 
142c60ec953SBarry Smith typedef struct _n_StageLog *StageLog;
1438738c821SJed Brown extern PETSCSYS_DLLEXPORT StageLog _stageLog;
1446a6a9b46SSatish Balay struct _n_StageLog {
1456a6a9b46SSatish Balay   int         numStages; /* The number of registered stages */
1466a6a9b46SSatish Balay   int         maxStages; /* The maximum number of stages */
1476a6a9b46SSatish Balay   IntStack    stack;     /* The stack for active stages */
1486a6a9b46SSatish Balay   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
1496a6a9b46SSatish Balay   StageInfo  *stageInfo; /* The information for each stage */
1506a6a9b46SSatish Balay   EventRegLog eventLog;  /* The registered events */
1516a6a9b46SSatish Balay   ClassRegLog classLog;  /* The registered classes */
1526a6a9b46SSatish Balay };
1536a6a9b46SSatish Balay 
154aa482453SBarry Smith #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
155614700edSBarry Smith 
156da63de55SLois Curfman McInnes /*
157da63de55SLois Curfman McInnes    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
158da63de55SLois Curfman McInnes 
159da63de55SLois Curfman McInnes    For the complex numbers version, note that
160da63de55SLois Curfman McInnes        1 complex addition = 2 flops
161da63de55SLois Curfman McInnes        1 complex multiplication = 6 flops,
162da63de55SLois Curfman McInnes    where we define 1 flop as that for a double precision scalar.  We roughly approximate
163da63de55SLois Curfman McInnes    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
164da63de55SLois Curfman McInnes    to the assumption that we're counting mostly additions and multiplications -- and
165da63de55SLois Curfman McInnes    roughly the same number of each.  More accurate counting could be done by distinguishing
166da63de55SLois Curfman McInnes    among the various arithmetic operations.
167da63de55SLois Curfman McInnes  */
168da63de55SLois Curfman McInnes 
169aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
170542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0
171da63de55SLois Curfman McInnes #else
172542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0
173bf3909cdSBarry Smith #endif
174bf3909cdSBarry Smith 
175bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG)
176542d4b3fSSatish 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)))
177542d4b3fSSatish Balay #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
178bf3909cdSBarry Smith #else
179542d4b3fSSatish Balay #define PetscLogFlops(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n),0)
180542d4b3fSSatish Balay #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n))
181da63de55SLois Curfman McInnes #endif
18277c4ece6SBarry Smith 
183aa482453SBarry Smith #if defined (PETSC_HAVE_MPE)
18477c4ece6SBarry Smith #include "mpe.h"
1858738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT        PetscLogMPEBegin(void);
1868738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT        PetscLogMPEDump(const char[]);
187ace3abfcSBarry Smith extern PetscBool  UseMPE;
188043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
189335e4f37SSatish Balay   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
190a1b71033SSatish Balay    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0)
191043328b6SSatish Balay 
192043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e) \
193335e4f37SSatish Balay   ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
194a1b71033SSatish Balay    MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0)
195043328b6SSatish Balay 
196614700edSBarry Smith #else
19752e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0
19852e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_END(e)   0
19977c4ece6SBarry Smith #endif
20077c4ece6SBarry Smith 
2018738c821SJed Brown EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
2028738c821SJed Brown EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
2038738c821SJed Brown EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPHC)(PetscObject);
2048738c821SJed Brown EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*_PetscLogPHD)(PetscObject);
20577c4ece6SBarry Smith 
206043328b6SSatish Balay #define PetscLogObjectParent(p,c) \
207*e0f8cd26SJed Brown   (c && p && (((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id,0))
20852e6d16bSBarry Smith 
209efee365bSSatish Balay #define PetscLogObjectParents(p,n,d)  0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}}
210d38fa0fbSBarry Smith #define PetscLogObjectCreate(h)      ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0)
211d38fa0fbSBarry Smith #define PetscLogObjectDestroy(h)     ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0)
21252e6d16bSBarry Smith #define PetscLogObjectMemory(p,m)    (((PetscObject)(p))->mem += (m),0)
2138ba1e511SMatthew Knepley /* Initialization functions */
2148738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogBegin(void);
2158738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogAllBegin(void);
2168738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogTraceBegin(FILE *);
217ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogActions(PetscBool);
218ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogObjects(PetscBool);
2198ba1e511SMatthew Knepley /* General functions */
2208738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogGetRGBColor(const char*[]);
2218738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogDestroy(void);
2228738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
2236849ba73SBarry Smith                    PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
2248738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogObjectState(PetscObject, const char[], ...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
2258ba1e511SMatthew Knepley /* Output functions */
2268738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogPrintSummary(MPI_Comm, const char[]);
2278738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogPrintSummaryPython(PetscViewer);
2288738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogPrintDetailed(MPI_Comm, const char[]);
2298738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogDump(const char[]);
23031d06abdSBarry Smith 
2318738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetFlops(PetscLogDouble *);
23231d06abdSBarry Smith 
2338738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageRegister(const char[],PetscLogStage*);
2348738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStagePush(PetscLogStage);
2358738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStagePop(void);
236ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageSetActive(PetscLogStage, PetscBool );
237ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageGetActive(PetscLogStage, PetscBool  *);
238ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageSetVisible(PetscLogStage, PetscBool );
239ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageGetVisible(PetscLogStage, PetscBool  *);
2408738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogStageGetId(const char [], PetscLogStage *);
2418ba1e511SMatthew Knepley /* Event functions */
2428738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*);
2438738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventActivate(PetscLogEvent);
2448738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventDeactivate(PetscLogEvent);
245ace3abfcSBarry Smith EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventSetActiveAll(PetscLogEvent, PetscBool );
2468738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventActivateClass(PetscClassId);
2478738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogEventDeactivateClass(PetscClassId);
2489afaeae2SBarry Smith 
2498ba1e511SMatthew Knepley 
2508ba1e511SMatthew Knepley /* Global counters */
2518738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble irecv_ct;
2528738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble isend_ct;
2538738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble recv_ct;
2548738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble send_ct;
2558738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble irecv_len;
2568738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble isend_len;
2578738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble recv_len;
2588738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble send_len;
2598738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble allreduce_ct;
2608738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble gather_ct;
2618738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble scatter_ct;
2628738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble wait_ct;
2638738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble wait_any_ct;
2648738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble wait_all_ct;
2658738c821SJed Brown extern PETSCSYS_DLLEXPORT PetscLogDouble sum_of_waits_ct;
2668ba1e511SMatthew Knepley 
26752e6d16bSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
26852e6d16bSBarry Smith   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active &&  _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
26952e6d16bSBarry Smith     (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \
27052e6d16bSBarry Smith    PetscLogEventBegin((e)+1,o1,o2,o3,o4))
27177c4ece6SBarry Smith 
27252e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \
27352e6d16bSBarry Smith   (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
27452e6d16bSBarry Smith     (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
27552e6d16bSBarry Smith   PETSC_LOG_EVENT_MPE_BEGIN(e))
276043328b6SSatish Balay 
277b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
278043328b6SSatish Balay 
27952e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
28052e6d16bSBarry Smith   (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \
28152e6d16bSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \
28252e6d16bSBarry Smith   PETSC_LOG_EVENT_MPE_END(e))
28377c4ece6SBarry Smith 
284003131ecSBarry Smith EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*);
285003131ecSBarry Smith EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent);
286003131ecSBarry Smith 
287ce85283eSBarry Smith /*
288f621e05eSBarry Smith      These are used internally in the PETSc routines to keep a count of MPI messages and
289f621e05eSBarry Smith    their sizes.
290f621e05eSBarry Smith 
2913c94ec11SBarry Smith      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
292ce85283eSBarry Smith    uses macros to defined the MPI operations.
29315308354SBarry Smith 
29415308354SBarry Smith      It does not work correctly from HP-UX because it processes the
295bb4af37aSBarry Smith    macros in a way that sometimes it double counts, hence
296b6410449SSatish Balay    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
2977c1e34a4SSatish Balay 
298f569fd43SBarry Smith      It does not work with Windows because winmpich lacks MPI_Type_size()
299ce85283eSBarry Smith */
300c8217ed5SSatish Balay #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
30177a39924SBarry Smith /*
30277a39924SBarry Smith    Logging of MPI activities
30377a39924SBarry Smith */
304f95db71bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode TypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type)
305f95db71bSBarry Smith {
306618e35e3SBarry Smith   PetscMPIInt mysize; return  (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0));
307f95db71bSBarry Smith }
30877a39924SBarry Smith 
30977a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
310f95db71bSBarry Smith  ((irecv_ct++,0) || TypeSize(&irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request))
31115308354SBarry Smith 
31277a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
313f95db71bSBarry Smith  ((isend_ct++,0) || TypeSize(&isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request))
31415308354SBarry Smith 
3150d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
316f95db71bSBarry Smith  ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(&irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
3170d4b0b6cSBarry Smith 
3180d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
319f95db71bSBarry Smith  ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests))
3200d4b0b6cSBarry Smith 
3210d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \
322f95db71bSBarry Smith  ((isend_ct++,0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Start(requests))
3230d4b0b6cSBarry Smith 
324ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
325f95db71bSBarry Smith  ((recv_ct++,0) || TypeSize(&recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status))
32615308354SBarry Smith 
32777a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \
328f95db71bSBarry Smith  ((send_ct++,0) || TypeSize(&send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm))
32977a39924SBarry Smith 
33077a39924SBarry Smith #define MPI_Wait(request,status) \
3315e3723c6SSatish Balay  ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status))
33277a39924SBarry Smith 
33377a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \
3345e3723c6SSatish Balay  ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d))
33577a39924SBarry Smith 
33677a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
337f95db71bSBarry Smith  ((wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses))
33877a39924SBarry Smith 
33977a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
3405e3723c6SSatish Balay  ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm))
3413914022bSBarry Smith 
34201faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
34301faf4e4SMatthew Knepley  ((gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm))
34401faf4e4SMatthew Knepley 
34501faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
34601faf4e4SMatthew Knepley  ((gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm))
34701faf4e4SMatthew Knepley 
34801faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
349f95db71bSBarry Smith  ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
35001faf4e4SMatthew Knepley 
35101faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
352f95db71bSBarry Smith  ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm))
35301faf4e4SMatthew Knepley 
35401faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
355f95db71bSBarry Smith   ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm))
35601faf4e4SMatthew Knepley 
35701faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
358f95db71bSBarry Smith   ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm))
35901faf4e4SMatthew Knepley 
3600d4b0b6cSBarry Smith #else
3610d4b0b6cSBarry Smith 
3620d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
3635e3723c6SSatish Balay  (MPI_Startall(number,requests))
3640d4b0b6cSBarry Smith 
3650d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
3665e3723c6SSatish Balay  (MPI_Startall(number,requests))
3670d4b0b6cSBarry Smith 
3680d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \
3695e3723c6SSatish Balay  (MPI_Start(requests))
3700d4b0b6cSBarry Smith 
371c8217ed5SSatish Balay #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
372614700edSBarry Smith 
373df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
374614700edSBarry Smith 
375b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
376d854a674SSatish Balay #define PetscLogFlopsNoError(n)
377614700edSBarry Smith 
378df8cf0b5SBarry Smith /*
379df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
380df8cf0b5SBarry Smith */
381b0a32e0cSBarry Smith #define PetscLogMPEBegin()         0
382b0a32e0cSBarry Smith #define PetscLogMPEDump(a)         0
383614700edSBarry Smith 
384b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
385b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
386614700edSBarry Smith 
387b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
388b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
389e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b)  0
39077c4ece6SBarry Smith 
391b0a32e0cSBarry Smith #define _PetscLogPLB                        0
392b0a32e0cSBarry Smith #define _PetscLogPLE                        0
393b0a32e0cSBarry Smith #define _PetscLogPHC                        0
394b0a32e0cSBarry Smith #define _PetscLogPHD                        0
39599de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
396b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
397b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
398b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
399b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
40052e6d16bSBarry Smith #define PetscLogObjectParent(p,c)           0
401efee365bSSatish Balay #define PetscLogObjectParents(p,n,c)        0
40252e6d16bSBarry Smith #define PetscLogObjectCreate(h)             0
40352e6d16bSBarry Smith #define PetscLogObjectDestroy(h)            0
40452e6d16bSBarry Smith #define PetscLogObjectMemory(p,m)           0
405b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
406b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
407b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
408b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
409b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
410b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file)     0
41199e523acSBarry Smith #define PetscLogPrintSummaryPy(file)        0
41278392ef1SBarry Smith #define PetscLogPrintDetailed(comm,file)    0
413b0a32e0cSBarry Smith #define PetscLogBegin()                     0
414b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
415b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
416b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
417b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
418043328b6SSatish Balay #define PetscLogEventRegister(a,b,c)        0
41973fda44aSBarry Smith #define PetscLogObjects(a)                  0
42073fda44aSBarry Smith #define PetscLogActions(a)                  0
4218738c821SJed Brown EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
422ce6058e1SBarry Smith 
423aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
424ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
425ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
426ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
427fad68dfaSSatish Balay #define PetscLogStageGetId(a,b)                      (*(b)=0,0)
428fad68dfaSSatish Balay #define PetscLogStageSetActive(a,b)                  0
4296a6a9b46SSatish Balay #define PetscLogStageGetActive(a,b)                  0
4306a6a9b46SSatish Balay #define PetscLogStageGetVisible(a,b)                 0
4316a6a9b46SSatish Balay #define PetscLogStageSetVisible(a,b)                 0
432f141ce34SMatthew Knepley 
433aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4346daaf66cSBarry Smith 
435bf5c43c7SMatthew Knepley /* Special support for C++ */
436bf5c43c7SMatthew Knepley #include "petsclog.hh"
437bf5c43c7SMatthew Knepley 
438043328b6SSatish Balay #define PreLoadBegin(flag,name) \
439043328b6SSatish Balay {\
440ace3abfcSBarry Smith   PetscBool      PreLoading = flag;\
4418cbcd9ccSBarry Smith   int            PreLoadMax,PreLoadIt;\
442166c7f25SBarry Smith   PetscLogStage  _stageNum;\
4438cbcd9ccSBarry Smith   PetscErrorCode _3_ierr;	\
444acfcf0e5SJed Brown   _3_ierr = PetscOptionsGetBool(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
445043328b6SSatish Balay   PreLoadMax = (int)(PreLoading);\
446043328b6SSatish Balay   PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
447e7592fafSBarry Smith   for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
448435da068SBarry Smith     PetscPreLoadingOn = PreLoading;\
4496e491fe6SBarry Smith     _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
4508e58c17dSMatthew Knepley     if (PreLoadIt>0) {\
4518e58c17dSMatthew Knepley       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4528e58c17dSMatthew Knepley     } else {\
453a3bc4eb9SBarry Smith       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
4548e58c17dSMatthew Knepley     }\
455ace3abfcSBarry Smith     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PreLoadMax || PreLoadIt));\
4568e58c17dSMatthew Knepley     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
4578e58c17dSMatthew Knepley 
458043328b6SSatish Balay #define PreLoadEnd() \
459043328b6SSatish Balay     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
460043328b6SSatish Balay     PreLoading = PETSC_FALSE;\
461043328b6SSatish Balay   }\
462043328b6SSatish Balay }
4638e58c17dSMatthew Knepley 
464043328b6SSatish Balay #define PreLoadStage(name) \
465043328b6SSatish Balay   _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
4668e58c17dSMatthew Knepley   if (PreLoadIt>0) {\
4678e58c17dSMatthew Knepley     _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4688e58c17dSMatthew Knepley   } else {\
469a3bc4eb9SBarry Smith     _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr);	\
4708e58c17dSMatthew Knepley   }\
471ace3abfcSBarry Smith   _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PreLoadMax || PreLoadIt));\
4728e58c17dSMatthew Knepley   _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
473e9fa29b7SSatish Balay 
474e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
47597bb86f7SLois Curfman McInnes #endif
476