xref: /petsc/include/petsclog.h (revision 8e58c17d92fd182847eda150482aa81aa9e1fb44)
173f4d377SMatthew Knepley /* $Id: petsclog.h,v 1.155 2001/09/06 14:51:20 bsmith Exp $ */
297bb86f7SLois Curfman McInnes 
397bb86f7SLois Curfman McInnes /*
47588ac45SBarry Smith     Defines profile/logging in PETSc.
597bb86f7SLois Curfman McInnes */
697bb86f7SLois Curfman McInnes 
7b0a32e0cSBarry Smith #if !defined(__PetscLog_H)
8b0a32e0cSBarry Smith #define __PetscLog_H
997bb86f7SLois Curfman McInnes #include "petsc.h"
1097bb86f7SLois Curfman McInnes 
1197bb86f7SLois Curfman McInnes /*
128ba1e511SMatthew Knepley   Each PETSc object class has it's own cookie (internal integer in the
138ba1e511SMatthew Knepley   data structure used for error checking). These are all defined by an offset
148ba1e511SMatthew Knepley   from the lowest one, PETSC_COOKIE.
1597bb86f7SLois Curfman McInnes */
168ba1e511SMatthew Knepley #define PETSC_COOKIE 1211211
178ba1e511SMatthew Knepley extern int PETSC_LARGEST_COOKIE;
188ba1e511SMatthew Knepley #define PETSC_EVENT  1311311
198ba1e511SMatthew Knepley extern int PETSC_LARGEST_EVENT;
2097bb86f7SLois Curfman McInnes 
218ba1e511SMatthew Knepley /* Events for the Petsc standard library */
228ba1e511SMatthew Knepley enum {PETSC_Barrier, PETSC_MAX_EVENTS};
238ba1e511SMatthew Knepley extern int PetscEvents[PETSC_MAX_EVENTS];
2497bb86f7SLois Curfman McInnes 
2519b02663SBarry Smith /* Global flop counter */
26b0a32e0cSBarry Smith extern PetscLogDouble _TotalFlops;
2719b02663SBarry Smith 
28edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */
29b0a32e0cSBarry Smith EXTERN int        PetscLogInfo(void*,const char[],...);
30b0a32e0cSBarry Smith EXTERN int        PetscLogInfoDeactivateClass(int);
31b0a32e0cSBarry Smith EXTERN int        PetscLogInfoActivateClass(int);
32b0a32e0cSBarry Smith extern PetscTruth PetscLogPrintInfo;  /* if true, indicates PetscLogInfo() is turned on */
33614700edSBarry Smith 
34aa482453SBarry Smith #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
35614700edSBarry Smith 
36da63de55SLois Curfman McInnes /*
37da63de55SLois Curfman McInnes    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
38da63de55SLois Curfman McInnes 
39da63de55SLois Curfman McInnes    For the complex numbers version, note that
40da63de55SLois Curfman McInnes        1 complex addition = 2 flops
41da63de55SLois Curfman McInnes        1 complex multiplication = 6 flops,
42da63de55SLois Curfman McInnes    where we define 1 flop as that for a double precision scalar.  We roughly approximate
43da63de55SLois Curfman McInnes    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
44da63de55SLois Curfman McInnes    to the assumption that we're counting mostly additions and multiplications -- and
45da63de55SLois Curfman McInnes    roughly the same number of each.  More accurate counting could be done by distinguishing
46da63de55SLois Curfman McInnes    among the various arithmetic operations.
47da63de55SLois Curfman McInnes  */
48da63de55SLois Curfman McInnes 
49aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
50b0a32e0cSBarry Smith #define PetscLogFlops(n) (_TotalFlops += (4*n),0)
51da63de55SLois Curfman McInnes #else
52b0a32e0cSBarry Smith #define PetscLogFlops(n) (_TotalFlops += (n),0)
53da63de55SLois Curfman McInnes #endif
5477c4ece6SBarry Smith 
55aa482453SBarry Smith #if defined (PETSC_HAVE_MPE)
5677c4ece6SBarry Smith #include "mpe.h"
57614700edSBarry Smith #define MPEBEGIN    1000
58b0a32e0cSBarry Smith EXTERN int        PetscLogMPEBegin(void);
59b0a32e0cSBarry Smith EXTERN int        PetscLogMPEDump(const char[]);
6035d8aa7fSBarry Smith extern PetscTruth UseMPE;
61b0a32e0cSBarry Smith extern int        PetscLogEventMPEFlags[];
62b0a32e0cSBarry Smith EXTERN int        PetscLogEventMPEActivate(int);
63b0a32e0cSBarry Smith EXTERN int        PetscLogEventMPEDeactivate(int);
64614700edSBarry Smith #else
65b0a32e0cSBarry Smith #define PetscLogEventMPEActivate(a) 0
66b0a32e0cSBarry Smith #define PetscLogEventMPEDeactivate(a) 0
6777c4ece6SBarry Smith #endif
6877c4ece6SBarry Smith 
69b0a32e0cSBarry Smith EXTERN int (*_PetscLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
70b0a32e0cSBarry Smith EXTERN int (*_PetscLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
71b0a32e0cSBarry Smith EXTERN int (*_PetscLogPHC)(PetscObject);
72b0a32e0cSBarry Smith EXTERN int (*_PetscLogPHD)(PetscObject);
7377c4ece6SBarry Smith 
748ba1e511SMatthew Knepley #define PetscLogObjectParent(p,c)       if (c) {PetscValidHeader((PetscObject)(c)); \
758ba1e511SMatthew Knepley                                                 PetscValidHeader((PetscObject)(p));\
768ba1e511SMatthew Knepley                                                 ((PetscObject)(c))->parent = (PetscObject)(p);\
778ba1e511SMatthew Knepley 				                ((PetscObject)(c))->parentid = ((PetscObject)p)->id;}
788ba1e511SMatthew Knepley #define PetscLogObjectParents(p,n,d)    {int _i; for (_i=0; _i<n; _i++) \
798ba1e511SMatthew Knepley                                          PetscLogObjectParent(p,(d)[_i]);}
808ba1e511SMatthew Knepley #define PetscLogObjectCreate(h)         {if (_PetscLogPHC) (*_PetscLogPHC)((PetscObject)h);}
818ba1e511SMatthew Knepley #define PetscLogObjectDestroy(h)        {if (_PetscLogPHD) (*_PetscLogPHD)((PetscObject)h);}
828ba1e511SMatthew Knepley #define PetscLogObjectMemory(p,m)       {PetscValidHeader((PetscObject)p);\
838ba1e511SMatthew Knepley                                          ((PetscObject)(p))->mem += (m);}
848ba1e511SMatthew Knepley /* Initialization functions */
858ba1e511SMatthew Knepley EXTERN int PetscLogBegin(void);
868ba1e511SMatthew Knepley EXTERN int PetscLogAllBegin(void);
878ba1e511SMatthew Knepley EXTERN int PetscLogTraceBegin(FILE *);
888ba1e511SMatthew Knepley /* General functions */
898ba1e511SMatthew Knepley EXTERN int PetscLogDestroy(void);
908ba1e511SMatthew Knepley EXTERN int PetscLogSet(int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
918ba1e511SMatthew Knepley                    int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
928ba1e511SMatthew Knepley EXTERN int PetscLogObjectState(PetscObject, const char[], ...);
938ba1e511SMatthew Knepley /* Output functions */
948ba1e511SMatthew Knepley EXTERN int PetscLogPrintSummary(MPI_Comm, const char[]);
958ba1e511SMatthew Knepley EXTERN int PetscLogDump(const char[]);
968ba1e511SMatthew Knepley /* Counter functions */
978ba1e511SMatthew Knepley EXTERN int PetscGetFlops(PetscLogDouble *);
988ba1e511SMatthew Knepley /* Stage functions */
998ba1e511SMatthew Knepley EXTERN int PetscLogStageRegister(int *, const char[]);
1008ba1e511SMatthew Knepley EXTERN int PetscLogStagePush(int);
1018ba1e511SMatthew Knepley EXTERN int PetscLogStagePop(void);
1028ba1e511SMatthew Knepley EXTERN int PetscLogStageSetVisible(int, PetscTruth);
1038ba1e511SMatthew Knepley EXTERN int PetscLogStageGetVisible(int, PetscTruth *);
104*8e58c17dSMatthew Knepley EXTERN int PetscLogStageGetId(const char [], int *);
1058ba1e511SMatthew Knepley /* Event functions */
1068ba1e511SMatthew Knepley EXTERN int PetscLogEventRegister(int *, const char[], const char[], int);
1078ba1e511SMatthew Knepley EXTERN int PetscLogEventActivate(int);
1088ba1e511SMatthew Knepley EXTERN int PetscLogEventDeactivate(int);
1098ba1e511SMatthew Knepley EXTERN int PetscLogEventActivateClass(int);
1108ba1e511SMatthew Knepley EXTERN int PetscLogEventDeactivateClass(int);
1118ba1e511SMatthew Knepley /* Class functions */
1128ba1e511SMatthew Knepley EXTERN int PetscLogClassRegister(int *, const char []);
1138ba1e511SMatthew Knepley 
1148ba1e511SMatthew Knepley /* Default log */
1158ba1e511SMatthew Knepley typedef struct _StageLog *StageLog;
1168ba1e511SMatthew Knepley extern StageLog _stageLog;
1178ba1e511SMatthew Knepley 
1188ba1e511SMatthew Knepley /* Global counters */
1198ba1e511SMatthew Knepley extern PetscLogDouble irecv_ct,  isend_ct,  recv_ct,  send_ct;
1208ba1e511SMatthew Knepley extern PetscLogDouble irecv_len, isend_len, recv_len, send_len;
1218ba1e511SMatthew Knepley extern PetscLogDouble allreduce_ct;
1228ba1e511SMatthew Knepley extern PetscLogDouble wait_ct, wait_any_ct, wait_all_ct, sum_of_waits_ct;
1238ba1e511SMatthew Knepley extern int            PETSC_DUMMY, PETSC_DUMMY_SIZE;
1248ba1e511SMatthew Knepley 
1258ba1e511SMatthew Knepley /* We must make these structures available if we are to access the event
1268ba1e511SMatthew Knepley    activation flags in the PetscLogEventBegin/End() macros. If we forced a
1278ba1e511SMatthew Knepley    function call each time, we could leave these structures in plog.h
1288ba1e511SMatthew Knepley */
1298ba1e511SMatthew Knepley /* The structure for logging performance */
1308ba1e511SMatthew Knepley typedef struct _PerfInfo {
1318ba1e511SMatthew Knepley   char          *name;          /* The name of this section */
1328ba1e511SMatthew Knepley   char          *color;         /* The color of this section */
1338ba1e511SMatthew Knepley   int            id;            /* The integer identifying this event */
1348ba1e511SMatthew Knepley   int            cookie;        /* The class id for this section */
1358ba1e511SMatthew Knepley   int            depth;         /* The nesting depth of the event call */
1368ba1e511SMatthew Knepley   int            count;         /* The number of times this section was executed */
1378ba1e511SMatthew Knepley   PetscLogDouble flops;         /* The flops used in this section */
1388ba1e511SMatthew Knepley   PetscLogDouble time;          /* The time taken for this section */
1398ba1e511SMatthew Knepley   PetscLogDouble numMessages;   /* The number of messages in this section */
1408ba1e511SMatthew Knepley   PetscLogDouble messageLength; /* The total message lengths in this section */
1418ba1e511SMatthew Knepley   PetscLogDouble numReductions; /* The number of reductions in this section */
1428ba1e511SMatthew Knepley } PerfInfo;
1438ba1e511SMatthew Knepley 
1448ba1e511SMatthew Knepley /* The structure for logging events */
1458ba1e511SMatthew Knepley typedef struct _EventLog *EventLog;
1468ba1e511SMatthew Knepley struct _EventLog {
1478ba1e511SMatthew Knepley   /* Size information */
1488ba1e511SMatthew Knepley   int       numEvents;   /* The number of registered events */
1498ba1e511SMatthew Knepley   int       maxEvents;   /* The maximum number of events */
1508ba1e511SMatthew Knepley   /* Event specific information */
1518ba1e511SMatthew Knepley   int      *eventActive; /* The flag for active events */
1528ba1e511SMatthew Knepley   PerfInfo *eventInfo;   /* The performance information for each event */
1538ba1e511SMatthew Knepley };
1548ba1e511SMatthew Knepley 
1558ba1e511SMatthew Knepley /* The structure for logging class information */
1568ba1e511SMatthew Knepley typedef struct _ClassInfo {
1578ba1e511SMatthew Knepley   char          *name;          /* The class name */
1588ba1e511SMatthew Knepley   int            cookie;        /* The integer identifying this class */
1598ba1e511SMatthew Knepley   int            creations;     /* The number of objects of this class created */
1608ba1e511SMatthew Knepley   int            destructions;  /* The number of objects of this class destroyed */
1618ba1e511SMatthew Knepley   PetscLogDouble mem;           /* The total memory allocated by objects of this class */
1628ba1e511SMatthew Knepley   PetscLogDouble descMem;       /* The total memory allocated by descendents of these objects */
1638ba1e511SMatthew Knepley } ClassInfo;
1648ba1e511SMatthew Knepley 
1658ba1e511SMatthew Knepley typedef struct _ClassLog *ClassLog;
1668ba1e511SMatthew Knepley struct _ClassLog {
1678ba1e511SMatthew Knepley   int        numClasses; /* The number of classes registered */
1688ba1e511SMatthew Knepley   int        maxClasses; /* The maximum number of classes */
1698ba1e511SMatthew Knepley   ClassInfo *classInfo;  /* The structure for classs information (cookies are monotonicly increasing) */
1708ba1e511SMatthew Knepley };
1718ba1e511SMatthew Knepley 
1728ba1e511SMatthew Knepley /* A simple stack (should replace) */
1738ba1e511SMatthew Knepley typedef struct _IntStack *IntStack;
1748ba1e511SMatthew Knepley 
1758ba1e511SMatthew Knepley /* The structure for logging in stages */
1768ba1e511SMatthew Knepley struct _StageLog {
1778ba1e511SMatthew Knepley   /* Size information */
1788ba1e511SMatthew Knepley   int         numStages;    /* The number of registered stages */
1798ba1e511SMatthew Knepley   int         maxStages;    /* The maximum number of stages */
1808ba1e511SMatthew Knepley   /* Runtime information */
1818ba1e511SMatthew Knepley   int        *stageUsed;    /* The flags for stages which were executed */
1828ba1e511SMatthew Knepley   PetscTruth *stageVisible; /* The flags for stages which are visible to PetscLogPrintSummary() */
1838ba1e511SMatthew Knepley   IntStack    stack;        /* The stack for active stages */
1848ba1e511SMatthew Knepley   int         curStage;     /* The current stage (only used in macros so we don't call StackTop) */
1858ba1e511SMatthew Knepley   /* Stage specific information */
1868ba1e511SMatthew Knepley   PerfInfo   *stageInfo;    /* The performance information for each stage */
1878ba1e511SMatthew Knepley   EventLog   *eventLog;     /* The event log for each stage */
1888ba1e511SMatthew Knepley   ClassLog   *classLog;     /* The class information for each stage */
1898ba1e511SMatthew Knepley };
1908ba1e511SMatthew Knepley 
1918ba1e511SMatthew Knepley EXTERN int EventLogGetEvent(EventLog, int, int *);
1920743b949SBarry Smith 
193aa482453SBarry Smith #if defined(PETSC_HAVE_MPE)
194b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
1958ba1e511SMatthew Knepley   0; { int _1_ierr, _1_eventNum; \
1968ba1e511SMatthew Knepley     _1_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_1_eventNum); \
1978ba1e511SMatthew Knepley     if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_1_eventNum]) { \
1986e491fe6SBarry Smith       _1_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_1_ierr);  \
199b0a32e0cSBarry Smith       if (UseMPE && PetscLogEventMPEFlags[(e)])                      \
200005c665bSBarry Smith         MPE_Log_event(MPEBEGIN+2*(e),0,"");                      \
2016e491fe6SBarry Smith       _1_ierr = MPI_Barrier(cm);CHKERRQ(_1_ierr);                  \
2026e491fe6SBarry Smith       _1_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_1_ierr);    \
203b0a32e0cSBarry Smith       if (UseMPE && PetscLogEventMPEFlags[(e)])                      \
204005c665bSBarry Smith         MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                  \
205005c665bSBarry Smith     }                                                            \
2066e491fe6SBarry Smith     _1_ierr = PetscLogEventBegin(e+1,o1,o2,o3,o4);CHKERRQ(_1_ierr);    \
207b0a32e0cSBarry Smith     if (UseMPE && PetscLogEventMPEFlags[(e)+1])                      \
208005c665bSBarry Smith       MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                    \
209005c665bSBarry Smith   }
210b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)  \
2118ba1e511SMatthew Knepley   0; { int _3_ierr, _3_eventNum; \
2128ba1e511SMatthew Knepley     _3_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_3_eventNum); \
2138ba1e511SMatthew Knepley    if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_3_eventNum]) {\
214b0a32e0cSBarry Smith      (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
215b0a32e0cSBarry Smith    if (UseMPE && PetscLogEventMPEFlags[(e)])\
216005c665bSBarry Smith      MPE_Log_event(MPEBEGIN+2*(e),0,"");\
21777c4ece6SBarry Smith   }
21877c4ece6SBarry Smith #else
219b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
2208ba1e511SMatthew Knepley   0; { int _2_ierr, _2_eventNum;\
2218ba1e511SMatthew Knepley     _2_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_2_eventNum); \
2228ba1e511SMatthew Knepley     if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_2_eventNum]) {                         \
2236e491fe6SBarry Smith       _2_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);    \
2246e491fe6SBarry Smith       _2_ierr = MPI_Barrier(cm);CHKERRQ(_2_ierr);                    \
2256e491fe6SBarry Smith       _2_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);      \
226005c665bSBarry Smith     }                                                              \
2276e491fe6SBarry Smith     _2_ierr = PetscLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(_2_ierr);    \
228005c665bSBarry Smith   }
229b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)  \
2308ba1e511SMatthew Knepley   0; { int _4_ierr, _4_eventNum; \
2318ba1e511SMatthew Knepley     _4_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_4_eventNum); \
2328ba1e511SMatthew Knepley    if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_4_eventNum]) {\
233b0a32e0cSBarry Smith      (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
23477c4ece6SBarry Smith   }
23577c4ece6SBarry Smith #endif
23677c4ece6SBarry Smith 
237aa482453SBarry Smith #if defined(PETSC_HAVE_MPE)
238b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
239b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2408ba1e511SMatthew Knepley   0; { int _5_ierr, _5_eventNum; \
2418ba1e511SMatthew Knepley     _5_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_5_eventNum); \
2428ba1e511SMatthew Knepley   if (_PetscLogPLE && _stageLog->eventLog[_stageLog->curStage]->eventActive[_5_eventNum]) {\
243b0a32e0cSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
244b0a32e0cSBarry Smith   if (UseMPE && PetscLogEventMPEFlags[(e)])\
245005c665bSBarry Smith      MPE_Log_event(MPEBEGIN+2*(e)+1,0,"");\
246a1b5d808SSatish Balay   }
24777c4ece6SBarry Smith #else
248b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
249b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2508ba1e511SMatthew Knepley   0; { int _6_ierr, _6_eventNum; \
2518ba1e511SMatthew Knepley     _6_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_6_eventNum); \
2528ba1e511SMatthew Knepley   if (_PetscLogPLE && _stageLog->eventLog[_stageLog->curStage]->eventActive[_6_eventNum]) {\
253b0a32e0cSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
254a1b5d808SSatish Balay   }
25577c4ece6SBarry Smith #endif
25677c4ece6SBarry Smith 
257ce85283eSBarry Smith /*
25884cb2905SBarry Smith      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
259ce85283eSBarry Smith    uses macros to defined the MPI operations.
26015308354SBarry Smith 
26115308354SBarry Smith      It does not work correctly from HP-UX because it processes the
262bb4af37aSBarry Smith    macros in a way that sometimes it double counts, hence
263aa482453SBarry Smith    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
2647c1e34a4SSatish Balay 
2657c1e34a4SSatish Balay      It does not work with Windows NT because winmpich lacks MPI_Type_size()
266ce85283eSBarry Smith */
2678ba1e511SMatthew Knepley #if !defined(HAVE_MPI_UNI) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
26877a39924SBarry Smith /*
26977a39924SBarry Smith    Logging of MPI activities
27077a39924SBarry Smith */
27177a39924SBarry Smith 
27277a39924SBarry Smith #define TypeSize(buff,count,type)                                                \
273ca161407SBarry Smith (\
274b0a32e0cSBarry Smith   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PetscLogDouble) ((count)*PETSC_DUMMY_SIZE)) \
275ca161407SBarry Smith )
27677a39924SBarry Smith 
27777a39924SBarry Smith #define MPI_Irecv(buf,count, datatype,source,tag,comm,request)        \
278ca161407SBarry Smith (\
279ca161407SBarry Smith   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),            \
280ca161407SBarry Smith   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY                            \
281ca161407SBarry Smith )
28215308354SBarry Smith 
28377a39924SBarry Smith #define MPI_Isend(buf,count, datatype,dest,tag,comm,request)          \
284ca161407SBarry Smith (\
285ca161407SBarry Smith   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),              \
286ca161407SBarry Smith   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY                          \
287ca161407SBarry Smith )
28815308354SBarry Smith 
2890d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests)                                     \
290ca161407SBarry Smith (\
291ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),                                                    \
29287828ca2SBarry Smith   irecv_ct += (PetscLogDouble)(number),irecv_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY \
293ca161407SBarry Smith )
2940d4b0b6cSBarry Smith 
2950d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests)                                    \
296ca161407SBarry Smith (\
297ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),                                                   \
29887828ca2SBarry Smith   isend_ct += (PetscLogDouble)(number),isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY \
299ca161407SBarry Smith )
3000d4b0b6cSBarry Smith 
3010d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests)\
302ca161407SBarry Smith (\
303ca161407SBarry Smith   PETSC_DUMMY = MPI_Start(requests),\
30487828ca2SBarry Smith   isend_ct++,isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
305ca161407SBarry Smith )
3060d4b0b6cSBarry Smith 
307ce85283eSBarry Smith #define MPI_Recv(buf,count, datatype,source,tag,comm,status)           \
308ca161407SBarry Smith (\
309ca161407SBarry Smith   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),               \
310ca161407SBarry Smith   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY                              \
311ca161407SBarry Smith )
31215308354SBarry Smith 
31377a39924SBarry Smith #define MPI_Send(buf,count, datatype,dest,tag,comm)                     \
314ca161407SBarry Smith (\
315ca161407SBarry Smith   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),                         \
316ca161407SBarry Smith   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY                              \
317ca161407SBarry Smith )
31877a39924SBarry Smith 
31977a39924SBarry Smith #define MPI_Wait(request,status) \
32077a39924SBarry Smith (\
321e0937024SBarry Smith   wait_ct++,sum_of_waits_ct++,  \
32277a39924SBarry Smith   MPI_Wait(request,status)       \
32377a39924SBarry Smith )
32477a39924SBarry Smith 
32577a39924SBarry Smith #define MPI_Waitany(a,b,c,d)     \
32677a39924SBarry Smith (\
327e0937024SBarry Smith   wait_any_ct++,sum_of_waits_ct++,\
32877a39924SBarry Smith   MPI_Waitany(a,b,c,d)           \
32977a39924SBarry Smith )
33077a39924SBarry Smith 
33177a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
33277a39924SBarry Smith (\
333b0a32e0cSBarry Smith   wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),       \
33477a39924SBarry Smith   MPI_Waitall(count,array_of_requests,array_of_statuses)       \
33577a39924SBarry Smith )
33677a39924SBarry Smith 
33777a39924SBarry Smith #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
3380743b949SBarry Smith (\
3390743b949SBarry Smith   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
3400743b949SBarry Smith )
3413914022bSBarry Smith 
3420d4b0b6cSBarry Smith #else
3430d4b0b6cSBarry Smith 
3440d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
345ca161407SBarry Smith (\
346ca161407SBarry Smith   MPI_Startall(number,requests)                 \
347ca161407SBarry Smith )
3480d4b0b6cSBarry Smith 
3490d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
350ca161407SBarry Smith (\
351ca161407SBarry Smith   MPI_Startall(number,requests)                 \
352ca161407SBarry Smith )
3530d4b0b6cSBarry Smith 
3540d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests) \
355ca161407SBarry Smith (\
356ca161407SBarry Smith   MPI_Start(requests)                   \
357ca161407SBarry Smith )
3580d4b0b6cSBarry Smith 
359aa482453SBarry Smith #endif /* !USING_MPIUNI && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
360614700edSBarry Smith 
361df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
362614700edSBarry Smith 
363b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
364614700edSBarry Smith 
365df8cf0b5SBarry Smith /*
366df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
367df8cf0b5SBarry Smith */
368614700edSBarry Smith #define MPEBEGIN                  1000
369b0a32e0cSBarry Smith #define PetscLogMPEBegin()            0
370b0a32e0cSBarry Smith #define PetscLogMPEDump(a)            0
371b0a32e0cSBarry Smith #define PetscLogEventMPEActivate(a)   0
372b0a32e0cSBarry Smith #define PetscLogEventMPEDeactivate(a) 0
373614700edSBarry Smith 
374b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
375b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
376614700edSBarry Smith 
377b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
378b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
37977c4ece6SBarry Smith 
380b0a32e0cSBarry Smith #define _PetscLogPLB                        0
381b0a32e0cSBarry Smith #define _PetscLogPLE                        0
382b0a32e0cSBarry Smith #define _PetscLogPHC                        0
383b0a32e0cSBarry Smith #define _PetscLogPHD                        0
38499de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
385b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
386b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
387b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
388b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
389b0a32e0cSBarry Smith #define PetscLogObjectParent(p,c)
390b0a32e0cSBarry Smith #define PetscLogObjectParents(p,n,c)
391b0a32e0cSBarry Smith #define PetscLogObjectCreate(h)
392b0a32e0cSBarry Smith #define PetscLogObjectDestroy(h)
393b0a32e0cSBarry Smith #define PetscLogObjectMemory(p,m)
394b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
395b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
396b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
397b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
398b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
399b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file)     0
400b0a32e0cSBarry Smith #define PetscLogBegin()                     0
401b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
402b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
403b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
404b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
405b0a32e0cSBarry Smith #define PetscLogEventRegister(a,b,c)        0
406b0a32e0cSBarry Smith EXTERN int PetscLogObjectState(PetscObject,const char[],...);
407ce6058e1SBarry Smith 
408aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
409ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
410ce6058e1SBarry Smith 
411ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
412ce6058e1SBarry Smith 
413ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
414ca161407SBarry Smith 
415aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4166daaf66cSBarry Smith 
417435da068SBarry Smith extern PetscTruth PetscPreLoadingUsed;       /* true if we are or have done preloading */
418435da068SBarry Smith extern PetscTruth PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
4191d1367b7SBarry Smith 
420*8e58c17dSMatthew Knepley #define PreLoadBegin(flag,name) {PetscTruth PreLoading = flag; \
421*8e58c17dSMatthew Knepley                                  int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
4226e491fe6SBarry Smith                                  _3_ierr = PetscOptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
4231d1367b7SBarry Smith                                  PreLoadMax = (int)(PreLoading);PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
424e7592fafSBarry Smith                                  for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
425435da068SBarry Smith                                    PetscPreLoadingOn = PreLoading;\
4266e491fe6SBarry Smith                                    _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
427*8e58c17dSMatthew Knepley                                    if (PreLoadIt>0) {\
428*8e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
429*8e58c17dSMatthew Knepley                                    } else {\
430*8e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
431*8e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageSetVisible(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
432*8e58c17dSMatthew Knepley                                    }\
433*8e58c17dSMatthew Knepley                                    _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
434*8e58c17dSMatthew Knepley 
4356e491fe6SBarry Smith #define PreLoadEnd()               _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);PreLoading = PETSC_FALSE;}}
436*8e58c17dSMatthew Knepley 
4376e491fe6SBarry Smith #define PreLoadStage(name)         _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
438*8e58c17dSMatthew Knepley                                    if (PreLoadIt>0) {\
439*8e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
440*8e58c17dSMatthew Knepley                                    } else {\
441*8e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
442*8e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageSetVisible(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
443*8e58c17dSMatthew Knepley                                    }\
444*8e58c17dSMatthew Knepley                                    _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
44597bb86f7SLois Curfman McInnes #endif
446