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 */ 11*fe9b927eSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],PetscObject,const char[],...); 12fa2bb9feSLisandro Dalcin #if defined(PETSC_USE_INFO) 13*fe9b927eSVaclav Hapla #define PetscInfo(A,S) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S) 14*fe9b927eSVaclav Hapla #define PetscInfo1(A,S,a1) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1) 15*fe9b927eSVaclav Hapla #define PetscInfo2(A,S,a1,a2) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2) 16*fe9b927eSVaclav Hapla #define PetscInfo3(A,S,a1,a2,a3) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3) 17*fe9b927eSVaclav Hapla #define PetscInfo4(A,S,a1,a2,a3,a4) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4) 18*fe9b927eSVaclav Hapla #define PetscInfo5(A,S,a1,a2,a3,a4,a5) PetscInfo_Private(PETSC_FUNCTION_NAME,((PetscObject)A),S,a1,a2,a3,a4,a5) 19*fe9b927eSVaclav 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) 20*fe9b927eSVaclav 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) 21fa2bb9feSLisandro Dalcin #else 22fa2bb9feSLisandro Dalcin #define PetscInfo(A,S) 0 23fa2bb9feSLisandro Dalcin #define PetscInfo1(A,S,a1) 0 24fa2bb9feSLisandro Dalcin #define PetscInfo2(A,S,a1,a2) 0 25fa2bb9feSLisandro Dalcin #define PetscInfo3(A,S,a1,a2,a3) 0 26fa2bb9feSLisandro Dalcin #define PetscInfo4(A,S,a1,a2,a3,a4) 0 27fa2bb9feSLisandro Dalcin #define PetscInfo5(A,S,a1,a2,a3,a4,a5) 0 28fa2bb9feSLisandro Dalcin #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) 0 29fa2bb9feSLisandro Dalcin #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0 30fa2bb9feSLisandro Dalcin #endif 31e94e781bSJacob Faibussowitsch 32e94e781bSJacob Faibussowitsch /*E 33e94e781bSJacob Faibussowitsch PetscInfoCommFlag - Describes the method by which to filter PetscInfo() by communicator size 34e94e781bSJacob Faibussowitsch 35e94e781bSJacob Faibussowitsch Used as an input for PetscInfoSetFilterCommSelf() 36e94e781bSJacob Faibussowitsch 37e94e781bSJacob Faibussowitsch $ PETSC_INFO_COMM_ALL - Default uninitialized value. PetscInfo() will not filter based on communicator size (i.e. will 38e94e781bSJacob Faibussowitsch print for all communicators) 39e94e781bSJacob Faibussowitsch $ PETSC_INFO_COMM_NO_SELF - PetscInfo() will NOT print for communicators with size = 1 (i.e. *_COMM_SELF) 40e94e781bSJacob Faibussowitsch $ PETSC_INFO_COMM_ONLY_SELF - PetscInfo will ONLY print for communicators with size = 1 41e94e781bSJacob Faibussowitsch 42e94e781bSJacob Faibussowitsch Level: intermediate 43e94e781bSJacob Faibussowitsch 44e94e781bSJacob Faibussowitsch .seealso: PetscInfo(), PetscInfoSetFromOptions(), PetscInfoSetFilterCommSelf() 45e94e781bSJacob Faibussowitsch E*/ 46e94e781bSJacob Faibussowitsch typedef enum { 47e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_ALL = -1, 48e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_NO_SELF = 0, 49e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_ONLY_SELF = 1 50e94e781bSJacob Faibussowitsch } PetscInfoCommFlag; 51e94e781bSJacob Faibussowitsch 52e94e781bSJacob Faibussowitsch PETSC_EXTERN const char * const PetscInfoCommFlags[]; 53fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId); 54fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId); 55e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoEnabled(PetscClassId, PetscBool *); 56e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoAllow(PetscBool); 57e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFile(const char[],const char[]); 58e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetFile(char **,FILE **); 59e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetClasses(PetscBool,PetscInt,const char *const *); 60e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetClass(const char *, PetscBool *); 61e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetInfo(PetscBool *,PetscBool *,PetscBool *,PetscBool *,PetscInfoCommFlag *); 62e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoProcessClass(const char[],PetscInt,PetscClassId[]); 63e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag); 64e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFromOptions(PetscOptions); 65e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoDestroy(void); 66fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */ 67fa2bb9feSLisandro Dalcin 68b859824cSBarry Smith /*MC 69b859824cSBarry Smith PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable) 70b859824cSBarry Smith code. 71b859824cSBarry Smith 72b859824cSBarry Smith Level: intermediate 73b859824cSBarry Smith 74b859824cSBarry Smith .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage 75b859824cSBarry Smith M*/ 76b859824cSBarry Smith typedef int PetscLogEvent; 77b859824cSBarry Smith 78b859824cSBarry Smith /*MC 79b859824cSBarry Smith PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging 80b859824cSBarry Smith 81b859824cSBarry Smith Level: intermediate 82b859824cSBarry Smith 83522ce795SJed Brown .seealso: PetscLogStageRegister(), PetscLogStagePush(), PetscLogStagePop(), PetscLogEvent 84b859824cSBarry Smith M*/ 85b859824cSBarry Smith typedef int PetscLogStage; 86b859824cSBarry Smith 878ba1e511SMatthew Knepley #define PETSC_EVENT 1311311 88014dd563SJed Brown PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT; 8997bb86f7SLois Curfman McInnes 9019b02663SBarry Smith /* Global flop counter */ 91014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_TotalFlops; 92014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_tmp_flops; 9319b02663SBarry Smith 94bec0b493Shannah_mairs /* Global GPU counters */ 95bec0b493Shannah_mairs #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) 96bec0b493Shannah_mairs PETSC_EXTERN PetscLogDouble petsc_ctog_ct; 97bec0b493Shannah_mairs PETSC_EXTERN PetscLogDouble petsc_gtoc_ct; 98bec0b493Shannah_mairs PETSC_EXTERN PetscLogDouble petsc_ctog_sz; 99bec0b493Shannah_mairs PETSC_EXTERN PetscLogDouble petsc_gtoc_sz; 100958c4211Shannah_mairs PETSC_EXTERN PetscLogDouble petsc_gflops; 101958c4211Shannah_mairs PETSC_EXTERN PetscLogDouble petsc_gtime; 102bec0b493Shannah_mairs #endif 103bec0b493Shannah_mairs 10431d06abdSBarry Smith /* We must make the following structures available to access the event 10531d06abdSBarry Smith activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public 10631d06abdSBarry Smith API and are not intended to be used by other parts of PETSc or by users. 107d49d4b11SBarry Smith 108fa2bb9feSLisandro Dalcin The code that manipulates these structures is in src/sys/logging/utils. 10931d06abdSBarry Smith */ 110aa213bdcSJed Brown typedef struct _n_PetscIntStack *PetscIntStack; 1116a6a9b46SSatish Balay 112217044c2SLisandro Dalcin /* -----------------------------------------------------------------------------------------------------*/ 113c60ec953SBarry Smith /* 114aa213bdcSJed Brown PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has 115c60ec953SBarry Smith static information about it, the second collects statistics on how many objects of the class are created, 116c60ec953SBarry Smith how much memory they use, etc. 117c60ec953SBarry Smith 118aa213bdcSJed Brown PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes. 119c60ec953SBarry Smith */ 1206a6a9b46SSatish Balay typedef struct { 121c60ec953SBarry Smith char *name; /* The class name */ 122c60ec953SBarry Smith PetscClassId classid; /* The integer identifying this class */ 123aa213bdcSJed Brown } PetscClassRegInfo; 1246a6a9b46SSatish Balay 1256a6a9b46SSatish Balay typedef struct { 1260700a824SBarry Smith PetscClassId id; /* The integer identifying this class */ 1276a6a9b46SSatish Balay int creations; /* The number of objects of this class created */ 1286a6a9b46SSatish Balay int destructions; /* The number of objects of this class destroyed */ 1296a6a9b46SSatish Balay PetscLogDouble mem; /* The total memory allocated by objects of this class */ 1306a6a9b46SSatish Balay PetscLogDouble descMem; /* The total memory allocated by descendents of these objects */ 131aa213bdcSJed Brown } PetscClassPerfInfo; 1326a6a9b46SSatish Balay 133aa213bdcSJed Brown typedef struct _n_PetscClassRegLog *PetscClassRegLog; 134aa213bdcSJed Brown struct _n_PetscClassRegLog { 135c60ec953SBarry Smith int numClasses; /* The number of classes registered */ 136c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 137aa213bdcSJed Brown PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 138c60ec953SBarry Smith }; 1396a6a9b46SSatish Balay 140aa213bdcSJed Brown typedef struct _n_PetscClassPerfLog *PetscClassPerfLog; 141aa213bdcSJed Brown struct _n_PetscClassPerfLog { 142c60ec953SBarry Smith int numClasses; /* The number of logging classes */ 143c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 144aa213bdcSJed Brown PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 145c60ec953SBarry Smith }; 146c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/ 147c60ec953SBarry Smith /* 148aa213bdcSJed Brown PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has 149c60ec953SBarry Smith static information about it, the second collects statistics on how many times the event is used, how 150c60ec953SBarry Smith much time it takes, etc. 151c60ec953SBarry Smith 152aa213bdcSJed Brown PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one 153c60ec953SBarry Smith of these for each stage. 154c60ec953SBarry Smith 155c60ec953SBarry Smith */ 1566a6a9b46SSatish Balay typedef struct { 1576a6a9b46SSatish Balay char *name; /* The name of this event */ 158c60ec953SBarry Smith PetscClassId classid; /* The class the event is associated with */ 159217044c2SLisandro Dalcin PetscBool collective; /* Flag this event as collective */ 1606a6a9b46SSatish Balay #if defined (PETSC_HAVE_MPE) 1616a6a9b46SSatish Balay int mpe_id_begin; /* MPE IDs that define the event */ 1626a6a9b46SSatish Balay int mpe_id_end; 1636a6a9b46SSatish Balay #endif 164aa213bdcSJed Brown } PetscEventRegInfo; 1656a6a9b46SSatish Balay 166c60ec953SBarry Smith typedef struct { 167c60ec953SBarry Smith int id; /* The integer identifying this event */ 168ace3abfcSBarry Smith PetscBool active; /* The flag to activate logging */ 169ace3abfcSBarry Smith PetscBool visible; /* The flag to print info in summary */ 170c60ec953SBarry Smith int depth; /* The nesting depth of the event call */ 171c60ec953SBarry Smith int count; /* The number of times this event was executed */ 172a42e5b54SMatthew G Knepley PetscLogDouble flops, flops2, flopsTmp; /* The flops and flops^2 used in this event */ 173a42e5b54SMatthew G Knepley PetscLogDouble time, time2, timeTmp; /* The time and time^2 taken for this event */ 174217044c2SLisandro Dalcin PetscLogDouble syncTime; /* The synchronization barrier time */ 175891e75beSMatthew G. Knepley PetscLogDouble dof[8]; /* The number of degrees of freedom associated with this event */ 1765d68e14cSMatthew G. Knepley PetscLogDouble errors[8]; /* The errors (user-defined) associated with this event */ 177c60ec953SBarry Smith PetscLogDouble numMessages; /* The number of messages in this event */ 178c60ec953SBarry Smith PetscLogDouble messageLength; /* The total message lengths in this event */ 179c60ec953SBarry Smith PetscLogDouble numReductions; /* The number of reductions in this event */ 180e3ed9ee7SBarry Smith PetscLogDouble memIncrease; /* How much the resident memory has increased in this event */ 181e3ed9ee7SBarry Smith PetscLogDouble mallocIncrease;/* How much the maximum malloced space has increased in this event */ 182e3ed9ee7SBarry Smith PetscLogDouble mallocSpace; /* How much the space was malloced and kept during this event */ 183e3ed9ee7SBarry Smith PetscLogDouble mallocIncreaseEvent; /* Maximum of the high water mark with in event minus memory available at the end of the event */ 184bec0b493Shannah_mairs #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) 185bec0b493Shannah_mairs PetscLogDouble CpuToGpuCount; /* The total number of CPU to GPU copies */ 186bec0b493Shannah_mairs PetscLogDouble GpuToCpuCount; /* The total number of GPU to CPU copies */ 187bec0b493Shannah_mairs PetscLogDouble CpuToGpuSize; /* The total size of CPU to GPU copies */ 188bec0b493Shannah_mairs PetscLogDouble GpuToCpuSize; /* The total size of GPU to CPU copies */ 189958c4211Shannah_mairs PetscLogDouble GpuFlops; /* The flops done on a GPU in this event */ 190958c4211Shannah_mairs PetscLogDouble GpuTime; /* The time spent on a GPU in this event */ 191bec0b493Shannah_mairs #endif 192aa213bdcSJed Brown } PetscEventPerfInfo; 193c60ec953SBarry Smith 194aa213bdcSJed Brown typedef struct _n_PetscEventRegLog *PetscEventRegLog; 195aa213bdcSJed Brown struct _n_PetscEventRegLog { 1966a6a9b46SSatish Balay int numEvents; /* The number of registered events */ 1976a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 198aa213bdcSJed Brown PetscEventRegInfo *eventInfo; /* The registration information for each event */ 1996a6a9b46SSatish Balay }; 2006a6a9b46SSatish Balay 201aa213bdcSJed Brown typedef struct _n_PetscEventPerfLog *PetscEventPerfLog; 202aa213bdcSJed Brown struct _n_PetscEventPerfLog { 2036a6a9b46SSatish Balay int numEvents; /* The number of logging events */ 2046a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 205aa213bdcSJed Brown PetscEventPerfInfo *eventInfo; /* The performance information for each event */ 2066a6a9b46SSatish Balay }; 207c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/ 208c60ec953SBarry Smith /* 209aa213bdcSJed Brown PetscStageInfo - Contains all the information about a particular stage. 2106a6a9b46SSatish Balay 211aa213bdcSJed Brown PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code. 212c60ec953SBarry Smith */ 213aa213bdcSJed Brown typedef struct _PetscStageInfo { 2146a6a9b46SSatish Balay char *name; /* The stage name */ 215ace3abfcSBarry Smith PetscBool used; /* The stage was pushed on this processor */ 216aa213bdcSJed Brown PetscEventPerfInfo perfInfo; /* The stage performance information */ 217aa213bdcSJed Brown PetscEventPerfLog eventLog; /* The event information for this stage */ 218aa213bdcSJed Brown PetscClassPerfLog classLog; /* The class information for this stage */ 219aa213bdcSJed Brown } PetscStageInfo; 2206a6a9b46SSatish Balay 221aa213bdcSJed Brown typedef struct _n_PetscStageLog *PetscStageLog; 222aa213bdcSJed Brown struct _n_PetscStageLog { 2236a6a9b46SSatish Balay int numStages; /* The number of registered stages */ 2246a6a9b46SSatish Balay int maxStages; /* The maximum number of stages */ 225aa213bdcSJed Brown PetscIntStack stack; /* The stack for active stages */ 226aa213bdcSJed Brown int curStage; /* The current stage (only used in macros so we don't call PetscIntStackTop) */ 227aa213bdcSJed Brown PetscStageInfo *stageInfo; /* The information for each stage */ 228aa213bdcSJed Brown PetscEventRegLog eventLog; /* The registered events */ 229aa213bdcSJed Brown PetscClassRegLog classLog; /* The registered classes */ 2306a6a9b46SSatish Balay }; 231217044c2SLisandro Dalcin /* -----------------------------------------------------------------------------------------------------*/ 232fee518ebSJed Brown 2333bb1ff40SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogObjectParent(PetscObject,PetscObject); 2343bb1ff40SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogObjectMemory(PetscObject,PetscLogDouble); 2353bb1ff40SBarry Smith 236aa482453SBarry Smith #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 237aeeda9f6SJohn Fettig PETSC_EXTERN PetscStageLog petsc_stageLog; 238f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog*); 239f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog,int*); 240f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog,int,PetscEventPerfLog*); 241614700edSBarry Smith 242da63de55SLois Curfman McInnes /* 243da63de55SLois Curfman McInnes Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 244da63de55SLois Curfman McInnes 245da63de55SLois Curfman McInnes For the complex numbers version, note that 246da63de55SLois Curfman McInnes 1 complex addition = 2 flops 247da63de55SLois Curfman McInnes 1 complex multiplication = 6 flops, 248da63de55SLois Curfman McInnes where we define 1 flop as that for a double precision scalar. We roughly approximate 249da63de55SLois Curfman McInnes flop counting for complex numbers by multiplying the total flops by 4; this corresponds 250da63de55SLois Curfman McInnes to the assumption that we're counting mostly additions and multiplications -- and 251da63de55SLois Curfman McInnes roughly the same number of each. More accurate counting could be done by distinguishing 252da63de55SLois Curfman McInnes among the various arithmetic operations. 253da63de55SLois Curfman McInnes */ 254da63de55SLois Curfman McInnes 255aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 256542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0 257da63de55SLois Curfman McInnes #else 258542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0 259bf3909cdSBarry Smith #endif 260bf3909cdSBarry Smith 261dd19b90bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n) 262dd19b90bSBarry Smith { 263dd19b90bSBarry Smith PetscFunctionBegin; 264bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG) 265dd19b90bSBarry Smith if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 266da63de55SLois Curfman McInnes #endif 267dd19b90bSBarry Smith petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 268dd19b90bSBarry Smith PetscFunctionReturn(0); 269dd19b90bSBarry Smith } 270fa2bb9feSLisandro Dalcin 271bec0b493Shannah_mairs #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) 2724db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size) 2734db21f4bSStefano Zampini { 274958c4211Shannah_mairs PetscFunctionBegin; 275bec0b493Shannah_mairs petsc_ctog_ct += 1; 276bec0b493Shannah_mairs petsc_ctog_sz += size; 277bec0b493Shannah_mairs PetscFunctionReturn(0); 278bec0b493Shannah_mairs } 2794db21f4bSStefano Zampini 2804db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size) 2814db21f4bSStefano Zampini { 282958c4211Shannah_mairs PetscFunctionBegin; 283bec0b493Shannah_mairs petsc_gtoc_ct += 1; 284bec0b493Shannah_mairs petsc_gtoc_sz += size; 285bec0b493Shannah_mairs PetscFunctionReturn(0); 286bec0b493Shannah_mairs } 2874db21f4bSStefano Zampini 2884db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuFlops(PetscLogDouble n) 2894db21f4bSStefano Zampini { 290958c4211Shannah_mairs PetscFunctionBegin; 291958c4211Shannah_mairs #if defined(PETSC_USE_DEBUG) 292958c4211Shannah_mairs if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 293958c4211Shannah_mairs #endif 294958c4211Shannah_mairs petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 295958c4211Shannah_mairs petsc_gflops += PETSC_FLOPS_PER_OP*n; 296958c4211Shannah_mairs PetscFunctionReturn(0); 297958c4211Shannah_mairs } 2984db21f4bSStefano Zampini 2994db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeBegin() 3004db21f4bSStefano Zampini { 301958c4211Shannah_mairs PetscErrorCode ierr; 302958c4211Shannah_mairs PetscFunctionBegin; 303958c4211Shannah_mairs ierr = PetscTimeSubtract(&petsc_gtime);CHKERRQ(ierr); 304958c4211Shannah_mairs PetscFunctionReturn(0); 305958c4211Shannah_mairs } 3064db21f4bSStefano Zampini 3074db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeEnd() 3084db21f4bSStefano Zampini { 309958c4211Shannah_mairs PetscErrorCode ierr; 310958c4211Shannah_mairs PetscFunctionBegin; 311958c4211Shannah_mairs ierr = PetscTimeAdd(&petsc_gtime);CHKERRQ(ierr); 312958c4211Shannah_mairs PetscFunctionReturn(0); 313958c4211Shannah_mairs } 3144db21f4bSStefano Zampini 3154db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t) 3164db21f4bSStefano Zampini { 3174db21f4bSStefano Zampini PetscFunctionBegin; 3184db21f4bSStefano Zampini petsc_gtime += t; 3194db21f4bSStefano Zampini PetscFunctionReturn(0); 3204db21f4bSStefano Zampini } 321bec0b493Shannah_mairs #endif 322bec0b493Shannah_mairs 323fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 32477c4ece6SBarry Smith 325aa482453SBarry Smith #if defined (PETSC_HAVE_MPE) 326014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 327014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 32877c4ece6SBarry Smith #endif 32977c4ece6SBarry Smith 330014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 331014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 332014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 333014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 33477c4ece6SBarry Smith 335e83a5d19SLisandro 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) 336fa2bb9feSLisandro Dalcin #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : 0) 337fa2bb9feSLisandro Dalcin #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : 0) 338fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...); 339fa2bb9feSLisandro Dalcin 3408ba1e511SMatthew Knepley /* Initialization functions */ 341bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void); 342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 343bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void); 344014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 345014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 346014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 347fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble,PetscLogDouble*); 348014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 3496849ba73SBarry Smith PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 350fa2bb9feSLisandro Dalcin 3518ba1e511SMatthew Knepley /* Output functions */ 352014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 353f14045dbSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void); 354014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 35531d06abdSBarry Smith 356fa2bb9feSLisandro Dalcin /* Stage functions */ 357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*); 358014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 360014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage,PetscBool); 361014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage,PetscBool*); 362014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage,PetscBool); 363014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage,PetscBool*); 364014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[],PetscLogStage*); 365f5d6ab90SLisandro Dalcin 3668ba1e511SMatthew Knepley /* Event functions */ 367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[],PetscClassId,PetscLogEvent*); 368217044c2SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent,PetscBool); 369fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId); 370fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId); 371014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent,PetscBool); 374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 375014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 3768c49a8d9SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[],PetscLogEvent*); 37713230571SMichael Lange PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int,PetscLogEvent,PetscEventPerfInfo*); 378891e75beSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble); 3795d68e14cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble); 3808ba1e511SMatthew Knepley 3818ba1e511SMatthew Knepley /* Global counters */ 382014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 383014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_ct; 384014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_ct; 385014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_ct; 386014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_len; 387014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_len; 388014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_len; 389014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_len; 390014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 391014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_gather_ct; 392014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 393014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_ct; 394014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 395014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 396014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 3978ba1e511SMatthew Knepley 398e3ed9ee7SBarry Smith PETSC_EXTERN PetscBool PetscLogMemory; 399e3ed9ee7SBarry Smith 400fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */ 40162872c28SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm); 40262872c28SLisandro Dalcin 40362872c28SLisandro Dalcin #define PetscLogEventSync(e,comm) \ 40462872c28SLisandro Dalcin (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 40562872c28SLisandro Dalcin PetscLogEventSynchronize((e),(comm)) : 0 )) 40677c4ece6SBarry Smith 40752e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 4088b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 409495fc317SBarry Smith (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 )) 410043328b6SSatish Balay 41152e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 4128b5db460SBarry Smith (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 413495fc317SBarry Smith (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 )) 41477c4ece6SBarry Smith 415014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent,PetscLogDouble*); 416014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 417003131ecSBarry Smith 418ce85283eSBarry Smith /* 419f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 420f621e05eSBarry Smith their sizes. 421f621e05eSBarry Smith 422af0996ceSBarry Smith This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file 423ce85283eSBarry Smith uses macros to defined the MPI operations. 42415308354SBarry Smith 42515308354SBarry Smith It does not work correctly from HP-UX because it processes the 426bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 427b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 4287c1e34a4SSatish Balay 429f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 430ce85283eSBarry Smith */ 431c9b973beSBarry Smith #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 43277a39924SBarry Smith /* 43377a39924SBarry Smith Logging of MPI activities 43477a39924SBarry Smith */ 435b23bfdefSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscInt count,MPI_Datatype type,PetscLogDouble *length) 436f95db71bSBarry Smith { 437f12d10ccSJunchao Zhang PetscMPIInt typesize; 438f12d10ccSJunchao Zhang PetscErrorCode ierr; 4397d30fa4aSBarry Smith if (type == MPI_DATATYPE_NULL) return 0; 440f12d10ccSJunchao Zhang ierr = MPI_Type_size(type,&typesize);CHKERRQ(ierr); 441f12d10ccSJunchao Zhang *length += (PetscLogDouble) (count*typesize); 4429c72ff1eSSatish Balay return 0; 443f95db71bSBarry Smith } 44477a39924SBarry Smith 445f12d10ccSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length) 4463b9284c0SMatthew G Knepley { 447f12d10ccSJunchao Zhang PetscMPIInt typesize,size,p; 448f12d10ccSJunchao Zhang PetscErrorCode ierr; 4493b9284c0SMatthew G Knepley 4507d30fa4aSBarry Smith if (type == MPI_DATATYPE_NULL) return 0; 451f12d10ccSJunchao Zhang ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 452f12d10ccSJunchao Zhang ierr = MPI_Type_size(type,&typesize);CHKERRQ(ierr); 453f12d10ccSJunchao Zhang for (p=0; p<size; ++p) { 454f12d10ccSJunchao Zhang *length += (PetscLogDouble) (counts[p]*typesize); 455f12d10ccSJunchao Zhang } 456f12d10ccSJunchao Zhang return 0; 457f12d10ccSJunchao Zhang } 458f12d10ccSJunchao Zhang 459f12d10ccSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeCount(PetscInt n,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length) 460f12d10ccSJunchao Zhang { 461f12d10ccSJunchao Zhang PetscMPIInt typesize,p; 462f12d10ccSJunchao Zhang PetscErrorCode ierr; 463f12d10ccSJunchao Zhang 464f12d10ccSJunchao Zhang if (type == MPI_DATATYPE_NULL) return 0; 465f12d10ccSJunchao Zhang ierr = MPI_Type_size(type,&typesize);CHKERRQ(ierr); 466f12d10ccSJunchao Zhang for (p=0; p<n; ++p) { 467f12d10ccSJunchao Zhang *length += (PetscLogDouble) (counts[p]*typesize); 4683b9284c0SMatthew G Knepley } 4693b9284c0SMatthew G Knepley return 0; 4703b9284c0SMatthew G Knepley } 4713b9284c0SMatthew G Knepley 47272b11a25SBarry Smith /* 47372b11a25SBarry Smith Returns 1 if the communicator is parallel else zero 47472b11a25SBarry Smith */ 47572b11a25SBarry Smith PETSC_STATIC_INLINE int PetscMPIParallelComm(MPI_Comm comm) 47672b11a25SBarry Smith { 47772b11a25SBarry Smith PetscMPIInt size; MPI_Comm_size(comm,&size); return size > 1; 47872b11a25SBarry Smith } 47972b11a25SBarry Smith 48077a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 481f12d10ccSJunchao Zhang ((petsc_irecv_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || MPI_Irecv((buf),(count),(datatype),(source),(tag),(comm),(request))) 48215308354SBarry Smith 48377a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 484f12d10ccSJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || MPI_Isend((buf),(count),(datatype),(dest),(tag),(comm),(request))) 48515308354SBarry Smith 486457b14b1SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) \ 487f12d10ccSJunchao Zhang ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || ((number) && MPI_Startall((number),(requests)))) 4880d4b0b6cSBarry Smith 489457b14b1SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) \ 490f12d10ccSJunchao Zhang ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || ((number) && MPI_Startall((number),(requests)))) 4910d4b0b6cSBarry Smith 492457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) \ 493f12d10ccSJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_isend_len)) || MPI_Start((requests))) 4940d4b0b6cSBarry Smith 495ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 496f12d10ccSJunchao Zhang ((petsc_recv_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_recv_len)) || MPI_Recv((buf),(count),(datatype),(source),(tag),(comm),(status))) 49715308354SBarry Smith 49877a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 499f12d10ccSJunchao Zhang ((petsc_send_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_send_len)) || MPI_Send((buf),(count),(datatype),(dest),(tag),(comm))) 50077a39924SBarry Smith 50177a39924SBarry Smith #define MPI_Wait(request,status) \ 5025fa69175SJed Brown ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait((request),(status))) 50377a39924SBarry Smith 50477a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \ 5055fa69175SJed Brown ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany((a),(b),(c),(d))) 50677a39924SBarry Smith 50777a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 5085fa69175SJed Brown ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall((count),(array_of_requests),(array_of_statuses))) 50977a39924SBarry Smith 51077a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 5115fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Allreduce((sendbuf),(recvbuf),(count),(datatype),(op),(comm))) 5123914022bSBarry Smith 51354fe5c21SBarry Smith #define MPI_Bcast(buffer,count,datatype,root,comm) \ 5145fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Bcast((buffer),(count),(datatype),(root),(comm))) 51554fe5c21SBarry Smith 516d6e4c47cSJed Brown #define MPI_Reduce_scatter_block(sendbuf,recvbuf,recvcount,datatype,op,comm) \ 5175fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Reduce_scatter_block((sendbuf),(recvbuf),(recvcount),(datatype),(op),(comm))) 518d6e4c47cSJed Brown 5193b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 520f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Alltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm))) 5213b9284c0SMatthew G Knepley 5223b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 523f12d10ccSJunchao 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))) 5243b9284c0SMatthew G Knepley 52501faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 5265fa69175SJed Brown ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm))) 52701faf4e4SMatthew Knepley 52801faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 5295fa69175SJed Brown ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm))) 53001faf4e4SMatthew Knepley 53101faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 532f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 53301faf4e4SMatthew Knepley 53401faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 535f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm))) 53601faf4e4SMatthew Knepley 53701faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 538f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 53901faf4e4SMatthew Knepley 54001faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 541f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 542f12d10ccSJunchao Zhang 543f12d10ccSJunchao Zhang #define MPI_Ialltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \ 544f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Ialltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request))) 545f12d10ccSJunchao Zhang 546f12d10ccSJunchao Zhang #define MPI_Ialltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 547f12d10ccSJunchao 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))) 548f12d10ccSJunchao Zhang 549f12d10ccSJunchao Zhang #define MPI_Iallgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \ 550f12d10ccSJunchao Zhang ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request))) 551f12d10ccSJunchao Zhang 552f12d10ccSJunchao Zhang #define MPI_Iallgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm,request) \ 553f12d10ccSJunchao Zhang ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm),(request))) 554f12d10ccSJunchao Zhang 555f12d10ccSJunchao Zhang #define MPI_Igather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 556f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 557f12d10ccSJunchao Zhang 558f12d10ccSJunchao Zhang #define MPI_Igatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm,request) \ 559f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm),(request))) 560f12d10ccSJunchao Zhang 561f12d10ccSJunchao Zhang #define MPI_Iscatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 562f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 563f12d10ccSJunchao Zhang 564f12d10ccSJunchao Zhang #define MPI_Iscatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 565f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 566f12d10ccSJunchao Zhang 567f12d10ccSJunchao Zhang /* We treat MPI_Ineighbor_alltoallv as a set of isend/irecv instead of a traditional MPI collective. 568f12d10ccSJunchao Zhang OpenMPI-3.0 ran into error with outdegree = indegree = 0, so we use ((outdegree) || (indegree)) as a workaround. 569f12d10ccSJunchao Zhang */ 570f12d10ccSJunchao Zhang #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 571f12d10ccSJunchao Zhang ((petsc_isend_ct += (PetscLogDouble)(outdegree),0) || (petsc_irecv_ct += (PetscLogDouble)(indegree),0) || PetscMPITypeSizeCount((outdegree),(sendcnts),(sendtype),(&petsc_isend_len)) || PetscMPITypeSizeCount((indegree),(recvcnts),(recvtype),(&petsc_irecv_len)) || (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request)))) 572f12d10ccSJunchao Zhang 573f12d10ccSJunchao Zhang #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 574f12d10ccSJunchao Zhang ((petsc_isend_ct += (PetscLogDouble)(outdegree),0) || (petsc_irecv_ct += (PetscLogDouble)(indegree),0) || PetscMPITypeSizeCount((outdegree),(sendcnts),(sendtype),(&petsc_isend_len)) || PetscMPITypeSizeCount((indegree),(recvcnts),(recvtype),(&petsc_irecv_len)) || (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm)))) 57501faf4e4SMatthew Knepley 5760d4b0b6cSBarry Smith #else 5770d4b0b6cSBarry Smith 578457b14b1SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) \ 579ea1c87f7SJunchao Zhang ((number) && MPI_Startall((number),(requests))) 5800d4b0b6cSBarry Smith 581457b14b1SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) \ 582ea1c87f7SJunchao Zhang ((number) && MPI_Startall((number),(requests))) 5830d4b0b6cSBarry Smith 584457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) \ 5855fa69175SJed Brown (MPI_Start((requests))) 5860d4b0b6cSBarry Smith 587f12d10ccSJunchao Zhang #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 588f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request))) 589f12d10ccSJunchao Zhang 590f12d10ccSJunchao Zhang #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 591f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm))) 592c9b973beSBarry Smith #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 593614700edSBarry Smith 594df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 595614700edSBarry Smith 596e3ed9ee7SBarry Smith #define PetscLogMemory PETSC_FALSE 597e3ed9ee7SBarry Smith 598b0a32e0cSBarry Smith #define PetscLogFlops(n) 0 599fa2bb9feSLisandro Dalcin #define PetscGetFlops(a) (*(a) = 0.0,0) 600614700edSBarry Smith 601fa2bb9feSLisandro Dalcin #define PetscLogStageRegister(a,b) 0 602fa2bb9feSLisandro Dalcin #define PetscLogStagePush(a) 0 603fa2bb9feSLisandro Dalcin #define PetscLogStagePop() 0 604f5d6ab90SLisandro Dalcin #define PetscLogStageSetActive(a,b) 0 605f5d6ab90SLisandro Dalcin #define PetscLogStageGetActive(a,b) 0 606f5d6ab90SLisandro Dalcin #define PetscLogStageGetVisible(a,b) 0 607f5d6ab90SLisandro Dalcin #define PetscLogStageSetVisible(a,b) 0 608f5d6ab90SLisandro Dalcin #define PetscLogStageGetId(a,b) (*(b)=0,0) 609f5d6ab90SLisandro Dalcin 610fa2bb9feSLisandro Dalcin #define PetscLogEventRegister(a,b,c) 0 611fa2bb9feSLisandro Dalcin #define PetscLogEventSetCollective(a,b) 0 612fa2bb9feSLisandro Dalcin #define PetscLogEventIncludeClass(a) 0 613fa2bb9feSLisandro Dalcin #define PetscLogEventExcludeClass(a) 0 614b0a32e0cSBarry Smith #define PetscLogEventActivate(a) 0 615b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0 616b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a) 0 617b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0 618e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b) 0 61946eb3cd7SSatish Balay #define PetscLogEventGetId(a,b) (*(b)=0,0) 620561b2a67SSatish Balay #define PetscLogEventGetPerfInfo(a,b,c) 0 6219c702cfcSMatthew G. Knepley #define PetscLogEventSetDof(a,b,c) 0 6229c702cfcSMatthew G. Knepley #define PetscLogEventSetError(a,b,c) 0 62377c4ece6SBarry Smith 6248b5db460SBarry Smith #define PetscLogPLB 0 6258b5db460SBarry Smith #define PetscLogPLE 0 6268b5db460SBarry Smith #define PetscLogPHC 0 6278b5db460SBarry Smith #define PetscLogPHD 0 628f5d6ab90SLisandro Dalcin 629efee365bSSatish Balay #define PetscLogObjectParents(p,n,c) 0 63052e6d16bSBarry Smith #define PetscLogObjectCreate(h) 0 63152e6d16bSBarry Smith #define PetscLogObjectDestroy(h) 0 632fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...); 633fa2bb9feSLisandro Dalcin 634bb1d7374SBarry Smith #define PetscLogDefaultBegin() 0 635b0a32e0cSBarry Smith #define PetscLogAllBegin() 0 636bb1d7374SBarry Smith #define PetscLogNestedBegin() 0 637fa2bb9feSLisandro Dalcin #define PetscLogTraceBegin(file) 0 63873fda44aSBarry Smith #define PetscLogActions(a) 0 639fa2bb9feSLisandro Dalcin #define PetscLogObjects(a) 0 640fa2bb9feSLisandro Dalcin #define PetscLogSetThreshold(a,b) 0 641fa2bb9feSLisandro Dalcin #define PetscLogSet(lb,le) 0 642fa2bb9feSLisandro Dalcin 643fa2bb9feSLisandro Dalcin #define PetscLogView(viewer) 0 644fa2bb9feSLisandro Dalcin #define PetscLogViewFromOptions() 0 645fa2bb9feSLisandro Dalcin #define PetscLogDump(c) 0 646fa2bb9feSLisandro Dalcin 64762872c28SLisandro Dalcin #define PetscLogEventSync(e,comm) 0 648fa2bb9feSLisandro Dalcin #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 649fa2bb9feSLisandro Dalcin #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 650ce6058e1SBarry Smith 651aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 652ea1c87f7SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) ((number) && MPI_Startall(number,requests)) 653ea1c87f7SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) ((number) && MPI_Startall(number,requests)) 654457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) MPI_Start(requests) 655f12d10ccSJunchao Zhang #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 656f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request))) 657f12d10ccSJunchao Zhang #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 658f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm))) 659f141ce34SMatthew Knepley 660aa482453SBarry Smith #endif /* PETSC_USE_LOG */ 6616daaf66cSBarry Smith 662204a6943SJed Brown #define PetscPreLoadBegin(flag,name) \ 663204a6943SJed Brown do {\ 664204a6943SJed Brown PetscBool PetscPreLoading = flag;\ 665204a6943SJed Brown int PetscPreLoadMax,PetscPreLoadIt;\ 666166c7f25SBarry Smith PetscLogStage _stageNum;\ 6678cbcd9ccSBarry Smith PetscErrorCode _3_ierr; \ 668c5929fdfSBarry Smith _3_ierr = PetscOptionsGetBool(NULL,NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr); \ 669204a6943SJed Brown PetscPreLoadMax = (int)(PetscPreLoading);\ 670204a6943SJed Brown PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 671204a6943SJed Brown for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\ 672204a6943SJed Brown PetscPreLoadingOn = PetscPreLoading;\ 6730298fd71SBarry Smith _3_ierr = PetscBarrier(NULL);CHKERRQ(_3_ierr);\ 674204a6943SJed Brown if (PetscPreLoadIt>0) {\ 6758e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 6768e58c17dSMatthew Knepley } else {\ 677a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 6788e58c17dSMatthew Knepley }\ 679204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\ 6808e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 6818e58c17dSMatthew Knepley 682204a6943SJed Brown #define PetscPreLoadEnd() \ 683043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 684204a6943SJed Brown PetscPreLoading = PETSC_FALSE;\ 685043328b6SSatish Balay }\ 686204a6943SJed Brown } while (0) 6878e58c17dSMatthew Knepley 688204a6943SJed Brown #define PetscPreLoadStage(name) do { \ 689043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr); \ 690204a6943SJed Brown if (PetscPreLoadIt>0) { \ 6918e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr); \ 6928e58c17dSMatthew Knepley } else { \ 693a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 6948e58c17dSMatthew Knepley } \ 695204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \ 696204a6943SJed Brown _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); \ 697204a6943SJed Brown } while (0) 698e9fa29b7SSatish Balay 699ad14c47eSJed Brown /* some vars for logging */ 700ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */ 701ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingOn; /* true if we are currently in a preloading calculation */ 702ad14c47eSJed Brown 70397bb86f7SLois Curfman McInnes #endif 704