197bb86f7SLois Curfman McInnes /* 27588ac45SBarry Smith Defines profile/logging in PETSc. 397bb86f7SLois Curfman McInnes */ 46524c165SJacob Faibussowitsch #ifndef PETSCLOG_H 526bd1501SBarry Smith #define PETSCLOG_H 6ac09b921SBarry Smith 7aaa7dc30SBarry Smith #include <petscsys.h> 8958c4211Shannah_mairs #include <petsctime.h> 96873511fSToby Isaac #include <petscbt.h> 101c1ad86eSToby Isaac #include <petsclogtypes.h> 11c8d78d4dSSatish Balay 121c1ad86eSToby Isaac /* SUBMANSEC = Profiling */ 13ac09b921SBarry Smith 14fa2bb9feSLisandro Dalcin /* General logging of information; different from event logging */ 153ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[], PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4); 16fa2bb9feSLisandro Dalcin #if defined(PETSC_USE_INFO) 177d3de750SJacob Faibussowitsch #define PetscInfo(A, ...) PetscInfo_Private(PETSC_FUNCTION_NAME, ((PetscObject)A), __VA_ARGS__) 18fa2bb9feSLisandro Dalcin #else 193ba16761SJacob Faibussowitsch #define PetscInfo(A, ...) PETSC_SUCCESS 20fa2bb9feSLisandro Dalcin #endif 21e94e781bSJacob Faibussowitsch 22edd03b47SJacob Faibussowitsch #define PetscInfo1(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 23edd03b47SJacob Faibussowitsch #define PetscInfo2(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 24edd03b47SJacob Faibussowitsch #define PetscInfo3(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 25edd03b47SJacob Faibussowitsch #define PetscInfo4(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 26edd03b47SJacob Faibussowitsch #define PetscInfo5(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 27edd03b47SJacob Faibussowitsch #define PetscInfo6(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 28edd03b47SJacob Faibussowitsch #define PetscInfo7(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 29edd03b47SJacob Faibussowitsch #define PetscInfo8(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 30edd03b47SJacob Faibussowitsch #define PetscInfo9(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__) 317d3de750SJacob Faibussowitsch 32e94e781bSJacob Faibussowitsch /*E 3316a05f60SBarry Smith PetscInfoCommFlag - Describes the method by which to filter information displayed by `PetscInfo()` by communicator size 34e94e781bSJacob Faibussowitsch 35667f096bSBarry Smith Values: 36d1f92df0SBarry Smith + `PETSC_INFO_COMM_ALL` - Default uninitialized value. `PetscInfo()` will not filter based on 378b86dd2eSJacob Faibussowitsch communicator size (i.e. will print for all communicators) 38d1f92df0SBarry Smith . `PETSC_INFO_COMM_NO_SELF` - `PetscInfo()` will NOT print for communicators with size = 1 (i.e. *_COMM_SELF) 39d1f92df0SBarry Smith - `PETSC_INFO_COMM_ONLY_SELF` - `PetscInfo()` will ONLY print for communicators with size = 1 40e94e781bSJacob Faibussowitsch 41e94e781bSJacob Faibussowitsch Level: intermediate 42e94e781bSJacob Faibussowitsch 43667f096bSBarry Smith Note: 44667f096bSBarry Smith Used as an input for `PetscInfoSetFilterCommSelf()` 45667f096bSBarry Smith 46db781477SPatrick Sanan .seealso: `PetscInfo()`, `PetscInfoSetFromOptions()`, `PetscInfoSetFilterCommSelf()` 47e94e781bSJacob Faibussowitsch E*/ 48e94e781bSJacob Faibussowitsch typedef enum { 49e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_ALL = -1, 50e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_NO_SELF = 0, 51e94e781bSJacob Faibussowitsch PETSC_INFO_COMM_ONLY_SELF = 1 52e94e781bSJacob Faibussowitsch } PetscInfoCommFlag; 53e94e781bSJacob Faibussowitsch 54e94e781bSJacob Faibussowitsch PETSC_EXTERN const char *const PetscInfoCommFlags[]; 55fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId); 56fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId); 57e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoEnabled(PetscClassId, PetscBool *); 58e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoAllow(PetscBool); 59e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFile(const char[], const char[]); 60e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetFile(char **, FILE **); 61e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetClasses(PetscBool, PetscInt, const char *const *); 62e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetClass(const char *, PetscBool *); 63e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoGetInfo(PetscBool *, PetscBool *, PetscBool *, PetscBool *, PetscInfoCommFlag *); 648b86dd2eSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoProcessClass(const char[], PetscInt, const PetscClassId[]); 65e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag); 66e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoSetFromOptions(PetscOptions); 67e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscInfoDestroy(void); 68fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */ 69fa2bb9feSLisandro Dalcin 708ba1e511SMatthew Knepley #define PETSC_EVENT 1311311 71014dd563SJed Brown PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT; 7297bb86f7SLois Curfman McInnes 731c1ad86eSToby Isaac PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *); 741c1ad86eSToby Isaac PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack); 751c1ad86eSToby Isaac PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int); 761c1ad86eSToby Isaac PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *); 771c1ad86eSToby Isaac PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *); 781c1ad86eSToby Isaac PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *); 791c1ad86eSToby Isaac 806873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateCreate(PetscLogState *); 816873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateDestroy(PetscLogState *); 826873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetRegistry(PetscLogState, PetscLogRegistry *); 836873511fSToby Isaac 846873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateClassRegister(PetscLogState, const char[], PetscClassId, PetscLogStage *); 856873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActive(PetscLogState, PetscLogStage, PetscClassId, PetscBool); 866873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState, PetscClassId, PetscBool); 876873511fSToby Isaac 886873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateStageRegister(PetscLogState, const char[], PetscLogStage *); 896873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateStagePush(PetscLogState, PetscLogStage); 906873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateStagePop(PetscLogState); 916873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateStageSetActive(PetscLogState, PetscLogStage, PetscBool); 926873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateStageGetActive(PetscLogState, PetscLogStage, PetscBool *); 936873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetCurrentStage(PetscLogState, PetscLogStage *); 946873511fSToby Isaac 956873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateEventRegister(PetscLogState, const char[], PetscClassId, PetscLogEvent *); 966873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateEventSetCollective(PetscLogState, PetscLogEvent, PetscBool); 976873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool); 986873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActiveAll(PetscLogState, PetscLogEvent, PetscBool); 996873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateEventGetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool *); 1006873511fSToby Isaac 1016873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetEventFromName(PetscLogState, const char[], PetscLogEvent *); 1026873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetStageFromName(PetscLogState, const char[], PetscLogStage *); 1036873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromName(PetscLogState, const char[], PetscLogClass *); 1046873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState, PetscClassId, PetscLogClass *); 1056873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetNumEvents(PetscLogState, PetscInt *); 1066873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetNumStages(PetscLogState, PetscInt *); 1076873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateGetNumClasses(PetscLogState, PetscInt *); 1086873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateEventGetInfo(PetscLogState, PetscLogEvent, PetscLogEventInfo *); 1096873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateStageGetInfo(PetscLogState, PetscLogStage, PetscLogStageInfo *); 1106873511fSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogStateClassGetInfo(PetscLogState, PetscLogClass, PetscLogClassInfo *); 1116873511fSToby Isaac 11219ef957cSToby Isaac PETSC_EXTERN PetscClassId PETSCLOGHANDLER_CLASSID; 11319ef957cSToby Isaac 11419ef957cSToby Isaac PETSC_EXTERN PetscFunctionList PetscLogHandlerList; 11519ef957cSToby Isaac 11619ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerRegister(const char[], PetscErrorCode (*)(PetscLogHandler)); 11719ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerCreate(MPI_Comm, PetscLogHandler *); 11819ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerSetType(PetscLogHandler, PetscLogHandlerType); 11919ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerGetType(PetscLogHandler, PetscLogHandlerType *); 12019ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerDestroy(PetscLogHandler *); 12119ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerSetState(PetscLogHandler, PetscLogState); 12219ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerGetState(PetscLogHandler, PetscLogState *); 12319ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerEventBegin(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject); 12419ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerEventEnd(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject); 12519ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerEventSync(PetscLogHandler, PetscLogEvent, MPI_Comm); 12619ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectCreate(PetscLogHandler, PetscObject); 12719ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectDestroy(PetscLogHandler, PetscObject); 12819ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePush(PetscLogHandler, PetscLogStage); 12919ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePop(PetscLogHandler, PetscLogStage); 13019ef957cSToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerView(PetscLogHandler, PetscViewer); 13119ef957cSToby Isaac 132*6467efc9SToby Isaac PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateTrace(MPI_Comm, FILE *, PetscLogHandler *); 133*6467efc9SToby Isaac 1346873511fSToby Isaac /* All events are inactive if an invalid stage is set, like if there have been more stage pops than stage pushes */ 1356873511fSToby Isaac #define PetscLogStateStageEventIsActive(state, stage, event) ((stage >= 0) && PetscBTLookup((state)->active, (stage)) && PetscBTLookup((state)->active, (stage) + (event + 1) * (state)->bt_num_stages)) 1366873511fSToby Isaac 137c708d6e3SStefano Zampini /* Handle multithreading */ 138c708d6e3SStefano Zampini #if defined(PETSC_HAVE_THREADSAFETY) 139c708d6e3SStefano Zampini #if defined(__cplusplus) 140c708d6e3SStefano Zampini #define PETSC_TLS thread_local 141c708d6e3SStefano Zampini #else 142c708d6e3SStefano Zampini #define PETSC_TLS _Thread_local 143c708d6e3SStefano Zampini #endif 144c708d6e3SStefano Zampini #define PETSC_EXTERN_TLS extern PETSC_TLS PETSC_VISIBILITY_PUBLIC 145c708d6e3SStefano Zampini PETSC_EXTERN PetscErrorCode PetscAddLogDouble(PetscLogDouble *, PetscLogDouble *, PetscLogDouble); 146c708d6e3SStefano Zampini PETSC_EXTERN PetscErrorCode PetscAddLogDoubleCnt(PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble); 147c708d6e3SStefano Zampini #else 148c708d6e3SStefano Zampini #define PETSC_EXTERN_TLS PETSC_EXTERN 149c708d6e3SStefano Zampini #define PETSC_TLS 1503ba16761SJacob Faibussowitsch #define PetscAddLogDouble(a, b, c) ((PetscErrorCode)((*(a) += (c), PETSC_SUCCESS) || ((*(b) += (c)), PETSC_SUCCESS))) 1513ba16761SJacob Faibussowitsch #define PetscAddLogDoubleCnt(a, b, c, d, e) ((PetscErrorCode)(PetscAddLogDouble(a, c, 1) || PetscAddLogDouble(b, d, e))) 152c708d6e3SStefano Zampini #endif 15319b02663SBarry Smith 154c60ec953SBarry Smith /* 155aa213bdcSJed Brown PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has 156c60ec953SBarry Smith static information about it, the second collects statistics on how many objects of the class are created, 157c60ec953SBarry Smith how much memory they use, etc. 158c60ec953SBarry Smith 159aa213bdcSJed Brown PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes. 160c60ec953SBarry Smith */ 1616a6a9b46SSatish Balay typedef struct { 162c60ec953SBarry Smith char *name; /* The class name */ 163c60ec953SBarry Smith PetscClassId classid; /* The integer identifying this class */ 164aa213bdcSJed Brown } PetscClassRegInfo; 1656a6a9b46SSatish Balay 1666a6a9b46SSatish Balay typedef struct { 1670700a824SBarry Smith PetscClassId id; /* The integer identifying this class */ 1686a6a9b46SSatish Balay int creations; /* The number of objects of this class created */ 1696a6a9b46SSatish Balay int destructions; /* The number of objects of this class destroyed */ 1704851f57dSBarry Smith PetscLogDouble mem; /* The total memory allocated by objects of this class; this is completely wrong and should possibly be removed */ 1714851f57dSBarry Smith PetscLogDouble descMem; /* The total memory allocated by descendents of these objects; this is completely wrong and should possibly be removed */ 172aa213bdcSJed Brown } PetscClassPerfInfo; 1736a6a9b46SSatish Balay 174aa213bdcSJed Brown typedef struct _n_PetscClassRegLog *PetscClassRegLog; 175aa213bdcSJed Brown struct _n_PetscClassRegLog { 176c60ec953SBarry Smith int numClasses; /* The number of classes registered */ 177c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 178aa213bdcSJed Brown PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 179c60ec953SBarry Smith }; 1806a6a9b46SSatish Balay 181aa213bdcSJed Brown typedef struct _n_PetscClassPerfLog *PetscClassPerfLog; 182aa213bdcSJed Brown struct _n_PetscClassPerfLog { 183c60ec953SBarry Smith int numClasses; /* The number of logging classes */ 184c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 185aa213bdcSJed Brown PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 186c60ec953SBarry Smith }; 18716a05f60SBarry Smith 188c60ec953SBarry Smith /* 189aa213bdcSJed Brown PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has 190c60ec953SBarry Smith static information about it, the second collects statistics on how many times the event is used, how 191c60ec953SBarry Smith much time it takes, etc. 192c60ec953SBarry Smith 193aa213bdcSJed Brown PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one 194c60ec953SBarry Smith of these for each stage. 195c60ec953SBarry Smith 196c60ec953SBarry Smith */ 1976a6a9b46SSatish Balay typedef struct { 1986a6a9b46SSatish Balay char *name; /* The name of this event */ 199c60ec953SBarry Smith PetscClassId classid; /* The class the event is associated with */ 200217044c2SLisandro Dalcin PetscBool collective; /* Flag this event as collective */ 201a0c7f9aaSSamuel Khuvis #if defined(PETSC_HAVE_TAU_PERFSTUBS) 202a0c7f9aaSSamuel Khuvis void *timer; /* Associated external tool timer for this event */ 203a0c7f9aaSSamuel Khuvis #endif 2046a6a9b46SSatish Balay #if defined(PETSC_HAVE_MPE) 2056a6a9b46SSatish Balay int mpe_id_begin; /* MPE IDs that define the event */ 2066a6a9b46SSatish Balay int mpe_id_end; 2076a6a9b46SSatish Balay #endif 208aa213bdcSJed Brown } PetscEventRegInfo; 2096a6a9b46SSatish Balay 210aa213bdcSJed Brown typedef struct _n_PetscEventRegLog *PetscEventRegLog; 211aa213bdcSJed Brown struct _n_PetscEventRegLog { 2126a6a9b46SSatish Balay int numEvents; /* The number of registered events */ 2136a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 214aa213bdcSJed Brown PetscEventRegInfo *eventInfo; /* The registration information for each event */ 2156a6a9b46SSatish Balay }; 2166a6a9b46SSatish Balay 217aa213bdcSJed Brown typedef struct _n_PetscEventPerfLog *PetscEventPerfLog; 218aa213bdcSJed Brown struct _n_PetscEventPerfLog { 2196a6a9b46SSatish Balay int numEvents; /* The number of logging events */ 2206a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 221aa213bdcSJed Brown PetscEventPerfInfo *eventInfo; /* The performance information for each event */ 2226a6a9b46SSatish Balay }; 22316a05f60SBarry Smith 224c60ec953SBarry Smith /* 225aa213bdcSJed Brown PetscStageInfo - Contains all the information about a particular stage. 2266a6a9b46SSatish Balay 227aa213bdcSJed Brown PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code. 228c60ec953SBarry Smith */ 229aa213bdcSJed Brown typedef struct _PetscStageInfo { 2306a6a9b46SSatish Balay char *name; /* The stage name */ 231ace3abfcSBarry Smith PetscBool used; /* The stage was pushed on this processor */ 232aa213bdcSJed Brown PetscEventPerfInfo perfInfo; /* The stage performance information */ 233aa213bdcSJed Brown PetscEventPerfLog eventLog; /* The event information for this stage */ 234aa213bdcSJed Brown PetscClassPerfLog classLog; /* The class information for this stage */ 235a0c7f9aaSSamuel Khuvis #if defined(PETSC_HAVE_TAU_PERFSTUBS) 236a0c7f9aaSSamuel Khuvis void *timer; /* Associated external tool timer for this stage */ 237a0c7f9aaSSamuel Khuvis #endif 238aa213bdcSJed Brown } PetscStageInfo; 2396a6a9b46SSatish Balay 240aa213bdcSJed Brown typedef struct _n_PetscStageLog *PetscStageLog; 241aa213bdcSJed Brown struct _n_PetscStageLog { 2426a6a9b46SSatish Balay int numStages; /* The number of registered stages */ 2436a6a9b46SSatish Balay int maxStages; /* The maximum number of stages */ 244aa213bdcSJed Brown PetscIntStack stack; /* The stack for active stages */ 245aa213bdcSJed Brown int curStage; /* The current stage (only used in macros so we don't call PetscIntStackTop) */ 246aa213bdcSJed Brown PetscStageInfo *stageInfo; /* The information for each stage */ 247aa213bdcSJed Brown PetscEventRegLog eventLog; /* The registered events */ 248aa213bdcSJed Brown PetscClassRegLog classLog; /* The registered classes */ 2496a6a9b46SSatish Balay }; 250fee518ebSJed Brown 251edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectParent()", ) static inline PetscErrorCode PetscLogObjectParent(PetscObject o, PetscObject p) 252d71ae5a4SJacob Faibussowitsch { 2534f839811SJacob Faibussowitsch (void)o; 2544f839811SJacob Faibussowitsch (void)p; 2553ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 2564dfa11a4SJacob Faibussowitsch } 2574dfa11a4SJacob Faibussowitsch 258edd03b47SJacob Faibussowitsch PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectMemory()", ) static inline PetscErrorCode PetscLogObjectMemory(PetscObject o, PetscLogDouble m) 259d71ae5a4SJacob Faibussowitsch { 2604f839811SJacob Faibussowitsch (void)o; 2614f839811SJacob Faibussowitsch (void)m; 2623ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 2634dfa11a4SJacob Faibussowitsch } 2643bb1ff40SBarry Smith 265aa482453SBarry Smith #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 266aeeda9f6SJohn Fettig PETSC_EXTERN PetscStageLog petsc_stageLog; 267f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog *); 268f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog, int *); 269f5d6ab90SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog, int, PetscEventPerfLog *); 270614700edSBarry Smith 271fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 27277c4ece6SBarry Smith 273aa482453SBarry Smith #if defined(PETSC_HAVE_MPE) 274014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 27677c4ece6SBarry Smith #endif 27777c4ece6SBarry Smith 278014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject); 279014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject); 280014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 281014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 28277c4ece6SBarry Smith 2839566063dSJacob Faibussowitsch #define PetscLogObjectParents(p, n, d) PetscMacroReturnStandard(for (int _i = 0; _i < (n); ++_i) PetscCall(PetscLogObjectParent((PetscObject)(p), (PetscObject)(d)[_i]));) 2843ba16761SJacob Faibussowitsch #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : PETSC_SUCCESS) 2853ba16761SJacob Faibussowitsch #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : PETSC_SUCCESS) 2863ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 287fa2bb9feSLisandro Dalcin 2888ba1e511SMatthew Knepley /* Initialization functions */ 289bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void); 290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 291bb1d7374SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void); 292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 295fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble, PetscLogDouble *); 2969371c9d4SSatish Balay PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 297fa2bb9feSLisandro Dalcin 2988ba1e511SMatthew Knepley /* Output functions */ 299014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 300f14045dbSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void); 301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 30231d06abdSBarry Smith 3034dd65854SConnor Ward /* Status checking functions */ 3044dd65854SConnor Ward PETSC_EXTERN PetscErrorCode PetscLogIsActive(PetscBool *); 3054dd65854SConnor Ward 306fa2bb9feSLisandro Dalcin /* Stage functions */ 307014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[], PetscLogStage *); 308014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 310014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool); 311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *); 312014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool); 313014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *); 314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[], PetscLogStage *); 315f5d6ab90SLisandro Dalcin 3168ba1e511SMatthew Knepley /* Event functions */ 317014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId, PetscLogEvent *); 318217044c2SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent, PetscBool); 319fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId); 320fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId); 321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 322014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 323c00cb57fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent); 324c00cb57fSBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent); 325014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool); 326014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 327014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 3288c49a8d9SBarry Smith PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[], PetscLogEvent *); 32913230571SMichael Lange PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int, PetscLogEvent, PetscEventPerfInfo *); 330891e75beSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble); 3315d68e14cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble); 3327a101e5eSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscLogPushCurrentEvent_Internal(PetscLogEvent); 3337a101e5eSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscLogPopCurrentEvent_Internal(void); 3348ba1e511SMatthew Knepley 335e3ed9ee7SBarry Smith PETSC_EXTERN PetscBool PetscLogMemory; 336e3ed9ee7SBarry Smith 337fa2bb9feSLisandro Dalcin PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */ 33862872c28SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm); 33962872c28SLisandro Dalcin 34062872c28SLisandro Dalcin #define PetscLogEventSync(e, comm) \ 3413ba16761SJacob Faibussowitsch ((PetscErrorCode)(((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? PetscLogEventSynchronize((e), (comm)) : PETSC_SUCCESS))) 34277c4ece6SBarry Smith 34352e6d16bSBarry Smith #define PetscLogEventBegin(e, o1, o2, o3, o4) \ 3443ba16761SJacob Faibussowitsch ((PetscErrorCode)((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? (PetscErrorCode)(((*PetscLogPLB)((e), 0, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))) || PetscLogPushCurrentEvent_Internal(e)) : PETSC_SUCCESS)) 345043328b6SSatish Balay 34652e6d16bSBarry Smith #define PetscLogEventEnd(e, o1, o2, o3, o4) \ 3473ba16761SJacob Faibussowitsch ((PetscErrorCode)((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? (PetscErrorCode)(((*PetscLogPLE)((e), 0, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))) || PetscLogPopCurrentEvent_Internal()) : PETSC_SUCCESS)) 34877c4ece6SBarry Smith 349014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble *); 350014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 351003131ecSBarry Smith 352c708d6e3SStefano Zampini /* Global flop counter */ 353c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_TotalFlops; 354c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 355c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_isend_ct; 356c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_recv_ct; 357c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_send_ct; 358c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_irecv_len; 359c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_isend_len; 360c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_recv_len; 361c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_send_len; 362c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 363c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gather_ct; 364c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 365c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_wait_ct; 366c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 367c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 368c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 369c708d6e3SStefano Zampini 370c708d6e3SStefano Zampini /* Thread local storage */ 371c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_TotalFlops_th; 372c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_irecv_ct_th; 373c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_isend_ct_th; 374c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_recv_ct_th; 375c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_send_ct_th; 376c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_irecv_len_th; 377c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_isend_len_th; 378c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_recv_len_th; 379c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_send_len_th; 380c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_allreduce_ct_th; 381c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gather_ct_th; 382c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_scatter_ct_th; 383c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_wait_ct_th; 384c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_wait_any_ct_th; 385c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_wait_all_ct_th; 386c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_sum_of_waits_ct_th; 387c708d6e3SStefano Zampini 388c708d6e3SStefano Zampini /* 389c708d6e3SStefano Zampini Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 390c708d6e3SStefano Zampini 391c708d6e3SStefano Zampini For the complex numbers version, note that 392c708d6e3SStefano Zampini 1 complex addition = 2 flops 393c708d6e3SStefano Zampini 1 complex multiplication = 6 flops, 394c708d6e3SStefano Zampini where we define 1 flop as that for a double precision scalar. We roughly approximate 395c708d6e3SStefano Zampini flop counting for complex numbers by multiplying the total flops by 4; this corresponds 396c708d6e3SStefano Zampini to the assumption that we're counting mostly additions and multiplications -- and 397c708d6e3SStefano Zampini roughly the same number of each. More accurate counting could be done by distinguishing 398c708d6e3SStefano Zampini among the various arithmetic operations. 399c708d6e3SStefano Zampini */ 400c708d6e3SStefano Zampini 401c708d6e3SStefano Zampini #if defined(PETSC_USE_COMPLEX) 402c708d6e3SStefano Zampini #define PETSC_FLOPS_PER_OP 4.0 403c708d6e3SStefano Zampini #else 404c708d6e3SStefano Zampini #define PETSC_FLOPS_PER_OP 1.0 405c708d6e3SStefano Zampini #endif 406c708d6e3SStefano Zampini 407c708d6e3SStefano Zampini /*@C 408c708d6e3SStefano Zampini PetscLogFlops - Log how many flops are performed in a calculation 409c708d6e3SStefano Zampini 410c708d6e3SStefano Zampini Input Parameter: 411c708d6e3SStefano Zampini . flops - the number of flops 412c708d6e3SStefano Zampini 413c708d6e3SStefano Zampini Level: intermediate 414c708d6e3SStefano Zampini 415c200f75eSSatish Balay Note: 416c200f75eSSatish Balay To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double, 417c200f75eSSatish Balay not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n) 418c200f75eSSatish Balay 419c200f75eSSatish Balay .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()` 420c708d6e3SStefano Zampini @*/ 421c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogFlops(PetscLogDouble n) 422c708d6e3SStefano Zampini { 423c708d6e3SStefano Zampini PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops"); 424c708d6e3SStefano Zampini return PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n); 425c708d6e3SStefano Zampini } 426c708d6e3SStefano Zampini 427ce85283eSBarry Smith /* 428f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 429f621e05eSBarry Smith their sizes. 430f621e05eSBarry Smith 431af0996ceSBarry Smith This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file 432ce85283eSBarry Smith uses macros to defined the MPI operations. 43315308354SBarry Smith 43415308354SBarry Smith It does not work correctly from HP-UX because it processes the 435bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 436b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 4377c1e34a4SSatish Balay 438f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 439ce85283eSBarry Smith */ 440d5bc873cSPierre Jolivet #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) 44177a39924SBarry Smith /* 44277a39924SBarry Smith Logging of MPI activities 44377a39924SBarry Smith */ 444c708d6e3SStefano Zampini static inline PetscErrorCode PetscMPITypeSize(PetscInt count, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th) 445d71ae5a4SJacob Faibussowitsch { 446f12d10ccSJunchao Zhang PetscMPIInt typesize; 4475f80ce2aSJacob Faibussowitsch 4483ba16761SJacob Faibussowitsch if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS; 4499566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(type, &typesize)); 450c708d6e3SStefano Zampini return PetscAddLogDouble(length, length_th, (PetscLogDouble)(count * typesize)); 451f95db71bSBarry Smith } 45277a39924SBarry Smith 453c708d6e3SStefano Zampini static inline PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, const PetscMPIInt *counts, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th) 454d71ae5a4SJacob Faibussowitsch { 455f12d10ccSJunchao Zhang PetscMPIInt typesize, size, p; 456c708d6e3SStefano Zampini PetscLogDouble l; 4573b9284c0SMatthew G Knepley 4583ba16761SJacob Faibussowitsch if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS; 4599566063dSJacob Faibussowitsch PetscCallMPI(MPI_Comm_size(comm, &size)); 4609566063dSJacob Faibussowitsch PetscCallMPI(MPI_Type_size(type, &typesize)); 461c708d6e3SStefano Zampini for (p = 0, l = 0.0; p < size; ++p) l += (PetscLogDouble)(counts[p] * typesize); 462c708d6e3SStefano Zampini return PetscAddLogDouble(length, length_th, l); 4633b9284c0SMatthew G Knepley } 4643b9284c0SMatthew G Knepley 46572b11a25SBarry Smith /* 46672b11a25SBarry Smith Returns 1 if the communicator is parallel else zero 46772b11a25SBarry Smith */ 468d71ae5a4SJacob Faibussowitsch static inline int PetscMPIParallelComm(MPI_Comm comm) 469d71ae5a4SJacob Faibussowitsch { 4709371c9d4SSatish Balay PetscMPIInt size; 4719371c9d4SSatish Balay MPI_Comm_size(comm, &size); 4729371c9d4SSatish Balay return size > 1; 47372b11a25SBarry Smith } 47472b11a25SBarry Smith 475c708d6e3SStefano Zampini #define MPI_Irecv(buf, count, datatype, source, tag, comm, request) \ 476c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || MPI_Irecv((buf), (count), (datatype), (source), (tag), (comm), (request))) 47715308354SBarry Smith 478c708d6e3SStefano Zampini #define MPI_Irecv_c(buf, count, datatype, source, tag, comm, request) \ 479c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || MPI_Irecv_c((buf), (count), (datatype), (source), (tag), (comm), (request))) 480c87b50c4SJunchao Zhang 481c708d6e3SStefano Zampini #define MPI_Isend(buf, count, datatype, dest, tag, comm, request) \ 482c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || MPI_Isend((buf), (count), (datatype), (dest), (tag), (comm), (request))) 48315308354SBarry Smith 484c708d6e3SStefano Zampini #define MPI_Isend_c(buf, count, datatype, dest, tag, comm, request) \ 485c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || MPI_Isend_c((buf), (count), (datatype), (dest), (tag), (comm), (request))) 486c87b50c4SJunchao Zhang 487c708d6e3SStefano Zampini #define MPI_Startall_irecv(count, datatype, number, requests) \ 488c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || ((number) && MPI_Startall((number), (requests)))) 4890d4b0b6cSBarry Smith 490c708d6e3SStefano Zampini #define MPI_Startall_isend(count, datatype, number, requests) \ 491c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || ((number) && MPI_Startall((number), (requests)))) 4920d4b0b6cSBarry Smith 493c708d6e3SStefano Zampini #define MPI_Start_isend(count, datatype, requests) (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_isend_len), (&petsc_isend_len_th)) || MPI_Start((requests))) 4940d4b0b6cSBarry Smith 495c708d6e3SStefano Zampini #define MPI_Recv(buf, count, datatype, source, tag, comm, status) \ 496c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPI_Recv((buf), (count), (datatype), (source), (tag), (comm), (status))) 49715308354SBarry Smith 498c708d6e3SStefano Zampini #define MPI_Recv_c(buf, count, datatype, source, tag, comm, status) \ 499c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_recv_len), &(petsc_recv_len_th)) || MPI_Recv_c((buf), (count), (datatype), (source), (tag), (comm), (status))) 500c87b50c4SJunchao Zhang 501c708d6e3SStefano Zampini #define MPI_Send(buf, count, datatype, dest, tag, comm) \ 502c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Send((buf), (count), (datatype), (dest), (tag), (comm))) 50377a39924SBarry Smith 504c708d6e3SStefano Zampini #define MPI_Send_c(buf, count, datatype, dest, tag, comm) \ 505c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Send_c((buf), (count), (datatype), (dest), (tag), (comm))) 506c87b50c4SJunchao Zhang 507c708d6e3SStefano Zampini #define MPI_Wait(request, status) (PetscAddLogDouble(&petsc_wait_ct, &petsc_wait_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, 1) || MPI_Wait((request), (status))) 50877a39924SBarry Smith 509c708d6e3SStefano Zampini #define MPI_Waitany(a, b, c, d) (PetscAddLogDouble(&petsc_wait_any_ct, &petsc_wait_any_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, 1) || MPI_Waitany((a), (b), (c), (d))) 51077a39924SBarry Smith 511c708d6e3SStefano Zampini #define MPI_Waitall(count, array_of_requests, array_of_statuses) \ 512c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_wait_all_ct, &petsc_wait_all_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, count) || MPI_Waitall((count), (array_of_requests), (array_of_statuses))) 51377a39924SBarry Smith 514c708d6e3SStefano Zampini #define MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm) (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Allreduce((sendbuf), (recvbuf), (count), (datatype), (op), (comm))) 5153914022bSBarry Smith 516c708d6e3SStefano Zampini #define MPI_Bcast(buffer, count, datatype, root, comm) (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Bcast((buffer), (count), (datatype), (root), (comm))) 51754fe5c21SBarry Smith 518c708d6e3SStefano Zampini #define MPI_Reduce_scatter_block(sendbuf, recvbuf, recvcount, datatype, op, comm) \ 519c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Reduce_scatter_block((sendbuf), (recvbuf), (recvcount), (datatype), (op), (comm))) 520d6e4c47cSJed Brown 5213b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \ 522c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Alltoall((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm))) 5233b9284c0SMatthew G Knepley 5243b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm) \ 525c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSizeComm((comm), (sendcnts), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Alltoallv((sendbuf), (sendcnts), (sdispls), (sendtype), (recvbuf), (recvcnts), (rdispls), (recvtype), (comm))) 5263b9284c0SMatthew G Knepley 527c708d6e3SStefano Zampini #define MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \ 528c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm))) 52901faf4e4SMatthew Knepley 53001faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm) \ 531c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm))) 53201faf4e4SMatthew Knepley 53301faf4e4SMatthew Knepley #define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \ 534c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Gather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm))) 53501faf4e4SMatthew Knepley 53601faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm) \ 537c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Gatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (root), (comm))) 53801faf4e4SMatthew Knepley 53901faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \ 540c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), &(petsc_recv_len_th)) || MPI_Scatter((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm))) 54101faf4e4SMatthew Knepley 54201faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \ 543c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), &(petsc_recv_len_th)) || MPI_Scatterv((sendbuf), (sendcount), (displs), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm))) 544f12d10ccSJunchao Zhang 545f12d10ccSJunchao Zhang #define MPI_Ialltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \ 546c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Ialltoall((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm), (request))) 547f12d10ccSJunchao Zhang 548f12d10ccSJunchao Zhang #define MPI_Ialltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm, request) \ 549c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSizeComm((comm), (sendcnts), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Ialltoallv((sendbuf), (sendcnts), (sdispls), (sendtype), (recvbuf), (recvcnts), (rdispls), (recvtype), (comm), (request))) 550f12d10ccSJunchao Zhang 551f12d10ccSJunchao Zhang #define MPI_Iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \ 552c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm), (request))) 553f12d10ccSJunchao Zhang 554f12d10ccSJunchao Zhang #define MPI_Iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm, request) \ 555c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm), (request))) 556f12d10ccSJunchao Zhang 557f12d10ccSJunchao Zhang #define MPI_Igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \ 558c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Igather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm), (request))) 559f12d10ccSJunchao Zhang 560f12d10ccSJunchao Zhang #define MPI_Igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm, request) \ 561c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Igatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (root), (comm), (request))) 562f12d10ccSJunchao Zhang 563f12d10ccSJunchao Zhang #define MPI_Iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \ 564c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPI_Iscatter((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm), (request))) 565f12d10ccSJunchao Zhang 566f12d10ccSJunchao Zhang #define MPI_Iscatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \ 567c708d6e3SStefano Zampini (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPI_Iscatterv((sendbuf), (sendcount), (displs), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm), (request))) 568f12d10ccSJunchao Zhang 569715b587bSJunchao Zhang #define MPIX_Send_enqueue(buf, count, datatype, dest, tag, comm) \ 570715b587bSJunchao Zhang (PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_send_len), (&petsc_send_len_th)) || MPIX_Send_enqueue((buf), (count), (datatype), (dest), (tag), (comm))) 571715b587bSJunchao Zhang 572715b587bSJunchao Zhang #define MPIX_Recv_enqueue(buf, count, datatype, source, tag, comm, status) \ 573715b587bSJunchao Zhang (PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPIX_Recv_enqueue((buf), (count), (datatype), (source), (tag), (comm), (status))) 574715b587bSJunchao Zhang 575715b587bSJunchao Zhang #define MPIX_Isend_enqueue(buf, count, datatype, dest, tag, comm, request) \ 576715b587bSJunchao Zhang (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || MPIX_Isend_enqueue((buf), (count), (datatype), (dest), (tag), (comm), (request))) 577715b587bSJunchao Zhang 578715b587bSJunchao Zhang #define MPIX_Irecv_enqueue(buf, count, datatype, source, tag, comm, request) \ 579715b587bSJunchao Zhang (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || MPIX_Irecv_enqueue((buf), (count), (datatype), (source), (tag), (comm), (request))) 580715b587bSJunchao Zhang 581715b587bSJunchao Zhang #define MPIX_Allreduce_enqueue(sendbuf, recvbuf, count, datatype, op, comm) \ 582715b587bSJunchao Zhang (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPIX_Allreduce_enqueue((sendbuf), (recvbuf), (count), (datatype), (op), (comm))) 583715b587bSJunchao Zhang 584715b587bSJunchao Zhang #define MPIX_Wait_enqueue(request, status) (PetscAddLogDouble(&petsc_wait_ct, &petsc_wait_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, 1) || MPIX_Wait_enqueue((request), (status))) 585715b587bSJunchao Zhang 586715b587bSJunchao Zhang #define MPIX_Waitall_enqueue(count, array_of_requests, array_of_statuses) \ 587715b587bSJunchao Zhang (PetscAddLogDouble(&petsc_wait_all_ct, &petsc_wait_all_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, count) || MPIX_Waitall_enqueue((count), (array_of_requests), (array_of_statuses))) 5880d4b0b6cSBarry Smith #else 5890d4b0b6cSBarry Smith 5909371c9d4SSatish Balay #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests))) 5910d4b0b6cSBarry Smith 5929371c9d4SSatish Balay #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests))) 5930d4b0b6cSBarry Smith 5949371c9d4SSatish Balay #define MPI_Start_isend(count, datatype, requests) (MPI_Start((requests))) 5950d4b0b6cSBarry Smith 596c9b973beSBarry Smith #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 597614700edSBarry Smith 598df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 599614700edSBarry Smith 600e3ed9ee7SBarry Smith #define PetscLogMemory PETSC_FALSE 601e3ed9ee7SBarry Smith 6023ba16761SJacob Faibussowitsch #define PetscLogFlops(n) ((void)(n), PETSC_SUCCESS) 6033ba16761SJacob Faibussowitsch #define PetscGetFlops(a) (*(a) = 0.0, PETSC_SUCCESS) 604614700edSBarry Smith 6053ba16761SJacob Faibussowitsch #define PetscLogStageRegister(a, b) PETSC_SUCCESS 6063ba16761SJacob Faibussowitsch #define PetscLogStagePush(a) PETSC_SUCCESS 6073ba16761SJacob Faibussowitsch #define PetscLogStagePop() PETSC_SUCCESS 6083ba16761SJacob Faibussowitsch #define PetscLogStageSetActive(a, b) PETSC_SUCCESS 6093ba16761SJacob Faibussowitsch #define PetscLogStageGetActive(a, b) PETSC_SUCCESS 6103ba16761SJacob Faibussowitsch #define PetscLogStageGetVisible(a, b) PETSC_SUCCESS 6113ba16761SJacob Faibussowitsch #define PetscLogStageSetVisible(a, b) PETSC_SUCCESS 6123ba16761SJacob Faibussowitsch #define PetscLogStageGetId(a, b) (*(b) = 0, PETSC_SUCCESS) 613f5d6ab90SLisandro Dalcin 6143ba16761SJacob Faibussowitsch #define PetscLogEventRegister(a, b, c) PETSC_SUCCESS 6153ba16761SJacob Faibussowitsch #define PetscLogEventSetCollective(a, b) PETSC_SUCCESS 6163ba16761SJacob Faibussowitsch #define PetscLogEventIncludeClass(a) PETSC_SUCCESS 6173ba16761SJacob Faibussowitsch #define PetscLogEventExcludeClass(a) PETSC_SUCCESS 6183ba16761SJacob Faibussowitsch #define PetscLogEventActivate(a) PETSC_SUCCESS 6193ba16761SJacob Faibussowitsch #define PetscLogEventDeactivate(a) PETSC_SUCCESS 6203ba16761SJacob Faibussowitsch #define PetscLogEventDeactivatePush(a) PETSC_SUCCESS 6213ba16761SJacob Faibussowitsch #define PetscLogEventDeactivatePop(a) PETSC_SUCCESS 6223ba16761SJacob Faibussowitsch #define PetscLogEventActivateClass(a) PETSC_SUCCESS 6233ba16761SJacob Faibussowitsch #define PetscLogEventDeactivateClass(a) PETSC_SUCCESS 6243ba16761SJacob Faibussowitsch #define PetscLogEventSetActiveAll(a, b) PETSC_SUCCESS 6253ba16761SJacob Faibussowitsch #define PetscLogEventGetId(a, b) (*(b) = 0, PETSC_SUCCESS) 6263ba16761SJacob Faibussowitsch #define PetscLogEventGetPerfInfo(a, b, c) PETSC_SUCCESS 6273ba16761SJacob Faibussowitsch #define PetscLogEventSetDof(a, b, c) PETSC_SUCCESS 6283ba16761SJacob Faibussowitsch #define PetscLogEventSetError(a, b, c) PETSC_SUCCESS 62977c4ece6SBarry Smith 6303ba16761SJacob Faibussowitsch #define PetscLogPLB PETSC_SUCCESS 6313ba16761SJacob Faibussowitsch #define PetscLogPLE PETSC_SUCCESS 6323ba16761SJacob Faibussowitsch #define PetscLogPHC PETSC_SUCCESS 6333ba16761SJacob Faibussowitsch #define PetscLogPHD PETSC_SUCCESS 634f5d6ab90SLisandro Dalcin 6353ba16761SJacob Faibussowitsch #define PetscLogObjectParents(p, n, c) PETSC_SUCCESS 6363ba16761SJacob Faibussowitsch #define PetscLogObjectCreate(h) PETSC_SUCCESS 6373ba16761SJacob Faibussowitsch #define PetscLogObjectDestroy(h) PETSC_SUCCESS 6383ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3); 639fa2bb9feSLisandro Dalcin 6403ba16761SJacob Faibussowitsch #define PetscLogDefaultBegin() PETSC_SUCCESS 6413ba16761SJacob Faibussowitsch #define PetscLogAllBegin() PETSC_SUCCESS 6423ba16761SJacob Faibussowitsch #define PetscLogNestedBegin() PETSC_SUCCESS 6433ba16761SJacob Faibussowitsch #define PetscLogTraceBegin(file) PETSC_SUCCESS 6443ba16761SJacob Faibussowitsch #define PetscLogActions(a) PETSC_SUCCESS 6453ba16761SJacob Faibussowitsch #define PetscLogObjects(a) PETSC_SUCCESS 6463ba16761SJacob Faibussowitsch #define PetscLogSetThreshold(a, b) PETSC_SUCCESS 6473ba16761SJacob Faibussowitsch #define PetscLogSet(lb, le) PETSC_SUCCESS 6483ba16761SJacob Faibussowitsch #define PetscLogIsActive(flag) (*(flag) = PETSC_FALSE, PETSC_SUCCESS) 649fa2bb9feSLisandro Dalcin 6503ba16761SJacob Faibussowitsch #define PetscLogView(viewer) PETSC_SUCCESS 6513ba16761SJacob Faibussowitsch #define PetscLogViewFromOptions() PETSC_SUCCESS 6523ba16761SJacob Faibussowitsch #define PetscLogDump(c) PETSC_SUCCESS 653fa2bb9feSLisandro Dalcin 6543ba16761SJacob Faibussowitsch #define PetscLogEventSync(e, comm) PETSC_SUCCESS 6553ba16761SJacob Faibussowitsch #define PetscLogEventBegin(e, o1, o2, o3, o4) PETSC_SUCCESS 6563ba16761SJacob Faibussowitsch #define PetscLogEventEnd(e, o1, o2, o3, o4) PETSC_SUCCESS 657ce6058e1SBarry Smith 65823c86b1bSSatish Balay /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 65923c86b1bSSatish Balay #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall(number, requests)) 66023c86b1bSSatish Balay #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall(number, requests)) 66123c86b1bSSatish Balay #define MPI_Start_isend(count, datatype, requests) MPI_Start(requests) 66223c86b1bSSatish Balay 66323c86b1bSSatish Balay #endif /* PETSC_USE_LOG */ 66423c86b1bSSatish Balay 665204a6943SJed Brown #define PetscPreLoadBegin(flag, name) \ 666204a6943SJed Brown do { \ 667204a6943SJed Brown PetscBool PetscPreLoading = flag; \ 668204a6943SJed Brown int PetscPreLoadMax, PetscPreLoadIt; \ 669166c7f25SBarry Smith PetscLogStage _stageNum; \ 6709566063dSJacob Faibussowitsch PetscCall(PetscOptionsGetBool(NULL, NULL, "-preload", &PetscPreLoading, NULL)); \ 671204a6943SJed Brown PetscPreLoadMax = (int)(PetscPreLoading); \ 672204a6943SJed Brown PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed; \ 673204a6943SJed Brown for (PetscPreLoadIt = 0; PetscPreLoadIt <= PetscPreLoadMax; PetscPreLoadIt++) { \ 674204a6943SJed Brown PetscPreLoadingOn = PetscPreLoading; \ 6759566063dSJacob Faibussowitsch PetscCall(PetscBarrier(NULL)); \ 6769566063dSJacob Faibussowitsch if (PetscPreLoadIt > 0) PetscCall(PetscLogStageGetId(name, &_stageNum)); \ 6779566063dSJacob Faibussowitsch else PetscCall(PetscLogStageRegister(name, &_stageNum)); \ 6789566063dSJacob Faibussowitsch PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(!PetscPreLoadMax || PetscPreLoadIt))); \ 679a8f51744SPierre Jolivet PetscCall(PetscLogStagePush(_stageNum)) 6808e58c17dSMatthew Knepley 681204a6943SJed Brown #define PetscPreLoadEnd() \ 6829566063dSJacob Faibussowitsch PetscCall(PetscLogStagePop()); \ 683204a6943SJed Brown PetscPreLoading = PETSC_FALSE; \ 684043328b6SSatish Balay } \ 6859371c9d4SSatish Balay } \ 6869371c9d4SSatish Balay while (0) 6878e58c17dSMatthew Knepley 6889371c9d4SSatish Balay #define PetscPreLoadStage(name) \ 6899371c9d4SSatish Balay do { \ 6909566063dSJacob Faibussowitsch PetscCall(PetscLogStagePop()); \ 6919566063dSJacob Faibussowitsch if (PetscPreLoadIt > 0) PetscCall(PetscLogStageGetId(name, &_stageNum)); \ 6929566063dSJacob Faibussowitsch else PetscCall(PetscLogStageRegister(name, &_stageNum)); \ 6939566063dSJacob Faibussowitsch PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(!PetscPreLoadMax || PetscPreLoadIt))); \ 6949566063dSJacob Faibussowitsch PetscCall(PetscLogStagePush(_stageNum)); \ 695204a6943SJed Brown } while (0) 696e9fa29b7SSatish Balay 697ad14c47eSJed Brown /* some vars for logging */ 698ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */ 699ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingOn; /* true if we are currently in a preloading calculation */ 700ad14c47eSJed Brown 701c708d6e3SStefano Zampini #if defined(PETSC_USE_LOG) && defined(PETSC_HAVE_DEVICE) 702c708d6e3SStefano Zampini 703c708d6e3SStefano Zampini /* Global GPU counters */ 704c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_ctog_ct; 705c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gtoc_ct; 706c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_ctog_sz; 707c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gtoc_sz; 708c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_ctog_ct_scalar; 709c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gtoc_ct_scalar; 710c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_ctog_sz_scalar; 711c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gtoc_sz_scalar; 712c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gflops; 713c708d6e3SStefano Zampini PETSC_EXTERN PetscLogDouble petsc_gtime; 714c708d6e3SStefano Zampini 715c708d6e3SStefano Zampini /* Thread local storage */ 716c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_ct_th; 717c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_ct_th; 718c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_sz_th; 719c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_sz_th; 720c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_ct_scalar_th; 721c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_ct_scalar_th; 722c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_sz_scalar_th; 723c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_sz_scalar_th; 724c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gflops_th; 725c708d6e3SStefano Zampini PETSC_EXTERN_TLS PetscLogDouble petsc_gtime_th; 726c708d6e3SStefano Zampini 727c708d6e3SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLogGpuTime(void); 728c708d6e3SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLogGpuTimeBegin(void); 729c708d6e3SStefano Zampini PETSC_EXTERN PetscErrorCode PetscLogGpuTimeEnd(void); 730c708d6e3SStefano Zampini 731c708d6e3SStefano Zampini /*@C 732c708d6e3SStefano Zampini PetscLogGpuFlops - Log how many flops are performed in a calculation on the device 733c708d6e3SStefano Zampini 734c708d6e3SStefano Zampini Input Parameter: 735c708d6e3SStefano Zampini . flops - the number of flops 736c708d6e3SStefano Zampini 737c200f75eSSatish Balay Level: intermediate 738c200f75eSSatish Balay 739c708d6e3SStefano Zampini Notes: 740c708d6e3SStefano Zampini To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double, 741c200f75eSSatish Balay not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n) 742c708d6e3SStefano Zampini 743c708d6e3SStefano Zampini The values are also added to the total flop count for the MPI rank that is set with `PetscLogFlops()`; hence the number of flops 744c708d6e3SStefano Zampini just on the CPU would be the value from set from `PetscLogFlops()` minus the value set from `PetscLogGpuFlops()` 745c708d6e3SStefano Zampini 746c200f75eSSatish Balay .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogFlops()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()` 747c708d6e3SStefano Zampini @*/ 748c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogGpuFlops(PetscLogDouble n) 749c708d6e3SStefano Zampini { 750c708d6e3SStefano Zampini PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops"); 7513ba16761SJacob Faibussowitsch PetscCall(PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n)); 7523ba16761SJacob Faibussowitsch PetscCall(PetscAddLogDouble(&petsc_gflops, &petsc_gflops_th, PETSC_FLOPS_PER_OP * n)); 7533ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 754c708d6e3SStefano Zampini } 755c708d6e3SStefano Zampini 756c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t) 757c708d6e3SStefano Zampini { 7583ba16761SJacob Faibussowitsch return PetscAddLogDouble(&petsc_gtime, &petsc_gtime_th, t); 759c708d6e3SStefano Zampini } 760c708d6e3SStefano Zampini 761c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size) 762c708d6e3SStefano Zampini { 7633ba16761SJacob Faibussowitsch return PetscAddLogDoubleCnt(&petsc_ctog_ct, &petsc_ctog_sz, &petsc_ctog_ct_th, &petsc_ctog_sz_th, size); 764c708d6e3SStefano Zampini } 765c708d6e3SStefano Zampini 766c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size) 767c708d6e3SStefano Zampini { 7683ba16761SJacob Faibussowitsch return PetscAddLogDoubleCnt(&petsc_gtoc_ct, &petsc_gtoc_sz, &petsc_gtoc_ct_th, &petsc_gtoc_sz_th, size); 769c708d6e3SStefano Zampini } 770c708d6e3SStefano Zampini 771c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogCpuToGpuScalar(PetscLogDouble size) 772c708d6e3SStefano Zampini { 7733ba16761SJacob Faibussowitsch return PetscAddLogDoubleCnt(&petsc_ctog_ct_scalar, &petsc_ctog_sz_scalar, &petsc_ctog_ct_scalar_th, &petsc_ctog_sz_scalar_th, size); 774c708d6e3SStefano Zampini } 775c708d6e3SStefano Zampini 776c708d6e3SStefano Zampini static inline PetscErrorCode PetscLogGpuToCpuScalar(PetscLogDouble size) 777c708d6e3SStefano Zampini { 7783ba16761SJacob Faibussowitsch return PetscAddLogDoubleCnt(&petsc_gtoc_ct_scalar, &petsc_gtoc_sz_scalar, &petsc_gtoc_ct_scalar_th, &petsc_gtoc_sz_scalar_th, size); 779c708d6e3SStefano Zampini } 780c708d6e3SStefano Zampini #else 781c708d6e3SStefano Zampini 7823ba16761SJacob Faibussowitsch #define PetscLogCpuToGpu(a) PETSC_SUCCESS 7833ba16761SJacob Faibussowitsch #define PetscLogGpuToCpu(a) PETSC_SUCCESS 7843ba16761SJacob Faibussowitsch #define PetscLogCpuToGpuScalar(a) PETSC_SUCCESS 7853ba16761SJacob Faibussowitsch #define PetscLogGpuToCpuScalar(a) PETSC_SUCCESS 7863ba16761SJacob Faibussowitsch #define PetscLogGpuFlops(a) PETSC_SUCCESS 7873ba16761SJacob Faibussowitsch #define PetscLogGpuTime() PETSC_SUCCESS 7883ba16761SJacob Faibussowitsch #define PetscLogGpuTimeAdd(a) PETSC_SUCCESS 7893ba16761SJacob Faibussowitsch #define PetscLogGpuTimeBegin() PETSC_SUCCESS 7903ba16761SJacob Faibussowitsch #define PetscLogGpuTimeEnd() PETSC_SUCCESS 791c708d6e3SStefano Zampini 792c708d6e3SStefano Zampini #endif /* PETSC_USE_LOG && PETSC_HAVE_DEVICE */ 793c708d6e3SStefano Zampini 794c708d6e3SStefano Zampini /* remove TLS defines */ 795c708d6e3SStefano Zampini #undef PETSC_EXTERN_TLS 796c708d6e3SStefano Zampini #undef PETSC_TLS 797c708d6e3SStefano Zampini 79897bb86f7SLois Curfman McInnes #endif 799