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