xref: /petsc/include/petsclog.h (revision f569fd4353ee1dcb9bb82ae4300f32559aecd5e3)
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
797bb86f7SLois Curfman McInnes #include "petsc.h"
8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN
997bb86f7SLois Curfman McInnes /*
108ba1e511SMatthew Knepley   Each PETSc object class has it's own cookie (internal integer in the
118ba1e511SMatthew Knepley   data structure used for error checking). These are all defined by an offset
128ba1e511SMatthew Knepley   from the lowest one, PETSC_COOKIE.
1397bb86f7SLois Curfman McInnes */
148ba1e511SMatthew Knepley #define PETSC_COOKIE 1211211
158ba1e511SMatthew Knepley extern int PETSC_LARGEST_COOKIE;
168ba1e511SMatthew Knepley #define PETSC_EVENT  1311311
178ba1e511SMatthew Knepley extern int PETSC_LARGEST_EVENT;
1897bb86f7SLois Curfman McInnes 
198ba1e511SMatthew Knepley /* Events for the Petsc standard library */
20d5ba7fb7SMatthew Knepley extern int PETSC_Barrier;
2197bb86f7SLois Curfman McInnes 
2219b02663SBarry Smith /* Global flop counter */
23b0a32e0cSBarry Smith extern PetscLogDouble _TotalFlops;
2419b02663SBarry Smith 
25edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */
26f80b7eb0SBarry Smith EXTERN int        PetscLogInfo(void*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
27b0a32e0cSBarry Smith EXTERN int        PetscLogInfoDeactivateClass(int);
28b0a32e0cSBarry Smith EXTERN int        PetscLogInfoActivateClass(int);
29b0a32e0cSBarry Smith extern PetscTruth PetscLogPrintInfo;  /* if true, indicates PetscLogInfo() is turned on */
30614700edSBarry Smith 
31aa482453SBarry Smith #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
32614700edSBarry Smith 
33da63de55SLois Curfman McInnes /*
34da63de55SLois Curfman McInnes    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
35da63de55SLois Curfman McInnes 
36da63de55SLois Curfman McInnes    For the complex numbers version, note that
37da63de55SLois Curfman McInnes        1 complex addition = 2 flops
38da63de55SLois Curfman McInnes        1 complex multiplication = 6 flops,
39da63de55SLois Curfman McInnes    where we define 1 flop as that for a double precision scalar.  We roughly approximate
40da63de55SLois Curfman McInnes    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
41da63de55SLois Curfman McInnes    to the assumption that we're counting mostly additions and multiplications -- and
42da63de55SLois Curfman McInnes    roughly the same number of each.  More accurate counting could be done by distinguishing
43da63de55SLois Curfman McInnes    among the various arithmetic operations.
44da63de55SLois Curfman McInnes  */
45da63de55SLois Curfman McInnes 
46aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
47b0a32e0cSBarry Smith #define PetscLogFlops(n) (_TotalFlops += (4*n),0)
48da63de55SLois Curfman McInnes #else
49b0a32e0cSBarry Smith #define PetscLogFlops(n) (_TotalFlops += (n),0)
50da63de55SLois Curfman McInnes #endif
5177c4ece6SBarry Smith 
52aa482453SBarry Smith #if defined (PETSC_HAVE_MPE)
5377c4ece6SBarry Smith #include "mpe.h"
54b0a32e0cSBarry Smith EXTERN int        PetscLogMPEBegin(void);
55b0a32e0cSBarry Smith EXTERN int        PetscLogMPEDump(const char[]);
5635d8aa7fSBarry Smith extern PetscTruth UseMPE;
57043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e) \
5874968b1dSMatthew Knepley   if(UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) \
59639ffa60SSatish Balay     MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,(char*)"");
60043328b6SSatish Balay 
61043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e) \
6274968b1dSMatthew Knepley   if(UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) \
63639ffa60SSatish Balay     MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,(char*)"");
64043328b6SSatish Balay 
65614700edSBarry Smith #else
66043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e)
67043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e)
6877c4ece6SBarry Smith #endif
6977c4ece6SBarry Smith 
70b0a32e0cSBarry Smith EXTERN int (*_PetscLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
71b0a32e0cSBarry Smith EXTERN int (*_PetscLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
72b0a32e0cSBarry Smith EXTERN int (*_PetscLogPHC)(PetscObject);
73b0a32e0cSBarry Smith EXTERN int (*_PetscLogPHD)(PetscObject);
7477c4ece6SBarry Smith 
75043328b6SSatish Balay #define PetscLogObjectParent(p,c) \
76043328b6SSatish Balay   if (c) {\
774482741eSBarry Smith     PetscValidHeader((PetscObject)(c),2);\
784482741eSBarry Smith     PetscValidHeader((PetscObject)(p),1);\
798ba1e511SMatthew Knepley     ((PetscObject)(c))->parent = (PetscObject)(p);\
80043328b6SSatish Balay     ((PetscObject)(c))->parentid = ((PetscObject)p)->id;\
81043328b6SSatish Balay   }
82043328b6SSatish Balay #define PetscLogObjectParents(p,n,d) {int _i; for (_i=0; _i<n; _i++) PetscLogObjectParent(p,(d)[_i]);}
838ba1e511SMatthew Knepley #define PetscLogObjectCreate(h)      {if (_PetscLogPHC) (*_PetscLogPHC)((PetscObject)h);}
848ba1e511SMatthew Knepley #define PetscLogObjectDestroy(h)     {if (_PetscLogPHD) (*_PetscLogPHD)((PetscObject)h);}
854482741eSBarry Smith #define PetscLogObjectMemory(p,m)    {PetscValidHeader((PetscObject)p,1);((PetscObject)(p))->mem += (m);}
868ba1e511SMatthew Knepley /* Initialization functions */
878ba1e511SMatthew Knepley EXTERN int PetscLogBegin(void);
888ba1e511SMatthew Knepley EXTERN int PetscLogAllBegin(void);
898ba1e511SMatthew Knepley EXTERN int PetscLogTraceBegin(FILE *);
909c7ebac3SMatthew Knepley EXTERN int PetscLogActions(PetscTruth);
919c7ebac3SMatthew Knepley EXTERN int PetscLogObjects(PetscTruth);
928ba1e511SMatthew Knepley /* General functions */
932fc52814SBarry Smith EXTERN int PetscLogGetRGBColor(const char*[]);
948ba1e511SMatthew Knepley EXTERN int PetscLogDestroy(void);
958ba1e511SMatthew Knepley EXTERN int PetscLogSet(int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
968ba1e511SMatthew Knepley                    int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
97f80b7eb0SBarry Smith EXTERN int PetscLogObjectState(PetscObject, const char[], ...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
988ba1e511SMatthew Knepley /* Output functions */
998ba1e511SMatthew Knepley EXTERN int PetscLogPrintSummary(MPI_Comm, const char[]);
1008ba1e511SMatthew Knepley EXTERN int PetscLogDump(const char[]);
1018ba1e511SMatthew Knepley /* Counter functions */
1028ba1e511SMatthew Knepley EXTERN int PetscGetFlops(PetscLogDouble *);
1038ba1e511SMatthew Knepley /* Stage functions */
1048ba1e511SMatthew Knepley EXTERN int PetscLogStageRegister(int*, const char[]);
1058ba1e511SMatthew Knepley EXTERN int PetscLogStagePush(int);
1068ba1e511SMatthew Knepley EXTERN int PetscLogStagePop(void);
107773a6509SMatthew Knepley EXTERN int PetscLogStageSetActive(int, PetscTruth);
108773a6509SMatthew Knepley EXTERN int PetscLogStageGetActive(int, PetscTruth *);
1098ba1e511SMatthew Knepley EXTERN int PetscLogStageSetVisible(int, PetscTruth);
1108ba1e511SMatthew Knepley EXTERN int PetscLogStageGetVisible(int, PetscTruth *);
1118e58c17dSMatthew Knepley EXTERN int PetscLogStageGetId(const char [], int *);
1128ba1e511SMatthew Knepley /* Event functions */
113043328b6SSatish Balay EXTERN int PetscLogEventRegister(int*, const char[], int);
1148ba1e511SMatthew Knepley EXTERN int PetscLogEventActivate(int);
1158ba1e511SMatthew Knepley EXTERN int PetscLogEventDeactivate(int);
116cda78268SMatthew Knepley EXTERN int PetscLogEventSetActiveAll(int, PetscTruth);
1178ba1e511SMatthew Knepley EXTERN int PetscLogEventActivateClass(int);
1188ba1e511SMatthew Knepley EXTERN int PetscLogEventDeactivateClass(int);
1198ba1e511SMatthew Knepley /* Class functions */
1208ba1e511SMatthew Knepley EXTERN int PetscLogClassRegister(int*, const char []);
1218ba1e511SMatthew Knepley 
1228ba1e511SMatthew Knepley /* Global counters */
1238ba1e511SMatthew Knepley extern PetscLogDouble irecv_ct,  isend_ct,  recv_ct,  send_ct;
1248ba1e511SMatthew Knepley extern PetscLogDouble irecv_len, isend_len, recv_len, send_len;
1258ba1e511SMatthew Knepley extern PetscLogDouble allreduce_ct;
1268ba1e511SMatthew Knepley extern PetscLogDouble wait_ct, wait_any_ct, wait_all_ct, sum_of_waits_ct;
1278ba1e511SMatthew Knepley extern int            PETSC_DUMMY, PETSC_DUMMY_SIZE;
1288ba1e511SMatthew Knepley 
1298ba1e511SMatthew Knepley /* We must make these structures available if we are to access the event
1308ba1e511SMatthew Knepley    activation flags in the PetscLogEventBegin/End() macros. If we forced a
1318ba1e511SMatthew Knepley    function call each time, we could leave these structures in plog.h
1328ba1e511SMatthew Knepley */
133e855f6f8SMatthew Knepley /* Default log */
134e855f6f8SMatthew Knepley typedef struct _StageLog *StageLog;
135e855f6f8SMatthew Knepley extern StageLog _stageLog;
136e855f6f8SMatthew Knepley 
137e855f6f8SMatthew Knepley /* A simple stack (should replace) */
138e855f6f8SMatthew Knepley typedef struct _IntStack *IntStack;
139e855f6f8SMatthew Knepley 
140e855f6f8SMatthew Knepley /* The structures for logging performance */
141af80a1fbSMatthew Knepley typedef struct _EventPerfInfo {
142e855f6f8SMatthew Knepley   int            id;            /* The integer identifying this section */
143800883a5SMatthew Knepley   PetscTruth     active;        /* The flag to activate logging */
144800883a5SMatthew Knepley   PetscTruth     visible;       /* The flag to print info in summary */
1458ba1e511SMatthew Knepley   int            depth;         /* The nesting depth of the event call */
1468ba1e511SMatthew Knepley   int            count;         /* The number of times this section was executed */
1478ba1e511SMatthew Knepley   PetscLogDouble flops;         /* The flops used in this section */
1488ba1e511SMatthew Knepley   PetscLogDouble time;          /* The time taken for this section */
1498ba1e511SMatthew Knepley   PetscLogDouble numMessages;   /* The number of messages in this section */
1508ba1e511SMatthew Knepley   PetscLogDouble messageLength; /* The total message lengths in this section */
1518ba1e511SMatthew Knepley   PetscLogDouble numReductions; /* The number of reductions in this section */
152af80a1fbSMatthew Knepley } EventPerfInfo;
1538ba1e511SMatthew Knepley 
154e855f6f8SMatthew Knepley typedef struct _ClassPerfInfo {
155e855f6f8SMatthew Knepley   int            id;           /* The integer identifying this class */
1568ba1e511SMatthew Knepley   int            creations;    /* The number of objects of this class created */
1578ba1e511SMatthew Knepley   int            destructions; /* The number of objects of this class destroyed */
1588ba1e511SMatthew Knepley   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
1598ba1e511SMatthew Knepley   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
160e855f6f8SMatthew Knepley } ClassPerfInfo;
1618ba1e511SMatthew Knepley 
162e855f6f8SMatthew Knepley /* The structures for logging registration */
163e855f6f8SMatthew Knepley typedef struct _ClassRegInfo {
164e855f6f8SMatthew Knepley   char *name;   /* The class name */
165e855f6f8SMatthew Knepley   int   cookie; /* The integer identifying this class */
166e855f6f8SMatthew Knepley } ClassRegInfo;
167e855f6f8SMatthew Knepley 
168e855f6f8SMatthew Knepley typedef struct _EventRegInfo {
169e855f6f8SMatthew Knepley   char *name;   /* The name of this event */
170e855f6f8SMatthew Knepley   int   cookie; /* The class id for this event (should maybe give class ID instead) */
17144451550SSatish Balay #if defined (PETSC_HAVE_MPE)
17244451550SSatish Balay   int   mpe_id_begin; /* MPE IDs that define the event */
17344451550SSatish Balay   int   mpe_id_end;
17444451550SSatish Balay #endif
175e855f6f8SMatthew Knepley } EventRegInfo;
176e855f6f8SMatthew Knepley 
177e855f6f8SMatthew Knepley /* The structure for logging events */
178e855f6f8SMatthew Knepley typedef int PetscEvent;
179e855f6f8SMatthew Knepley 
180e855f6f8SMatthew Knepley typedef struct _EventRegLog *EventRegLog;
181e855f6f8SMatthew Knepley struct _EventRegLog {
182e855f6f8SMatthew Knepley   int           numEvents; /* The number of registered events */
183e855f6f8SMatthew Knepley   int           maxEvents; /* The maximum number of events */
184e855f6f8SMatthew Knepley   EventRegInfo *eventInfo; /* The registration information for each event */
1858ba1e511SMatthew Knepley };
1868ba1e511SMatthew Knepley 
187e855f6f8SMatthew Knepley typedef struct _EventPerfLog *EventPerfLog;
188e855f6f8SMatthew Knepley struct _EventPerfLog {
189e855f6f8SMatthew Knepley   int            numEvents; /* The number of logging events */
190e855f6f8SMatthew Knepley   int            maxEvents; /* The maximum number of events */
191af80a1fbSMatthew Knepley   EventPerfInfo *eventInfo; /* The performance information for each event */
192e855f6f8SMatthew Knepley };
1938ba1e511SMatthew Knepley 
194e855f6f8SMatthew Knepley /* The structure for logging class information */
195e855f6f8SMatthew Knepley typedef struct _ClassRegLog *ClassRegLog;
196e855f6f8SMatthew Knepley struct _ClassRegLog {
197e855f6f8SMatthew Knepley   int           numClasses; /* The number of classes registered */
198e855f6f8SMatthew Knepley   int           maxClasses; /* The maximum number of classes */
199e855f6f8SMatthew Knepley   ClassRegInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
200e855f6f8SMatthew Knepley };
201e855f6f8SMatthew Knepley 
202e855f6f8SMatthew Knepley typedef struct _ClassPerfLog *ClassPerfLog;
203e855f6f8SMatthew Knepley struct _ClassPerfLog {
204e855f6f8SMatthew Knepley   int            numClasses; /* The number of logging classes */
205e855f6f8SMatthew Knepley   int            maxClasses; /* The maximum number of classes */
206e855f6f8SMatthew Knepley   ClassPerfInfo *classInfo;  /* The structure for class information (cookies are monotonicly increasing) */
207e855f6f8SMatthew Knepley };
208e855f6f8SMatthew Knepley 
209e855f6f8SMatthew Knepley /* The structures for logging in stages */
210e855f6f8SMatthew Knepley typedef struct _StageInfo {
211e855f6f8SMatthew Knepley   char         *name;     /* The stage name */
212773a6509SMatthew Knepley   PetscTruth    used;     /* The stage was pushed on this processor */
213af80a1fbSMatthew Knepley   EventPerfInfo perfInfo; /* The stage performance information */
214e855f6f8SMatthew Knepley   EventPerfLog  eventLog; /* The event information for this stage */
215e855f6f8SMatthew Knepley   ClassPerfLog  classLog; /* The class information for this stage */
216e855f6f8SMatthew Knepley } StageInfo;
217e855f6f8SMatthew Knepley 
2188ba1e511SMatthew Knepley struct _StageLog {
2198ba1e511SMatthew Knepley   /* Size information */
2208ba1e511SMatthew Knepley   int         numStages; /* The number of registered stages */
2218ba1e511SMatthew Knepley   int         maxStages; /* The maximum number of stages */
2228ba1e511SMatthew Knepley   /* Runtime information */
2238ba1e511SMatthew Knepley   IntStack    stack;     /* The stack for active stages */
2248ba1e511SMatthew Knepley   int         curStage;  /* The current stage (only used in macros so we don't call StackTop) */
2258ba1e511SMatthew Knepley   /* Stage specific information */
226e855f6f8SMatthew Knepley   StageInfo  *stageInfo; /* The information for each stage */
227e855f6f8SMatthew Knepley   EventRegLog eventLog;  /* The registered events */
228e855f6f8SMatthew Knepley   ClassRegLog classLog;  /* The registered classes */
2298ba1e511SMatthew Knepley };
2308ba1e511SMatthew Knepley 
231043328b6SSatish Balay #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0; \
232043328b6SSatish Balay {\
233043328b6SSatish Balay   int _2_ierr;\
234773a6509SMatthew Knepley   if (_PetscLogPLB && \
235773a6509SMatthew Knepley       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
236773a6509SMatthew Knepley       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
2376e491fe6SBarry Smith     _2_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);\
2386e491fe6SBarry Smith     _2_ierr = MPI_Barrier(cm);CHKERRQ(_2_ierr);\
2396e491fe6SBarry Smith     _2_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);\
240005c665bSBarry Smith   }\
2416e491fe6SBarry Smith   _2_ierr = PetscLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(_2_ierr);\
242005c665bSBarry Smith }
24377c4ece6SBarry Smith 
244043328b6SSatish Balay #define PetscLogEventBegin(e,o1,o2,o3,o4) 0; \
245043328b6SSatish Balay {\
246773a6509SMatthew Knepley   if (_PetscLogPLB && \
247773a6509SMatthew Knepley       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
248773a6509SMatthew Knepley       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
249043328b6SSatish Balay     (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
250043328b6SSatish Balay   }\
251043328b6SSatish Balay   PETSC_LOG_EVENT_MPE_BEGIN(e); \
252a1b5d808SSatish Balay }
253043328b6SSatish Balay 
254b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
255043328b6SSatish Balay 
256043328b6SSatish Balay #define PetscLogEventEnd(e,o1,o2,o3,o4) 0; \
257043328b6SSatish Balay {\
258773a6509SMatthew Knepley   if (_PetscLogPLE && \
259773a6509SMatthew Knepley       _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && \
260773a6509SMatthew Knepley       _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) {\
261043328b6SSatish Balay     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));\
262043328b6SSatish Balay   }\
263043328b6SSatish Balay   PETSC_LOG_EVENT_MPE_END(e); \
264a1b5d808SSatish Balay }
26577c4ece6SBarry Smith 
266f141ce34SMatthew Knepley /* Creation and destruction functions */
267f141ce34SMatthew Knepley EXTERN int StageLogCreate(StageLog *);
268f141ce34SMatthew Knepley EXTERN int StageLogDestroy(StageLog);
269f141ce34SMatthew Knepley /* Registration functions */
270f141ce34SMatthew Knepley EXTERN int StageLogRegister(StageLog, const char [], int *);
271f141ce34SMatthew Knepley /* Runtime functions */
272f141ce34SMatthew Knepley EXTERN int PetscLogGetStageLog(StageLog *);
273f141ce34SMatthew Knepley EXTERN int StageLogPush(StageLog, int);
274f141ce34SMatthew Knepley EXTERN int StageLogPop(StageLog);
275f141ce34SMatthew Knepley EXTERN int StageLogGetCurrent(StageLog, int *);
276f141ce34SMatthew Knepley EXTERN int StageLogSetActive(StageLog, int, PetscTruth);
277f141ce34SMatthew Knepley EXTERN int StageLogGetActive(StageLog, int, PetscTruth *);
278f141ce34SMatthew Knepley EXTERN int StageLogSetVisible(StageLog, int, PetscTruth);
279f141ce34SMatthew Knepley EXTERN int StageLogGetVisible(StageLog, int, PetscTruth *);
280f141ce34SMatthew Knepley EXTERN int StageLogGetStage(StageLog, const char [], int *);
281f141ce34SMatthew Knepley 
282ce85283eSBarry Smith /*
2833c94ec11SBarry Smith      This does not work for MPI-Uni because our include/mpiuni/mpi.h file
284ce85283eSBarry Smith    uses macros to defined the MPI operations.
28515308354SBarry Smith 
28615308354SBarry Smith      It does not work correctly from HP-UX because it processes the
287bb4af37aSBarry Smith    macros in a way that sometimes it double counts, hence
288b6410449SSatish Balay    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
2897c1e34a4SSatish Balay 
290*f569fd43SBarry Smith      It does not work with Windows because winmpich lacks MPI_Type_size()
291ce85283eSBarry Smith */
292f35a08a5SSatish Balay #if !defined(_petsc_mpi_uni) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
29377a39924SBarry Smith /*
29477a39924SBarry Smith    Logging of MPI activities
29577a39924SBarry Smith */
29677a39924SBarry Smith 
29777a39924SBarry Smith #define TypeSize(buff,count,type) \
298ca161407SBarry Smith (\
299b0a32e0cSBarry Smith   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PetscLogDouble) ((count)*PETSC_DUMMY_SIZE))\
300ca161407SBarry Smith )
30177a39924SBarry Smith 
30277a39924SBarry Smith #define MPI_Irecv(buf,count, datatype,source,tag,comm,request) \
303ca161407SBarry Smith (\
304ca161407SBarry Smith   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),\
305ca161407SBarry Smith   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY\
306ca161407SBarry Smith )
30715308354SBarry Smith 
30877a39924SBarry Smith #define MPI_Isend(buf,count, datatype,dest,tag,comm,request) \
309ca161407SBarry Smith (\
310ca161407SBarry Smith   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),\
311ca161407SBarry Smith   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY\
312ca161407SBarry Smith )
31315308354SBarry Smith 
3140d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
315ca161407SBarry Smith (\
316ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),\
31787828ca2SBarry Smith   irecv_ct += (PetscLogDouble)(number),irecv_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
318ca161407SBarry Smith )
3190d4b0b6cSBarry Smith 
3200d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
321ca161407SBarry Smith (\
322ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),\
32387828ca2SBarry Smith   isend_ct += (PetscLogDouble)(number),isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
324ca161407SBarry Smith )
3250d4b0b6cSBarry Smith 
3260d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests) \
327ca161407SBarry Smith (\
328ca161407SBarry Smith   PETSC_DUMMY = MPI_Start(requests),\
32987828ca2SBarry Smith   isend_ct++,isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
330ca161407SBarry Smith )
3310d4b0b6cSBarry Smith 
332ce85283eSBarry Smith #define MPI_Recv(buf,count, datatype,source,tag,comm,status) \
333ca161407SBarry Smith (\
334ca161407SBarry Smith   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),\
335ca161407SBarry Smith   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY\
336ca161407SBarry Smith )
33715308354SBarry Smith 
33877a39924SBarry Smith #define MPI_Send(buf,count, datatype,dest,tag,comm) \
339ca161407SBarry Smith (\
340ca161407SBarry Smith   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),\
341ca161407SBarry Smith   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY\
342ca161407SBarry Smith )
34377a39924SBarry Smith 
34477a39924SBarry Smith #define MPI_Wait(request,status) \
34577a39924SBarry Smith (\
346e0937024SBarry Smith   wait_ct++,sum_of_waits_ct++,\
34777a39924SBarry Smith   MPI_Wait(request,status)\
34877a39924SBarry Smith )
34977a39924SBarry Smith 
35077a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \
35177a39924SBarry Smith (\
352e0937024SBarry Smith   wait_any_ct++,sum_of_waits_ct++,\
35377a39924SBarry Smith   MPI_Waitany(a,b,c,d)\
35477a39924SBarry Smith )
35577a39924SBarry Smith 
35677a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
35777a39924SBarry Smith (\
358b0a32e0cSBarry Smith   wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),\
35977a39924SBarry Smith   MPI_Waitall(count,array_of_requests,array_of_statuses)\
36077a39924SBarry Smith )
36177a39924SBarry Smith 
36277a39924SBarry Smith #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
3630743b949SBarry Smith (\
3640743b949SBarry Smith   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
3650743b949SBarry Smith )
3663914022bSBarry Smith 
3670d4b0b6cSBarry Smith #else
3680d4b0b6cSBarry Smith 
3690d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
370ca161407SBarry Smith (\
371ca161407SBarry Smith   MPI_Startall(number,requests)\
372ca161407SBarry Smith )
3730d4b0b6cSBarry Smith 
3740d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
375ca161407SBarry Smith (\
376ca161407SBarry Smith   MPI_Startall(number,requests)\
377ca161407SBarry Smith )
3780d4b0b6cSBarry Smith 
3790d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests) \
380ca161407SBarry Smith (\
381ca161407SBarry Smith   MPI_Start(requests)\
382ca161407SBarry Smith )
3830d4b0b6cSBarry Smith 
384f35a08a5SSatish Balay #endif /* !_petsc_mpi_uni && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
385614700edSBarry Smith 
386df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
387614700edSBarry Smith 
388b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
389614700edSBarry Smith 
390df8cf0b5SBarry Smith /*
391df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
392df8cf0b5SBarry Smith */
393b0a32e0cSBarry Smith #define PetscLogMPEBegin()         0
394b0a32e0cSBarry Smith #define PetscLogMPEDump(a)         0
395614700edSBarry Smith 
396b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
397b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
398614700edSBarry Smith 
399b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
400b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
40177c4ece6SBarry Smith 
402b0a32e0cSBarry Smith #define _PetscLogPLB                        0
403b0a32e0cSBarry Smith #define _PetscLogPLE                        0
404b0a32e0cSBarry Smith #define _PetscLogPHC                        0
405b0a32e0cSBarry Smith #define _PetscLogPHD                        0
40699de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
407b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
408b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
409b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
410b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
411b0a32e0cSBarry Smith #define PetscLogObjectParent(p,c)
412b0a32e0cSBarry Smith #define PetscLogObjectParents(p,n,c)
413b0a32e0cSBarry Smith #define PetscLogObjectCreate(h)
414b0a32e0cSBarry Smith #define PetscLogObjectDestroy(h)
415b0a32e0cSBarry Smith #define PetscLogObjectMemory(p,m)
416b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
417b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
418b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
419b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
420b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
421b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file)     0
422b0a32e0cSBarry Smith #define PetscLogBegin()                     0
423b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
424b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
425b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
426b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
427043328b6SSatish Balay #define PetscLogEventRegister(a,b,c)        0
42873fda44aSBarry Smith #define PetscLogObjects(a)                  0
42973fda44aSBarry Smith #define PetscLogActions(a)                  0
430f80b7eb0SBarry Smith EXTERN int PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
431ce6058e1SBarry Smith 
432aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
433ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
434ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
435ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
436ca161407SBarry Smith 
437f141ce34SMatthew Knepley /* Creation and destruction functions */
438f141ce34SMatthew Knepley #define StageLogCreate(stageLog)                     0
439f141ce34SMatthew Knepley #define StageLogDestroy(stageLog)                    0
440f141ce34SMatthew Knepley /* Registration functions */
441f141ce34SMatthew Knepley #define StageLogRegister(stageLog, name, stage)      0
442f141ce34SMatthew Knepley /* Runtime functions */
443f141ce34SMatthew Knepley #define PetscLogGetStageLog(stageLog)                0
444f141ce34SMatthew Knepley #define StageLogPush(stageLog, stage)                0
445f141ce34SMatthew Knepley #define StageLogPop(stageLog)                        0
446f141ce34SMatthew Knepley #define StageLogGetCurrent(stageLog, stage)          0
447f141ce34SMatthew Knepley #define StageLogSetActive(stageLog, stage, active)   0
448f141ce34SMatthew Knepley #define StageLogGetActive(stageLog, stage, active)   0
449f141ce34SMatthew Knepley #define StageLogSetVisible(stageLog, stage, visible) 0
450f141ce34SMatthew Knepley #define StageLogGetVisible(stageLog, stage, visible) 0
451f141ce34SMatthew Knepley #define StageLogGetStage(stageLog, name, stage)      0
452f141ce34SMatthew Knepley 
453aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4546daaf66cSBarry Smith 
455435da068SBarry Smith extern PetscTruth PetscPreLoadingUsed;       /* true if we are or have done preloading */
456435da068SBarry Smith extern PetscTruth PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
4571d1367b7SBarry Smith 
458043328b6SSatish Balay #define PreLoadBegin(flag,name) \
459043328b6SSatish Balay {\
460043328b6SSatish Balay   PetscTruth PreLoading = flag;\
4618e58c17dSMatthew Knepley   int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
4626e491fe6SBarry Smith   _3_ierr = PetscOptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
463043328b6SSatish Balay   PreLoadMax = (int)(PreLoading);\
464043328b6SSatish Balay   PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
465e7592fafSBarry Smith   for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
466435da068SBarry Smith     PetscPreLoadingOn = PreLoading;\
4676e491fe6SBarry Smith     _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
4688e58c17dSMatthew Knepley     if (PreLoadIt>0) {\
4698e58c17dSMatthew Knepley       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4708e58c17dSMatthew Knepley     } else {\
4718e58c17dSMatthew Knepley       _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
4728e58c17dSMatthew Knepley     }\
473773a6509SMatthew Knepley     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
4748e58c17dSMatthew Knepley     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
4758e58c17dSMatthew Knepley 
476043328b6SSatish Balay #define PreLoadEnd() \
477043328b6SSatish Balay     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
478043328b6SSatish Balay     PreLoading = PETSC_FALSE;\
479043328b6SSatish Balay   }\
480043328b6SSatish Balay }
4818e58c17dSMatthew Knepley 
482043328b6SSatish Balay #define PreLoadStage(name) \
483043328b6SSatish Balay   _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
4848e58c17dSMatthew Knepley   if (PreLoadIt>0) {\
4858e58c17dSMatthew Knepley     _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4868e58c17dSMatthew Knepley   } else {\
4878e58c17dSMatthew Knepley     _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
4888e58c17dSMatthew Knepley   }\
489773a6509SMatthew Knepley   _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
4908e58c17dSMatthew Knepley   _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
491e9fa29b7SSatish Balay 
492e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END
49397bb86f7SLois Curfman McInnes #endif
494