197bb86f7SLois Curfman McInnes /* 27588ac45SBarry Smith Defines profile/logging in PETSc. 397bb86f7SLois Curfman McInnes */ 497bb86f7SLois Curfman McInnes 526bd1501SBarry Smith #if !defined(PETSCLOG_H) 626bd1501SBarry Smith #define PETSCLOG_H 7aaa7dc30SBarry Smith #include <petscsys.h> 8958c4211Shannah_mairs #include <petsctime.h> 9c8d78d4dSSatish Balay 10fa2bb9feSLisandro Dalcin /* General logging of information; different from event logging */ 113ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],PetscObject,const char[],...) PETSC_ATTRIBUTE_FORMAT(3,4); 12fa2bb9feSLisandro Dalcin #if defined(PETSC_USE_INFO) 13fe9b927eSVaclav Hapla #define PetscInfo(A,S) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S) 14fe9b927eSVaclav Hapla #define PetscInfo1(A,S,a1) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1) 15fe9b927eSVaclav Hapla #define PetscInfo2(A,S,a1,a2) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2) 16fe9b927eSVaclav Hapla #define PetscInfo3(A,S,a1,a2,a3) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3) 17fe9b927eSVaclav Hapla #define PetscInfo4(A,S,a1,a2,a3,a4) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4) 18fe9b927eSVaclav Hapla #define PetscInfo5(A,S,a1,a2,a3,a4,a5) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5) 19fe9b927eSVaclav Hapla #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5,a6) 20fe9b927eSVaclav Hapla #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5,a6,a7) 2100702c57SStefano Zampini #define PetscInfo8(A,S,a1,a2,a3,a4,a5,a6,a7,a8) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5,a6,a7,a8) 2200702c57SStefano Zampini #define PetscInfo9(A,S,a1,a2,a3,a4,a5,a6,a7,a8,a9) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5,a6,a7,a8,a9) 23fa2bb9feSLisandro Dalcin #else 24fa2bb9feSLisandro Dalcin #define PetscInfo(A,S) 0 25fa2bb9feSLisandro Dalcin #define PetscInfo1(A,S,a1) 0 26fa2bb9feSLisandro Dalcin #define PetscInfo2(A,S,a1,a2) 0 27fa2bb9feSLisandro Dalcin #define PetscInfo3(A,S,a1,a2,a3) 0 28fa2bb9feSLisandro Dalcin #define PetscInfo4(A,S,a1,a2,a3,a4) 0 29fa2bb9feSLisandro Dalcin #define PetscInfo5(A,S,a1,a2,a3,a4,a5) 0 30fa2bb9feSLisandro Dalcin #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) 0 31fa2bb9feSLisandro Dalcin #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0 3200702c57SStefano Zampini #define PetscInfo8(A,S,a1,a2,a3,a4,a5,a6,a7,a8) 0 3300702c57SStefano Zampini #define PetscInfo9(A,S,a1,a2,a3,a4,a5,a6,a7,a8,a9) 0 34fa2bb9feSLisandro Dalcin #endif 35e94e781bSJacob Faibussowitsch 36e94e781bSJacob Faibussowitsch /*E 37e94e781bSJacob Faibussowitsch PetscInfoCommFlag - Describes the method by which to filter PetscInfo() by communicator size 38e94e781bSJacob Faibussowitsch 39e94e781bSJacob Faibussowitsch Used as an input for PetscInfoSetFilterCommSelf() 40e94e781bSJacob Faibussowitsch 41e94e781bSJacob Faibussowitsch $ PETSC_INFO_COMM_ALL - Default uninitialized value. PetscInfo() will not filter based on communicator size (i.e. will 42e94e781bSJacob Faibussowitsch print for all communicators) 43e94e781bSJacob Faibussowitsch $ PETSC_INFO_COMM_NO_SELF - PetscInfo() will NOT print for communicators with size = 1 (i.e. *_COMM_SELF) 44e94e781bSJacob Faibussowitsch $ PETSC_INFO_COMM_ONLY_SELF - PetscInfo will ONLY print for communicators with size = 1 45e94e781bSJacob Faibussowitsch 46e94e781bSJacob Faibussowitsch Level: intermediate 47e94e781bSJacob Faibussowitsch 48e94e781bSJacob Faibussowitsch .seealso: PetscInfo(), PetscInfoSetFromOptions(), PetscInfoSetFilterCommSelf() 49e94e781bSJacob Faibussowitsch E*/ 50e94e781bSJacob Faibussowitsch typedef enum { 51e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_ALL = -1, 52e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_NO_SELF = 0, 53e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_ONLY_SELF = 1 54e94e781bSJacob Faibussowitsch } PetscInfoCommFlag; 55e94e781bSJacob Faibussowitsch 56e94e781bSJacob Faibussowitsch PETSC_EXTERN const char * const PetscInfoCommFlags[]; 57fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId); 58fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId); 59e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoEnabled(PetscClassId, PetscBool *); 60e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoAllow(PetscBool); 61e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFile(const char[],const char[]); 62e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetFile(char **,FILE **); 63e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetClasses(PetscBool,PetscInt,const char *const *); 64e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetClass(const char *, PetscBool *); 65e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetInfo(PetscBool *,PetscBool *,PetscBool *,PetscBool *,PetscInfoCommFlag *); 66e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoProcessClass(const char[],PetscInt,PetscClassId[]); 67e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag); 68e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFromOptions(PetscOptions); 69e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoDestroy(void); 70fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */ 71fa2bb9feSLisandro Dalcin 72b859824cSBarry Smith /*MC 73b859824cSBarry Smith PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable) 74b859824cSBarry Smith code. 75b859824cSBarry Smith 76b859824cSBarry Smith Level: intermediate 77b859824cSBarry Smith 78b859824cSBarry Smith .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage 79b859824cSBarry Smith M*/ 80b859824cSBarry Smith typedef int PetscLogEvent; 81b859824cSBarry Smith 82b859824cSBarry Smith /*MC 83b859824cSBarry Smith PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging 84b859824cSBarry Smith 85b859824cSBarry Smith Level: intermediate 86b859824cSBarry Smith 87522ce795SJed Brown .seealso: PetscLogStageRegister(), PetscLogStagePush(), PetscLogStagePop(), PetscLogEvent 88b859824cSBarry Smith M*/ 89b859824cSBarry Smith typedef int PetscLogStage; 90b859824cSBarry Smith 918ba1e511SMatthew Knepley #define PETSC_EVENT 1311311 92014dd563SJed Brown PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT; 9397bb86f7SLois Curfman McInnes 9419b02663SBarry Smith /* Global flop counter */ 95014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_TotalFlops; 96014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_tmp_flops; 9719b02663SBarry Smith 9831d06abdSBarry Smith /* We must make the following structures available to access the event 9931d06abdSBarry Smith activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public 10031d06abdSBarry Smith API and are not intended to be used by other parts of PETSc or by users. 101d49d4b11SBarry Smith 102fa2bb9feSLisandro Dalcin The code that manipulates these structures is in src/sys/logging/utils. 10331d06abdSBarry Smith */ 104aa213bdcSJed Brown typedef struct _n_PetscIntStack *PetscIntStack; 1056a6a9b46SSatish Balay 106217044c2SLisandro Dalcin /* -----------------------------------------------------------------------------------------------------*/ 107c60ec953SBarry Smith /* 108aa213bdcSJed Brown PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has 109c60ec953SBarry Smith static information about it, the second collects statistics on how many objects of the class are created, 110c60ec953SBarry Smith how much memory they use, etc. 111c60ec953SBarry Smith 112aa213bdcSJed Brown PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes. 113c60ec953SBarry Smith */ 1146a6a9b46SSatish Balay typedef struct { 115c60ec953SBarry Smith char *name; /* The class name */ 116c60ec953SBarry Smith PetscClassId classid; /* The integer identifying this class */ 117aa213bdcSJed Brown } PetscClassRegInfo; 1186a6a9b46SSatish Balay 1196a6a9b46SSatish Balay typedef struct { 1200700a824SBarry Smith PetscClassId id; /* The integer identifying this class */ 1216a6a9b46SSatish Balay int creations; /* The number of objects of this class created */ 1226a6a9b46SSatish Balay int destructions; /* The number of objects of this class destroyed */ 1236a6a9b46SSatish Balay PetscLogDouble mem; /* The total memory allocated by objects of this class */ 1246a6a9b46SSatish Balay PetscLogDouble descMem; /* The total memory allocated by descendents of these objects */ 125aa213bdcSJed Brown } PetscClassPerfInfo; 1266a6a9b46SSatish Balay 127aa213bdcSJed Brown typedef struct _n_PetscClassRegLog *PetscClassRegLog; 128aa213bdcSJed Brown struct _n_PetscClassRegLog { 129c60ec953SBarry Smith int numClasses; /* The number of classes registered */ 130c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 131aa213bdcSJed Brown PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 132c60ec953SBarry Smith }; 1336a6a9b46SSatish Balay 134aa213bdcSJed Brown typedef struct _n_PetscClassPerfLog *PetscClassPerfLog; 135aa213bdcSJed Brown struct _n_PetscClassPerfLog { 136c60ec953SBarry Smith int numClasses; /* The number of logging classes */ 137c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 138aa213bdcSJed Brown PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 139c60ec953SBarry Smith }; 140c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/ 141c60ec953SBarry Smith /* 142aa213bdcSJed Brown PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has 143c60ec953SBarry Smith static information about it, the second collects statistics on how many times the event is used, how 144c60ec953SBarry Smith much time it takes, etc. 145c60ec953SBarry Smith 146aa213bdcSJed Brown PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one 147c60ec953SBarry Smith of these for each stage. 148c60ec953SBarry Smith 149c60ec953SBarry Smith */ 1506a6a9b46SSatish Balay typedef struct { 1516a6a9b46SSatish Balay char *name; /* The name of this event */ 152c60ec953SBarry Smith PetscClassId classid; /* The class the event is associated with */ 153217044c2SLisandro Dalcin PetscBool collective; /* Flag this event as collective */ 1546a6a9b46SSatish Balay #if defined (PETSC_HAVE_MPE) 1556a6a9b46SSatish Balay int mpe_id_begin; /* MPE IDs that define the event */ 1566a6a9b46SSatish Balay int mpe_id_end; 1576a6a9b46SSatish Balay #endif 158aa213bdcSJed Brown } PetscEventRegInfo; 1596a6a9b46SSatish Balay 160c60ec953SBarry Smith typedef struct { 161c60ec953SBarry Smith int id; /* The integer identifying this event */ 162ace3abfcSBarry Smith PetscBool active; /* The flag to activate logging */ 163ace3abfcSBarry Smith PetscBool visible; /* The flag to print info in summary */ 164c60ec953SBarry Smith int depth; /* The nesting depth of the event call */ 165c60ec953SBarry Smith int count; /* The number of times this event was executed */ 166a42e5b54SMatthew G Knepley PetscLogDouble flops, flops2, flopsTmp; /* The flops and flops^2 used in this event */ 167a42e5b54SMatthew G Knepley PetscLogDouble time, time2, timeTmp; /* The time and time^2 taken for this event */ 168217044c2SLisandro Dalcin PetscLogDouble syncTime; /* The synchronization barrier time */ 169891e75beSMatthew G. Knepley PetscLogDouble dof[8]; /* The number of degrees of freedom associated with this event */ 1705d68e14cSMatthew G. Knepley PetscLogDouble errors[8]; /* The errors (user-defined) associated with this event */ 171c60ec953SBarry Smith PetscLogDouble numMessages; /* The number of messages in this event */ 172c60ec953SBarry Smith PetscLogDouble messageLength; /* The total message lengths in this event */ 173c60ec953SBarry Smith PetscLogDouble numReductions; /* The number of reductions in this event */ 174e3ed9ee7SBarry Smith PetscLogDouble memIncrease; /* How much the resident memory has increased in this event */ 175e3ed9ee7SBarry Smith PetscLogDouble mallocIncrease;/* How much the maximum malloced space has increased in this event */ 176e3ed9ee7SBarry Smith PetscLogDouble mallocSpace; /* How much the space was malloced and kept during this event */ 177e3ed9ee7SBarry Smith PetscLogDouble mallocIncreaseEvent; /* Maximum of the high water mark with in event minus memory available at the end of the event */ 178091bc5acSJunchao Zhang #if defined(PETSC_HAVE_DEVICE) 179bec0b493Shannah_mairs PetscLogDouble CpuToGpuCount; /* The total number of CPU to GPU copies */ 180bec0b493Shannah_mairs PetscLogDouble GpuToCpuCount; /* The total number of GPU to CPU copies */ 181bec0b493Shannah_mairs PetscLogDouble CpuToGpuSize; /* The total size of CPU to GPU copies */ 182bec0b493Shannah_mairs PetscLogDouble GpuToCpuSize; /* The total size of GPU to CPU copies */ 183958c4211Shannah_mairs PetscLogDouble GpuFlops; /* The flops done on a GPU in this event */ 184958c4211Shannah_mairs PetscLogDouble GpuTime; /* The time spent on a GPU in this event */ 185bec0b493Shannah_mairs #endif 186aa213bdcSJed Brown } PetscEventPerfInfo; 187c60ec953SBarry Smith 188aa213bdcSJed Brown typedef struct _n_PetscEventRegLog *PetscEventRegLog; 189aa213bdcSJed Brown struct _n_PetscEventRegLog { 1906a6a9b46SSatish Balay int numEvents; /* The number of registered events */ 1916a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 192aa213bdcSJed Brown PetscEventRegInfo *eventInfo; /* The registration information for each event */ 1936a6a9b46SSatish Balay }; 1946a6a9b46SSatish Balay 195aa213bdcSJed Brown typedef struct _n_PetscEventPerfLog *PetscEventPerfLog; 196aa213bdcSJed Brown struct _n_PetscEventPerfLog { 1976a6a9b46SSatish Balay int numEvents; /* The number of logging events */ 1986a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 199aa213bdcSJed Brown PetscEventPerfInfo *eventInfo; /* The performance information for each event */ 2006a6a9b46SSatish Balay }; 201c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/ 202c60ec953SBarry Smith /* 203aa213bdcSJed Brown PetscStageInfo - Contains all the information about a particular stage. 2046a6a9b46SSatish Balay 205aa213bdcSJed Brown PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code. 206c60ec953SBarry Smith */ 207aa213bdcSJed Brown typedef struct _PetscStageInfo { 2086a6a9b46SSatish Balay char *name; /* The stage name */ 209ace3abfcSBarry Smith PetscBool used; /* The stage was pushed on this processor */ 210aa213bdcSJed Brown PetscEventPerfInfo perfInfo; /* The stage performance information */ 211aa213bdcSJed Brown PetscEventPerfLog eventLog; /* The event information for this stage */ 212aa213bdcSJed Brown PetscClassPerfLog classLog; /* The class information for this stage */ 213aa213bdcSJed Brown } PetscStageInfo; 2146a6a9b46SSatish Balay 215aa213bdcSJed Brown typedef struct _n_PetscStageLog *PetscStageLog; 216aa213bdcSJed Brown struct _n_PetscStageLog { 2176a6a9b46SSatish Balay int numStages; /* The number of registered stages */ 2186a6a9b46SSatish Balay int maxStages; /* The maximum number of stages */ 219aa213bdcSJed Brown PetscIntStack stack; /* The stack for active stages */ 220aa213bdcSJed Brown int curStage; /* The current stage (only used in macros so we don't call PetscIntStackTop) */ 221aa213bdcSJed Brown PetscStageInfo *stageInfo; /* The information for each stage */ 222aa213bdcSJed Brown PetscEventRegLog eventLog; /* The registered events */ 223aa213bdcSJed Brown PetscClassRegLog classLog; /* The registered classes */ 2246a6a9b46SSatish Balay }; 225217044c2SLisandro Dalcin /* -----------------------------------------------------------------------------------------------------*/ 226fee518ebSJed Brown 2273bb1ff40SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogObjectParent(PetscObject,PetscObject); 2283bb1ff40SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogObjectMemory(PetscObject,PetscLogDouble); 2293bb1ff40SBarry Smith 230aa482453SBarry Smith #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 231aeeda9f6SJohn Fettig PETSC_EXTERN PetscStageLog petsc_stageLog; 232f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog*); 233f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog,int*); 234f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog,int,PetscEventPerfLog*); 235614700edSBarry Smith 236da63de55SLois Curfman McInnes /* 237da63de55SLois Curfman McInnes Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 238da63de55SLois Curfman McInnes 239da63de55SLois Curfman McInnes For the complex numbers version, note that 240da63de55SLois Curfman McInnes 1 complex addition = 2 flops 241da63de55SLois Curfman McInnes 1 complex multiplication = 6 flops, 242da63de55SLois Curfman McInnes where we define 1 flop as that for a double precision scalar. We roughly approximate 243da63de55SLois Curfman McInnes flop counting for complex numbers by multiplying the total flops by 4; this corresponds 244da63de55SLois Curfman McInnes to the assumption that we're counting mostly additions and multiplications -- and 245da63de55SLois Curfman McInnes roughly the same number of each. More accurate counting could be done by distinguishing 246da63de55SLois Curfman McInnes among the various arithmetic operations. 247da63de55SLois Curfman McInnes */ 248da63de55SLois Curfman McInnes 249aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 250542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0 251da63de55SLois Curfman McInnes #else 252542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0 253bf3909cdSBarry Smith #endif 254bf3909cdSBarry Smith 255f8bfbb56SSatish Balay /*@C 256ca0c957dSBarry Smith PetscLogFlops - Log how many flops are performed in a calculation 257ca0c957dSBarry Smith 258c3b874c4SJose E. Roman Input Parameter: 259c3b874c4SJose E. Roman . flops - the number of flops 260ca0c957dSBarry Smith 261ca0c957dSBarry Smith Notes: 262ca0c957dSBarry Smith To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double, 263ca0c957dSBarry Smith not an integer. Use PetscLogFlops(4.0*n) not PetscLogFlops(4*n) 264ca0c957dSBarry Smith 265ca0c957dSBarry Smith Level: intermediate 266ca0c957dSBarry Smith 26768481988SMark .seealso: PetscLogView(), PetscLogGpuFlops() 268ca0c957dSBarry Smith @*/ 269ca0c957dSBarry Smith 270dd19b90bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n) 271dd19b90bSBarry Smith { 272dd19b90bSBarry Smith PetscFunctionBegin; 273bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG) 274dd19b90bSBarry Smith if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 275da63de55SLois Curfman McInnes #endif 276dd19b90bSBarry Smith petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 277dd19b90bSBarry Smith PetscFunctionReturn(0); 278dd19b90bSBarry Smith } 279fa2bb9feSLisandro Dalcin 280fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 28177c4ece6SBarry Smith 282aa482453SBarry Smith #if defined (PETSC_HAVE_MPE) 283014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 284014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 28577c4ece6SBarry Smith #endif 28677c4ece6SBarry Smith 287014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 288014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 289014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 290014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 29177c4ece6SBarry Smith 292e83a5d19SLisandro Dalcin #define PetscLogObjectParents(p,n,d) 0;do{int _i; for (_i=0; _i<(n); _i++) {ierr = PetscLogObjectParent((PetscObject)(p),(PetscObject)(d)[_i]);CHKERRQ(ierr);}}while (0) 293fa2bb9feSLisandro Dalcin #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : 0) 294fa2bb9feSLisandro Dalcin #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : 0) 2953ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2,3); 296fa2bb9feSLisandro Dalcin 2978ba1e511SMatthew Knepley /* Initialization functions */ 298bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void); 299014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 300bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void); 301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 303014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 304fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble,PetscLogDouble*); 305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 3066849ba73SBarry Smith PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 307fa2bb9feSLisandro Dalcin 3088ba1e511SMatthew Knepley /* Output functions */ 309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 310f14045dbSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void); 311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 31231d06abdSBarry Smith 313fa2bb9feSLisandro Dalcin /* Stage functions */ 314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*); 315014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 316014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 317014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage,PetscBool); 318014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage,PetscBool*); 319014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage,PetscBool); 320014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage,PetscBool*); 321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[],PetscLogStage*); 322f5d6ab90SLisandro Dalcin 3238ba1e511SMatthew Knepley /* Event functions */ 324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[],PetscClassId,PetscLogEvent*); 325217044c2SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent,PetscBool); 326fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId); 327fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId); 328014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 329014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 330c00cb57fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent); 331c00cb57fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent); 332014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent,PetscBool); 333014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 334014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 3358c49a8d9SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[],PetscLogEvent*); 33613230571SMichael Lange PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int,PetscLogEvent,PetscEventPerfInfo*); 337891e75beSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble); 3385d68e14cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble); 3398ba1e511SMatthew Knepley 3408ba1e511SMatthew Knepley /* Global counters */ 341014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 342014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_ct; 343014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_ct; 344014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_ct; 345014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_len; 346014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_len; 347014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_len; 348014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_len; 349014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 350014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_gather_ct; 351014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 352014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_ct; 353014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 354014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 355014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 3568ba1e511SMatthew Knepley 357e3ed9ee7SBarry Smith PETSC_EXTERN PetscBool PetscLogMemory; 358e3ed9ee7SBarry Smith 359fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */ 36062872c28SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm); 36162872c28SLisandro Dalcin 36262872c28SLisandro Dalcin #define PetscLogEventSync(e,comm) \ 36362872c28SLisandro Dalcin (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 36462872c28SLisandro Dalcin PetscLogEventSynchronize((e),(comm)) : 0)) 36577c4ece6SBarry Smith 36652e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 3678b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 368495fc317SBarry Smith (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0)) 369043328b6SSatish Balay 37052e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 3718b5db460SBarry Smith (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 372495fc317SBarry Smith (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0)) 37377c4ece6SBarry Smith 374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent,PetscLogDouble*); 375014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 376003131ecSBarry Smith 377ce85283eSBarry Smith /* 378f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 379f621e05eSBarry Smith their sizes. 380f621e05eSBarry Smith 381af0996ceSBarry Smith This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file 382ce85283eSBarry Smith uses macros to defined the MPI operations. 38315308354SBarry Smith 38415308354SBarry Smith It does not work correctly from HP-UX because it processes the 385bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 386b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 3877c1e34a4SSatish Balay 388f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 389ce85283eSBarry Smith */ 390c9b973beSBarry Smith #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 39177a39924SBarry Smith /* 39277a39924SBarry Smith Logging of MPI activities 39377a39924SBarry Smith */ 394b23bfdefSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscInt count,MPI_Datatype type,PetscLogDouble *length) 395f95db71bSBarry Smith { 396f12d10ccSJunchao Zhang PetscMPIInt typesize; 397f12d10ccSJunchao Zhang PetscErrorCode ierr; 3987d30fa4aSBarry Smith if (type == MPI_DATATYPE_NULL) return 0; 39955b25c41SPierre Jolivet ierr = MPI_Type_size(type,&typesize);CHKERRMPI(ierr); 400f12d10ccSJunchao Zhang *length += (PetscLogDouble) (count*typesize); 4019c72ff1eSSatish Balay return 0; 402f95db71bSBarry Smith } 40377a39924SBarry Smith 404f12d10ccSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length) 4053b9284c0SMatthew G Knepley { 406f12d10ccSJunchao Zhang PetscMPIInt typesize,size,p; 407f12d10ccSJunchao Zhang PetscErrorCode ierr; 4083b9284c0SMatthew G Knepley 4097d30fa4aSBarry Smith if (type == MPI_DATATYPE_NULL) return 0; 410ffc4695bSBarry Smith ierr = MPI_Comm_size(comm,&size);CHKERRMPI(ierr); 411ffc4695bSBarry Smith ierr = MPI_Type_size(type,&typesize);CHKERRMPI(ierr); 412f12d10ccSJunchao Zhang for (p=0; p<size; ++p) { 413f12d10ccSJunchao Zhang *length += (PetscLogDouble) (counts[p]*typesize); 414f12d10ccSJunchao Zhang } 415f12d10ccSJunchao Zhang return 0; 416f12d10ccSJunchao Zhang } 417f12d10ccSJunchao Zhang 418f12d10ccSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeCount(PetscInt n,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length) 419f12d10ccSJunchao Zhang { 420f12d10ccSJunchao Zhang PetscMPIInt typesize,p; 421f12d10ccSJunchao Zhang PetscErrorCode ierr; 422f12d10ccSJunchao Zhang 423f12d10ccSJunchao Zhang if (type == MPI_DATATYPE_NULL) return 0; 424ffc4695bSBarry Smith ierr = MPI_Type_size(type,&typesize);CHKERRMPI(ierr); 425f12d10ccSJunchao Zhang for (p=0; p<n; ++p) { 426f12d10ccSJunchao Zhang *length += (PetscLogDouble) (counts[p]*typesize); 4273b9284c0SMatthew G Knepley } 4283b9284c0SMatthew G Knepley return 0; 4293b9284c0SMatthew G Knepley } 4303b9284c0SMatthew G Knepley 43172b11a25SBarry Smith /* 43272b11a25SBarry Smith Returns 1 if the communicator is parallel else zero 43372b11a25SBarry Smith */ 43472b11a25SBarry Smith PETSC_STATIC_INLINE int PetscMPIParallelComm(MPI_Comm comm) 43572b11a25SBarry Smith { 43672b11a25SBarry Smith PetscMPIInt size; MPI_Comm_size(comm,&size); return size > 1; 43772b11a25SBarry Smith } 43872b11a25SBarry Smith 43977a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 440f12d10ccSJunchao Zhang ((petsc_irecv_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || MPI_Irecv((buf),(count),(datatype),(source),(tag),(comm),(request))) 44115308354SBarry Smith 442c87b50c4SJunchao Zhang #define MPI_Irecv_c(buf,count,datatype,source,tag,comm,request) \ 443c87b50c4SJunchao Zhang ((petsc_irecv_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || MPI_Irecv_c((buf),(count),(datatype),(source),(tag),(comm),(request))) 444c87b50c4SJunchao Zhang 44577a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 446f12d10ccSJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || MPI_Isend((buf),(count),(datatype),(dest),(tag),(comm),(request))) 44715308354SBarry Smith 448c87b50c4SJunchao Zhang #define MPI_Isend_c(buf,count,datatype,dest,tag,comm,request) \ 449c87b50c4SJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || MPI_Isend_c((buf),(count),(datatype),(dest),(tag),(comm),(request))) 450c87b50c4SJunchao Zhang 451457b14b1SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) \ 452f12d10ccSJunchao Zhang ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || ((number) && MPI_Startall((number),(requests)))) 4530d4b0b6cSBarry Smith 454457b14b1SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) \ 455f12d10ccSJunchao Zhang ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || ((number) && MPI_Startall((number),(requests)))) 4560d4b0b6cSBarry Smith 457457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) \ 458f12d10ccSJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_isend_len)) || MPI_Start((requests))) 4590d4b0b6cSBarry Smith 460ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 461f12d10ccSJunchao Zhang ((petsc_recv_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_recv_len)) || MPI_Recv((buf),(count),(datatype),(source),(tag),(comm),(status))) 46215308354SBarry Smith 463c87b50c4SJunchao Zhang #define MPI_Recv_c(buf,count,datatype,source,tag,comm,status) \ 464c87b50c4SJunchao Zhang ((petsc_recv_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_recv_len)) || MPI_Recv_c((buf),(count),(datatype),(source),(tag),(comm),(status))) 465c87b50c4SJunchao Zhang 46677a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 467f12d10ccSJunchao Zhang ((petsc_send_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_send_len)) || MPI_Send((buf),(count),(datatype),(dest),(tag),(comm))) 46877a39924SBarry Smith 469c87b50c4SJunchao Zhang #define MPI_Send_c(buf,count,datatype,dest,tag,comm) \ 470c87b50c4SJunchao Zhang ((petsc_send_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_send_len)) || MPI_Send_c((buf),(count),(datatype),(dest),(tag),(comm))) 471c87b50c4SJunchao Zhang 47277a39924SBarry Smith #define MPI_Wait(request,status) \ 4735fa69175SJed Brown ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait((request),(status))) 47477a39924SBarry Smith 47577a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \ 4765fa69175SJed Brown ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany((a),(b),(c),(d))) 47777a39924SBarry Smith 47877a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 4795fa69175SJed Brown ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall((count),(array_of_requests),(array_of_statuses))) 48077a39924SBarry Smith 48177a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 482df05ca09SBarry Smith (petsc_allreduce_ct += PetscMPIParallelComm((comm)),MPI_Allreduce((sendbuf),(recvbuf),(count),(datatype),(op),(comm))) 4833914022bSBarry Smith 48454fe5c21SBarry Smith #define MPI_Bcast(buffer,count,datatype,root,comm) \ 4855fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Bcast((buffer),(count),(datatype),(root),(comm))) 48654fe5c21SBarry Smith 487d6e4c47cSJed Brown #define MPI_Reduce_scatter_block(sendbuf,recvbuf,recvcount,datatype,op,comm) \ 4885fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Reduce_scatter_block((sendbuf),(recvbuf),(recvcount),(datatype),(op),(comm))) 489d6e4c47cSJed Brown 4903b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 491f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Alltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm))) 4923b9284c0SMatthew G Knepley 4933b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 494f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSizeComm((comm),(sendcnts),(sendtype),(&petsc_send_len)) || MPI_Alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm))) 4953b9284c0SMatthew G Knepley 49601faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 4975fa69175SJed Brown ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm))) 49801faf4e4SMatthew Knepley 49901faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 5005fa69175SJed Brown ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm))) 50101faf4e4SMatthew Knepley 50201faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 503f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 50401faf4e4SMatthew Knepley 50501faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 506f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm))) 50701faf4e4SMatthew Knepley 50801faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 509f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 51001faf4e4SMatthew Knepley 51101faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 512f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 513f12d10ccSJunchao Zhang 514f12d10ccSJunchao Zhang #define MPI_Ialltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \ 515f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Ialltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request))) 516f12d10ccSJunchao Zhang 517f12d10ccSJunchao Zhang #define MPI_Ialltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 518f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSizeComm((comm),(sendcnts),(sendtype),(&petsc_send_len)) || MPI_Ialltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request))) 519f12d10ccSJunchao Zhang 520f12d10ccSJunchao Zhang #define MPI_Iallgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \ 521f12d10ccSJunchao Zhang ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request))) 522f12d10ccSJunchao Zhang 523f12d10ccSJunchao Zhang #define MPI_Iallgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm,request) \ 524f12d10ccSJunchao Zhang ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm),(request))) 525f12d10ccSJunchao Zhang 526f12d10ccSJunchao Zhang #define MPI_Igather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 527f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 528f12d10ccSJunchao Zhang 529f12d10ccSJunchao Zhang #define MPI_Igatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm,request) \ 530f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm),(request))) 531f12d10ccSJunchao Zhang 532f12d10ccSJunchao Zhang #define MPI_Iscatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 533f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 534f12d10ccSJunchao Zhang 535f12d10ccSJunchao Zhang #define MPI_Iscatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 536f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 537f12d10ccSJunchao Zhang 5380d4b0b6cSBarry Smith #else 5390d4b0b6cSBarry Smith 540457b14b1SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) \ 541ea1c87f7SJunchao Zhang ((number) && MPI_Startall((number),(requests))) 5420d4b0b6cSBarry Smith 543457b14b1SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) \ 544ea1c87f7SJunchao Zhang ((number) && MPI_Startall((number),(requests))) 5450d4b0b6cSBarry Smith 546457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) \ 5475fa69175SJed Brown (MPI_Start((requests))) 5480d4b0b6cSBarry Smith 549c9b973beSBarry Smith #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 550614700edSBarry Smith 551df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 552614700edSBarry Smith 553e3ed9ee7SBarry Smith #define PetscLogMemory PETSC_FALSE 554e3ed9ee7SBarry Smith 555b0a32e0cSBarry Smith #define PetscLogFlops(n) 0 556fa2bb9feSLisandro Dalcin #define PetscGetFlops(a) (*(a) = 0.0,0) 557614700edSBarry Smith 558fa2bb9feSLisandro Dalcin #define PetscLogStageRegister(a,b) 0 559fa2bb9feSLisandro Dalcin #define PetscLogStagePush(a) 0 560fa2bb9feSLisandro Dalcin #define PetscLogStagePop() 0 561f5d6ab90SLisandro Dalcin #define PetscLogStageSetActive(a,b) 0 562f5d6ab90SLisandro Dalcin #define PetscLogStageGetActive(a,b) 0 563f5d6ab90SLisandro Dalcin #define PetscLogStageGetVisible(a,b) 0 564f5d6ab90SLisandro Dalcin #define PetscLogStageSetVisible(a,b) 0 565f5d6ab90SLisandro Dalcin #define PetscLogStageGetId(a,b) (*(b)=0,0) 566f5d6ab90SLisandro Dalcin 567fa2bb9feSLisandro Dalcin #define PetscLogEventRegister(a,b,c) 0 568fa2bb9feSLisandro Dalcin #define PetscLogEventSetCollective(a,b) 0 569fa2bb9feSLisandro Dalcin #define PetscLogEventIncludeClass(a) 0 570fa2bb9feSLisandro Dalcin #define PetscLogEventExcludeClass(a) 0 571b0a32e0cSBarry Smith #define PetscLogEventActivate(a) 0 572b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0 573c00cb57fSBarry Smith #define PetscLogEventDeactivatePush(a) 0 574c00cb57fSBarry Smith #define PetscLogEventDeactivatePop(a) 0 575b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a) 0 576b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0 577e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b) 0 57846eb3cd7SSatish Balay #define PetscLogEventGetId(a,b) (*(b)=0,0) 579561b2a67SSatish Balay #define PetscLogEventGetPerfInfo(a,b,c) 0 5809c702cfcSMatthew G. Knepley #define PetscLogEventSetDof(a,b,c) 0 5819c702cfcSMatthew G. Knepley #define PetscLogEventSetError(a,b,c) 0 58277c4ece6SBarry Smith 5838b5db460SBarry Smith #define PetscLogPLB 0 5848b5db460SBarry Smith #define PetscLogPLE 0 5858b5db460SBarry Smith #define PetscLogPHC 0 5868b5db460SBarry Smith #define PetscLogPHD 0 587f5d6ab90SLisandro Dalcin 588efee365bSSatish Balay #define PetscLogObjectParents(p,n,c) 0 58952e6d16bSBarry Smith #define PetscLogObjectCreate(h) 0 59052e6d16bSBarry Smith #define PetscLogObjectDestroy(h) 0 5913ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3); 592fa2bb9feSLisandro Dalcin 593bb1d7374SBarry Smith #define PetscLogDefaultBegin() 0 594b0a32e0cSBarry Smith #define PetscLogAllBegin() 0 595bb1d7374SBarry Smith #define PetscLogNestedBegin() 0 596fa2bb9feSLisandro Dalcin #define PetscLogTraceBegin(file) 0 59773fda44aSBarry Smith #define PetscLogActions(a) 0 598fa2bb9feSLisandro Dalcin #define PetscLogObjects(a) 0 599fa2bb9feSLisandro Dalcin #define PetscLogSetThreshold(a,b) 0 600fa2bb9feSLisandro Dalcin #define PetscLogSet(lb,le) 0 601fa2bb9feSLisandro Dalcin 602fa2bb9feSLisandro Dalcin #define PetscLogView(viewer) 0 603fa2bb9feSLisandro Dalcin #define PetscLogViewFromOptions() 0 604fa2bb9feSLisandro Dalcin #define PetscLogDump(c) 0 605fa2bb9feSLisandro Dalcin 60662872c28SLisandro Dalcin #define PetscLogEventSync(e,comm) 0 607fa2bb9feSLisandro Dalcin #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 608fa2bb9feSLisandro Dalcin #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 609ce6058e1SBarry Smith 610*23c86b1bSSatish Balay /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 611*23c86b1bSSatish Balay #define MPI_Startall_irecv(count,datatype,number,requests) ((number) && MPI_Startall(number,requests)) 612*23c86b1bSSatish Balay #define MPI_Startall_isend(count,datatype,number,requests) ((number) && MPI_Startall(number,requests)) 613*23c86b1bSSatish Balay #define MPI_Start_isend(count,datatype,requests) MPI_Start(requests) 614*23c86b1bSSatish Balay 615*23c86b1bSSatish Balay #endif /* PETSC_USE_LOG */ 616*23c86b1bSSatish Balay 617*23c86b1bSSatish Balay #if defined (PETSC_USE_LOG) && defined(PETSC_HAVE_DEVICE) 618*23c86b1bSSatish Balay 619*23c86b1bSSatish Balay /* Global GPU counters */ 620*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_ctog_ct; 621*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_gtoc_ct; 622*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_ctog_sz; 623*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_gtoc_sz; 624*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_ctog_ct_scalar; 625*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_gtoc_ct_scalar; 626*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_ctog_sz_scalar; 627*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_gtoc_sz_scalar; 628*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_gflops; 629*23c86b1bSSatish Balay PETSC_EXTERN PetscLogDouble petsc_gtime; 630*23c86b1bSSatish Balay #if defined(PETSC_USE_DEBUG) 631*23c86b1bSSatish Balay PETSC_EXTERN PetscBool petsc_gtime_inuse; 632*23c86b1bSSatish Balay #endif 633*23c86b1bSSatish Balay 634*23c86b1bSSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size) 635*23c86b1bSSatish Balay { 636*23c86b1bSSatish Balay PetscFunctionBegin; 637*23c86b1bSSatish Balay petsc_ctog_ct += 1; 638*23c86b1bSSatish Balay petsc_ctog_sz += size; 639*23c86b1bSSatish Balay PetscFunctionReturn(0); 640*23c86b1bSSatish Balay } 641*23c86b1bSSatish Balay 642*23c86b1bSSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size) 643*23c86b1bSSatish Balay { 644*23c86b1bSSatish Balay PetscFunctionBegin; 645*23c86b1bSSatish Balay petsc_gtoc_ct += 1; 646*23c86b1bSSatish Balay petsc_gtoc_sz += size; 647*23c86b1bSSatish Balay PetscFunctionReturn(0); 648*23c86b1bSSatish Balay } 649*23c86b1bSSatish Balay 650*23c86b1bSSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscLogCpuToGpuScalar(PetscLogDouble size) 651*23c86b1bSSatish Balay { 652*23c86b1bSSatish Balay PetscFunctionBegin; 653*23c86b1bSSatish Balay petsc_ctog_ct_scalar += 1; 654*23c86b1bSSatish Balay petsc_ctog_sz_scalar += size; 655*23c86b1bSSatish Balay PetscFunctionReturn(0); 656*23c86b1bSSatish Balay } 657*23c86b1bSSatish Balay 658*23c86b1bSSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuToCpuScalar(PetscLogDouble size) 659*23c86b1bSSatish Balay { 660*23c86b1bSSatish Balay PetscFunctionBegin; 661*23c86b1bSSatish Balay petsc_gtoc_ct_scalar += 1; 662*23c86b1bSSatish Balay petsc_gtoc_sz_scalar += size; 663*23c86b1bSSatish Balay PetscFunctionReturn(0); 664*23c86b1bSSatish Balay } 665*23c86b1bSSatish Balay 666*23c86b1bSSatish Balay /*@C 667*23c86b1bSSatish Balay PetscLogGpuFlops - Log how many flops are performed in a calculation on the device 668*23c86b1bSSatish Balay 669*23c86b1bSSatish Balay Input Parameter: 670*23c86b1bSSatish Balay . flops - the number of flops 671*23c86b1bSSatish Balay 672*23c86b1bSSatish Balay Notes: 673*23c86b1bSSatish Balay To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double, 674*23c86b1bSSatish Balay not an integer. Use PetscLogFlops(4.0*n) not PetscLogFlops(4*n) 675*23c86b1bSSatish Balay 676*23c86b1bSSatish Balay Level: intermediate 677*23c86b1bSSatish Balay 678*23c86b1bSSatish Balay .seealso: PetscLogView(), PetscLogFlops(), PetscLogGpuTimeBegin(), PetscLogGpuTimeEnd() 679*23c86b1bSSatish Balay @*/ 680*23c86b1bSSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuFlops(PetscLogDouble n) 681*23c86b1bSSatish Balay { 682*23c86b1bSSatish Balay PetscFunctionBegin; 683*23c86b1bSSatish Balay #if defined(PETSC_USE_DEBUG) 684*23c86b1bSSatish Balay if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 685*23c86b1bSSatish Balay #endif 686*23c86b1bSSatish Balay petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 687*23c86b1bSSatish Balay petsc_gflops += PETSC_FLOPS_PER_OP*n; 688*23c86b1bSSatish Balay PetscFunctionReturn(0); 689*23c86b1bSSatish Balay } 690*23c86b1bSSatish Balay 691*23c86b1bSSatish Balay PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t) 692*23c86b1bSSatish Balay { 693*23c86b1bSSatish Balay PetscFunctionBegin; 694*23c86b1bSSatish Balay petsc_gtime += t; 695*23c86b1bSSatish Balay PetscFunctionReturn(0); 696*23c86b1bSSatish Balay } 697*23c86b1bSSatish Balay 698*23c86b1bSSatish Balay PETSC_EXTERN PetscErrorCode PetscLogGpuTimeBegin(void); 699*23c86b1bSSatish Balay PETSC_EXTERN PetscErrorCode PetscLogGpuTimeEnd(void); 700*23c86b1bSSatish Balay 701*23c86b1bSSatish Balay #else 702*23c86b1bSSatish Balay 7038157aad8SJunchao Zhang #define PetscLogCpuToGpu(a) 0 7048157aad8SJunchao Zhang #define PetscLogGpuToCpu(a) 0 70545c4b7c1SBarry Smith #define PetscLogCpuToGpuScalar(a) 0 70645c4b7c1SBarry Smith #define PetscLogGpuToCpuScalar(a) 0 7078157aad8SJunchao Zhang #define PetscLogGpuFlops(a) 0 7088157aad8SJunchao Zhang #define PetscLogGpuTimeBegin() 0 7098157aad8SJunchao Zhang #define PetscLogGpuTimeEnd() 0 7108157aad8SJunchao Zhang #define PetscLogGpuTimeAdd(a) 0 7118157aad8SJunchao Zhang 712*23c86b1bSSatish Balay #endif /* PETSC_USE_LOG && PETSC_HAVE_DEVICE */ 7136daaf66cSBarry Smith 714204a6943SJed Brown #define PetscPreLoadBegin(flag,name) \ 715204a6943SJed Brown do {\ 716204a6943SJed Brown PetscBool PetscPreLoading = flag;\ 717204a6943SJed Brown int PetscPreLoadMax,PetscPreLoadIt;\ 718166c7f25SBarry Smith PetscLogStage _stageNum;\ 7198cbcd9ccSBarry Smith PetscErrorCode _3_ierr; \ 720c5929fdfSBarry Smith _3_ierr = PetscOptionsGetBool(NULL,NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr); \ 721204a6943SJed Brown PetscPreLoadMax = (int)(PetscPreLoading);\ 722204a6943SJed Brown PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 723204a6943SJed Brown for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\ 724204a6943SJed Brown PetscPreLoadingOn = PetscPreLoading;\ 7250298fd71SBarry Smith _3_ierr = PetscBarrier(NULL);CHKERRQ(_3_ierr);\ 726204a6943SJed Brown if (PetscPreLoadIt>0) {\ 7278e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 7288e58c17dSMatthew Knepley } else {\ 729a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 7308e58c17dSMatthew Knepley }\ 731204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\ 7328e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 7338e58c17dSMatthew Knepley 734204a6943SJed Brown #define PetscPreLoadEnd() \ 735043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 736204a6943SJed Brown PetscPreLoading = PETSC_FALSE;\ 737043328b6SSatish Balay }\ 738204a6943SJed Brown } while (0) 7398e58c17dSMatthew Knepley 740204a6943SJed Brown #define PetscPreLoadStage(name) do { \ 741043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr); \ 742204a6943SJed Brown if (PetscPreLoadIt>0) { \ 7438e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr); \ 7448e58c17dSMatthew Knepley } else { \ 745a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 7468e58c17dSMatthew Knepley } \ 747204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \ 748204a6943SJed Brown _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); \ 749204a6943SJed Brown } while (0) 750e9fa29b7SSatish Balay 751ad14c47eSJed Brown /* some vars for logging */ 752ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */ 753ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingOn; /* true if we are currently in a preloading calculation */ 754ad14c47eSJed Brown 75597bb86f7SLois Curfman McInnes #endif 756