xref: /petsc/include/petsclog.h (revision b932d42acc3a4ed3ea440fa4c9637667e6a5036f)
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 */
22d5ba7fb7SMatthew 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 */
134800883a5SMatthew Knepley   PetscTruth     active;        /* The flag to activate logging */
135800883a5SMatthew Knepley   PetscTruth     visible;       /* The flag to print info in summary */
1368ba1e511SMatthew Knepley   int            depth;         /* The nesting depth of the event call */
1378ba1e511SMatthew Knepley   int            count;         /* The number of times this section was executed */
1388ba1e511SMatthew Knepley   PetscLogDouble flops;         /* The flops used in this section */
1398ba1e511SMatthew Knepley   PetscLogDouble time;          /* The time taken for this section */
1408ba1e511SMatthew Knepley   PetscLogDouble numMessages;   /* The number of messages in this section */
1418ba1e511SMatthew Knepley   PetscLogDouble messageLength; /* The total message lengths in this section */
1428ba1e511SMatthew Knepley   PetscLogDouble numReductions; /* The number of reductions in this section */
1438ba1e511SMatthew Knepley } PerfInfo;
1448ba1e511SMatthew Knepley 
1458ba1e511SMatthew Knepley /* The structure for logging events */
1468ba1e511SMatthew Knepley typedef struct _EventLog *EventLog;
1478ba1e511SMatthew Knepley struct _EventLog {
1488ba1e511SMatthew Knepley   int       numEvents;   /* The number of registered events */
1498ba1e511SMatthew Knepley   int       maxEvents;   /* The maximum number of events */
1508ba1e511SMatthew Knepley   PerfInfo *eventInfo;   /* The performance information for each event */
1518ba1e511SMatthew Knepley };
1528ba1e511SMatthew Knepley 
1538ba1e511SMatthew Knepley /* The structure for logging class information */
1548ba1e511SMatthew Knepley typedef struct _ClassInfo {
1558ba1e511SMatthew Knepley   char          *name;          /* The class name */
1568ba1e511SMatthew Knepley   int            cookie;        /* The integer identifying this class */
1578ba1e511SMatthew Knepley   int            creations;     /* The number of objects of this class created */
1588ba1e511SMatthew Knepley   int            destructions;  /* The number of objects of this class destroyed */
1598ba1e511SMatthew Knepley   PetscLogDouble mem;           /* The total memory allocated by objects of this class */
1608ba1e511SMatthew Knepley   PetscLogDouble descMem;       /* The total memory allocated by descendents of these objects */
1618ba1e511SMatthew Knepley } ClassInfo;
1628ba1e511SMatthew Knepley 
1638ba1e511SMatthew Knepley typedef struct _ClassLog *ClassLog;
1648ba1e511SMatthew Knepley struct _ClassLog {
1658ba1e511SMatthew Knepley   int        numClasses; /* The number of classes registered */
1668ba1e511SMatthew Knepley   int        maxClasses; /* The maximum number of classes */
1678ba1e511SMatthew Knepley   ClassInfo *classInfo;  /* The structure for classs information (cookies are monotonicly increasing) */
1688ba1e511SMatthew Knepley };
1698ba1e511SMatthew Knepley 
1708ba1e511SMatthew Knepley /* A simple stack (should replace) */
1718ba1e511SMatthew Knepley typedef struct _IntStack *IntStack;
1728ba1e511SMatthew Knepley 
1738ba1e511SMatthew Knepley /* The structure for logging in stages */
1748ba1e511SMatthew Knepley struct _StageLog {
1758ba1e511SMatthew Knepley   /* Size information */
1768ba1e511SMatthew Knepley   int         numStages;    /* The number of registered stages */
1778ba1e511SMatthew Knepley   int         maxStages;    /* The maximum number of stages */
1788ba1e511SMatthew Knepley   /* Runtime information */
1798ba1e511SMatthew Knepley   IntStack    stack;        /* The stack for active stages */
1808ba1e511SMatthew Knepley   int         curStage;     /* The current stage (only used in macros so we don't call StackTop) */
1818ba1e511SMatthew Knepley   /* Stage specific information */
1828ba1e511SMatthew Knepley   PerfInfo   *stageInfo;    /* The performance information for each stage */
1838ba1e511SMatthew Knepley   EventLog   *eventLog;     /* The event log for each stage */
1848ba1e511SMatthew Knepley   ClassLog   *classLog;     /* The class information for each stage */
1858ba1e511SMatthew Knepley };
1868ba1e511SMatthew Knepley 
1878ba1e511SMatthew Knepley EXTERN int EventLogGetEvent(EventLog, int, int *);
1880743b949SBarry Smith 
189aa482453SBarry Smith #if defined(PETSC_HAVE_MPE)
190b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
1918ba1e511SMatthew Knepley   0; { int _1_ierr, _1_eventNum; \
1928ba1e511SMatthew Knepley     _1_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_1_eventNum); \
193800883a5SMatthew Knepley     if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventInfo[_1_eventNum].active) { \
1946e491fe6SBarry Smith       _1_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_1_ierr);  \
195b0a32e0cSBarry Smith       if (UseMPE && PetscLogEventMPEFlags[(e)])                      \
196005c665bSBarry Smith         MPE_Log_event(MPEBEGIN+2*(e),0,"");                      \
1976e491fe6SBarry Smith       _1_ierr = MPI_Barrier(cm);CHKERRQ(_1_ierr);                  \
1986e491fe6SBarry Smith       _1_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_1_ierr);    \
199b0a32e0cSBarry Smith       if (UseMPE && PetscLogEventMPEFlags[(e)])                      \
200005c665bSBarry Smith         MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                  \
201005c665bSBarry Smith     }                                                            \
2026e491fe6SBarry Smith     _1_ierr = PetscLogEventBegin(e+1,o1,o2,o3,o4);CHKERRQ(_1_ierr);    \
203b0a32e0cSBarry Smith     if (UseMPE && PetscLogEventMPEFlags[(e)+1])                      \
204005c665bSBarry Smith       MPE_Log_event(MPEBEGIN+2*((e)+1),0,"");                    \
205005c665bSBarry Smith   }
206b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)  \
2078ba1e511SMatthew Knepley   0; { int _3_ierr, _3_eventNum; \
2088ba1e511SMatthew Knepley     _3_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_3_eventNum); \
209800883a5SMatthew Knepley    if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventInfo[_3_eventNum].active) {\
210b0a32e0cSBarry Smith      (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
211b0a32e0cSBarry Smith    if (UseMPE && PetscLogEventMPEFlags[(e)])\
212005c665bSBarry Smith      MPE_Log_event(MPEBEGIN+2*(e),0,"");\
21377c4ece6SBarry Smith   }
21477c4ece6SBarry Smith #else
215b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \
2168ba1e511SMatthew Knepley   0; { int _2_ierr, _2_eventNum;\
2178ba1e511SMatthew Knepley     _2_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_2_eventNum); \
218800883a5SMatthew Knepley     if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventInfo[_2_eventNum].active) {                         \
2196e491fe6SBarry Smith       _2_ierr = PetscLogEventBegin((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);    \
2206e491fe6SBarry Smith       _2_ierr = MPI_Barrier(cm);CHKERRQ(_2_ierr);                    \
2216e491fe6SBarry Smith       _2_ierr = PetscLogEventEnd((e),o1,o2,o3,o4);CHKERRQ(_2_ierr);      \
222005c665bSBarry Smith     }                                                              \
2236e491fe6SBarry Smith     _2_ierr = PetscLogEventBegin((e)+1,o1,o2,o3,o4);CHKERRQ(_2_ierr);    \
224005c665bSBarry Smith   }
225b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)  \
2268ba1e511SMatthew Knepley   0; { int _4_ierr, _4_eventNum; \
2278ba1e511SMatthew Knepley     _4_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_4_eventNum); \
228800883a5SMatthew Knepley    if (_PetscLogPLB && _stageLog->eventLog[_stageLog->curStage]->eventInfo[_4_eventNum].active) {\
229b0a32e0cSBarry Smith      (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
23077c4ece6SBarry Smith   }
23177c4ece6SBarry Smith #endif
23277c4ece6SBarry Smith 
233aa482453SBarry Smith #if defined(PETSC_HAVE_MPE)
234b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
235b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2368ba1e511SMatthew Knepley   0; { int _5_ierr, _5_eventNum; \
2378ba1e511SMatthew Knepley     _5_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_5_eventNum); \
238800883a5SMatthew Knepley   if (_PetscLogPLE && _stageLog->eventLog[_stageLog->curStage]->eventInfo[_5_eventNum].active) {\
239b0a32e0cSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
240b0a32e0cSBarry Smith   if (UseMPE && PetscLogEventMPEFlags[(e)])\
241005c665bSBarry Smith      MPE_Log_event(MPEBEGIN+2*(e)+1,0,"");\
242a1b5d808SSatish Balay   }
24377c4ece6SBarry Smith #else
244b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4)
245b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \
2468ba1e511SMatthew Knepley   0; { int _6_ierr, _6_eventNum; \
2478ba1e511SMatthew Knepley     _6_ierr = EventLogGetEvent(_stageLog->eventLog[_stageLog->curStage], (e), &_6_eventNum); \
248800883a5SMatthew Knepley   if (_PetscLogPLE && _stageLog->eventLog[_stageLog->curStage]->eventInfo[_6_eventNum].active) {\
249b0a32e0cSBarry Smith     (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4));}\
250a1b5d808SSatish Balay   }
25177c4ece6SBarry Smith #endif
25277c4ece6SBarry Smith 
253ce85283eSBarry Smith /*
25484cb2905SBarry Smith      This does not work for MPI-Uni because our src/mpiuni/mpi.h file
255ce85283eSBarry Smith    uses macros to defined the MPI operations.
25615308354SBarry Smith 
25715308354SBarry Smith      It does not work correctly from HP-UX because it processes the
258bb4af37aSBarry Smith    macros in a way that sometimes it double counts, hence
259*b932d42aSSatish Balay    HAVE_BROKEN_RECURSIVE_MACRO
2607c1e34a4SSatish Balay 
2617c1e34a4SSatish Balay      It does not work with Windows NT because winmpich lacks MPI_Type_size()
262ce85283eSBarry Smith */
263*b932d42aSSatish Balay #if !defined(PETSC_HAVE_MPI_UNI) && !defined(HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
26477a39924SBarry Smith /*
26577a39924SBarry Smith    Logging of MPI activities
26677a39924SBarry Smith */
26777a39924SBarry Smith 
26877a39924SBarry Smith #define TypeSize(buff,count,type)                                                \
269ca161407SBarry Smith (\
270b0a32e0cSBarry Smith   MPI_Type_size(type,&PETSC_DUMMY_SIZE),buff += ((PetscLogDouble) ((count)*PETSC_DUMMY_SIZE)) \
271ca161407SBarry Smith )
27277a39924SBarry Smith 
27377a39924SBarry Smith #define MPI_Irecv(buf,count, datatype,source,tag,comm,request)        \
274ca161407SBarry Smith (\
275ca161407SBarry Smith   PETSC_DUMMY = MPI_Irecv(buf,count, datatype,source,tag,comm,request),            \
276ca161407SBarry Smith   irecv_ct++,TypeSize(irecv_len,count,datatype),PETSC_DUMMY                            \
277ca161407SBarry Smith )
27815308354SBarry Smith 
27977a39924SBarry Smith #define MPI_Isend(buf,count, datatype,dest,tag,comm,request)          \
280ca161407SBarry Smith (\
281ca161407SBarry Smith   PETSC_DUMMY = MPI_Isend(buf,count, datatype,dest,tag,comm,request),              \
282ca161407SBarry Smith   isend_ct++,  TypeSize(isend_len,count,datatype),PETSC_DUMMY                          \
283ca161407SBarry Smith )
28415308354SBarry Smith 
2850d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests)                                     \
286ca161407SBarry Smith (\
287ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),                                                    \
28887828ca2SBarry Smith   irecv_ct += (PetscLogDouble)(number),irecv_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY \
289ca161407SBarry Smith )
2900d4b0b6cSBarry Smith 
2910d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests)                                    \
292ca161407SBarry Smith (\
293ca161407SBarry Smith   PETSC_DUMMY = MPI_Startall(number,requests),                                                   \
29487828ca2SBarry Smith   isend_ct += (PetscLogDouble)(number),isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY \
295ca161407SBarry Smith )
2960d4b0b6cSBarry Smith 
2970d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests)\
298ca161407SBarry Smith (\
299ca161407SBarry Smith   PETSC_DUMMY = MPI_Start(requests),\
30087828ca2SBarry Smith   isend_ct++,isend_len += ((PetscLogDouble) ((count)*sizeof(PetscScalar))),PETSC_DUMMY\
301ca161407SBarry Smith )
3020d4b0b6cSBarry Smith 
303ce85283eSBarry Smith #define MPI_Recv(buf,count, datatype,source,tag,comm,status)           \
304ca161407SBarry Smith (\
305ca161407SBarry Smith   PETSC_DUMMY = MPI_Recv(buf,count, datatype,source,tag,comm,status),               \
306ca161407SBarry Smith   recv_ct++,TypeSize(recv_len,count,datatype),PETSC_DUMMY                              \
307ca161407SBarry Smith )
30815308354SBarry Smith 
30977a39924SBarry Smith #define MPI_Send(buf,count, datatype,dest,tag,comm)                     \
310ca161407SBarry Smith (\
311ca161407SBarry Smith   PETSC_DUMMY = MPI_Send(buf,count, datatype,dest,tag,comm),                         \
312ca161407SBarry Smith   send_ct++, TypeSize(send_len,count,datatype),PETSC_DUMMY                              \
313ca161407SBarry Smith )
31477a39924SBarry Smith 
31577a39924SBarry Smith #define MPI_Wait(request,status) \
31677a39924SBarry Smith (\
317e0937024SBarry Smith   wait_ct++,sum_of_waits_ct++,  \
31877a39924SBarry Smith   MPI_Wait(request,status)       \
31977a39924SBarry Smith )
32077a39924SBarry Smith 
32177a39924SBarry Smith #define MPI_Waitany(a,b,c,d)     \
32277a39924SBarry Smith (\
323e0937024SBarry Smith   wait_any_ct++,sum_of_waits_ct++,\
32477a39924SBarry Smith   MPI_Waitany(a,b,c,d)           \
32577a39924SBarry Smith )
32677a39924SBarry Smith 
32777a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
32877a39924SBarry Smith (\
329b0a32e0cSBarry Smith   wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),       \
33077a39924SBarry Smith   MPI_Waitall(count,array_of_requests,array_of_statuses)       \
33177a39924SBarry Smith )
33277a39924SBarry Smith 
33377a39924SBarry Smith #define MPI_Allreduce(sendbuf, recvbuf,count,datatype,op,comm) \
3340743b949SBarry Smith (\
3350743b949SBarry Smith   allreduce_ct++,MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)\
3360743b949SBarry Smith )
3373914022bSBarry Smith 
3380d4b0b6cSBarry Smith #else
3390d4b0b6cSBarry Smith 
3400d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \
341ca161407SBarry Smith (\
342ca161407SBarry Smith   MPI_Startall(number,requests)                 \
343ca161407SBarry Smith )
3440d4b0b6cSBarry Smith 
3450d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \
346ca161407SBarry Smith (\
347ca161407SBarry Smith   MPI_Startall(number,requests)                 \
348ca161407SBarry Smith )
3490d4b0b6cSBarry Smith 
3500d4b0b6cSBarry Smith #define MPI_Start_isend(count, requests) \
351ca161407SBarry Smith (\
352ca161407SBarry Smith   MPI_Start(requests)                   \
353ca161407SBarry Smith )
3540d4b0b6cSBarry Smith 
355*b932d42aSSatish Balay #endif /* !PETSC_HAVE_MPI_UNI && ! HAVE_BROKEN_RECURSIVE_MACRO */
356614700edSBarry Smith 
357df8cf0b5SBarry Smith #else  /* ---Logging is turned off --------------------------------------------*/
358614700edSBarry Smith 
359b0a32e0cSBarry Smith #define PetscLogFlops(n) 0
360614700edSBarry Smith 
361df8cf0b5SBarry Smith /*
362df8cf0b5SBarry Smith      With logging turned off, then MPE has to be turned off
363df8cf0b5SBarry Smith */
364614700edSBarry Smith #define MPEBEGIN                  1000
365b0a32e0cSBarry Smith #define PetscLogMPEBegin()            0
366b0a32e0cSBarry Smith #define PetscLogMPEDump(a)            0
367b0a32e0cSBarry Smith #define PetscLogEventMPEActivate(a)   0
368b0a32e0cSBarry Smith #define PetscLogEventMPEDeactivate(a) 0
369614700edSBarry Smith 
370b0a32e0cSBarry Smith #define PetscLogEventActivate(a)   0
371b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0
372614700edSBarry Smith 
373b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a)   0
374b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0
37577c4ece6SBarry Smith 
376b0a32e0cSBarry Smith #define _PetscLogPLB                        0
377b0a32e0cSBarry Smith #define _PetscLogPLE                        0
378b0a32e0cSBarry Smith #define _PetscLogPHC                        0
379b0a32e0cSBarry Smith #define _PetscLogPHD                        0
38099de4ba8SSatish Balay #define PetscGetFlops(a)                (*(a) = 0.0,0)
381b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4)   0
382b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4)     0
383b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0
384b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm)   0
385b0a32e0cSBarry Smith #define PetscLogObjectParent(p,c)
386b0a32e0cSBarry Smith #define PetscLogObjectParents(p,n,c)
387b0a32e0cSBarry Smith #define PetscLogObjectCreate(h)
388b0a32e0cSBarry Smith #define PetscLogObjectDestroy(h)
389b0a32e0cSBarry Smith #define PetscLogObjectMemory(p,m)
390b0a32e0cSBarry Smith #define PetscLogDestroy()                   0
391b0a32e0cSBarry Smith #define PetscLogStagePush(a)                0
392b0a32e0cSBarry Smith #define PetscLogStagePop()                  0
393b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b)          0
394b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg)           0
395b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file)     0
396b0a32e0cSBarry Smith #define PetscLogBegin()                     0
397b0a32e0cSBarry Smith #define PetscLogTraceBegin(file)            0
398b0a32e0cSBarry Smith #define PetscLogSet(lb,le)                  0
399b0a32e0cSBarry Smith #define PetscLogAllBegin()                  0
400b0a32e0cSBarry Smith #define PetscLogDump(c)                     0
401b0a32e0cSBarry Smith #define PetscLogEventRegister(a,b,c)        0
402b0a32e0cSBarry Smith EXTERN int PetscLogObjectState(PetscObject,const char[],...);
403ce6058e1SBarry Smith 
404aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */
405ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests)
406ce6058e1SBarry Smith 
407ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests)
408ce6058e1SBarry Smith 
409ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests)
410ca161407SBarry Smith 
411aa482453SBarry Smith #endif   /* PETSC_USE_LOG */
4126daaf66cSBarry Smith 
413435da068SBarry Smith extern PetscTruth PetscPreLoadingUsed;       /* true if we are or have done preloading */
414435da068SBarry Smith extern PetscTruth PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
4151d1367b7SBarry Smith 
4168e58c17dSMatthew Knepley #define PreLoadBegin(flag,name) {PetscTruth PreLoading = flag; \
4178e58c17dSMatthew Knepley                                  int        PreLoadMax,PreLoadIt,_stageNum,_3_ierr;\
4186e491fe6SBarry Smith                                  _3_ierr = PetscOptionsGetLogical(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\
4191d1367b7SBarry Smith                                  PreLoadMax = (int)(PreLoading);PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
420e7592fafSBarry Smith                                  for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\
421435da068SBarry Smith                                    PetscPreLoadingOn = PreLoading;\
4226e491fe6SBarry Smith                                    _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\
4238e58c17dSMatthew Knepley                                    if (PreLoadIt>0) {\
4248e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4258e58c17dSMatthew Knepley                                    } else {\
4268e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
4278e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageSetVisible(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
4288e58c17dSMatthew Knepley                                    }\
4298e58c17dSMatthew Knepley                                    _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
4308e58c17dSMatthew Knepley 
4316e491fe6SBarry Smith #define PreLoadEnd()               _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);PreLoading = PETSC_FALSE;}}
4328e58c17dSMatthew Knepley 
4336e491fe6SBarry Smith #define PreLoadStage(name)         _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
4348e58c17dSMatthew Knepley                                    if (PreLoadIt>0) {\
4358e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
4368e58c17dSMatthew Knepley                                    } else {\
4378e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageRegister(&_stageNum,name);CHKERRQ(_3_ierr);\
4388e58c17dSMatthew Knepley                                      _3_ierr = PetscLogStageSetVisible(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\
4398e58c17dSMatthew Knepley                                    }\
4408e58c17dSMatthew Knepley                                    _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
44197bb86f7SLois Curfman McInnes #endif
442