197bb86f7SLois Curfman McInnes /* 27588ac45SBarry Smith Defines profile/logging in PETSc. 397bb86f7SLois Curfman McInnes */ 497bb86f7SLois Curfman McInnes 5b0a32e0cSBarry Smith #if !defined(__PetscLog_H) 6b0a32e0cSBarry Smith #define __PetscLog_H 7d382aafbSBarry Smith #include "petscsys.h" 8c8d78d4dSSatish Balay 9b859824cSBarry Smith /*MC 10b859824cSBarry Smith PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable) 11b859824cSBarry Smith code. 12b859824cSBarry Smith 13b859824cSBarry Smith Level: intermediate 14b859824cSBarry Smith 15b859824cSBarry Smith .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage 16b859824cSBarry Smith M*/ 17b859824cSBarry Smith typedef int PetscLogEvent; 18b859824cSBarry Smith 19b859824cSBarry Smith /*MC 20b859824cSBarry Smith PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging 21b859824cSBarry Smith 22b859824cSBarry Smith Level: intermediate 23b859824cSBarry Smith 24b859824cSBarry Smith .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent 25b859824cSBarry Smith M*/ 26b859824cSBarry Smith typedef int PetscLogStage; 27b859824cSBarry Smith 288ba1e511SMatthew Knepley #define PETSC_EVENT 1311311 29014dd563SJed Brown PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT; 3097bb86f7SLois Curfman McInnes 3119b02663SBarry Smith /* Global flop counter */ 32014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_TotalFlops; 33014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_tmp_flops; 3419b02663SBarry Smith 35edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */ 36014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],void*,const char[],...); 376cf91177SBarry Smith #if defined(PETSC_USE_INFO) 382714b66aSJed Brown #define PetscInfo(A,S) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S) 392714b66aSJed Brown #define PetscInfo1(A,S,a1) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1) 402714b66aSJed Brown #define PetscInfo2(A,S,a1,a2) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2) 412714b66aSJed Brown #define PetscInfo3(A,S,a1,a2,a3) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3) 422714b66aSJed Brown #define PetscInfo4(A,S,a1,a2,a3,a4) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4) 432714b66aSJed Brown #define PetscInfo5(A,S,a1,a2,a3,a4,a5) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5) 442714b66aSJed Brown #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6) 452714b66aSJed Brown #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6,a7) 4663ba0a88SBarry Smith #else 47ae15b995SBarry Smith #define PetscInfo(A,S) 0 48ae15b995SBarry Smith #define PetscInfo1(A,S,a1) 0 49ae15b995SBarry Smith #define PetscInfo2(A,S,a1,a2) 0 50ae15b995SBarry Smith #define PetscInfo3(A,S,a1,a2,a3) 0 51ae15b995SBarry Smith #define PetscInfo4(A,S,a1,a2,a3,a4) 0 52ae15b995SBarry Smith #define PetscInfo5(A,S,a1,a2,a3,a4,a5) 0 53ae15b995SBarry Smith #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) 0 54ae15b995SBarry Smith #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0 5563ba0a88SBarry Smith #endif 56014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId); 57014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId); 58014dd563SJed Brown PETSC_EXTERN PetscBool PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */ 59614700edSBarry Smith 6031d06abdSBarry Smith /* We must make the following structures available to access the event 6131d06abdSBarry Smith activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public 6231d06abdSBarry Smith API and are not intended to be used by other parts of PETSc or by users. 63d49d4b11SBarry Smith 6431d06abdSBarry Smith The code that manipulates these structures is in src/sys/plog/utils. 6531d06abdSBarry Smith */ 66aa213bdcSJed Brown typedef struct _n_PetscIntStack *PetscIntStack; 676a6a9b46SSatish Balay 68c60ec953SBarry Smith /* 69aa213bdcSJed Brown PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has 70c60ec953SBarry Smith static information about it, the second collects statistics on how many objects of the class are created, 71c60ec953SBarry Smith how much memory they use, etc. 72c60ec953SBarry Smith 73aa213bdcSJed Brown PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes. 74c60ec953SBarry Smith */ 756a6a9b46SSatish Balay typedef struct { 76c60ec953SBarry Smith char *name; /* The class name */ 77c60ec953SBarry Smith PetscClassId classid; /* The integer identifying this class */ 78aa213bdcSJed Brown } PetscClassRegInfo; 796a6a9b46SSatish Balay 806a6a9b46SSatish Balay typedef struct { 810700a824SBarry Smith PetscClassId id; /* The integer identifying this class */ 826a6a9b46SSatish Balay int creations; /* The number of objects of this class created */ 836a6a9b46SSatish Balay int destructions; /* The number of objects of this class destroyed */ 846a6a9b46SSatish Balay PetscLogDouble mem; /* The total memory allocated by objects of this class */ 856a6a9b46SSatish Balay PetscLogDouble descMem; /* The total memory allocated by descendents of these objects */ 86aa213bdcSJed Brown } PetscClassPerfInfo; 876a6a9b46SSatish Balay 88aa213bdcSJed Brown typedef struct _n_PetscClassRegLog *PetscClassRegLog; 89aa213bdcSJed Brown struct _n_PetscClassRegLog { 90c60ec953SBarry Smith int numClasses; /* The number of classes registered */ 91c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 92aa213bdcSJed Brown PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 93c60ec953SBarry Smith }; 946a6a9b46SSatish Balay 95aa213bdcSJed Brown typedef struct _n_PetscClassPerfLog *PetscClassPerfLog; 96aa213bdcSJed Brown struct _n_PetscClassPerfLog { 97c60ec953SBarry Smith int numClasses; /* The number of logging classes */ 98c60ec953SBarry Smith int maxClasses; /* The maximum number of classes */ 99aa213bdcSJed Brown PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 100c60ec953SBarry Smith }; 101c60ec953SBarry Smith /* -----------------------------------------------------------------------------------------------------*/ 102c60ec953SBarry Smith /* 103aa213bdcSJed Brown PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has 104c60ec953SBarry Smith static information about it, the second collects statistics on how many times the event is used, how 105c60ec953SBarry Smith much time it takes, etc. 106c60ec953SBarry Smith 107aa213bdcSJed Brown PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one 108c60ec953SBarry Smith of these for each stage. 109c60ec953SBarry Smith 110c60ec953SBarry Smith */ 1116a6a9b46SSatish Balay typedef struct { 1126a6a9b46SSatish Balay char *name; /* The name of this event */ 113c60ec953SBarry Smith PetscClassId classid; /* The class the event is associated with */ 1146a6a9b46SSatish Balay #if defined (PETSC_HAVE_MPE) 1156a6a9b46SSatish Balay int mpe_id_begin; /* MPE IDs that define the event */ 1166a6a9b46SSatish Balay int mpe_id_end; 1176a6a9b46SSatish Balay #endif 118aa213bdcSJed Brown } PetscEventRegInfo; 1196a6a9b46SSatish Balay 120c60ec953SBarry Smith typedef struct { 121c60ec953SBarry Smith int id; /* The integer identifying this event */ 122ace3abfcSBarry Smith PetscBool active; /* The flag to activate logging */ 123ace3abfcSBarry Smith PetscBool visible; /* The flag to print info in summary */ 124c60ec953SBarry Smith int depth; /* The nesting depth of the event call */ 125c60ec953SBarry Smith int count; /* The number of times this event was executed */ 126a42e5b54SMatthew G Knepley PetscLogDouble flops, flops2,flopsTmp; /* The flops and flops^2 used in this event */ 127a42e5b54SMatthew G Knepley PetscLogDouble time, time2, timeTmp; /* The time and time^2 taken for this event */ 128c60ec953SBarry Smith PetscLogDouble numMessages; /* The number of messages in this event */ 129c60ec953SBarry Smith PetscLogDouble messageLength; /* The total message lengths in this event */ 130c60ec953SBarry Smith PetscLogDouble numReductions; /* The number of reductions in this event */ 131aa213bdcSJed Brown } PetscEventPerfInfo; 132c60ec953SBarry Smith 133aa213bdcSJed Brown typedef struct _n_PetscEventRegLog *PetscEventRegLog; 134aa213bdcSJed Brown struct _n_PetscEventRegLog { 1356a6a9b46SSatish Balay int numEvents; /* The number of registered events */ 1366a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 137aa213bdcSJed Brown PetscEventRegInfo *eventInfo; /* The registration information for each event */ 1386a6a9b46SSatish Balay }; 1396a6a9b46SSatish Balay 140aa213bdcSJed Brown typedef struct _n_PetscEventPerfLog *PetscEventPerfLog; 141aa213bdcSJed Brown struct _n_PetscEventPerfLog { 1426a6a9b46SSatish Balay int numEvents; /* The number of logging events */ 1436a6a9b46SSatish Balay int maxEvents; /* The maximum number of events */ 144aa213bdcSJed Brown PetscEventPerfInfo *eventInfo; /* The performance information for each event */ 1456a6a9b46SSatish Balay }; 146c60ec953SBarry Smith /* ------------------------------------------------------------------------------------------------------------*/ 147c60ec953SBarry Smith /* 148aa213bdcSJed Brown PetscStageInfo - Contains all the information about a particular stage. 1496a6a9b46SSatish Balay 150aa213bdcSJed Brown PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code. 151c60ec953SBarry Smith */ 152aa213bdcSJed Brown typedef struct _PetscStageInfo { 1536a6a9b46SSatish Balay char *name; /* The stage name */ 154ace3abfcSBarry Smith PetscBool used; /* The stage was pushed on this processor */ 155aa213bdcSJed Brown PetscEventPerfInfo perfInfo; /* The stage performance information */ 156aa213bdcSJed Brown PetscEventPerfLog eventLog; /* The event information for this stage */ 157aa213bdcSJed Brown PetscClassPerfLog classLog; /* The class information for this stage */ 158aa213bdcSJed Brown } PetscStageInfo; 1596a6a9b46SSatish Balay 160aa213bdcSJed Brown typedef struct _n_PetscStageLog *PetscStageLog; 161014dd563SJed Brown PETSC_EXTERN PetscStageLog petsc_stageLog; 162aa213bdcSJed Brown struct _n_PetscStageLog { 1636a6a9b46SSatish Balay int numStages; /* The number of registered stages */ 1646a6a9b46SSatish Balay int maxStages; /* The maximum number of stages */ 165aa213bdcSJed Brown PetscIntStack stack; /* The stack for active stages */ 166aa213bdcSJed Brown int curStage; /* The current stage (only used in macros so we don't call PetscIntStackTop) */ 167aa213bdcSJed Brown PetscStageInfo *stageInfo; /* The information for each stage */ 168aa213bdcSJed Brown PetscEventRegLog eventLog; /* The registered events */ 169aa213bdcSJed Brown PetscClassRegLog classLog; /* The registered classes */ 1706a6a9b46SSatish Balay }; 1716a6a9b46SSatish Balay 172fee518ebSJed Brown PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog*); 173fee518ebSJed Brown PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog,int*); 174fee518ebSJed Brown PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog,int,PetscEventPerfLog*); 175fee518ebSJed Brown 176fee518ebSJed Brown 177aa482453SBarry Smith #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 178614700edSBarry Smith 179da63de55SLois Curfman McInnes /* 180da63de55SLois Curfman McInnes Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 181da63de55SLois Curfman McInnes 182da63de55SLois Curfman McInnes For the complex numbers version, note that 183da63de55SLois Curfman McInnes 1 complex addition = 2 flops 184da63de55SLois Curfman McInnes 1 complex multiplication = 6 flops, 185da63de55SLois Curfman McInnes where we define 1 flop as that for a double precision scalar. We roughly approximate 186da63de55SLois Curfman McInnes flop counting for complex numbers by multiplying the total flops by 4; this corresponds 187da63de55SLois Curfman McInnes to the assumption that we're counting mostly additions and multiplications -- and 188da63de55SLois Curfman McInnes roughly the same number of each. More accurate counting could be done by distinguishing 189da63de55SLois Curfman McInnes among the various arithmetic operations. 190da63de55SLois Curfman McInnes */ 191da63de55SLois Curfman McInnes 192aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 193542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0 194da63de55SLois Curfman McInnes #else 195542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0 196bf3909cdSBarry Smith #endif 197bf3909cdSBarry Smith 198dd19b90bSBarry Smith #undef __FUNCT__ 199dd19b90bSBarry Smith #define __FUNCT__ "PetscLogFlops" 200dd19b90bSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n) 201dd19b90bSBarry Smith { 202dd19b90bSBarry Smith PetscFunctionBegin; 203bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG) 204dd19b90bSBarry Smith if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 205da63de55SLois Curfman McInnes #endif 206dd19b90bSBarry Smith petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 207dd19b90bSBarry Smith PetscFunctionReturn(0); 208dd19b90bSBarry Smith } 20977c4ece6SBarry Smith 210aa482453SBarry Smith #if defined (PETSC_HAVE_MPE) 211014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 212014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 21377c4ece6SBarry Smith #endif 21477c4ece6SBarry Smith 215014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 216014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 217014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 218014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 21977c4ece6SBarry Smith 220043328b6SSatish Balay #define PetscLogObjectParent(p,c) \ 221e0f8cd26SJed Brown (c && p && (((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id,0)) 22252e6d16bSBarry Smith 223efee365bSSatish Balay #define PetscLogObjectParents(p,n,d) 0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}} 2248b5db460SBarry Smith #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)h) : 0) 2258b5db460SBarry Smith #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)h) : 0) 22652e6d16bSBarry Smith #define PetscLogObjectMemory(p,m) (((PetscObject)(p))->mem += (m),0) 2278ba1e511SMatthew Knepley /* Initialization functions */ 228014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogBegin(void); 229014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 230014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 232014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 2338ba1e511SMatthew Knepley /* General functions */ 234014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDestroy(void); 235014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 2366849ba73SBarry Smith PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 237014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...); 2388ba1e511SMatthew Knepley /* Output functions */ 239014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 240014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogViewPython(PetscViewer); 241014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogPrintDetailed(MPI_Comm, const char[]); 242014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 24331d06abdSBarry Smith 244014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 24531d06abdSBarry Smith 246014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*); 247014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 248014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 249014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool ); 250014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *); 251014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool ); 252014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *); 253014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char [], PetscLogStage *); 2548ba1e511SMatthew Knepley /* Event functions */ 255014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*); 256014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 257014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 258014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool ); 259014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 260014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 2619afaeae2SBarry Smith 2628ba1e511SMatthew Knepley 2638ba1e511SMatthew Knepley /* Global counters */ 264014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 265014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_ct; 266014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_ct; 267014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_ct; 268014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_len; 269014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_len; 270014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_len; 271014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_len; 272014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 273014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_gather_ct; 274014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 275014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_ct; 276014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 277014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 278014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 2798ba1e511SMatthew Knepley 28052e6d16bSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \ 2818b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 28252e6d16bSBarry Smith (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \ 28352e6d16bSBarry Smith PetscLogEventBegin((e)+1,o1,o2,o3,o4)) 28477c4ece6SBarry Smith 28552e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 2868b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 287*495fc317SBarry Smith (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 )) 288043328b6SSatish Balay 289b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4) 290043328b6SSatish Balay 29152e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 2928b5db460SBarry Smith (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 293*495fc317SBarry Smith (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 )) 29477c4ece6SBarry Smith 295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*); 296014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 297003131ecSBarry Smith 298ce85283eSBarry Smith /* 299f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 300f621e05eSBarry Smith their sizes. 301f621e05eSBarry Smith 3023c94ec11SBarry Smith This does not work for MPI-Uni because our include/mpiuni/mpi.h file 303ce85283eSBarry Smith uses macros to defined the MPI operations. 30415308354SBarry Smith 30515308354SBarry Smith It does not work correctly from HP-UX because it processes the 306bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 307b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 3087c1e34a4SSatish Balay 309f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 310ce85283eSBarry Smith */ 311c8217ed5SSatish Balay #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 31277a39924SBarry Smith /* 31377a39924SBarry Smith Logging of MPI activities 31477a39924SBarry Smith */ 315ad39c06fSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type) 316f95db71bSBarry Smith { 317618e35e3SBarry Smith PetscMPIInt mysize; return (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0)); 318f95db71bSBarry Smith } 31977a39924SBarry Smith 320ad39c06fSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, PetscLogDouble *buff,PetscMPIInt *counts,MPI_Datatype type) 3213b9284c0SMatthew G Knepley { 3223b9284c0SMatthew G Knepley PetscMPIInt mysize, commsize, p; 3233b9284c0SMatthew G Knepley PetscErrorCode _myierr; 3243b9284c0SMatthew G Knepley 3253b9284c0SMatthew G Knepley _myierr = MPI_Comm_size(comm,&commsize);CHKERRQ(_myierr); 3263b9284c0SMatthew G Knepley _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr); 3273b9284c0SMatthew G Knepley for (p = 0; p < commsize; ++p) { 3283b9284c0SMatthew G Knepley *buff += (PetscLogDouble) (counts[p]*mysize); 3293b9284c0SMatthew G Knepley } 3303b9284c0SMatthew G Knepley return 0; 3313b9284c0SMatthew G Knepley } 3323b9284c0SMatthew G Knepley 33377a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 334ad39c06fSJed Brown ((petsc_irecv_ct++,0) || PetscMPITypeSize(&petsc_irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request)) 33515308354SBarry Smith 33677a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 337ad39c06fSJed Brown ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request)) 33815308354SBarry Smith 3390d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \ 340ad39c06fSJed Brown ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 3410d4b0b6cSBarry Smith 3420d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \ 343ad39c06fSJed Brown ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 3440d4b0b6cSBarry Smith 3450d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \ 346ad39c06fSJed Brown ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Start(requests)) 3470d4b0b6cSBarry Smith 348ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 349ad39c06fSJed Brown ((petsc_recv_ct++,0) || PetscMPITypeSize(&petsc_recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status)) 35015308354SBarry Smith 35177a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 352ad39c06fSJed Brown ((petsc_send_ct++,0) || PetscMPITypeSize(&petsc_send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm)) 35377a39924SBarry Smith 35477a39924SBarry Smith #define MPI_Wait(request,status) \ 355ad39c06fSJed Brown ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait(request,status)) 35677a39924SBarry Smith 35777a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \ 358ad39c06fSJed Brown ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d)) 35977a39924SBarry Smith 36077a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 361ad39c06fSJed Brown ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses)) 36277a39924SBarry Smith 36377a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 364ad39c06fSJed Brown ((petsc_allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)) 3653914022bSBarry Smith 3663b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 367ad39c06fSJed Brown ((petsc_allreduce_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 3683b9284c0SMatthew G Knepley 3693b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 370ad39c06fSJed Brown ((petsc_allreduce_ct++,0) || PetscMPITypeSizeComm(comm,&petsc_send_len,sendcnts,sendtype) || MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm)) 3713b9284c0SMatthew G Knepley 37201faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 373ad39c06fSJed Brown ((petsc_gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 37401faf4e4SMatthew Knepley 37501faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 376ad39c06fSJed Brown ((petsc_gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm)) 37701faf4e4SMatthew Knepley 37801faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 379ad39c06fSJed Brown ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 38001faf4e4SMatthew Knepley 38101faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 382ad39c06fSJed Brown ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm)) 38301faf4e4SMatthew Knepley 38401faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 385ad39c06fSJed Brown ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 38601faf4e4SMatthew Knepley 38701faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 388ad39c06fSJed Brown ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm)) 38901faf4e4SMatthew Knepley 3900d4b0b6cSBarry Smith #else 3910d4b0b6cSBarry Smith 3920d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \ 3935e3723c6SSatish Balay (MPI_Startall(number,requests)) 3940d4b0b6cSBarry Smith 3950d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \ 3965e3723c6SSatish Balay (MPI_Startall(number,requests)) 3970d4b0b6cSBarry Smith 3980d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \ 3995e3723c6SSatish Balay (MPI_Start(requests)) 4000d4b0b6cSBarry Smith 401c8217ed5SSatish Balay #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 402614700edSBarry Smith 403df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 404614700edSBarry Smith 405b0a32e0cSBarry Smith #define PetscLogFlops(n) 0 406614700edSBarry Smith 407b0a32e0cSBarry Smith #define PetscLogEventActivate(a) 0 408b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0 409614700edSBarry Smith 410b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a) 0 411b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0 412e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b) 0 41377c4ece6SBarry Smith 4148b5db460SBarry Smith #define PetscLogPLB 0 4158b5db460SBarry Smith #define PetscLogPLE 0 4168b5db460SBarry Smith #define PetscLogPHC 0 4178b5db460SBarry Smith #define PetscLogPHD 0 41899de4ba8SSatish Balay #define PetscGetFlops(a) (*(a) = 0.0,0) 419b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 420b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 421b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0 422b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) 0 42352e6d16bSBarry Smith #define PetscLogObjectParent(p,c) 0 424efee365bSSatish Balay #define PetscLogObjectParents(p,n,c) 0 42552e6d16bSBarry Smith #define PetscLogObjectCreate(h) 0 42652e6d16bSBarry Smith #define PetscLogObjectDestroy(h) 0 42752e6d16bSBarry Smith #define PetscLogObjectMemory(p,m) 0 428b0a32e0cSBarry Smith #define PetscLogDestroy() 0 429b0a32e0cSBarry Smith #define PetscLogStagePush(a) 0 430b0a32e0cSBarry Smith #define PetscLogStagePop() 0 431b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b) 0 432b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg) 0 43391eabc43SBarry Smith #define PetscLogView(viewer) 0 43491eabc43SBarry Smith #define PetscLogViewPython(viewer) 0 43578392ef1SBarry Smith #define PetscLogPrintDetailed(comm,file) 0 436b0a32e0cSBarry Smith #define PetscLogBegin() 0 437b0a32e0cSBarry Smith #define PetscLogTraceBegin(file) 0 438b0a32e0cSBarry Smith #define PetscLogSet(lb,le) 0 439b0a32e0cSBarry Smith #define PetscLogAllBegin() 0 440b0a32e0cSBarry Smith #define PetscLogDump(c) 0 441043328b6SSatish Balay #define PetscLogEventRegister(a,b,c) 0 44273fda44aSBarry Smith #define PetscLogObjects(a) 0 44373fda44aSBarry Smith #define PetscLogActions(a) 0 444014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...); 445ce6058e1SBarry Smith 446aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 447ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests) 448ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests) 449ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests) 450fad68dfaSSatish Balay #define PetscLogStageGetId(a,b) (*(b)=0,0) 451fad68dfaSSatish Balay #define PetscLogStageSetActive(a,b) 0 4526a6a9b46SSatish Balay #define PetscLogStageGetActive(a,b) 0 4536a6a9b46SSatish Balay #define PetscLogStageGetVisible(a,b) 0 4546a6a9b46SSatish Balay #define PetscLogStageSetVisible(a,b) 0 455f141ce34SMatthew Knepley 456aa482453SBarry Smith #endif /* PETSC_USE_LOG */ 4576daaf66cSBarry Smith 458014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *); 459014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack); 460014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int); 461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *); 462014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *); 463014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *); 464fcfd50ebSBarry Smith 465bf5c43c7SMatthew Knepley /* Special support for C++ */ 4662c280183SJed Brown #if defined(PETSC_CLANGUAGE_CXX) && defined(__cplusplus) 4672c8e378dSBarry Smith #include <petsclog.hh> 4682c8e378dSBarry Smith #endif 469bf5c43c7SMatthew Knepley 470204a6943SJed Brown #define PetscPreLoadBegin(flag,name) \ 471204a6943SJed Brown do {\ 472204a6943SJed Brown PetscBool PetscPreLoading = flag;\ 473204a6943SJed Brown int PetscPreLoadMax,PetscPreLoadIt;\ 474166c7f25SBarry Smith PetscLogStage _stageNum;\ 4758cbcd9ccSBarry Smith PetscErrorCode _3_ierr; \ 4760298fd71SBarry Smith _3_ierr = PetscOptionsGetBool(NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr);\ 477204a6943SJed Brown PetscPreLoadMax = (int)(PetscPreLoading);\ 478204a6943SJed Brown PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 479204a6943SJed Brown for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\ 480204a6943SJed Brown PetscPreLoadingOn = PetscPreLoading;\ 4810298fd71SBarry Smith _3_ierr = PetscBarrier(NULL);CHKERRQ(_3_ierr);\ 482204a6943SJed Brown if (PetscPreLoadIt>0) {\ 4838e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 4848e58c17dSMatthew Knepley } else {\ 485a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 4868e58c17dSMatthew Knepley }\ 487204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\ 4888e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 4898e58c17dSMatthew Knepley 490204a6943SJed Brown #define PetscPreLoadEnd() \ 491043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 492204a6943SJed Brown PetscPreLoading = PETSC_FALSE;\ 493043328b6SSatish Balay }\ 494204a6943SJed Brown } while (0) 4958e58c17dSMatthew Knepley 496204a6943SJed Brown #define PetscPreLoadStage(name) do { \ 497043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr); \ 498204a6943SJed Brown if (PetscPreLoadIt>0) { \ 4998e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr); \ 5008e58c17dSMatthew Knepley } else { \ 501a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 5028e58c17dSMatthew Knepley } \ 503204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \ 504204a6943SJed Brown _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); \ 505204a6943SJed Brown } while (0) 506e9fa29b7SSatish Balay 507ad14c47eSJed Brown /* some vars for logging */ 508ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */ 509ad14c47eSJed Brown PETSC_EXTERN PetscBool PetscPreLoadingOn; /* true if we are currently in a preloading calculation */ 510ad14c47eSJed Brown 51197bb86f7SLois Curfman McInnes #endif 512