197bb86f7SLois Curfman McInnes /* 27588ac45SBarry Smith Defines profile/logging in PETSc. 397bb86f7SLois Curfman McInnes */ 497bb86f7SLois Curfman McInnes 5b0a32e0cSBarry Smith #if !defined(__PetscLog_H) 6b0a32e0cSBarry Smith #define __PetscLog_H 7d382aafbSBarry Smith #include "petscsys.h" 8e9fa29b7SSatish Balay PETSC_EXTERN_CXX_BEGIN 9c8d78d4dSSatish Balay 108ba1e511SMatthew Knepley #define PETSC_EVENT 1311311 11166c7f25SBarry Smith extern PetscLogEvent PETSC_LARGEST_EVENT; 1297bb86f7SLois Curfman McInnes 1319b02663SBarry Smith /* Global flop counter */ 14ff73aad6SKris Buschelman extern PetscLogDouble PETSC_DLLEXPORT _TotalFlops; 1590fdf44cSMatthew Knepley extern PetscLogDouble petsc_tmp_flops; 1619b02663SBarry Smith 17edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */ 18ae15b995SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfo_Private(const char[],void*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 196cf91177SBarry Smith #if defined(PETSC_USE_INFO) 20ae15b995SBarry Smith #define PetscInfo(A,S) PetscInfo_Private(__FUNCT__,A,S) 21ae15b995SBarry Smith #define PetscInfo1(A,S,a1) PetscInfo_Private(__FUNCT__,A,S,a1) 22ae15b995SBarry Smith #define PetscInfo2(A,S,a1,a2) PetscInfo_Private(__FUNCT__,A,S,a1,a2) 23ae15b995SBarry Smith #define PetscInfo3(A,S,a1,a2,a3) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3) 24ae15b995SBarry Smith #define PetscInfo4(A,S,a1,a2,a3,a4) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4) 25ae15b995SBarry Smith #define PetscInfo5(A,S,a1,a2,a3,a4,a5) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4,a5) 26ae15b995SBarry Smith #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4,a5,a6) 27ae15b995SBarry Smith #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(__FUNCT__,A,S,a1,a2,a3,a4,a5,a6,a7) 2863ba0a88SBarry Smith #else 29ae15b995SBarry Smith #define PetscInfo(A,S) 0 30ae15b995SBarry Smith #define PetscInfo1(A,S,a1) 0 31ae15b995SBarry Smith #define PetscInfo2(A,S,a1,a2) 0 32ae15b995SBarry Smith #define PetscInfo3(A,S,a1,a2,a3) 0 33ae15b995SBarry Smith #define PetscInfo4(A,S,a1,a2,a3,a4) 0 34ae15b995SBarry Smith #define PetscInfo5(A,S,a1,a2,a3,a4,a5) 0 35ae15b995SBarry Smith #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) 0 36ae15b995SBarry Smith #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0 3763ba0a88SBarry Smith #endif 380700a824SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfoDeactivateClass(PetscClassId); 390700a824SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfoActivateClass(PetscClassId); 406cf91177SBarry Smith extern PetscTruth PETSC_DLLEXPORT PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */ 41614700edSBarry Smith 426a6a9b46SSatish Balay /* We must make these structures available if we are to access the event 436a6a9b46SSatish Balay activation flags in the PetscLogEventBegin/End() macros. If we forced a 446a6a9b46SSatish Balay function call each time, we could make these private. 456a6a9b46SSatish Balay */ 46d49d4b11SBarry Smith 476a6a9b46SSatish Balay /* A simple stack (should replace) */ 486a6a9b46SSatish Balay typedef struct _n_IntStack *IntStack; 496a6a9b46SSatish Balay 50*c60ec953SBarry Smith /* 51*c60ec953SBarry Smith ClassRegInfo, ClassPerfInfo - Each class has two data structures associated with it. The first has 52*c60ec953SBarry Smith static information about it, the second collects statistics on how many objects of the class are created, 53*c60ec953SBarry Smith how much memory they use, etc. 54*c60ec953SBarry Smith 55*c60ec953SBarry Smith ClassRegLog, ClassPerfLog - arrays of the ClassRegInfo and ClassPerfInfo for all classes. 56*c60ec953SBarry Smith */ 576a6a9b46SSatish Balay typedef struct { 58*c60ec953SBarry Smith char *name; /* The class name */ 59*c60ec953SBarry Smith PetscClassId classid; /* The integer identifying this class */ 60*c60ec953SBarry Smith } ClassRegInfo; 616a6a9b46SSatish Balay 626a6a9b46SSatish Balay typedef struct { 630700a824SBarry Smith PetscClassId id; /* The integer identifying this class */ 646a6a9b46SSatish Balay int creations; /* The number of objects of this class created */ 656a6a9b46SSatish Balay int destructions; /* The number of objects of this class destroyed */ 666a6a9b46SSatish Balay PetscLogDouble mem; /* The total memory allocated by objects of this class */ 676a6a9b46SSatish Balay PetscLogDouble descMem; /* The total memory allocated by descendents of these objects */ 686a6a9b46SSatish Balay } ClassPerfInfo; 696a6a9b46SSatish Balay 70*c60ec953SBarry Smith typedef struct _n_ClassRegLog *ClassRegLog; 71*c60ec953SBarry Smith struct _n_ClassRegLog { 72*c60ec953SBarry Smith int numClasses; /* The number of classes registered */ 73*c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 74*c60ec953SBarry Smith ClassRegInfo * classInfo; /* The structure for class information (classids are monotonicly increasing) */ 75*c60ec953SBarry Smith }; 766a6a9b46SSatish Balay 77*c60ec953SBarry Smith typedef struct _n_ClassPerfLog *ClassPerfLog; 78*c60ec953SBarry Smith struct _n_ClassPerfLog { 79*c60ec953SBarry Smith int numClasses; /* The number of logging classes */ 80*c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 81*c60ec953SBarry Smith ClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 82*c60ec953SBarry Smith }; 83*c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/ 84*c60ec953SBarry Smith /* 85*c60ec953SBarry Smith EventRegInfo, EventPerfInfo - Each event has two data structures associated with it. The first has 86*c60ec953SBarry Smith static information about it, the second collects statistics on how many times the event is used, how 87*c60ec953SBarry Smith much time it takes, etc. 88*c60ec953SBarry Smith 89*c60ec953SBarry Smith EventRegLog, EventPerfLog - an array of all EventRegInfo and EventPerfInfo for all events. There is one 90*c60ec953SBarry Smith of these for each stage. 91*c60ec953SBarry Smith 92*c60ec953SBarry Smith */ 936a6a9b46SSatish Balay typedef struct { 946a6a9b46SSatish Balay char *name; /* The name of this event */ 95*c60ec953SBarry Smith PetscClassId classid; /* The class the event is associated with */ 966a6a9b46SSatish Balay #if defined (PETSC_HAVE_MPE) 976a6a9b46SSatish Balay int mpe_id_begin; /* MPE IDs that define the event */ 986a6a9b46SSatish Balay int mpe_id_end; 996a6a9b46SSatish Balay #endif 1006a6a9b46SSatish Balay } EventRegInfo; 1016a6a9b46SSatish Balay 102*c60ec953SBarry Smith typedef struct { 103*c60ec953SBarry Smith int id; /* The integer identifying this event */ 104*c60ec953SBarry Smith PetscTruth active; /* The flag to activate logging */ 105*c60ec953SBarry Smith PetscTruth visible; /* The flag to print info in summary */ 106*c60ec953SBarry Smith int depth; /* The nesting depth of the event call */ 107*c60ec953SBarry Smith int count; /* The number of times this event was executed */ 108*c60ec953SBarry Smith PetscLogDouble flops; /* The flops used in this event */ 109*c60ec953SBarry Smith PetscLogDouble time; /* The time taken for this event */ 110*c60ec953SBarry Smith PetscLogDouble numMessages; /* The number of messages in this event */ 111*c60ec953SBarry Smith PetscLogDouble messageLength; /* The total message lengths in this event */ 112*c60ec953SBarry Smith PetscLogDouble numReductions; /* The number of reductions in this event */ 113*c60ec953SBarry Smith } EventPerfInfo; 114*c60ec953SBarry Smith 1156a6a9b46SSatish Balay typedef struct _n_EventRegLog *EventRegLog; 1166a6a9b46SSatish Balay struct _n_EventRegLog { 1176a6a9b46SSatish Balay int numEvents; /* The number of registered events */ 1186a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 1196a6a9b46SSatish Balay EventRegInfo *eventInfo; /* The registration information for each event */ 1206a6a9b46SSatish Balay }; 1216a6a9b46SSatish Balay 1226a6a9b46SSatish Balay typedef struct _n_EventPerfLog *EventPerfLog; 1236a6a9b46SSatish Balay struct _n_EventPerfLog { 1246a6a9b46SSatish Balay int numEvents; /* The number of logging events */ 1256a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 1266a6a9b46SSatish Balay EventPerfInfo *eventInfo; /* The performance information for each event */ 1276a6a9b46SSatish Balay }; 128*c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/ 129*c60ec953SBarry Smith /* 130*c60ec953SBarry Smith StageInfo - Contains all the information about a particular stage. 1316a6a9b46SSatish Balay 132*c60ec953SBarry Smith StageLog - An array of StageInfo for each registered stage. There is a single one of these in the code. 133*c60ec953SBarry Smith */ 1346a6a9b46SSatish Balay typedef struct _StageInfo { 1356a6a9b46SSatish Balay char *name; /* The stage name */ 1366a6a9b46SSatish Balay PetscTruth used; /* The stage was pushed on this processor */ 1376a6a9b46SSatish Balay EventPerfInfo perfInfo; /* The stage performance information */ 1386a6a9b46SSatish Balay EventPerfLog eventLog; /* The event information for this stage */ 1396a6a9b46SSatish Balay ClassPerfLog classLog; /* The class information for this stage */ 1406a6a9b46SSatish Balay } StageInfo; 1416a6a9b46SSatish Balay 142*c60ec953SBarry Smith typedef struct _n_StageLog *StageLog; 143*c60ec953SBarry Smith extern PETSC_DLLEXPORT StageLog _stageLog; 1446a6a9b46SSatish Balay struct _n_StageLog { 1456a6a9b46SSatish Balay int numStages; /* The number of registered stages */ 1466a6a9b46SSatish Balay int maxStages; /* The maximum number of stages */ 1476a6a9b46SSatish Balay IntStack stack; /* The stack for active stages */ 1486a6a9b46SSatish Balay int curStage; /* The current stage (only used in macros so we don't call StackTop) */ 1496a6a9b46SSatish Balay StageInfo *stageInfo; /* The information for each stage */ 1506a6a9b46SSatish Balay EventRegLog eventLog; /* The registered events */ 1516a6a9b46SSatish Balay ClassRegLog classLog; /* The registered classes */ 1526a6a9b46SSatish Balay }; 1536a6a9b46SSatish Balay 154aa482453SBarry Smith #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 155614700edSBarry Smith 156da63de55SLois Curfman McInnes /* 157da63de55SLois Curfman McInnes Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 158da63de55SLois Curfman McInnes 159da63de55SLois Curfman McInnes For the complex numbers version, note that 160da63de55SLois Curfman McInnes 1 complex addition = 2 flops 161da63de55SLois Curfman McInnes 1 complex multiplication = 6 flops, 162da63de55SLois Curfman McInnes where we define 1 flop as that for a double precision scalar. We roughly approximate 163da63de55SLois Curfman McInnes flop counting for complex numbers by multiplying the total flops by 4; this corresponds 164da63de55SLois Curfman McInnes to the assumption that we're counting mostly additions and multiplications -- and 165da63de55SLois Curfman McInnes roughly the same number of each. More accurate counting could be done by distinguishing 166da63de55SLois Curfman McInnes among the various arithmetic operations. 167da63de55SLois Curfman McInnes */ 168da63de55SLois Curfman McInnes 169aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 170542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0 171da63de55SLois Curfman McInnes #else 172542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0 173bf3909cdSBarry Smith #endif 174bf3909cdSBarry Smith 175bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG) 176542d4b3fSSatish Balay #define PetscLogFlops(n) (petsc_tmp_flops = (PETSC_FLOPS_PER_OP*((PetscLogDouble)n)), ((petsc_tmp_flops < 0) ? PETSC_ERR_FLOP_COUNT : (_TotalFlops += petsc_tmp_flops,0))) 177542d4b3fSSatish Balay #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n)) 178bf3909cdSBarry Smith #else 179542d4b3fSSatish Balay #define PetscLogFlops(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n),0) 180542d4b3fSSatish Balay #define PetscLogFlopsNoError(n) (_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n)) 181da63de55SLois Curfman McInnes #endif 18277c4ece6SBarry Smith 183aa482453SBarry Smith #if defined (PETSC_HAVE_MPE) 18477c4ece6SBarry Smith #include "mpe.h" 185ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogMPEBegin(void); 186ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogMPEDump(const char[]); 18735d8aa7fSBarry Smith extern PetscTruth UseMPE; 188043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e) \ 189335e4f37SSatish Balay ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 190a1b71033SSatish Balay MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0) 191043328b6SSatish Balay 192043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e) \ 193335e4f37SSatish Balay ((UseMPE && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 194a1b71033SSatish Balay MPE_Log_event(_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0) 195043328b6SSatish Balay 196614700edSBarry Smith #else 19752e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0 19852e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_END(e) 0 19977c4ece6SBarry Smith #endif 20077c4ece6SBarry Smith 201166c7f25SBarry Smith EXTERN PETSC_DLLEXPORT PetscErrorCode (*_PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 202166c7f25SBarry Smith EXTERN PETSC_DLLEXPORT PetscErrorCode (*_PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 203ff73aad6SKris Buschelman EXTERN PETSC_DLLEXPORT PetscErrorCode (*_PetscLogPHC)(PetscObject); 204ff73aad6SKris Buschelman EXTERN PETSC_DLLEXPORT PetscErrorCode (*_PetscLogPHD)(PetscObject); 20577c4ece6SBarry Smith 206043328b6SSatish Balay #define PetscLogObjectParent(p,c) \ 20752e6d16bSBarry Smith ((c && p) ? ((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id : 0, 0) 20852e6d16bSBarry Smith 209efee365bSSatish Balay #define PetscLogObjectParents(p,n,d) 0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}} 210d38fa0fbSBarry Smith #define PetscLogObjectCreate(h) ((_PetscLogPHC) ? (*_PetscLogPHC)((PetscObject)h) : 0) 211d38fa0fbSBarry Smith #define PetscLogObjectDestroy(h) ((_PetscLogPHD) ? (*_PetscLogPHD)((PetscObject)h) : 0) 21252e6d16bSBarry Smith #define PetscLogObjectMemory(p,m) (((PetscObject)(p))->mem += (m),0) 2138ba1e511SMatthew Knepley /* Initialization functions */ 214ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogBegin(void); 215ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogAllBegin(void); 216ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogTraceBegin(FILE *); 217ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogActions(PetscTruth); 218ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogObjects(PetscTruth); 2198ba1e511SMatthew Knepley /* General functions */ 220ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogGetRGBColor(const char*[]); 221ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogDestroy(void); 222ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 2236849ba73SBarry Smith PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 224ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogObjectState(PetscObject, const char[], ...) PETSC_PRINTF_FORMAT_CHECK(2,3); 2258ba1e511SMatthew Knepley /* Output functions */ 226ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogPrintSummary(MPI_Comm, const char[]); 22778392ef1SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogPrintDetailed(MPI_Comm, const char[]); 228ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogDump(const char[]); 2298ba1e511SMatthew Knepley /* Counter functions */ 230ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetFlops(PetscLogDouble *); 2318ba1e511SMatthew Knepley /* Stage functions */ 232166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStageRegister(const char[],PetscLogStage*); 233166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStagePush(PetscLogStage); 234ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStagePop(void); 235166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStageSetActive(PetscLogStage, PetscTruth); 236166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStageGetActive(PetscLogStage, PetscTruth *); 237166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStageSetVisible(PetscLogStage, PetscTruth); 238166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStageGetVisible(PetscLogStage, PetscTruth *); 239166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogStageGetId(const char [], PetscLogStage *); 2408ba1e511SMatthew Knepley /* Event functions */ 2410700a824SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*); 242166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogEventActivate(PetscLogEvent); 243166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogEventDeactivate(PetscLogEvent); 244166c7f25SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogEventSetActiveAll(PetscLogEvent, PetscTruth); 2450700a824SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogEventActivateClass(PetscClassId); 2460700a824SBarry Smith EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogEventDeactivateClass(PetscClassId); 2479afaeae2SBarry Smith 2488ba1e511SMatthew Knepley 2498ba1e511SMatthew Knepley /* Global counters */ 250ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble irecv_ct; 251ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble isend_ct; 252ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble recv_ct; 253ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble send_ct; 254ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble irecv_len; 255ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble isend_len; 256ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble recv_len; 257ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble send_len; 258ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble allreduce_ct; 25901faf4e4SMatthew Knepley extern PETSC_DLLEXPORT PetscLogDouble gather_ct; 26001faf4e4SMatthew Knepley extern PETSC_DLLEXPORT PetscLogDouble scatter_ct; 261ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble wait_ct; 262ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble wait_any_ct; 263ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble wait_all_ct; 264ff73aad6SKris Buschelman extern PETSC_DLLEXPORT PetscLogDouble sum_of_waits_ct; 2658ba1e511SMatthew Knepley 26652e6d16bSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \ 26752e6d16bSBarry Smith (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 26852e6d16bSBarry Smith (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \ 26952e6d16bSBarry Smith PetscLogEventBegin((e)+1,o1,o2,o3,o4)) 27077c4ece6SBarry Smith 27152e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 27252e6d16bSBarry Smith (((_PetscLogPLB && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 27352e6d16bSBarry Smith (*_PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \ 27452e6d16bSBarry Smith PETSC_LOG_EVENT_MPE_BEGIN(e)) 275043328b6SSatish Balay 276b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4) 277043328b6SSatish Balay 27852e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 27952e6d16bSBarry Smith (((_PetscLogPLE && _stageLog->stageInfo[_stageLog->curStage].perfInfo.active && _stageLog->stageInfo[_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 28052e6d16bSBarry Smith (*_PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \ 28152e6d16bSBarry Smith PETSC_LOG_EVENT_MPE_END(e)) 28277c4ece6SBarry Smith 283f141ce34SMatthew Knepley /* Creation and destruction functions */ 284ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogCreate(StageLog *); 285ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogDestroy(StageLog); 286f141ce34SMatthew Knepley /* Registration functions */ 287ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogRegister(StageLog, const char [], int *); 288f141ce34SMatthew Knepley /* Runtime functions */ 289ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogGetStageLog(StageLog *); 290ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogPush(StageLog, int); 291ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogPop(StageLog); 292ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetCurrent(StageLog, int *); 293ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogSetActive(StageLog, int, PetscTruth); 294ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetActive(StageLog, int, PetscTruth *); 295ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogSetVisible(StageLog, int, PetscTruth); 296ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetVisible(StageLog, int, PetscTruth *); 297ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetStage(StageLog, const char [], int *); 298ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetClassRegLog(StageLog, ClassRegLog *); 299ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetEventRegLog(StageLog, EventRegLog *); 300ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetClassPerfLog(StageLog, int, ClassPerfLog *); 301ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT StageLogGetEventPerfLog(StageLog, int, EventPerfLog *); 302f141ce34SMatthew Knepley 303e630d40cSMatthew Knepley EXTERN PetscErrorCode PETSC_DLLEXPORT EventRegLogGetEvent(EventRegLog, const char [], PetscLogEvent *); 304e630d40cSMatthew Knepley 305003131ecSBarry Smith EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*); 306003131ecSBarry Smith EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 307003131ecSBarry Smith 308ce85283eSBarry Smith /* 309f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 310f621e05eSBarry Smith their sizes. 311f621e05eSBarry Smith 3123c94ec11SBarry Smith This does not work for MPI-Uni because our include/mpiuni/mpi.h file 313ce85283eSBarry Smith uses macros to defined the MPI operations. 31415308354SBarry Smith 31515308354SBarry Smith It does not work correctly from HP-UX because it processes the 316bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 317b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 3187c1e34a4SSatish Balay 319f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 320ce85283eSBarry Smith */ 321c8217ed5SSatish Balay #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 32277a39924SBarry Smith /* 32377a39924SBarry Smith Logging of MPI activities 32477a39924SBarry Smith */ 325f95db71bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode TypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type) 326f95db71bSBarry Smith { 327618e35e3SBarry Smith PetscMPIInt mysize; return (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0)); 328f95db71bSBarry Smith } 32977a39924SBarry Smith 33077a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 331f95db71bSBarry Smith ((irecv_ct++,0) || TypeSize(&irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request)) 33215308354SBarry Smith 33377a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 334f95db71bSBarry Smith ((isend_ct++,0) || TypeSize(&isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request)) 33515308354SBarry Smith 3360d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \ 337f95db71bSBarry Smith ((irecv_ct += (PetscLogDouble)(number),0) || TypeSize(&irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 3380d4b0b6cSBarry Smith 3390d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \ 340f95db71bSBarry Smith ((isend_ct += (PetscLogDouble)(number),0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 3410d4b0b6cSBarry Smith 3420d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \ 343f95db71bSBarry Smith ((isend_ct++,0) || TypeSize(&isend_len,count,MPIU_SCALAR) || MPI_Start(requests)) 3440d4b0b6cSBarry Smith 345ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 346f95db71bSBarry Smith ((recv_ct++,0) || TypeSize(&recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status)) 34715308354SBarry Smith 34877a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 349f95db71bSBarry Smith ((send_ct++,0) || TypeSize(&send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm)) 35077a39924SBarry Smith 35177a39924SBarry Smith #define MPI_Wait(request,status) \ 3525e3723c6SSatish Balay ((wait_ct++,sum_of_waits_ct++,0) || MPI_Wait(request,status)) 35377a39924SBarry Smith 35477a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \ 3555e3723c6SSatish Balay ((wait_any_ct++,sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d)) 35677a39924SBarry Smith 35777a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 358f95db71bSBarry Smith ((wait_all_ct++,sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses)) 35977a39924SBarry Smith 36077a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 3615e3723c6SSatish Balay ((allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)) 3623914022bSBarry Smith 36301faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 36401faf4e4SMatthew Knepley ((gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 36501faf4e4SMatthew Knepley 36601faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 36701faf4e4SMatthew Knepley ((gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm)) 36801faf4e4SMatthew Knepley 36901faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 370f95db71bSBarry Smith ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 37101faf4e4SMatthew Knepley 37201faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 373f95db71bSBarry Smith ((gather_ct++,0) || TypeSize(&send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm)) 37401faf4e4SMatthew Knepley 37501faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 376f95db71bSBarry Smith ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 37701faf4e4SMatthew Knepley 37801faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 379f95db71bSBarry Smith ((scatter_ct++,0) || TypeSize(&recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm)) 38001faf4e4SMatthew Knepley 3810d4b0b6cSBarry Smith #else 3820d4b0b6cSBarry Smith 3830d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \ 3845e3723c6SSatish Balay (MPI_Startall(number,requests)) 3850d4b0b6cSBarry Smith 3860d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \ 3875e3723c6SSatish Balay (MPI_Startall(number,requests)) 3880d4b0b6cSBarry Smith 3890d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \ 3905e3723c6SSatish Balay (MPI_Start(requests)) 3910d4b0b6cSBarry Smith 392c8217ed5SSatish Balay #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 393614700edSBarry Smith 394df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 395614700edSBarry Smith 396b0a32e0cSBarry Smith #define PetscLogFlops(n) 0 397d854a674SSatish Balay #define PetscLogFlopsNoError(n) 398614700edSBarry Smith 399df8cf0b5SBarry Smith /* 400df8cf0b5SBarry Smith With logging turned off, then MPE has to be turned off 401df8cf0b5SBarry Smith */ 402b0a32e0cSBarry Smith #define PetscLogMPEBegin() 0 403b0a32e0cSBarry Smith #define PetscLogMPEDump(a) 0 404614700edSBarry Smith 405b0a32e0cSBarry Smith #define PetscLogEventActivate(a) 0 406b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0 407614700edSBarry Smith 408b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a) 0 409b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0 410e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b) 0 41177c4ece6SBarry Smith 412b0a32e0cSBarry Smith #define _PetscLogPLB 0 413b0a32e0cSBarry Smith #define _PetscLogPLE 0 414b0a32e0cSBarry Smith #define _PetscLogPHC 0 415b0a32e0cSBarry Smith #define _PetscLogPHD 0 41699de4ba8SSatish Balay #define PetscGetFlops(a) (*(a) = 0.0,0) 417b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 418b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 419b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0 420b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) 0 42152e6d16bSBarry Smith #define PetscLogObjectParent(p,c) 0 422efee365bSSatish Balay #define PetscLogObjectParents(p,n,c) 0 42352e6d16bSBarry Smith #define PetscLogObjectCreate(h) 0 42452e6d16bSBarry Smith #define PetscLogObjectDestroy(h) 0 42552e6d16bSBarry Smith #define PetscLogObjectMemory(p,m) 0 426b0a32e0cSBarry Smith #define PetscLogDestroy() 0 427b0a32e0cSBarry Smith #define PetscLogStagePush(a) 0 428b0a32e0cSBarry Smith #define PetscLogStagePop() 0 429b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b) 0 430b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg) 0 431b0a32e0cSBarry Smith #define PetscLogPrintSummary(comm,file) 0 43278392ef1SBarry Smith #define PetscLogPrintDetailed(comm,file) 0 433b0a32e0cSBarry Smith #define PetscLogBegin() 0 434b0a32e0cSBarry Smith #define PetscLogTraceBegin(file) 0 435b0a32e0cSBarry Smith #define PetscLogSet(lb,le) 0 436b0a32e0cSBarry Smith #define PetscLogAllBegin() 0 437b0a32e0cSBarry Smith #define PetscLogDump(c) 0 438043328b6SSatish Balay #define PetscLogEventRegister(a,b,c) 0 43973fda44aSBarry Smith #define PetscLogObjects(a) 0 44073fda44aSBarry Smith #define PetscLogActions(a) 0 441ff73aad6SKris Buschelman EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogObjectState(PetscObject,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 442ce6058e1SBarry Smith 443aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 444ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests) 445ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests) 446ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests) 447ca161407SBarry Smith 448f141ce34SMatthew Knepley /* Creation and destruction functions */ 449f141ce34SMatthew Knepley #define StageLogCreate(stageLog) 0 450f141ce34SMatthew Knepley #define StageLogDestroy(stageLog) 0 451f141ce34SMatthew Knepley /* Registration functions */ 452f141ce34SMatthew Knepley #define StageLogRegister(stageLog, name, stage) 0 453f141ce34SMatthew Knepley /* Runtime functions */ 454f141ce34SMatthew Knepley #define PetscLogGetStageLog(stageLog) 0 455f141ce34SMatthew Knepley #define StageLogPush(stageLog, stage) 0 456f141ce34SMatthew Knepley #define StageLogPop(stageLog) 0 457f141ce34SMatthew Knepley #define StageLogGetCurrent(stageLog, stage) 0 458f141ce34SMatthew Knepley #define StageLogSetActive(stageLog, stage, active) 0 459f141ce34SMatthew Knepley #define StageLogGetActive(stageLog, stage, active) 0 460f141ce34SMatthew Knepley #define StageLogSetVisible(stageLog, stage, visible) 0 461f141ce34SMatthew Knepley #define StageLogGetVisible(stageLog, stage, visible) 0 462f141ce34SMatthew Knepley #define StageLogGetStage(stageLog, name, stage) 0 463fad68dfaSSatish Balay #define PetscLogStageGetId(a,b) (*(b)=0,0) 464fad68dfaSSatish Balay #define PetscLogStageSetActive(a,b) 0 4656a6a9b46SSatish Balay #define PetscLogStageGetActive(a,b) 0 4666a6a9b46SSatish Balay #define PetscLogStageGetVisible(a,b) 0 4676a6a9b46SSatish Balay #define PetscLogStageSetVisible(a,b) 0 468f141ce34SMatthew Knepley 469aa482453SBarry Smith #endif /* PETSC_USE_LOG */ 4706daaf66cSBarry Smith 471bf5c43c7SMatthew Knepley /* Special support for C++ */ 472bf5c43c7SMatthew Knepley #include "petsclog.hh" 473bf5c43c7SMatthew Knepley 474043328b6SSatish Balay #define PreLoadBegin(flag,name) \ 475043328b6SSatish Balay {\ 476c4411e17SBarry Smith PetscTruth PreLoading = flag;\ 4778cbcd9ccSBarry Smith int PreLoadMax,PreLoadIt;\ 478166c7f25SBarry Smith PetscLogStage _stageNum;\ 4798cbcd9ccSBarry Smith PetscErrorCode _3_ierr; \ 4804dc4c822SBarry Smith _3_ierr = PetscOptionsGetTruth(PETSC_NULL,"-preload",&PreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\ 481043328b6SSatish Balay PreLoadMax = (int)(PreLoading);\ 482043328b6SSatish Balay PetscPreLoadingUsed = PreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 483e7592fafSBarry Smith for (PreLoadIt=0; PreLoadIt<=PreLoadMax; PreLoadIt++) {\ 484435da068SBarry Smith PetscPreLoadingOn = PreLoading;\ 4856e491fe6SBarry Smith _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\ 4868e58c17dSMatthew Knepley if (PreLoadIt>0) {\ 4878e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 4888e58c17dSMatthew Knepley } else {\ 489a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 4908e58c17dSMatthew Knepley }\ 491773a6509SMatthew Knepley _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\ 4928e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 4938e58c17dSMatthew Knepley 494043328b6SSatish Balay #define PreLoadEnd() \ 495043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 496043328b6SSatish Balay PreLoading = PETSC_FALSE;\ 497043328b6SSatish Balay }\ 498043328b6SSatish Balay } 4998e58c17dSMatthew Knepley 500043328b6SSatish Balay #define PreLoadStage(name) \ 501043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 5028e58c17dSMatthew Knepley if (PreLoadIt>0) {\ 5038e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 5048e58c17dSMatthew Knepley } else {\ 505a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 5068e58c17dSMatthew Knepley }\ 507773a6509SMatthew Knepley _3_ierr = PetscLogStageSetActive(_stageNum,(PetscTruth)(!PreLoadMax || PreLoadIt));\ 5088e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 509e9fa29b7SSatish Balay 510e9fa29b7SSatish Balay PETSC_EXTERN_CXX_END 51197bb86f7SLois Curfman McInnes #endif 512