1 /* 2 Defines profile/logging in PETSc. 3 */ 4 5 #if !defined(__PetscLog_H) 6 #define __PetscLog_H 7 #include "petscsys.h" 8 9 /*MC 10 PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable) 11 code. 12 13 Level: intermediate 14 15 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage 16 M*/ 17 typedef int PetscLogEvent; 18 19 /*MC 20 PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging 21 22 Level: intermediate 23 24 .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent 25 M*/ 26 typedef int PetscLogStage; 27 28 #define PETSC_EVENT 1311311 29 PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT; 30 31 /* Global flop counter */ 32 PETSC_EXTERN PetscLogDouble petsc_TotalFlops; 33 PETSC_EXTERN PetscLogDouble petsc_tmp_flops; 34 35 /* General logging of information; different from event logging */ 36 PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],void*,const char[],...); 37 #if defined(PETSC_USE_INFO) 38 #define PetscInfo(A,S) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S) 39 #define PetscInfo1(A,S,a1) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1) 40 #define PetscInfo2(A,S,a1,a2) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2) 41 #define PetscInfo3(A,S,a1,a2,a3) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3) 42 #define PetscInfo4(A,S,a1,a2,a3,a4) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4) 43 #define PetscInfo5(A,S,a1,a2,a3,a4,a5) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5) 44 #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6) 45 #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) 46 #else 47 #define PetscInfo(A,S) 0 48 #define PetscInfo1(A,S,a1) 0 49 #define PetscInfo2(A,S,a1,a2) 0 50 #define PetscInfo3(A,S,a1,a2,a3) 0 51 #define PetscInfo4(A,S,a1,a2,a3,a4) 0 52 #define PetscInfo5(A,S,a1,a2,a3,a4,a5) 0 53 #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6) 0 54 #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0 55 #endif 56 PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId); 57 PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId); 58 PETSC_EXTERN PetscBool PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */ 59 60 /* We must make the following structures available to access the event 61 activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public 62 API and are not intended to be used by other parts of PETSc or by users. 63 64 The code that manipulates these structures is in src/sys/plog/utils. 65 */ 66 typedef struct _n_PetscIntStack *PetscIntStack; 67 68 /* 69 PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has 70 static information about it, the second collects statistics on how many objects of the class are created, 71 how much memory they use, etc. 72 73 PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes. 74 */ 75 typedef struct { 76 char *name; /* The class name */ 77 PetscClassId classid; /* The integer identifying this class */ 78 } PetscClassRegInfo; 79 80 typedef struct { 81 PetscClassId id; /* The integer identifying this class */ 82 int creations; /* The number of objects of this class created */ 83 int destructions; /* The number of objects of this class destroyed */ 84 PetscLogDouble mem; /* The total memory allocated by objects of this class */ 85 PetscLogDouble descMem; /* The total memory allocated by descendents of these objects */ 86 } PetscClassPerfInfo; 87 88 typedef struct _n_PetscClassRegLog *PetscClassRegLog; 89 struct _n_PetscClassRegLog { 90 int numClasses; /* The number of classes registered */ 91 int maxClasses; /* The maximum number of classes */ 92 PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 93 }; 94 95 typedef struct _n_PetscClassPerfLog *PetscClassPerfLog; 96 struct _n_PetscClassPerfLog { 97 int numClasses; /* The number of logging classes */ 98 int maxClasses; /* The maximum number of classes */ 99 PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */ 100 }; 101 /* -----------------------------------------------------------------------------------------------------*/ 102 /* 103 PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has 104 static information about it, the second collects statistics on how many times the event is used, how 105 much time it takes, etc. 106 107 PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one 108 of these for each stage. 109 110 */ 111 typedef struct { 112 char *name; /* The name of this event */ 113 PetscClassId classid; /* The class the event is associated with */ 114 #if defined (PETSC_HAVE_MPE) 115 int mpe_id_begin; /* MPE IDs that define the event */ 116 int mpe_id_end; 117 #endif 118 } PetscEventRegInfo; 119 120 typedef struct { 121 int id; /* The integer identifying this event */ 122 PetscBool active; /* The flag to activate logging */ 123 PetscBool visible; /* The flag to print info in summary */ 124 int depth; /* The nesting depth of the event call */ 125 int count; /* The number of times this event was executed */ 126 PetscLogDouble flops, flops2,flopsTmp; /* The flops and flops^2 used in this event */ 127 PetscLogDouble time, time2, timeTmp; /* The time and time^2 taken for this event */ 128 PetscLogDouble numMessages; /* The number of messages in this event */ 129 PetscLogDouble messageLength; /* The total message lengths in this event */ 130 PetscLogDouble numReductions; /* The number of reductions in this event */ 131 } PetscEventPerfInfo; 132 133 typedef struct _n_PetscEventRegLog *PetscEventRegLog; 134 struct _n_PetscEventRegLog { 135 int numEvents; /* The number of registered events */ 136 int maxEvents; /* The maximum number of events */ 137 PetscEventRegInfo *eventInfo; /* The registration information for each event */ 138 }; 139 140 typedef struct _n_PetscEventPerfLog *PetscEventPerfLog; 141 struct _n_PetscEventPerfLog { 142 int numEvents; /* The number of logging events */ 143 int maxEvents; /* The maximum number of events */ 144 PetscEventPerfInfo *eventInfo; /* The performance information for each event */ 145 }; 146 /* ------------------------------------------------------------------------------------------------------------*/ 147 /* 148 PetscStageInfo - Contains all the information about a particular stage. 149 150 PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code. 151 */ 152 typedef struct _PetscStageInfo { 153 char *name; /* The stage name */ 154 PetscBool used; /* The stage was pushed on this processor */ 155 PetscEventPerfInfo perfInfo; /* The stage performance information */ 156 PetscEventPerfLog eventLog; /* The event information for this stage */ 157 PetscClassPerfLog classLog; /* The class information for this stage */ 158 } PetscStageInfo; 159 160 typedef struct _n_PetscStageLog *PetscStageLog; 161 PETSC_EXTERN PetscStageLog petsc_stageLog; 162 struct _n_PetscStageLog { 163 int numStages; /* The number of registered stages */ 164 int maxStages; /* The maximum number of stages */ 165 PetscIntStack stack; /* The stack for active stages */ 166 int curStage; /* The current stage (only used in macros so we don't call PetscIntStackTop) */ 167 PetscStageInfo *stageInfo; /* The information for each stage */ 168 PetscEventRegLog eventLog; /* The registered events */ 169 PetscClassRegLog classLog; /* The registered classes */ 170 }; 171 172 #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/ 173 174 /* 175 Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately. 176 177 For the complex numbers version, note that 178 1 complex addition = 2 flops 179 1 complex multiplication = 6 flops, 180 where we define 1 flop as that for a double precision scalar. We roughly approximate 181 flop counting for complex numbers by multiplying the total flops by 4; this corresponds 182 to the assumption that we're counting mostly additions and multiplications -- and 183 roughly the same number of each. More accurate counting could be done by distinguishing 184 among the various arithmetic operations. 185 */ 186 187 #if defined(PETSC_USE_COMPLEX) 188 #define PETSC_FLOPS_PER_OP 4.0 189 #else 190 #define PETSC_FLOPS_PER_OP 1.0 191 #endif 192 193 #undef __FUNCT__ 194 #define __FUNCT__ "PetscLogFlops" 195 PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n) 196 { 197 PetscFunctionBegin; 198 #if defined(PETSC_USE_DEBUG) 199 if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops"); 200 #endif 201 petsc_TotalFlops += PETSC_FLOPS_PER_OP*n; 202 PetscFunctionReturn(0); 203 } 204 205 #if defined (PETSC_HAVE_MPE) 206 #include "mpe.h" 207 PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void); 208 PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]); 209 PETSC_EXTERN PetscBool UseMPE; 210 #define PETSC_LOG_EVENT_MPE_BEGIN(e) \ 211 ((UseMPE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 212 MPE_Log_event(petsc_stageLog->eventLog->eventInfo[e].mpe_id_begin,0,NULL) : 0) 213 214 #define PETSC_LOG_EVENT_MPE_END(e) \ 215 ((UseMPE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 216 MPE_Log_event(petsc_stageLog->eventLog->eventInfo[e].mpe_id_end,0,NULL) : 0) 217 218 #else 219 #define PETSC_LOG_EVENT_MPE_BEGIN(e) 0 220 #define PETSC_LOG_EVENT_MPE_END(e) 0 221 #endif 222 223 PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 224 PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject); 225 PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject); 226 PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject); 227 228 #define PetscLogObjectParent(p,c) \ 229 (c && p && (((PetscObject)(c))->parent = (PetscObject)(p),((PetscObject)(c))->parentid = ((PetscObject)p)->id,0)) 230 231 #define PetscLogObjectParents(p,n,d) 0;{int _i; for (_i=0; _i<n; _i++) {ierr = PetscLogObjectParent(p,(d)[_i]);CHKERRQ(ierr);}} 232 #define PetscLogObjectCreate(h) ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)h) : 0) 233 #define PetscLogObjectDestroy(h) ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)h) : 0) 234 #define PetscLogObjectMemory(p,m) (((PetscObject)(p))->mem += (m),0) 235 /* Initialization functions */ 236 PETSC_EXTERN PetscErrorCode PetscLogBegin(void); 237 PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void); 238 PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *); 239 PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool); 240 PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool); 241 /* General functions */ 242 PETSC_EXTERN PetscErrorCode PetscLogGetRGBColor(const char*[]); 243 PETSC_EXTERN PetscErrorCode PetscLogDestroy(void); 244 PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject), 245 PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject)); 246 PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...); 247 /* Output functions */ 248 PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer); 249 PETSC_EXTERN PetscErrorCode PetscLogViewPython(PetscViewer); 250 PETSC_EXTERN PetscErrorCode PetscLogPrintDetailed(MPI_Comm, const char[]); 251 PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]); 252 253 PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *); 254 255 PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*); 256 PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage); 257 PETSC_EXTERN PetscErrorCode PetscLogStagePop(void); 258 PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool ); 259 PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *); 260 PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool ); 261 PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *); 262 PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char [], PetscLogStage *); 263 /* Event functions */ 264 PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId,PetscLogEvent*); 265 PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent); 266 PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent); 267 PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool ); 268 PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId); 269 PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId); 270 271 272 /* Global counters */ 273 PETSC_EXTERN PetscLogDouble petsc_irecv_ct; 274 PETSC_EXTERN PetscLogDouble petsc_isend_ct; 275 PETSC_EXTERN PetscLogDouble petsc_recv_ct; 276 PETSC_EXTERN PetscLogDouble petsc_send_ct; 277 PETSC_EXTERN PetscLogDouble petsc_irecv_len; 278 PETSC_EXTERN PetscLogDouble petsc_isend_len; 279 PETSC_EXTERN PetscLogDouble petsc_recv_len; 280 PETSC_EXTERN PetscLogDouble petsc_send_len; 281 PETSC_EXTERN PetscLogDouble petsc_allreduce_ct; 282 PETSC_EXTERN PetscLogDouble petsc_gather_ct; 283 PETSC_EXTERN PetscLogDouble petsc_scatter_ct; 284 PETSC_EXTERN PetscLogDouble petsc_wait_ct; 285 PETSC_EXTERN PetscLogDouble petsc_wait_any_ct; 286 PETSC_EXTERN PetscLogDouble petsc_wait_all_ct; 287 PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct; 288 289 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) \ 290 (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 291 (PetscLogEventBegin((e),o1,o2,o3,o4) || MPI_Barrier(cm) || PetscLogEventEnd((e),o1,o2,o3,o4)) : 0 ) || \ 292 PetscLogEventBegin((e)+1,o1,o2,o3,o4)) 293 294 #define PetscLogEventBegin(e,o1,o2,o3,o4) \ 295 (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 296 (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \ 297 PETSC_LOG_EVENT_MPE_BEGIN(e)) 298 299 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) PetscLogEventEnd(e+1,o1,o2,o3,o4) 300 301 #define PetscLogEventEnd(e,o1,o2,o3,o4) \ 302 (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \ 303 (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ) || \ 304 PETSC_LOG_EVENT_MPE_END(e)) 305 306 PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent, PetscLogDouble*); 307 PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent); 308 309 /* 310 These are used internally in the PETSc routines to keep a count of MPI messages and 311 their sizes. 312 313 This does not work for MPI-Uni because our include/mpiuni/mpi.h file 314 uses macros to defined the MPI operations. 315 316 It does not work correctly from HP-UX because it processes the 317 macros in a way that sometimes it double counts, hence 318 PETSC_HAVE_BROKEN_RECURSIVE_MACRO 319 320 It does not work with Windows because winmpich lacks MPI_Type_size() 321 */ 322 #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE) 323 /* 324 Logging of MPI activities 325 */ 326 PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type) 327 { 328 PetscMPIInt mysize; return (MPI_Type_size(type,&mysize) || ((*buff += (PetscLogDouble) (count*mysize)),0)); 329 } 330 331 PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, PetscLogDouble *buff,PetscMPIInt *counts,MPI_Datatype type) 332 { 333 PetscMPIInt mysize, commsize, p; 334 PetscErrorCode _myierr; 335 336 _myierr = MPI_Comm_size(comm,&commsize);CHKERRQ(_myierr); 337 _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr); 338 for (p = 0; p < commsize; ++p) { 339 *buff += (PetscLogDouble) (counts[p]*mysize); 340 } 341 return 0; 342 } 343 344 #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \ 345 ((petsc_irecv_ct++,0) || PetscMPITypeSize(&petsc_irecv_len,count,datatype) || MPI_Irecv(buf,count,datatype,source,tag,comm,request)) 346 347 #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \ 348 ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,datatype) || MPI_Isend(buf,count,datatype,dest,tag,comm,request)) 349 350 #define MPI_Startall_irecv(count,number,requests) \ 351 ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_irecv_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 352 353 #define MPI_Startall_isend(count,number,requests) \ 354 ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Startall(number,requests)) 355 356 #define MPI_Start_isend(count,requests) \ 357 ((petsc_isend_ct++,0) || PetscMPITypeSize(&petsc_isend_len,count,MPIU_SCALAR) || MPI_Start(requests)) 358 359 #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \ 360 ((petsc_recv_ct++,0) || PetscMPITypeSize(&petsc_recv_len,count,datatype) || MPI_Recv(buf,count,datatype,source,tag,comm,status)) 361 362 #define MPI_Send(buf,count,datatype,dest,tag,comm) \ 363 ((petsc_send_ct++,0) || PetscMPITypeSize(&petsc_send_len,count,datatype) || MPI_Send(buf,count,datatype,dest,tag,comm)) 364 365 #define MPI_Wait(request,status) \ 366 ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait(request,status)) 367 368 #define MPI_Waitany(a,b,c,d) \ 369 ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany(a,b,c,d)) 370 371 #define MPI_Waitall(count,array_of_requests,array_of_statuses) \ 372 ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall(count,array_of_requests,array_of_statuses)) 373 374 #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \ 375 ((petsc_allreduce_ct++,0) || MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm)) 376 377 #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 378 ((petsc_allreduce_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 379 380 #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \ 381 ((petsc_allreduce_ct++,0) || PetscMPITypeSizeComm(comm,&petsc_send_len,sendcnts,sendtype) || MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm)) 382 383 #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \ 384 ((petsc_gather_ct++,0) || MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm)) 385 386 #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \ 387 ((petsc_gather_ct++,0) || MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm)) 388 389 #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 390 ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 391 392 #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \ 393 ((petsc_gather_ct++,0) || PetscMPITypeSize(&petsc_send_len,sendcount,sendtype) || MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm)) 394 395 #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 396 ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm)) 397 398 #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \ 399 ((petsc_scatter_ct++,0) || PetscMPITypeSize(&petsc_recv_len,recvcount,recvtype) || MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm)) 400 401 #else 402 403 #define MPI_Startall_irecv(count,number,requests) \ 404 (MPI_Startall(number,requests)) 405 406 #define MPI_Startall_isend(count,number,requests) \ 407 (MPI_Startall(number,requests)) 408 409 #define MPI_Start_isend(count,requests) \ 410 (MPI_Start(requests)) 411 412 #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */ 413 414 #else /* ---Logging is turned off --------------------------------------------*/ 415 416 #define PetscLogFlops(n) 0 417 418 /* 419 With logging turned off, then MPE has to be turned off 420 */ 421 #define PetscLogMPEBegin() 0 422 #define PetscLogMPEDump(a) 0 423 424 #define PetscLogEventActivate(a) 0 425 #define PetscLogEventDeactivate(a) 0 426 427 #define PetscLogEventActivateClass(a) 0 428 #define PetscLogEventDeactivateClass(a) 0 429 #define PetscLogEventSetActiveAll(a,b) 0 430 431 #define PetscLogPLB 0 432 #define PetscLogPLE 0 433 #define PetscLogPHC 0 434 #define PetscLogPHD 0 435 #define PetscGetFlops(a) (*(a) = 0.0,0) 436 #define PetscLogEventBegin(e,o1,o2,o3,o4) 0 437 #define PetscLogEventEnd(e,o1,o2,o3,o4) 0 438 #define PetscLogEventBarrierBegin(e,o1,o2,o3,o4,cm) 0 439 #define PetscLogEventBarrierEnd(e,o1,o2,o3,o4,cm) 0 440 #define PetscLogObjectParent(p,c) 0 441 #define PetscLogObjectParents(p,n,c) 0 442 #define PetscLogObjectCreate(h) 0 443 #define PetscLogObjectDestroy(h) 0 444 #define PetscLogObjectMemory(p,m) 0 445 #define PetscLogDestroy() 0 446 #define PetscLogStagePush(a) 0 447 #define PetscLogStagePop() 0 448 #define PetscLogStageRegister(a,b) 0 449 #define PetscLogStagePrint(a,flg) 0 450 #define PetscLogView(viewer) 0 451 #define PetscLogViewPython(viewer) 0 452 #define PetscLogPrintDetailed(comm,file) 0 453 #define PetscLogBegin() 0 454 #define PetscLogTraceBegin(file) 0 455 #define PetscLogSet(lb,le) 0 456 #define PetscLogAllBegin() 0 457 #define PetscLogDump(c) 0 458 #define PetscLogEventRegister(a,b,c) 0 459 #define PetscLogObjects(a) 0 460 #define PetscLogActions(a) 0 461 PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...); 462 463 /* If PETSC_USE_LOG is NOT defined, these still need to be! */ 464 #define MPI_Startall_irecv(count,number,requests) MPI_Startall(number,requests) 465 #define MPI_Startall_isend(count,number,requests) MPI_Startall(number,requests) 466 #define MPI_Start_isend(count,requests) MPI_Start(requests) 467 #define PetscLogStageGetId(a,b) (*(b)=0,0) 468 #define PetscLogStageSetActive(a,b) 0 469 #define PetscLogStageGetActive(a,b) 0 470 #define PetscLogStageGetVisible(a,b) 0 471 #define PetscLogStageSetVisible(a,b) 0 472 473 #endif /* PETSC_USE_LOG */ 474 475 PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *); 476 PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack); 477 PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int); 478 PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *); 479 PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *); 480 PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *); 481 482 #undef __FUNCT__ 483 #define __FUNCT__ "PetscLogGetStageLog" 484 /*@C 485 PetscLogGetStageLog - This function returns the default stage logging object. 486 487 Not collective 488 489 Output Parameter: 490 . stageLog - The default PetscStageLog 491 492 Level: developer 493 494 Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault() 495 496 .keywords: log, stage 497 .seealso: PetscStageLogCreate() 498 @*/ 499 PETSC_STATIC_INLINE PetscErrorCode PetscLogGetStageLog(PetscStageLog *stageLog) 500 { 501 PetscFunctionBegin; 502 PetscValidPointer(stageLog,1); 503 if (!petsc_stageLog) { 504 fprintf(stderr, "PETSC ERROR: Logging has not been enabled.\nYou might have forgotten to call PetscInitialize().\n"); 505 MPI_Abort(MPI_COMM_WORLD, PETSC_ERR_SUP); 506 } 507 *stageLog = petsc_stageLog; 508 PetscFunctionReturn(0); 509 } 510 511 #undef __FUNCT__ 512 #define __FUNCT__ "PetscStageLogGetCurrent" 513 /*@C 514 PetscStageLogGetCurrent - This function returns the stage from the top of the stack. 515 516 Not Collective 517 518 Input Parameter: 519 . stageLog - The PetscStageLog 520 521 Output Parameter: 522 . stage - The current stage 523 524 Notes: 525 If no stage is currently active, stage is set to -1. 526 527 Level: developer 528 529 Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault() 530 531 .keywords: log, stage 532 .seealso: PetscStageLogPush(), PetscStageLogPop(), PetscLogGetStageLog() 533 @*/ 534 PETSC_STATIC_INLINE PetscErrorCode PetscStageLogGetCurrent(PetscStageLog stageLog, int *stage) 535 { 536 PetscBool empty; 537 PetscErrorCode ierr; 538 539 PetscFunctionBegin; 540 ierr = PetscIntStackEmpty(stageLog->stack, &empty);CHKERRQ(ierr); 541 if (empty) { 542 *stage = -1; 543 } else { 544 ierr = PetscIntStackTop(stageLog->stack, stage);CHKERRQ(ierr); 545 } 546 #ifdef PETSC_USE_DEBUG 547 if (*stage != stageLog->curStage) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB, "Inconsistency in stage log: stage %d should be %d", *stage, stageLog->curStage); 548 #endif 549 PetscFunctionReturn(0); 550 } 551 552 #undef __FUNCT__ 553 #define __FUNCT__ "PetscStageLogGetEventPerfLog" 554 /*@C 555 PetscStageLogGetEventPerfLog - This function returns the PetscEventPerfLog for the given stage. 556 557 Not Collective 558 559 Input Parameters: 560 + stageLog - The PetscStageLog 561 - stage - The stage 562 563 Output Parameter: 564 . eventLog - The PetscEventPerfLog 565 566 Level: developer 567 568 Developer Notes: Inline since called for EACH PetscEventLogBeginDefault() and PetscEventLogEndDefault() 569 570 .keywords: log, stage 571 .seealso: PetscStageLogPush(), PetscStageLogPop(), PetscLogGetStageLog() 572 @*/ 573 PETSC_STATIC_INLINE PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog stageLog, int stage, PetscEventPerfLog *eventLog) 574 { 575 PetscFunctionBegin; 576 PetscValidPointer(eventLog,3); 577 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); 578 *eventLog = stageLog->stageInfo[stage].eventLog; 579 PetscFunctionReturn(0); 580 } 581 582 /* Special support for C++ */ 583 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX) 584 #include <petsclog.hh> 585 #endif 586 587 #define PetscPreLoadBegin(flag,name) \ 588 do {\ 589 PetscBool PetscPreLoading = flag;\ 590 int PetscPreLoadMax,PetscPreLoadIt;\ 591 PetscLogStage _stageNum;\ 592 PetscErrorCode _3_ierr; \ 593 _3_ierr = PetscOptionsGetBool(PETSC_NULL,"-preload",&PetscPreLoading,PETSC_NULL);CHKERRQ(_3_ierr);\ 594 PetscPreLoadMax = (int)(PetscPreLoading);\ 595 PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\ 596 for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\ 597 PetscPreLoadingOn = PetscPreLoading;\ 598 _3_ierr = PetscBarrier(PETSC_NULL);CHKERRQ(_3_ierr);\ 599 if (PetscPreLoadIt>0) {\ 600 _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\ 601 } else {\ 602 _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 603 }\ 604 _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\ 605 _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); 606 607 #define PetscPreLoadEnd() \ 608 _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\ 609 PetscPreLoading = PETSC_FALSE;\ 610 }\ 611 } while (0) 612 613 #define PetscPreLoadStage(name) do { \ 614 _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr); \ 615 if (PetscPreLoadIt>0) { \ 616 _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr); \ 617 } else { \ 618 _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \ 619 } \ 620 _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \ 621 _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr); \ 622 } while (0) 623 624 #endif 625