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 */ 11fe9b927eSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],PetscObject,const char[],...); 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) 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 261*ca0c957dSBarry Smith /*@ 262*ca0c957dSBarry Smith PetscLogFlops - Log how many flops are performed in a calculation 263*ca0c957dSBarry Smith 264*ca0c957dSBarry Smith Input Paramters: 265*ca0c957dSBarry Smith flops - the number of flops 266*ca0c957dSBarry Smith 267*ca0c957dSBarry Smith Notes: 268*ca0c957dSBarry Smith To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double, 269*ca0c957dSBarry Smith not an integer. Use PetscLogFlops(4.0*n) not PetscLogFlops(4*n) 270*ca0c957dSBarry Smith 271*ca0c957dSBarry Smith Level: intermediate 272*ca0c957dSBarry Smith 273*ca0c957dSBarry Smith .seealso: PetscLogView() 274*ca0c957dSBarry Smith @*/ 275*ca0c957dSBarry Smith 276dd19b90bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n) 277dd19b90bSBarry Smith { 278dd19b90bSBarry Smith PetscFunctionBegin; 279bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG) 280dd19b90bSBarry Smith if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 281da63de55SLois Curfman McInnes #endif 282dd19b90bSBarry Smith petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 283dd19b90bSBarry Smith PetscFunctionReturn(0); 284dd19b90bSBarry Smith } 285fa2bb9feSLisandro Dalcin 286bec0b493Shannah_mairs #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) 2874db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size) 2884db21f4bSStefano Zampini { 289958c4211Shannah_mairs PetscFunctionBegin; 290bec0b493Shannah_mairs petsc_ctog_ct += 1; 291bec0b493Shannah_mairs petsc_ctog_sz += size; 292bec0b493Shannah_mairs PetscFunctionReturn(0); 293bec0b493Shannah_mairs } 2944db21f4bSStefano Zampini 2954db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size) 2964db21f4bSStefano Zampini { 297958c4211Shannah_mairs PetscFunctionBegin; 298bec0b493Shannah_mairs petsc_gtoc_ct += 1; 299bec0b493Shannah_mairs petsc_gtoc_sz += size; 300bec0b493Shannah_mairs PetscFunctionReturn(0); 301bec0b493Shannah_mairs } 3024db21f4bSStefano Zampini 3034db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuFlops(PetscLogDouble n) 3044db21f4bSStefano Zampini { 305958c4211Shannah_mairs PetscFunctionBegin; 306958c4211Shannah_mairs #if defined(PETSC_USE_DEBUG) 307958c4211Shannah_mairs if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 308958c4211Shannah_mairs #endif 309958c4211Shannah_mairs petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 310958c4211Shannah_mairs petsc_gflops += PETSC_FLOPS_PER_OP*n; 311958c4211Shannah_mairs PetscFunctionReturn(0); 312958c4211Shannah_mairs } 3134db21f4bSStefano Zampini 3144db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeBegin() 3154db21f4bSStefano Zampini { 316958c4211Shannah_mairs PetscErrorCode ierr; 317958c4211Shannah_mairs PetscFunctionBegin; 318958c4211Shannah_mairs ierr = PetscTimeSubtract(&petsc_gtime);CHKERRQ(ierr); 319958c4211Shannah_mairs PetscFunctionReturn(0); 320958c4211Shannah_mairs } 3214db21f4bSStefano Zampini 3224db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeEnd() 3234db21f4bSStefano Zampini { 324958c4211Shannah_mairs PetscErrorCode ierr; 325958c4211Shannah_mairs PetscFunctionBegin; 326958c4211Shannah_mairs ierr = PetscTimeAdd(&petsc_gtime);CHKERRQ(ierr); 327958c4211Shannah_mairs PetscFunctionReturn(0); 328958c4211Shannah_mairs } 3294db21f4bSStefano Zampini 3304db21f4bSStefano Zampini PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t) 3314db21f4bSStefano Zampini { 3324db21f4bSStefano Zampini PetscFunctionBegin; 3334db21f4bSStefano Zampini petsc_gtime += t; 3344db21f4bSStefano Zampini PetscFunctionReturn(0); 3354db21f4bSStefano Zampini } 336bec0b493Shannah_mairs #endif 337bec0b493Shannah_mairs 338fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 33977c4ece6SBarry Smith 340aa482453SBarry Smith #if defined (PETSC_HAVE_MPE) 341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 34377c4ece6SBarry Smith #endif 34477c4ece6SBarry Smith 345014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 346014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 347014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 348014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 34977c4ece6SBarry Smith 350e83a5d19SLisandro 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) 351fa2bb9feSLisandro Dalcin #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : 0) 352fa2bb9feSLisandro Dalcin #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : 0) 353fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...); 354fa2bb9feSLisandro Dalcin 3558ba1e511SMatthew Knepley /* Initialization functions */ 356bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void); 357014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 358bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void); 359014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 360014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 361014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 362fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble,PetscLogDouble*); 363014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 3646849ba73SBarry Smith PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 365fa2bb9feSLisandro Dalcin 3668ba1e511SMatthew Knepley /* Output functions */ 367014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 368f14045dbSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void); 369014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 37031d06abdSBarry Smith 371fa2bb9feSLisandro Dalcin /* Stage functions */ 372014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*); 373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 374014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 375014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage,PetscBool); 376014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage,PetscBool*); 377014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage,PetscBool); 378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage,PetscBool*); 379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[],PetscLogStage*); 380f5d6ab90SLisandro Dalcin 3818ba1e511SMatthew Knepley /* Event functions */ 382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[],PetscClassId,PetscLogEvent*); 383217044c2SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent,PetscBool); 384fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId); 385fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId); 386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent,PetscBool); 389014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 3918c49a8d9SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[],PetscLogEvent*); 39213230571SMichael Lange PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int,PetscLogEvent,PetscEventPerfInfo*); 393891e75beSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble); 3945d68e14cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble); 3958ba1e511SMatthew Knepley 3968ba1e511SMatthew Knepley /* Global counters */ 397014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 398014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_ct; 399014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_ct; 400014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_ct; 401014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_len; 402014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_len; 403014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_len; 404014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_len; 405014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 406014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_gather_ct; 407014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 408014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_ct; 409014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 410014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 411014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 4128ba1e511SMatthew Knepley 413e3ed9ee7SBarry Smith PETSC_EXTERN PetscBool PetscLogMemory; 414e3ed9ee7SBarry Smith 415fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */ 41662872c28SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm); 41762872c28SLisandro Dalcin 41862872c28SLisandro Dalcin #define PetscLogEventSync(e,comm) \ 41962872c28SLisandro Dalcin (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 42062872c28SLisandro Dalcin PetscLogEventSynchronize((e),(comm)) : 0 )) 42177c4ece6SBarry Smith 42252e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 4238b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 424495fc317SBarry Smith (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 )) 425043328b6SSatish Balay 42652e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 4278b5db460SBarry Smith (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 428495fc317SBarry Smith (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 )) 42977c4ece6SBarry Smith 430014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent,PetscLogDouble*); 431014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 432003131ecSBarry Smith 433ce85283eSBarry Smith /* 434f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 435f621e05eSBarry Smith their sizes. 436f621e05eSBarry Smith 437af0996ceSBarry Smith This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file 438ce85283eSBarry Smith uses macros to defined the MPI operations. 43915308354SBarry Smith 44015308354SBarry Smith It does not work correctly from HP-UX because it processes the 441bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 442b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 4437c1e34a4SSatish Balay 444f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 445ce85283eSBarry Smith */ 446c9b973beSBarry Smith #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 44777a39924SBarry Smith /* 44877a39924SBarry Smith Logging of MPI activities 44977a39924SBarry Smith */ 450b23bfdefSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscInt count,MPI_Datatype type,PetscLogDouble *length) 451f95db71bSBarry Smith { 452f12d10ccSJunchao Zhang PetscMPIInt typesize; 453f12d10ccSJunchao Zhang PetscErrorCode ierr; 4547d30fa4aSBarry Smith if (type == MPI_DATATYPE_NULL) return 0; 455f12d10ccSJunchao Zhang ierr = MPI_Type_size(type,&typesize);CHKERRQ(ierr); 456f12d10ccSJunchao Zhang *length += (PetscLogDouble) (count*typesize); 4579c72ff1eSSatish Balay return 0; 458f95db71bSBarry Smith } 45977a39924SBarry Smith 460f12d10ccSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length) 4613b9284c0SMatthew G Knepley { 462f12d10ccSJunchao Zhang PetscMPIInt typesize,size,p; 463f12d10ccSJunchao Zhang PetscErrorCode ierr; 4643b9284c0SMatthew G Knepley 4657d30fa4aSBarry Smith if (type == MPI_DATATYPE_NULL) return 0; 466f12d10ccSJunchao Zhang ierr = MPI_Comm_size(comm,&size);CHKERRQ(ierr); 467f12d10ccSJunchao Zhang ierr = MPI_Type_size(type,&typesize);CHKERRQ(ierr); 468f12d10ccSJunchao Zhang for (p=0; p<size; ++p) { 469f12d10ccSJunchao Zhang *length += (PetscLogDouble) (counts[p]*typesize); 470f12d10ccSJunchao Zhang } 471f12d10ccSJunchao Zhang return 0; 472f12d10ccSJunchao Zhang } 473f12d10ccSJunchao Zhang 474f12d10ccSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeCount(PetscInt n,const PetscMPIInt *counts,MPI_Datatype type,PetscLogDouble *length) 475f12d10ccSJunchao Zhang { 476f12d10ccSJunchao Zhang PetscMPIInt typesize,p; 477f12d10ccSJunchao Zhang PetscErrorCode ierr; 478f12d10ccSJunchao Zhang 479f12d10ccSJunchao Zhang if (type == MPI_DATATYPE_NULL) return 0; 480f12d10ccSJunchao Zhang ierr = MPI_Type_size(type,&typesize);CHKERRQ(ierr); 481f12d10ccSJunchao Zhang for (p=0; p<n; ++p) { 482f12d10ccSJunchao Zhang *length += (PetscLogDouble) (counts[p]*typesize); 4833b9284c0SMatthew G Knepley } 4843b9284c0SMatthew G Knepley return 0; 4853b9284c0SMatthew G Knepley } 4863b9284c0SMatthew G Knepley 48772b11a25SBarry Smith /* 48872b11a25SBarry Smith Returns 1 if the communicator is parallel else zero 48972b11a25SBarry Smith */ 49072b11a25SBarry Smith PETSC_STATIC_INLINE int PetscMPIParallelComm(MPI_Comm comm) 49172b11a25SBarry Smith { 49272b11a25SBarry Smith PetscMPIInt size; MPI_Comm_size(comm,&size); return size > 1; 49372b11a25SBarry Smith } 49472b11a25SBarry Smith 49577a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 496f12d10ccSJunchao Zhang ((petsc_irecv_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || MPI_Irecv((buf),(count),(datatype),(source),(tag),(comm),(request))) 49715308354SBarry Smith 49877a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 499f12d10ccSJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || MPI_Isend((buf),(count),(datatype),(dest),(tag),(comm),(request))) 50015308354SBarry Smith 501457b14b1SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) \ 502f12d10ccSJunchao Zhang ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_irecv_len)) || ((number) && MPI_Startall((number),(requests)))) 5030d4b0b6cSBarry Smith 504457b14b1SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) \ 505f12d10ccSJunchao Zhang ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize((count),(datatype),&(petsc_isend_len)) || ((number) && MPI_Startall((number),(requests)))) 5060d4b0b6cSBarry Smith 507457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) \ 508f12d10ccSJunchao Zhang ((petsc_isend_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_isend_len)) || MPI_Start((requests))) 5090d4b0b6cSBarry Smith 510ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 511f12d10ccSJunchao Zhang ((petsc_recv_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_recv_len)) || MPI_Recv((buf),(count),(datatype),(source),(tag),(comm),(status))) 51215308354SBarry Smith 51377a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 514f12d10ccSJunchao Zhang ((petsc_send_ct++,0) || PetscMPITypeSize((count),(datatype),(&petsc_send_len)) || MPI_Send((buf),(count),(datatype),(dest),(tag),(comm))) 51577a39924SBarry Smith 51677a39924SBarry Smith #define MPI_Wait(request,status) \ 5175fa69175SJed Brown ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait((request),(status))) 51877a39924SBarry Smith 51977a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \ 5205fa69175SJed Brown ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany((a),(b),(c),(d))) 52177a39924SBarry Smith 52277a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 5235fa69175SJed Brown ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall((count),(array_of_requests),(array_of_statuses))) 52477a39924SBarry Smith 52577a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 5265fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Allreduce((sendbuf),(recvbuf),(count),(datatype),(op),(comm))) 5273914022bSBarry Smith 52854fe5c21SBarry Smith #define MPI_Bcast(buffer,count,datatype,root,comm) \ 5295fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Bcast((buffer),(count),(datatype),(root),(comm))) 53054fe5c21SBarry Smith 531d6e4c47cSJed Brown #define MPI_Reduce_scatter_block(sendbuf,recvbuf,recvcount,datatype,op,comm) \ 5325fa69175SJed Brown ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Reduce_scatter_block((sendbuf),(recvbuf),(recvcount),(datatype),(op),(comm))) 533d6e4c47cSJed Brown 5343b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 535f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Alltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm))) 5363b9284c0SMatthew G Knepley 5373b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 538f12d10ccSJunchao 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))) 5393b9284c0SMatthew G Knepley 54001faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 5415fa69175SJed Brown ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm))) 54201faf4e4SMatthew Knepley 54301faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 5445fa69175SJed Brown ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm))) 54501faf4e4SMatthew Knepley 54601faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 547f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 54801faf4e4SMatthew Knepley 54901faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 550f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Gatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm))) 55101faf4e4SMatthew Knepley 55201faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 553f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 55401faf4e4SMatthew Knepley 55501faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 556f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Scatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm))) 557f12d10ccSJunchao Zhang 558f12d10ccSJunchao Zhang #define MPI_Ialltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \ 559f12d10ccSJunchao Zhang ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Ialltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request))) 560f12d10ccSJunchao Zhang 561f12d10ccSJunchao Zhang #define MPI_Ialltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 562f12d10ccSJunchao 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))) 563f12d10ccSJunchao Zhang 564f12d10ccSJunchao Zhang #define MPI_Iallgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm,request) \ 565f12d10ccSJunchao Zhang ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm),(request))) 566f12d10ccSJunchao Zhang 567f12d10ccSJunchao Zhang #define MPI_Iallgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm,request) \ 568f12d10ccSJunchao Zhang ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Iallgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm),(request))) 569f12d10ccSJunchao Zhang 570f12d10ccSJunchao Zhang #define MPI_Igather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 571f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 572f12d10ccSJunchao Zhang 573f12d10ccSJunchao Zhang #define MPI_Igatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm,request) \ 574f12d10ccSJunchao Zhang ((petsc_gather_ct++,0) || PetscMPITypeSize((sendcount),(sendtype),(&petsc_send_len)) || MPI_Igatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm),(request))) 575f12d10ccSJunchao Zhang 576f12d10ccSJunchao Zhang #define MPI_Iscatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 577f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 578f12d10ccSJunchao Zhang 579f12d10ccSJunchao Zhang #define MPI_Iscatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm,request) \ 580f12d10ccSJunchao Zhang ((petsc_scatter_ct++,0) || PetscMPITypeSize((recvcount),(recvtype),(&petsc_recv_len)) || MPI_Iscatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm),(request))) 581f12d10ccSJunchao Zhang 582f12d10ccSJunchao Zhang /* We treat MPI_Ineighbor_alltoallv as a set of isend/irecv instead of a traditional MPI collective. 583f12d10ccSJunchao Zhang OpenMPI-3.0 ran into error with outdegree = indegree = 0, so we use ((outdegree) || (indegree)) as a workaround. 584f12d10ccSJunchao Zhang */ 585f12d10ccSJunchao Zhang #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 586f12d10ccSJunchao 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)))) 587f12d10ccSJunchao Zhang 588f12d10ccSJunchao Zhang #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 589f12d10ccSJunchao 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)))) 59001faf4e4SMatthew Knepley 5910d4b0b6cSBarry Smith #else 5920d4b0b6cSBarry Smith 593457b14b1SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) \ 594ea1c87f7SJunchao Zhang ((number) && MPI_Startall((number),(requests))) 5950d4b0b6cSBarry Smith 596457b14b1SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) \ 597ea1c87f7SJunchao Zhang ((number) && MPI_Startall((number),(requests))) 5980d4b0b6cSBarry Smith 599457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) \ 6005fa69175SJed Brown (MPI_Start((requests))) 6010d4b0b6cSBarry Smith 602f12d10ccSJunchao Zhang #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 603f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request))) 604f12d10ccSJunchao Zhang 605f12d10ccSJunchao Zhang #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 606f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm))) 607c9b973beSBarry Smith #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 608614700edSBarry Smith 609df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 610614700edSBarry Smith 611e3ed9ee7SBarry Smith #define PetscLogMemory PETSC_FALSE 612e3ed9ee7SBarry Smith 613b0a32e0cSBarry Smith #define PetscLogFlops(n) 0 614fa2bb9feSLisandro Dalcin #define PetscGetFlops(a) (*(a) = 0.0,0) 615614700edSBarry Smith 616fa2bb9feSLisandro Dalcin #define PetscLogStageRegister(a,b) 0 617fa2bb9feSLisandro Dalcin #define PetscLogStagePush(a) 0 618fa2bb9feSLisandro Dalcin #define PetscLogStagePop() 0 619f5d6ab90SLisandro Dalcin #define PetscLogStageSetActive(a,b) 0 620f5d6ab90SLisandro Dalcin #define PetscLogStageGetActive(a,b) 0 621f5d6ab90SLisandro Dalcin #define PetscLogStageGetVisible(a,b) 0 622f5d6ab90SLisandro Dalcin #define PetscLogStageSetVisible(a,b) 0 623f5d6ab90SLisandro Dalcin #define PetscLogStageGetId(a,b) (*(b)=0,0) 624f5d6ab90SLisandro Dalcin 625fa2bb9feSLisandro Dalcin #define PetscLogEventRegister(a,b,c) 0 626fa2bb9feSLisandro Dalcin #define PetscLogEventSetCollective(a,b) 0 627fa2bb9feSLisandro Dalcin #define PetscLogEventIncludeClass(a) 0 628fa2bb9feSLisandro Dalcin #define PetscLogEventExcludeClass(a) 0 629b0a32e0cSBarry Smith #define PetscLogEventActivate(a) 0 630b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0 631b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a) 0 632b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0 633e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b) 0 63446eb3cd7SSatish Balay #define PetscLogEventGetId(a,b) (*(b)=0,0) 635561b2a67SSatish Balay #define PetscLogEventGetPerfInfo(a,b,c) 0 6369c702cfcSMatthew G. Knepley #define PetscLogEventSetDof(a,b,c) 0 6379c702cfcSMatthew G. Knepley #define PetscLogEventSetError(a,b,c) 0 63877c4ece6SBarry Smith 6398b5db460SBarry Smith #define PetscLogPLB 0 6408b5db460SBarry Smith #define PetscLogPLE 0 6418b5db460SBarry Smith #define PetscLogPHC 0 6428b5db460SBarry Smith #define PetscLogPHD 0 643f5d6ab90SLisandro Dalcin 644efee365bSSatish Balay #define PetscLogObjectParents(p,n,c) 0 64552e6d16bSBarry Smith #define PetscLogObjectCreate(h) 0 64652e6d16bSBarry Smith #define PetscLogObjectDestroy(h) 0 647fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...); 648fa2bb9feSLisandro Dalcin 649bb1d7374SBarry Smith #define PetscLogDefaultBegin() 0 650b0a32e0cSBarry Smith #define PetscLogAllBegin() 0 651bb1d7374SBarry Smith #define PetscLogNestedBegin() 0 652fa2bb9feSLisandro Dalcin #define PetscLogTraceBegin(file) 0 65373fda44aSBarry Smith #define PetscLogActions(a) 0 654fa2bb9feSLisandro Dalcin #define PetscLogObjects(a) 0 655fa2bb9feSLisandro Dalcin #define PetscLogSetThreshold(a,b) 0 656fa2bb9feSLisandro Dalcin #define PetscLogSet(lb,le) 0 657fa2bb9feSLisandro Dalcin 658fa2bb9feSLisandro Dalcin #define PetscLogView(viewer) 0 659fa2bb9feSLisandro Dalcin #define PetscLogViewFromOptions() 0 660fa2bb9feSLisandro Dalcin #define PetscLogDump(c) 0 661fa2bb9feSLisandro Dalcin 66262872c28SLisandro Dalcin #define PetscLogEventSync(e,comm) 0 663fa2bb9feSLisandro Dalcin #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 664fa2bb9feSLisandro Dalcin #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 665ce6058e1SBarry Smith 6668157aad8SJunchao Zhang #define PetscLogCpuToGpu(a) 0 6678157aad8SJunchao Zhang #define PetscLogGpuToCpu(a) 0 6688157aad8SJunchao Zhang #define PetscLogGpuFlops(a) 0 6698157aad8SJunchao Zhang #define PetscLogGpuTimeBegin() 0 6708157aad8SJunchao Zhang #define PetscLogGpuTimeEnd() 0 6718157aad8SJunchao Zhang #define PetscLogGpuTimeAdd(a) 0 6728157aad8SJunchao Zhang 673aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 674ea1c87f7SJunchao Zhang #define MPI_Startall_irecv(count,datatype,number,requests) ((number) && MPI_Startall(number,requests)) 675ea1c87f7SJunchao Zhang #define MPI_Startall_isend(count,datatype,number,requests) ((number) && MPI_Startall(number,requests)) 676457b14b1SJunchao Zhang #define MPI_Start_isend(count,datatype,requests) MPI_Start(requests) 677f12d10ccSJunchao Zhang #define MPI_Start_ineighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm,request) \ 678f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Ineighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm),(request))) 679f12d10ccSJunchao Zhang #define MPI_Start_neighbor_alltoallv(outdegree,indegree,sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 680f12d10ccSJunchao Zhang (((outdegree) || (indegree)) && MPI_Neighbor_alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm))) 681f141ce34SMatthew Knepley 682aa482453SBarry Smith #endif /* PETSC_USE_LOG */ 6836daaf66cSBarry Smith 684204a6943SJed Brown #define PetscPreLoadBegin(flag,name) \ 685204a6943SJed Brown do {\ 686204a6943SJed Brown PetscBool PetscPreLoading = flag;\ 687204a6943SJed Brown int PetscPreLoadMax,PetscPreLoadIt;\ 688166c7f25SBarry Smith PetscLogStage _stageNum;\ 6898cbcd9ccSBarry Smith PetscErrorCode _3_ierr; \ 690c5929fdfSBarry Smith _3_ierr = PetscOptionsGetBool(NULL,NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr); \ 691204a6943SJed Brown PetscPreLoadMax = (int)(PetscPreLoading);\ 692204a6943SJed Brown PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 693204a6943SJed Brown for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\ 694204a6943SJed Brown PetscPreLoadingOn = PetscPreLoading;\ 6950298fd71SBarry Smith _3_ierr = PetscBarrier(NULL);CHKERRQ(_3_ierr);\ 696204a6943SJed Brown if (PetscPreLoadIt>0) {\ 6978e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 6988e58c17dSMatthew Knepley } else {\ 699a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 7008e58c17dSMatthew Knepley }\ 701204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\ 7028e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 7038e58c17dSMatthew Knepley 704204a6943SJed Brown #define PetscPreLoadEnd() \ 705043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 706204a6943SJed Brown PetscPreLoading = PETSC_FALSE;\ 707043328b6SSatish Balay }\ 708204a6943SJed Brown } while (0) 7098e58c17dSMatthew Knepley 710204a6943SJed Brown #define PetscPreLoadStage(name) do { \ 711043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr); \ 712204a6943SJed Brown if (PetscPreLoadIt>0) { \ 7138e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr); \ 7148e58c17dSMatthew Knepley } else { \ 715a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 7168e58c17dSMatthew Knepley } \ 717204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \ 718204a6943SJed Brown _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); \ 719204a6943SJed Brown } while (0) 720e9fa29b7SSatish Balay 721ad14c47eSJed Brown /* some vars for logging */ 722ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */ 723ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingOn; /* true if we are currently in a preloading calculation */ 724ad14c47eSJed Brown 72597bb86f7SLois Curfman McInnes #endif 726