xref: /petsc/include/petsclog.h (revision d5ba7fb7d3f82433fc93946f26018f4b1c7683c8)
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 */
22*d5ba7fb7SMatthew Knepley extern int PETSC_Barrier;
2397bb86f7SLois Curfman McInnes 
2419b02663SBarry Smith /* Global flop counter */
25b0a32e0cSBarry Smith extern PetscLogDouble _TotalFlops;
2619b02663SBarry Smith 
27edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */
28b0a32e0cSBarry Smith EXTERN int        PetscLogInfo(void*,const char[],...);
29b0a32e0cSBarry Smith EXTERN int        PetscLogInfoDeactivateClass(int);
30b0a32e0cSBarry Smith EXTERN int        PetscLogInfoActivateClass(int);
31b0a32e0cSBarry Smith extern PetscTruth PetscLogPrintInfo;  /* if true, indicates PetscLogInfo() is turned on */
32614700edSBarry Smith 
33aa482453SBarry Smith #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
34614700edSBarry Smith 
35da63de55SLois Curfman McInnes /*
36da63de55SLois Curfman McInnes    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
37da63de55SLois Curfman McInnes 
38da63de55SLois Curfman McInnes    For the complex numbers version, note that
39da63de55SLois Curfman McInnes        1 complex addition = 2 flops
40da63de55SLois Curfman McInnes        1 complex multiplication = 6 flops,
41da63de55SLois Curfman McInnes    where we define 1 flop as that for a double precision scalar.  We roughly approximate
42da63de55SLois Curfman McInnes    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
43da63de55SLois Curfman McInnes    to the assumption that we're counting mostly additions and multiplications -- and
44da63de55SLois Curfman McInnes    roughly the same number of each.  More accurate counting could be done by distinguishing
45da63de55SLois Curfman McInnes    among the various arithmetic operations.
46da63de55SLois Curfman McInnes  */
47da63de55SLois Curfman McInnes 
48aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX)
49b0a32e0cSBarry Smith #define PetscLogFlops(n) (_TotalFlops += (4*n),0)
50da63de55SLois Curfman McInnes #else
51b0a32e0cSBarry Smith #define PetscLogFlops(n) (_TotalFlops += (n),0)
52da63de55SLois Curfman McInnes #endif
5377c4ece6SBarry Smith 
54aa482453SBarry Smith #if defined (PETSC_HAVE_MPE)
5577c4ece6SBarry Smith #include "mpe.h"
56614700edSBarry Smith #define MPEBEGIN    1000
57b0a32e0cSBarry Smith EXTERN int        PetscLogMPEBegin(void);
58b0a32e0cSBarry Smith EXTERN int        PetscLogMPEDump(const char[]);
5935d8aa7fSBarry Smith extern PetscTruth UseMPE;
60b0a32e0cSBarry Smith extern int        PetscLogEventMPEFlags[];
61b0a32e0cSBarry Smith EXTERN int        PetscLogEventMPEActivate(int);
62b0a32e0cSBarry Smith EXTERN int        PetscLogEventMPEDeactivate(int);
63614700edSBarry Smith #else
64b0a32e0cSBarry Smith #define PetscLogEventMPEActivate(a) 0
65b0a32e0cSBarry Smith #define PetscLogEventMPEDeactivate(a) 0
6677c4ece6SBarry Smith #endif
6777c4ece6SBarry Smith 
68b0a32e0cSBarry Smith EXTERN int (*_PetscLogPLB)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
69b0a32e0cSBarry Smith EXTERN int (*_PetscLogPLE)(int,int,PetscObject,PetscObject,PetscObject,PetscObject);
70b0a32e0cSBarry Smith EXTERN int (*_PetscLogPHC)(PetscObject);
71b0a32e0cSBarry Smith EXTERN int (*_PetscLogPHD)(PetscObject);
7277c4ece6SBarry Smith 
738ba1e511SMatthew Knepley #define PetscLogObjectParent(p,c)       if (c) {PetscValidHeader((PetscObject)(c)); \
748ba1e511SMatthew Knepley                                                 PetscValidHeader((PetscObject)(p));\
758ba1e511SMatthew Knepley                                                 ((PetscObject)(c))->parent = (PetscObject)(p);\
768ba1e511SMatthew Knepley 				                ((PetscObject)(c))->parentid = ((PetscObject)p)->id;}
778ba1e511SMatthew Knepley #define PetscLogObjectParents(p,n,d)    {int _i; for (_i=0; _i<n; _i++) \
788ba1e511SMatthew Knepley                                          PetscLogObjectParent(p,(d)[_i]);}
798ba1e511SMatthew Knepley #define PetscLogObjectCreate(h)         {if (_PetscLogPHC) (*_PetscLogPHC)((PetscObject)h);}
808ba1e511SMatthew Knepley #define PetscLogObjectDestroy(h)        {if (_PetscLogPHD) (*_PetscLogPHD)((PetscObject)h);}
818ba1e511SMatthew Knepley #define PetscLogObjectMemory(p,m)       {PetscValidHeader((PetscObject)p);\
828ba1e511SMatthew Knepley                                          ((PetscObject)(p))->mem += (m);}
838ba1e511SMatthew Knepley /* Initialization functions */
848ba1e511SMatthew Knepley EXTERN int PetscLogBegin(void);
858ba1e511SMatthew Knepley EXTERN int PetscLogAllBegin(void);
868ba1e511SMatthew Knepley EXTERN int PetscLogTraceBegin(FILE *);
878ba1e511SMatthew Knepley /* General functions */
888ba1e511SMatthew Knepley EXTERN int PetscLogDestroy(void);
898ba1e511SMatthew Knepley EXTERN int PetscLogSet(int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
908ba1e511SMatthew Knepley                    int (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
918ba1e511SMatthew Knepley EXTERN int PetscLogObjectState(PetscObject, const char[], ...);
928ba1e511SMatthew Knepley /* Output functions */
938ba1e511SMatthew Knepley EXTERN int PetscLogPrintSummary(MPI_Comm, const char[]);
948ba1e511SMatthew Knepley EXTERN int PetscLogDump(const char[]);
958ba1e511SMatthew Knepley /* Counter functions */
968ba1e511SMatthew Knepley EXTERN int PetscGetFlops(PetscLogDouble *);
978ba1e511SMatthew Knepley /* Stage functions */
988ba1e511SMatthew Knepley EXTERN int PetscLogStageRegister(int *, const char[]);
998ba1e511SMatthew Knepley EXTERN int PetscLogStagePush(int);
1008ba1e511SMatthew Knepley EXTERN int PetscLogStagePop(void);
1018ba1e511SMatthew Knepley EXTERN int PetscLogStageSetVisible(int, PetscTruth);
1028ba1e511SMatthew Knepley EXTERN int PetscLogStageGetVisible(int, PetscTruth *);
1038e58c17dSMatthew Knepley EXTERN int PetscLogStageGetId(const char [], int *);
1048ba1e511SMatthew Knepley /* Event functions */
1058ba1e511SMatthew Knepley EXTERN int PetscLogEventRegister(int *, const char[], const char[], int);
1068ba1e511SMatthew Knepley EXTERN int PetscLogEventActivate(int);
1078ba1e511SMatthew Knepley EXTERN int PetscLogEventDeactivate(int);
1088ba1e511SMatthew Knepley EXTERN int PetscLogEventActivateClass(int);
1098ba1e511SMatthew Knepley EXTERN int PetscLogEventDeactivateClass(int);
1108ba1e511SMatthew Knepley /* Class functions */
1118ba1e511SMatthew Knepley EXTERN int PetscLogClassRegister(int *, const char []);
1128ba1e511SMatthew Knepley 
1138ba1e511SMatthew Knepley /* Default log */
1148ba1e511SMatthew Knepley typedef struct _StageLog *StageLog;
1158ba1e511SMatthew Knepley extern StageLog _stageLog;
1168ba1e511SMatthew Knepley 
1178ba1e511SMatthew Knepley /* Global counters */
1188ba1e511SMatthew Knepley extern PetscLogDouble irecv_ct,  isend_ct,  recv_ct,  send_ct;
1198ba1e511SMatthew Knepley extern PetscLogDouble irecv_len, isend_len, recv_len, send_len;
1208ba1e511SMatthew Knepley extern PetscLogDouble allreduce_ct;
1218ba1e511SMatthew Knepley extern PetscLogDouble wait_ct, wait_any_ct, wait_all_ct, sum_of_waits_ct;
1228ba1e511SMatthew Knepley extern int            PETSC_DUMMY, PETSC_DUMMY_SIZE;
1238ba1e511SMatthew Knepley 
1248ba1e511SMatthew Knepley /* We must make these structures available if we are to access the event
1258ba1e511SMatthew Knepley    activation flags in the PetscLogEventBegin/End() macros. If we forced a
1268ba1e511SMatthew Knepley    function call each time, we could leave these structures in plog.h
1278ba1e511SMatthew Knepley */
1288ba1e511SMatthew Knepley /* The structure for logging performance */
1298ba1e511SMatthew Knepley typedef struct _PerfInfo {
1308ba1e511SMatthew Knepley   char          *name;          /* The name of this section */
1318ba1e511SMatthew Knepley   char          *color;         /* The color of this section */
1328ba1e511SMatthew Knepley   int            id;            /* The integer identifying this event */
1338ba1e511SMatthew Knepley   int            cookie;        /* The class id for this section */
1348ba1e511SMatthew Knepley   int            depth;         /* The nesting depth of the event call */
1358ba1e511SMatthew Knepley   int            count;         /* The number of times this section was executed */
1368ba1e511SMatthew Knepley   PetscLogDouble flops;         /* The flops used in this section */
1378ba1e511SMatthew Knepley   PetscLogDouble time;          /* The time taken for this section */
1388ba1e511SMatthew Knepley   PetscLogDouble numMessages;   /* The number of messages in this section */
1398ba1e511SMatthew Knepley   PetscLogDouble messageLength; /* The total message lengths in this section */
1408ba1e511SMatthew Knepley   PetscLogDouble numReductions; /* The number of reductions in this section */
1418ba1e511SMatthew Knepley } PerfInfo;
1428ba1e511SMatthew Knepley 
1438ba1e511SMatthew Knepley /* The structure for logging events */
1448ba1e511SMatthew Knepley typedef struct _EventLog *EventLog;
1458ba1e511SMatthew Knepley struct _EventLog {
1468ba1e511SMatthew Knepley   /* Size information */
1478ba1e511SMatthew Knepley   int       numEvents;   /* The number of registered events */
1488ba1e511SMatthew Knepley   int       maxEvents;   /* The maximum number of events */
1498ba1e511SMatthew Knepley   /* Event specific information */
1508ba1e511SMatthew Knepley   int      *eventActive; /* The flag for active events */
1518ba1e511SMatthew Knepley   PerfInfo *eventInfo;   /* The performance information for each event */
1528ba1e511SMatthew Knepley };
1538ba1e511SMatthew Knepley 
1548ba1e511SMatthew Knepley /* The structure for logging class information */
1558ba1e511SMatthew Knepley typedef struct _ClassInfo {
1568ba1e511SMatthew Knepley   char          *name;          /* The class name */
1578ba1e511SMatthew Knepley   int            cookie;        /* The integer identifying this class */
1588ba1e511SMatthew Knepley   int            creations;     /* The number of objects of this class created */
1598ba1e511SMatthew Knepley   int            destructions;  /* The number of objects of this class destroyed */
1608ba1e511SMatthew Knepley   PetscLogDouble mem;           /* The total memory allocated by objects of this class */
1618ba1e511SMatthew Knepley   PetscLogDouble descMem;       /* The total memory allocated by descendents of these objects */
1628ba1e511SMatthew Knepley } ClassInfo;
1638ba1e511SMatthew Knepley 
1648ba1e511SMatthew Knepley typedef struct _ClassLog *ClassLog;
1658ba1e511SMatthew Knepley struct _ClassLog {
1668ba1e511SMatthew Knepley   int        numClasses; /* The number of classes registered */
1678ba1e511SMatthew Knepley   int        maxClasses; /* The maximum number of classes */
1688ba1e511SMatthew Knepley   ClassInfo *classInfo;  /* The structure for classs information (cookies are monotonicly increasing) */
1698ba1e511SMatthew Knepley };
1708ba1e511SMatthew Knepley 
1718ba1e511SMatthew Knepley /* A simple stack (should replace) */
1728ba1e511SMatthew Knepley typedef struct _IntStack *IntStack;
1738ba1e511SMatthew Knepley 
1748ba1e511SMatthew Knepley /* The structure for logging in stages */
1758ba1e511SMatthew Knepley struct _StageLog {
1768ba1e511SMatthew Knepley   /* Size information */
1778ba1e511SMatthew Knepley   int         numStages;    /* The number of registered stages */
1788ba1e511SMatthew Knepley   int         maxStages;    /* The maximum number of stages */
1798ba1e511SMatthew Knepley   /* Runtime information */
1808ba1e511SMatthew Knepley   int        *stageUsed;    /* The flags for stages which were executed */
1818ba1e511SMatthew Knepley   PetscTruth *stageVisible; /* The flags for stages which are visible to PetscLogPrintSummary() */
1828ba1e511SMatthew Knepley   IntStack    stack;        /* The stack for active stages */
1838ba1e511SMatthew Knepley   int         curStage;     /* The current stage (only used in macros so we don't call StackTop) */
1848ba1e511SMatthew Knepley   /* Stage specific information */
1858ba1e511SMatthew Knepley   PerfInfo   *stageInfo;    /* The performance information for each stage */
1868ba1e511SMatthew Knepley   EventLog   *eventLog;     /* The event log for each stage */
1878ba1e511SMatthew Knepley   ClassLog   *classLog;     /* The class information for each stage */
1888ba1e511SMatthew Knepley };
1898ba1e511SMatthew Knepley 
1908ba1e511SMatthew Knepley EXTERN int EventLogGetEvent(EventLog, int, int *);
1910743b949SBarry Smith 
192aa482453SBarry Smith #if defined(PETSC_HAVE_MPE)
193b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
1948ba1e511SMatthew Knepley   0; { int _1_ierr, _1_eventNum; \
1958ba1e511SMatthew Knepley     _1_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_1_eventNum); \
1968ba1e511SMatthew Knepley     if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_1_eventNum]) { \
1976e491fe6SBarry Smith       _1_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_1_ierr);  \
198b0a32e0cSBarry Smith       if (UseMPE && PetscLogEventMPEFlags[(e)])                      \
199005c665bSBarry Smith         MPE_Log_event(MPEBEGIN+2*(e),0,"");                      \
2006e491fe6SBarry Smith       _1_ierr = MPI_Barrier(cm);CHKERRQ(_1_ierr);                  \
2016e491fe6SBarry Smith       _1_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_1_ierr);    \
202b0a32e0cSBarry Smith       if (UseMPE && PetscLogEventMPEFlags[(e)])                      \
203005c665bSBarry Smith         MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                  \
204005c665bSBarry Smith     }                                                            \
2056e491fe6SBarry Smith     _1_ierr = PetscLogEventBegin(e+1,o1,o2,o3,o4);CHKERRQ(_1_ierr);    \
206b0a32e0cSBarry Smith     if (UseMPE && PetscLogEventMPEFlags[(e)+1])                      \
207005c665bSBarry Smith       MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                    \
208005c665bSBarry Smith   }
209b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)  \
2108ba1e511SMatthew Knepley   0; { int _3_ierr, _3_eventNum; \
2118ba1e511SMatthew Knepley     _3_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_3_eventNum); \
2128ba1e511SMatthew Knepley    if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_3_eventNum]) {\
213b0a32e0cSBarry Smith      (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
214b0a32e0cSBarry Smith    if (UseMPE && PetscLogEventMPEFlags[(e)])\
215005c665bSBarry Smith      MPE_Log_event(MPEBEGIN+2*(e),0,"");\
21677c4ece6SBarry Smith   }
21777c4ece6SBarry Smith #else
218b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
2198ba1e511SMatthew Knepley   0; { int _2_ierr, _2_eventNum;\
2208ba1e511SMatthew Knepley     _2_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_2_eventNum); \
2218ba1e511SMatthew Knepley     if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_2_eventNum]) {                         \
2226e491fe6SBarry Smith       _2_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);    \
2236e491fe6SBarry Smith       _2_ierr = MPI_Barrier(cm);CHKERRQ(_2_ierr);                    \
2246e491fe6SBarry Smith       _2_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);      \
225005c665bSBarry Smith     }                                                              \
2266e491fe6SBarry Smith     _2_ierr = PetscLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(_2_ierr);    \
227005c665bSBarry Smith   }
228b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)  \
2298ba1e511SMatthew Knepley   0; { int _4_ierr, _4_eventNum; \
2308ba1e511SMatthew Knepley     _4_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_4_eventNum); \
2318ba1e511SMatthew Knepley    if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventActive[_4_eventNum]) {\
232b0a32e0cSBarry Smith      (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
23377c4ece6SBarry Smith   }
23477c4ece6SBarry Smith #endif
23577c4ece6SBarry Smith 
236aa482453SBarry Smith #if defined(PETSC_HAVE_MPE)
237b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
238b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2398ba1e511SMatthew Knepley   0; { int _5_ierr, _5_eventNum; \
2408ba1e511SMatthew Knepley     _5_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_5_eventNum); \
2418ba1e511SMatthew Knepley   if (_PetscLogPLE && _stageLog->eventLog[_stageLog->curStage]->eventActive[_5_eventNum]) {\
242b0a32e0cSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
243b0a32e0cSBarry Smith   if (UseMPE && PetscLogEventMPEFlags[(e)])\
244005c665bSBarry Smith      MPE_Log_event(MPEBEGIN+2*(e)+1,0,"");\
245a1b5d808SSatish Balay   }
24677c4ece6SBarry Smith #else
247b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
248b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2498ba1e511SMatthew Knepley   0; { int _6_ierr, _6_eventNum; \
2508ba1e511SMatthew Knepley     _6_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_6_eventNum); \
2518ba1e511SMatthew Knepley   if (_PetscLogPLE && _stageLog->eventLog[_stageLog->curStage]->eventActive[_6_eventNum]) {\
252b0a32e0cSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
253a1b5d808SSatish Balay   }
25477c4ece6SBarry Smith #endif
25577c4ece6SBarry Smith 
256ce85283eSBarry Smith /*
25784cb2905SBarry Smith      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
258ce85283eSBarry Smith    uses macros to defined the MPI operations.
25915308354SBarry Smith 
26015308354SBarry Smith      It does not work correctly from HP-UX because it processes the
261bb4af37aSBarry Smith    macros in a way that sometimes it double counts, hence
262aa482453SBarry Smith    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
2637c1e34a4SSatish Balay 
2647c1e34a4SSatish Balay      It does not work with Windows NT because winmpich lacks MPI_Type_size()
265ce85283eSBarry Smith */
2668ba1e511SMatthew Knepley #if !defined(HAVE_MPI_UNI) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
26777a39924SBarry Smith /*
26877a39924SBarry Smith    Logging of MPI activities
26977a39924SBarry Smith */
27077a39924SBarry Smith 
27177a39924SBarry Smith #define TypeSize(buff,count,type)                                                \
272ca161407SBarry Smith (\
273b0a32e0cSBarry Smith   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PetscLogDouble) ((count)*PETSC_DUMMY_SIZE)) \
274ca161407SBarry Smith )
27577a39924SBarry Smith 
27677a39924SBarry Smith #define MPI_Irecv(buf,count, datatype,source,tag,comm,request)        \
277ca161407SBarry Smith (\
278ca161407SBarry Smith   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),            \
279ca161407SBarry Smith   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY                            \
280ca161407SBarry Smith )
28115308354SBarry Smith 
28277a39924SBarry Smith #define MPI_Isend(buf,count, datatype,dest,tag,comm,request)          \
283ca161407SBarry Smith (\
284ca161407SBarry Smith   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),              \
285ca161407SBarry Smith   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY                          \
286ca161407SBarry Smith )
28715308354SBarry Smith 
2880d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests)                                     \
289ca161407SBarry Smith (\
290ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),                                                    \
29187828ca2SBarry Smith   irecv_ct += (PetscLogDouble)(number),irecv_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY \
292ca161407SBarry Smith )
2930d4b0b6cSBarry Smith 
2940d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests)                                    \
295ca161407SBarry Smith (\
296ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),                                                   \
29787828ca2SBarry Smith   isend_ct += (PetscLogDouble)(number),isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY \
298ca161407SBarry Smith )
2990d4b0b6cSBarry Smith 
3000d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests)\
301ca161407SBarry Smith (\
302ca161407SBarry Smith   PETSC_DUMMY = MPI_Start(requests),\
30387828ca2SBarry Smith   isend_ct++,isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
304ca161407SBarry Smith )
3050d4b0b6cSBarry Smith 
306ce85283eSBarry Smith #define MPI_Recv(buf,count, datatype,source,tag,comm,status)           \
307ca161407SBarry Smith (\
308ca161407SBarry Smith   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),               \
309ca161407SBarry Smith   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY                              \
310ca161407SBarry Smith )
31115308354SBarry Smith 
31277a39924SBarry Smith #define MPI_Send(buf,count, datatype,dest,tag,comm)                     \
313ca161407SBarry Smith (\
314ca161407SBarry Smith   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),                         \
315ca161407SBarry Smith   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY                              \
316ca161407SBarry Smith )
31777a39924SBarry Smith 
31877a39924SBarry Smith #define MPI_Wait(request,status) \
31977a39924SBarry Smith (\
320e0937024SBarry Smith   wait_ct++,sum_of_waits_ct++,  \
32177a39924SBarry Smith   MPI_Wait(request,status)       \
32277a39924SBarry Smith )
32377a39924SBarry Smith 
32477a39924SBarry Smith #define MPI_Waitany(a,b,c,d)     \
32577a39924SBarry Smith (\
326e0937024SBarry Smith   wait_any_ct++,sum_of_waits_ct++,\
32777a39924SBarry Smith   MPI_Waitany(a,b,c,d)           \
32877a39924SBarry Smith )
32977a39924SBarry Smith 
33077a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
33177a39924SBarry Smith (\
332b0a32e0cSBarry Smith   wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),       \
33377a39924SBarry Smith   MPI_Waitall(count,array_of_requests,array_of_statuses)       \
33477a39924SBarry Smith )
33577a39924SBarry Smith 
33677a39924SBarry Smith #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
3370743b949SBarry Smith (\
3380743b949SBarry Smith   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
3390743b949SBarry Smith )
3403914022bSBarry Smith 
3410d4b0b6cSBarry Smith #else
3420d4b0b6cSBarry Smith 
3430d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
344ca161407SBarry Smith (\
345ca161407SBarry Smith   MPI_Startall(number,requests)                 \
346ca161407SBarry Smith )
3470d4b0b6cSBarry Smith 
3480d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
349ca161407SBarry Smith (\
350ca161407SBarry Smith   MPI_Startall(number,requests)                 \
351ca161407SBarry Smith )
3520d4b0b6cSBarry Smith 
3530d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests) \
354ca161407SBarry Smith (\
355ca161407SBarry Smith   MPI_Start(requests)                   \
356ca161407SBarry Smith )
3570d4b0b6cSBarry Smith 
358aa482453SBarry Smith #endif /* !USING_MPIUNI && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
359614700edSBarry Smith 
360df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
361614700edSBarry Smith 
362b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
363614700edSBarry Smith 
364df8cf0b5SBarry Smith /*
365df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
366df8cf0b5SBarry Smith */
367614700edSBarry Smith #define MPEBEGIN                  1000
368b0a32e0cSBarry Smith #define PetscLogMPEBegin()            0
369b0a32e0cSBarry Smith #define PetscLogMPEDump(a)            0
370b0a32e0cSBarry Smith #define PetscLogEventMPEActivate(a)   0
371b0a32e0cSBarry Smith #define PetscLogEventMPEDeactivate(a) 0
372614700edSBarry Smith 
373b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
374b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
375614700edSBarry Smith 
376b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
377b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
37877c4ece6SBarry Smith 
379b0a32e0cSBarry Smith #define _PetscLogPLB                        0
380b0a32e0cSBarry Smith #define _PetscLogPLE                        0
381b0a32e0cSBarry Smith #define _PetscLogPHC                        0
382b0a32e0cSBarry Smith #define _PetscLogPHD                        0
38399de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
384b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
385b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
386b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
387b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
388b0a32e0cSBarry Smith #define PetscLogObjectParent(p,c)
389b0a32e0cSBarry Smith #define PetscLogObjectParents(p,n,c)
390b0a32e0cSBarry Smith #define PetscLogObjectCreate(h)
391b0a32e0cSBarry Smith #define PetscLogObjectDestroy(h)
392b0a32e0cSBarry Smith #define PetscLogObjectMemory(p,m)
393b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
394b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
395b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
396b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
397b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
398b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file)     0
399b0a32e0cSBarry Smith #define PetscLogBegin()                     0
400b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
401b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
402b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
403b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
404b0a32e0cSBarry Smith #define PetscLogEventRegister(a,b,c)        0
405b0a32e0cSBarry Smith EXTERN int PetscLogObjectState(PetscObject,const char[],...);
406ce6058e1SBarry Smith 
407aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
408ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
409ce6058e1SBarry Smith 
410ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
411ce6058e1SBarry Smith 
412ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
413ca161407SBarry Smith 
414aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4156daaf66cSBarry Smith 
416435da068SBarry Smith extern PetscTruth PetscPreLoadingUsed;       /* true if we are or have done preloading */
417435da068SBarry Smith extern PetscTruth PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
4181d1367b7SBarry Smith 
4198e58c17dSMatthew Knepley #define PreLoadBegin(flag,name) {PetscTruth PreLoading = flag; \
4208e58c17dSMatthew Knepley                                  int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
4216e491fe6SBarry Smith                                  _3_ierr = PetscOptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
4221d1367b7SBarry Smith                                  PreLoadMax = (int)(PreLoading);PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
423e7592fafSBarry Smith                                  for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
424435da068SBarry Smith                                    PetscPreLoadingOn = PreLoading;\
4256e491fe6SBarry Smith                                    _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
4268e58c17dSMatthew Knepley                                    if (PreLoadIt>0) {\
4278e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4288e58c17dSMatthew Knepley                                    } else {\
4298e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
4308e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageSetVisible(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
4318e58c17dSMatthew Knepley                                    }\
4328e58c17dSMatthew Knepley                                    _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
4338e58c17dSMatthew Knepley 
4346e491fe6SBarry Smith #define PreLoadEnd()               _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);PreLoading = PETSC_FALSE;}}
4358e58c17dSMatthew Knepley 
4366e491fe6SBarry Smith #define PreLoadStage(name)         _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
4378e58c17dSMatthew Knepley                                    if (PreLoadIt>0) {\
4388e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4398e58c17dSMatthew Knepley                                    } else {\
4408e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
4418e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageSetVisible(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
4428e58c17dSMatthew Knepley                                    }\
4438e58c17dSMatthew Knepley                                    _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
44497bb86f7SLois Curfman McInnes #endif
445