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 29*014dd563SJed Brown PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT; 3097bb86f7SLois Curfman McInnes 3119b02663SBarry Smith /* Global flop counter */ 32*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_TotalFlops; 33*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_tmp_flops; 3419b02663SBarry Smith 35edde42fcSLois Curfman McInnes /* General logging of information; different from event logging */ 36*014dd563SJed 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 56*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId); 57*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId); 58*014dd563SJed 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 */ 126c60ec953SBarry Smith PetscLogDouble flops; /* The flops used in this event */ 127c60ec953SBarry Smith PetscLogDouble time; /* The time 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; 161*014dd563SJed 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 172aa482453SBarry Smith #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 173614700edSBarry Smith 174da63de55SLois Curfman McInnes /* 175da63de55SLois Curfman McInnes Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 176da63de55SLois Curfman McInnes 177da63de55SLois Curfman McInnes For the complex numbers version, note that 178da63de55SLois Curfman McInnes 1 complex addition = 2 flops 179da63de55SLois Curfman McInnes 1 complex multiplication = 6 flops, 180da63de55SLois Curfman McInnes where we define 1 flop as that for a double precision scalar. We roughly approximate 181da63de55SLois Curfman McInnes flop counting for complex numbers by multiplying the total flops by 4; this corresponds 182da63de55SLois Curfman McInnes to the assumption that we're counting mostly additions and multiplications -- and 183da63de55SLois Curfman McInnes roughly the same number of each. More accurate counting could be done by distinguishing 184da63de55SLois Curfman McInnes among the various arithmetic operations. 185da63de55SLois Curfman McInnes */ 186da63de55SLois Curfman McInnes 187aa482453SBarry Smith #if defined(PETSC_USE_COMPLEX) 188542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 4.0 189da63de55SLois Curfman McInnes #else 190542d4b3fSSatish Balay #define PETSC_FLOPS_PER_OP 1.0 191bf3909cdSBarry Smith #endif 192bf3909cdSBarry Smith 193bf3909cdSBarry Smith #if defined(PETSC_USE_DEBUG) 194205a32c2SJed Brown #define PetscLogFlops(n) (petsc_tmp_flops = (PETSC_FLOPS_PER_OP*((PetscLogDouble)n)), ((petsc_tmp_flops < 0) ? PETSC_ERR_FLOP_COUNT : (petsc_TotalFlops += petsc_tmp_flops,0))) 195205a32c2SJed Brown #define PetscLogFlopsNoError(n) (petsc_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n)) 196bf3909cdSBarry Smith #else 197205a32c2SJed Brown #define PetscLogFlops(n) (petsc_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n),0) 198205a32c2SJed Brown #define PetscLogFlopsNoError(n) (petsc_TotalFlops += PETSC_FLOPS_PER_OP*((PetscLogDouble)n)) 199da63de55SLois Curfman McInnes #endif 20077c4ece6SBarry Smith 201aa482453SBarry Smith #if defined (PETSC_HAVE_MPE) 20277c4ece6SBarry Smith #include "mpe.h" 203*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 204*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 205*014dd563SJed Brown PETSC_EXTERN PetscBool UseMPE; 206043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_BEGIN(e) \ 207205a32c2SJed Brown ((UseMPE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 208205a32c2SJed Brown MPE_Log_event(petsc_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0) 209043328b6SSatish Balay 210043328b6SSatish Balay #define PETSC_LOG_EVENT_MPE_END(e) \ 211205a32c2SJed Brown ((UseMPE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 212205a32c2SJed Brown MPE_Log_event(petsc_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0) 213043328b6SSatish Balay 214614700edSBarry Smith #else 21552e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0 21652e6d16bSBarry Smith #define PETSC_LOG_EVENT_MPE_END(e) 0 21777c4ece6SBarry Smith #endif 21877c4ece6SBarry Smith 219*014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 220*014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 221*014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 222*014dd563SJed Brown PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 22377c4ece6SBarry Smith 224043328b6SSatish Balay #define PetscLogObjectParent(p,c) \ 225e0f8cd26SJed Brown (c && p && (((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id,0)) 22652e6d16bSBarry Smith 227efee365bSSatish Balay #define PetscLogObjectParents(p,n,d) 0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}} 2288b5db460SBarry Smith #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)h) : 0) 2298b5db460SBarry Smith #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)h) : 0) 23052e6d16bSBarry Smith #define PetscLogObjectMemory(p,m) (((PetscObject)(p))->mem += (m),0) 2318ba1e511SMatthew Knepley /* Initialization functions */ 232*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogBegin(void); 233*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 234*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 235*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 236*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 2378ba1e511SMatthew Knepley /* General functions */ 238*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogGetRGBColor(const char*[]); 239*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDestroy(void); 240*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 2416849ba73SBarry Smith PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 242*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...); 2438ba1e511SMatthew Knepley /* Output functions */ 244*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 245*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogViewPython(PetscViewer); 246*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogPrintDetailed(MPI_Comm, const char[]); 247*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 24831d06abdSBarry Smith 249*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 25031d06abdSBarry Smith 251*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*); 252*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 253*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 254*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool ); 255*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *); 256*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool ); 257*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *); 258*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char [], PetscLogStage *); 2598ba1e511SMatthew Knepley /* Event functions */ 260*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*); 261*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 262*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 263*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool ); 264*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 265*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 2669afaeae2SBarry Smith 2678ba1e511SMatthew Knepley 2688ba1e511SMatthew Knepley /* Global counters */ 269*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 270*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_ct; 271*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_ct; 272*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_ct; 273*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_irecv_len; 274*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_isend_len; 275*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_recv_len; 276*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_send_len; 277*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 278*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_gather_ct; 279*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 280*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_ct; 281*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 282*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 283*014dd563SJed Brown PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 2848ba1e511SMatthew Knepley 28552e6d16bSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \ 2868b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 28752e6d16bSBarry Smith (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \ 28852e6d16bSBarry Smith PetscLogEventBegin((e)+1,o1,o2,o3,o4)) 28977c4ece6SBarry Smith 29052e6d16bSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 2918b5db460SBarry Smith (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 2928b5db460SBarry Smith (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \ 29352e6d16bSBarry Smith PETSC_LOG_EVENT_MPE_BEGIN(e)) 294043328b6SSatish Balay 295b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4) 296043328b6SSatish Balay 29752e6d16bSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 2988b5db460SBarry Smith (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 2998b5db460SBarry Smith (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \ 30052e6d16bSBarry Smith PETSC_LOG_EVENT_MPE_END(e)) 30177c4ece6SBarry Smith 302*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*); 303*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 304003131ecSBarry Smith 305ce85283eSBarry Smith /* 306f621e05eSBarry Smith These are used internally in the PETSc routines to keep a count of MPI messages and 307f621e05eSBarry Smith their sizes. 308f621e05eSBarry Smith 3093c94ec11SBarry Smith This does not work for MPI-Uni because our include/mpiuni/mpi.h file 310ce85283eSBarry Smith uses macros to defined the MPI operations. 31115308354SBarry Smith 31215308354SBarry Smith It does not work correctly from HP-UX because it processes the 313bb4af37aSBarry Smith macros in a way that sometimes it double counts, hence 314b6410449SSatish Balay PETSC_HAVE_BROKEN_RECURSIVE_MACRO 3157c1e34a4SSatish Balay 316f569fd43SBarry Smith It does not work with Windows because winmpich lacks MPI_Type_size() 317ce85283eSBarry Smith */ 318c8217ed5SSatish Balay #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 31977a39924SBarry Smith /* 32077a39924SBarry Smith Logging of MPI activities 32177a39924SBarry Smith */ 322ad39c06fSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type) 323f95db71bSBarry Smith { 324618e35e3SBarry Smith PetscMPIInt mysize; return (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0)); 325f95db71bSBarry Smith } 32677a39924SBarry Smith 327ad39c06fSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, PetscLogDouble *buff,PetscMPIInt *counts,MPI_Datatype type) 3283b9284c0SMatthew G Knepley { 3293b9284c0SMatthew G Knepley PetscMPIInt mysize, commsize, p; 3303b9284c0SMatthew G Knepley PetscErrorCode _myierr; 3313b9284c0SMatthew G Knepley 3323b9284c0SMatthew G Knepley _myierr = MPI_Comm_size(comm,&commsize);CHKERRQ(_myierr); 3333b9284c0SMatthew G Knepley _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr); 3343b9284c0SMatthew G Knepley for(p = 0; p < commsize; ++p) { 3353b9284c0SMatthew G Knepley *buff += (PetscLogDouble) (counts[p]*mysize); 3363b9284c0SMatthew G Knepley } 3373b9284c0SMatthew G Knepley return 0; 3383b9284c0SMatthew G Knepley } 3393b9284c0SMatthew G Knepley 34077a39924SBarry Smith #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 341ad39c06fSJed Brown ((petsc_irecv_ct++,0) || PetscMPITypeSize(&petsc_irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request)) 34215308354SBarry Smith 34377a39924SBarry Smith #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 344ad39c06fSJed Brown ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request)) 34515308354SBarry Smith 3460d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \ 347ad39c06fSJed Brown ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 3480d4b0b6cSBarry Smith 3490d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \ 350ad39c06fSJed Brown ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 3510d4b0b6cSBarry Smith 3520d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \ 353ad39c06fSJed Brown ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Start(requests)) 3540d4b0b6cSBarry Smith 355ce85283eSBarry Smith #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 356ad39c06fSJed Brown ((petsc_recv_ct++,0) || PetscMPITypeSize(&petsc_recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status)) 35715308354SBarry Smith 35877a39924SBarry Smith #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 359ad39c06fSJed Brown ((petsc_send_ct++,0) || PetscMPITypeSize(&petsc_send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm)) 36077a39924SBarry Smith 36177a39924SBarry Smith #define MPI_Wait(request,status) \ 362ad39c06fSJed Brown ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait(request,status)) 36377a39924SBarry Smith 36477a39924SBarry Smith #define MPI_Waitany(a,b,c,d) \ 365ad39c06fSJed Brown ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d)) 36677a39924SBarry Smith 36777a39924SBarry Smith #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 368ad39c06fSJed Brown ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses)) 36977a39924SBarry Smith 37077a39924SBarry Smith #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 371ad39c06fSJed Brown ((petsc_allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)) 3723914022bSBarry Smith 3733b9284c0SMatthew G Knepley #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 374ad39c06fSJed Brown ((petsc_allreduce_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 3753b9284c0SMatthew G Knepley 3763b9284c0SMatthew G Knepley #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 377ad39c06fSJed Brown ((petsc_allreduce_ct++,0) || PetscMPITypeSizeComm(comm,&petsc_send_len,sendcnts,sendtype) || MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm)) 3783b9284c0SMatthew G Knepley 37901faf4e4SMatthew Knepley #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 380ad39c06fSJed Brown ((petsc_gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 38101faf4e4SMatthew Knepley 38201faf4e4SMatthew Knepley #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 383ad39c06fSJed Brown ((petsc_gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm)) 38401faf4e4SMatthew Knepley 38501faf4e4SMatthew Knepley #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 386ad39c06fSJed Brown ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 38701faf4e4SMatthew Knepley 38801faf4e4SMatthew Knepley #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 389ad39c06fSJed Brown ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm)) 39001faf4e4SMatthew Knepley 39101faf4e4SMatthew Knepley #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 392ad39c06fSJed Brown ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 39301faf4e4SMatthew Knepley 39401faf4e4SMatthew Knepley #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 395ad39c06fSJed Brown ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm)) 39601faf4e4SMatthew Knepley 3970d4b0b6cSBarry Smith #else 3980d4b0b6cSBarry Smith 3990d4b0b6cSBarry Smith #define MPI_Startall_irecv(count,number,requests) \ 4005e3723c6SSatish Balay (MPI_Startall(number,requests)) 4010d4b0b6cSBarry Smith 4020d4b0b6cSBarry Smith #define MPI_Startall_isend(count,number,requests) \ 4035e3723c6SSatish Balay (MPI_Startall(number,requests)) 4040d4b0b6cSBarry Smith 4050d4b0b6cSBarry Smith #define MPI_Start_isend(count,requests) \ 4065e3723c6SSatish Balay (MPI_Start(requests)) 4070d4b0b6cSBarry Smith 408c8217ed5SSatish Balay #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 409614700edSBarry Smith 410df8cf0b5SBarry Smith #else /* ---Logging is turned off --------------------------------------------*/ 411614700edSBarry Smith 412b0a32e0cSBarry Smith #define PetscLogFlops(n) 0 413d854a674SSatish Balay #define PetscLogFlopsNoError(n) 414614700edSBarry Smith 415df8cf0b5SBarry Smith /* 416df8cf0b5SBarry Smith With logging turned off, then MPE has to be turned off 417df8cf0b5SBarry Smith */ 418b0a32e0cSBarry Smith #define PetscLogMPEBegin() 0 419b0a32e0cSBarry Smith #define PetscLogMPEDump(a) 0 420614700edSBarry Smith 421b0a32e0cSBarry Smith #define PetscLogEventActivate(a) 0 422b0a32e0cSBarry Smith #define PetscLogEventDeactivate(a) 0 423614700edSBarry Smith 424b0a32e0cSBarry Smith #define PetscLogEventActivateClass(a) 0 425b0a32e0cSBarry Smith #define PetscLogEventDeactivateClass(a) 0 426e8e7597cSSatish Balay #define PetscLogEventSetActiveAll(a,b) 0 42777c4ece6SBarry Smith 4288b5db460SBarry Smith #define PetscLogPLB 0 4298b5db460SBarry Smith #define PetscLogPLE 0 4308b5db460SBarry Smith #define PetscLogPHC 0 4318b5db460SBarry Smith #define PetscLogPHD 0 43299de4ba8SSatish Balay #define PetscGetFlops(a) (*(a) = 0.0,0) 433b0a32e0cSBarry Smith #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 434b0a32e0cSBarry Smith #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 435b0a32e0cSBarry Smith #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0 436b0a32e0cSBarry Smith #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) 0 43752e6d16bSBarry Smith #define PetscLogObjectParent(p,c) 0 438efee365bSSatish Balay #define PetscLogObjectParents(p,n,c) 0 43952e6d16bSBarry Smith #define PetscLogObjectCreate(h) 0 44052e6d16bSBarry Smith #define PetscLogObjectDestroy(h) 0 44152e6d16bSBarry Smith #define PetscLogObjectMemory(p,m) 0 442b0a32e0cSBarry Smith #define PetscLogDestroy() 0 443b0a32e0cSBarry Smith #define PetscLogStagePush(a) 0 444b0a32e0cSBarry Smith #define PetscLogStagePop() 0 445b0a32e0cSBarry Smith #define PetscLogStageRegister(a,b) 0 446b0a32e0cSBarry Smith #define PetscLogStagePrint(a,flg) 0 44791eabc43SBarry Smith #define PetscLogView(viewer) 0 44891eabc43SBarry Smith #define PetscLogViewPython(viewer) 0 44978392ef1SBarry Smith #define PetscLogPrintDetailed(comm,file) 0 450b0a32e0cSBarry Smith #define PetscLogBegin() 0 451b0a32e0cSBarry Smith #define PetscLogTraceBegin(file) 0 452b0a32e0cSBarry Smith #define PetscLogSet(lb,le) 0 453b0a32e0cSBarry Smith #define PetscLogAllBegin() 0 454b0a32e0cSBarry Smith #define PetscLogDump(c) 0 455043328b6SSatish Balay #define PetscLogEventRegister(a,b,c) 0 45673fda44aSBarry Smith #define PetscLogObjects(a) 0 45773fda44aSBarry Smith #define PetscLogActions(a) 0 458*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...); 459ce6058e1SBarry Smith 460aa482453SBarry Smith /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 461ca161407SBarry Smith #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests) 462ca161407SBarry Smith #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests) 463ca161407SBarry Smith #define MPI_Start_isend(count,requests) MPI_Start(requests) 464fad68dfaSSatish Balay #define PetscLogStageGetId(a,b) (*(b)=0,0) 465fad68dfaSSatish Balay #define PetscLogStageSetActive(a,b) 0 4666a6a9b46SSatish Balay #define PetscLogStageGetActive(a,b) 0 4676a6a9b46SSatish Balay #define PetscLogStageGetVisible(a,b) 0 4686a6a9b46SSatish Balay #define PetscLogStageSetVisible(a,b) 0 469f141ce34SMatthew Knepley 470aa482453SBarry Smith #endif /* PETSC_USE_LOG */ 4716daaf66cSBarry Smith 472*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *); 473*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack); 474*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int); 475*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *); 476*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *); 477*014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *); 478fcfd50ebSBarry Smith 479fcfd50ebSBarry Smith #undef __FUNCT__ 480fcfd50ebSBarry Smith #define __FUNCT__ "PetscLogGetStageLog" 481fcfd50ebSBarry Smith /*@C 482fcfd50ebSBarry Smith PetscLogGetStageLog - This function returns the default stage logging object. 483fcfd50ebSBarry Smith 484fcfd50ebSBarry Smith Not collective 485fcfd50ebSBarry Smith 486fcfd50ebSBarry Smith Output Parameter: 487aa213bdcSJed Brown . stageLog - The default PetscStageLog 488fcfd50ebSBarry Smith 489fcfd50ebSBarry Smith Level: developer 490fcfd50ebSBarry Smith 491fcfd50ebSBarry Smith Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault() 492fcfd50ebSBarry Smith 493fcfd50ebSBarry Smith .keywords: log, stage 494aa213bdcSJed Brown .seealso: PetscStageLogCreate() 495fcfd50ebSBarry Smith @*/ 496aa213bdcSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscLogGetStageLog(PetscStageLog *stageLog) 497fcfd50ebSBarry Smith { 498fcfd50ebSBarry Smith PetscFunctionBegin; 499fcfd50ebSBarry Smith PetscValidPointer(stageLog,1); 500205a32c2SJed Brown if (!petsc_stageLog) { 501fcfd50ebSBarry Smith fprintf(stderr, "PETSC ERROR: Logging has not been enabled.\nYou might have forgotten to call PetscInitialize().\n"); 502fcfd50ebSBarry Smith MPI_Abort(MPI_COMM_WORLD, PETSC_ERR_SUP); 503fcfd50ebSBarry Smith } 504205a32c2SJed Brown *stageLog = petsc_stageLog; 505fcfd50ebSBarry Smith PetscFunctionReturn(0); 506fcfd50ebSBarry Smith } 507fcfd50ebSBarry Smith 508fcfd50ebSBarry Smith #undef __FUNCT__ 509aa213bdcSJed Brown #define __FUNCT__ "PetscStageLogGetCurrent" 510fcfd50ebSBarry Smith /*@C 511aa213bdcSJed Brown PetscStageLogGetCurrent - This function returns the stage from the top of the stack. 512fcfd50ebSBarry Smith 513fcfd50ebSBarry Smith Not Collective 514fcfd50ebSBarry Smith 515fcfd50ebSBarry Smith Input Parameter: 516aa213bdcSJed Brown . stageLog - The PetscStageLog 517fcfd50ebSBarry Smith 518fcfd50ebSBarry Smith Output Parameter: 519fcfd50ebSBarry Smith . stage - The current stage 520fcfd50ebSBarry Smith 521fcfd50ebSBarry Smith Notes: 522fcfd50ebSBarry Smith If no stage is currently active, stage is set to -1. 523fcfd50ebSBarry Smith 524fcfd50ebSBarry Smith Level: developer 525fcfd50ebSBarry Smith 526fcfd50ebSBarry Smith Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault() 527fcfd50ebSBarry Smith 528fcfd50ebSBarry Smith .keywords: log, stage 529aa213bdcSJed Brown .seealso: PetscStageLogPush(), PetscStageLogPop(), PetscLogGetStageLog() 530fcfd50ebSBarry Smith @*/ 531aa213bdcSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscStageLogGetCurrent(PetscStageLog stageLog, int *stage) 532fcfd50ebSBarry Smith { 533fcfd50ebSBarry Smith PetscBool empty; 534fcfd50ebSBarry Smith PetscErrorCode ierr; 535fcfd50ebSBarry Smith 536fcfd50ebSBarry Smith PetscFunctionBegin; 537aa213bdcSJed Brown ierr = PetscIntStackEmpty(stageLog->stack, &empty);CHKERRQ(ierr); 538fcfd50ebSBarry Smith if (empty) { 539fcfd50ebSBarry Smith *stage = -1; 540fcfd50ebSBarry Smith } else { 541aa213bdcSJed Brown ierr = PetscIntStackTop(stageLog->stack, stage);CHKERRQ(ierr); 542fcfd50ebSBarry Smith } 543fcfd50ebSBarry Smith #ifdef PETSC_USE_DEBUG 544e47d2de2SBarry Smith if (*stage != stageLog->curStage) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB, "Inconsistency in stage log: stage %d should be %d", *stage, stageLog->curStage); 545fcfd50ebSBarry Smith #endif 546fcfd50ebSBarry Smith PetscFunctionReturn(0); 547fcfd50ebSBarry Smith } 548fcfd50ebSBarry Smith 549fcfd50ebSBarry Smith #undef __FUNCT__ 550aa213bdcSJed Brown #define __FUNCT__ "PetscStageLogGetEventPerfLog" 551fcfd50ebSBarry Smith /*@C 552aa213bdcSJed Brown PetscStageLogGetEventPerfLog - This function returns the PetscEventPerfLog for the given stage. 553fcfd50ebSBarry Smith 554fcfd50ebSBarry Smith Not Collective 555fcfd50ebSBarry Smith 556fcfd50ebSBarry Smith Input Parameters: 557aa213bdcSJed Brown + stageLog - The PetscStageLog 558fcfd50ebSBarry Smith - stage - The stage 559fcfd50ebSBarry Smith 560fcfd50ebSBarry Smith Output Parameter: 561aa213bdcSJed Brown . eventLog - The PetscEventPerfLog 562fcfd50ebSBarry Smith 563fcfd50ebSBarry Smith Level: developer 564fcfd50ebSBarry Smith 565fcfd50ebSBarry Smith Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault() 566fcfd50ebSBarry Smith 567fcfd50ebSBarry Smith .keywords: log, stage 568aa213bdcSJed Brown .seealso: PetscStageLogPush(), PetscStageLogPop(), PetscLogGetStageLog() 569fcfd50ebSBarry Smith @*/ 570aa213bdcSJed Brown PETSC_STATIC_INLINE PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog stageLog, int stage, PetscEventPerfLog *eventLog) 571fcfd50ebSBarry Smith { 572fcfd50ebSBarry Smith PetscFunctionBegin; 573fcfd50ebSBarry Smith PetscValidPointer(eventLog,3); 574e47d2de2SBarry Smith if ((stage < 0) || (stage >= stageLog->numStages)) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE, "Invalid stage %d should be in [0,%d)", stage, stageLog->numStages); 575fcfd50ebSBarry Smith *eventLog = stageLog->stageInfo[stage].eventLog; 576fcfd50ebSBarry Smith PetscFunctionReturn(0); 577fcfd50ebSBarry Smith } 578fcfd50ebSBarry Smith 579bf5c43c7SMatthew Knepley /* Special support for C++ */ 580bf5c43c7SMatthew Knepley #include "petsclog.hh" 581bf5c43c7SMatthew Knepley 582204a6943SJed Brown #define PetscPreLoadBegin(flag,name) \ 583204a6943SJed Brown do {\ 584204a6943SJed Brown PetscBool PetscPreLoading = flag;\ 585204a6943SJed Brown int PetscPreLoadMax,PetscPreLoadIt;\ 586166c7f25SBarry Smith PetscLogStage _stageNum;\ 5878cbcd9ccSBarry Smith PetscErrorCode _3_ierr; \ 588204a6943SJed Brown _3_ierr = PetscOptionsGetBool(PETSC_NULL,"-preload",&PetscPreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\ 589204a6943SJed Brown PetscPreLoadMax = (int)(PetscPreLoading);\ 590204a6943SJed Brown PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 591204a6943SJed Brown for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\ 592204a6943SJed Brown PetscPreLoadingOn = PetscPreLoading;\ 5936e491fe6SBarry Smith _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\ 594204a6943SJed Brown if (PetscPreLoadIt>0) {\ 5958e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 5968e58c17dSMatthew Knepley } else {\ 597a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 5988e58c17dSMatthew Knepley }\ 599204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\ 6008e58c17dSMatthew Knepley _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 6018e58c17dSMatthew Knepley 602204a6943SJed Brown #define PetscPreLoadEnd() \ 603043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 604204a6943SJed Brown PetscPreLoading = PETSC_FALSE;\ 605043328b6SSatish Balay }\ 606204a6943SJed Brown } while (0) 6078e58c17dSMatthew Knepley 608204a6943SJed Brown #define PetscPreLoadStage(name) do { \ 609043328b6SSatish Balay _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr); \ 610204a6943SJed Brown if (PetscPreLoadIt>0) { \ 6118e58c17dSMatthew Knepley _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr); \ 6128e58c17dSMatthew Knepley } else { \ 613a3bc4eb9SBarry Smith _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 6148e58c17dSMatthew Knepley } \ 615204a6943SJed Brown _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \ 616204a6943SJed Brown _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); \ 617204a6943SJed Brown } while (0) 618e9fa29b7SSatish Balay 61997bb86f7SLois Curfman McInnes #endif 620