15c6c1daeSBarry Smith /* 25c6c1daeSBarry Smith PETSc code to log object creation and destruction and PETSc events. 35c6c1daeSBarry Smith 45c6c1daeSBarry Smith This provides the public API used by the rest of PETSc and by users. 55c6c1daeSBarry Smith 65c6c1daeSBarry Smith These routines use a private API that is not used elsewhere in PETSc and is not 75c6c1daeSBarry Smith accessible to users. The private API is defined in logimpl.h and the utils directory. 85c6c1daeSBarry Smith 9b665b14eSToby Isaac *** 10b665b14eSToby Isaac 11b665b14eSToby Isaac This file, and only this file, is for functions that interact with the global logging state 125c6c1daeSBarry Smith */ 13af0996ceSBarry Smith #include <petsc/private/logimpl.h> /*I "petscsys.h" I*/ 1453e0a2f3SToby Isaac #include <petsc/private/loghandlerimpl.h> 155c6c1daeSBarry Smith #include <petsctime.h> 16665c2dedSJed Brown #include <petscviewer.h> 178fe3844cSJunchao Zhang #include <petscdevice.h> 188fe3844cSJunchao Zhang #include <petsc/private/deviceimpl.h> 195c6c1daeSBarry Smith 20c708d6e3SStefano Zampini #if defined(PETSC_HAVE_THREADSAFETY) 21c708d6e3SStefano Zampini 22c708d6e3SStefano Zampini PetscInt petsc_log_gid = -1; /* Global threadId counter */ 23c708d6e3SStefano Zampini PETSC_TLS PetscInt petsc_log_tid = -1; /* Local threadId */ 24c708d6e3SStefano Zampini 25c708d6e3SStefano Zampini /* shared variables */ 26c708d6e3SStefano Zampini PetscSpinlock PetscLogSpinLock; 27c708d6e3SStefano Zampini 282611ad71SToby Isaac PetscInt PetscLogGetTid(void) 292611ad71SToby Isaac { 302611ad71SToby Isaac if (petsc_log_tid < 0) { 312611ad71SToby Isaac PetscCall(PetscSpinlockLock(&PetscLogSpinLock)); 322611ad71SToby Isaac petsc_log_tid = ++petsc_log_gid; 332611ad71SToby Isaac PetscCall(PetscSpinlockUnlock(&PetscLogSpinLock)); 342611ad71SToby Isaac } 352611ad71SToby Isaac return petsc_log_tid; 362611ad71SToby Isaac } 372611ad71SToby Isaac 38c708d6e3SStefano Zampini #endif 39c708d6e3SStefano Zampini 405c6c1daeSBarry Smith /* Global counters */ 415c6c1daeSBarry Smith PetscLogDouble petsc_BaseTime = 0.0; 425c6c1daeSBarry Smith PetscLogDouble petsc_TotalFlops = 0.0; /* The number of flops */ 435c6c1daeSBarry Smith PetscLogDouble petsc_send_ct = 0.0; /* The number of sends */ 445c6c1daeSBarry Smith PetscLogDouble petsc_recv_ct = 0.0; /* The number of receives */ 455c6c1daeSBarry Smith PetscLogDouble petsc_send_len = 0.0; /* The total length of all sent messages */ 465c6c1daeSBarry Smith PetscLogDouble petsc_recv_len = 0.0; /* The total length of all received messages */ 475c6c1daeSBarry Smith PetscLogDouble petsc_isend_ct = 0.0; /* The number of immediate sends */ 485c6c1daeSBarry Smith PetscLogDouble petsc_irecv_ct = 0.0; /* The number of immediate receives */ 495c6c1daeSBarry Smith PetscLogDouble petsc_isend_len = 0.0; /* The total length of all immediate send messages */ 505c6c1daeSBarry Smith PetscLogDouble petsc_irecv_len = 0.0; /* The total length of all immediate receive messages */ 515c6c1daeSBarry Smith PetscLogDouble petsc_wait_ct = 0.0; /* The number of waits */ 525c6c1daeSBarry Smith PetscLogDouble petsc_wait_any_ct = 0.0; /* The number of anywaits */ 535c6c1daeSBarry Smith PetscLogDouble petsc_wait_all_ct = 0.0; /* The number of waitalls */ 545c6c1daeSBarry Smith PetscLogDouble petsc_sum_of_waits_ct = 0.0; /* The total number of waits */ 555c6c1daeSBarry Smith PetscLogDouble petsc_allreduce_ct = 0.0; /* The number of reductions */ 565c6c1daeSBarry Smith PetscLogDouble petsc_gather_ct = 0.0; /* The number of gathers and gathervs */ 575c6c1daeSBarry Smith PetscLogDouble petsc_scatter_ct = 0.0; /* The number of scatters and scattervs */ 58c708d6e3SStefano Zampini 59c708d6e3SStefano Zampini /* Thread Local storage */ 60c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_TotalFlops_th = 0.0; 61c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_send_ct_th = 0.0; 62c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_recv_ct_th = 0.0; 63c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_send_len_th = 0.0; 64c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_recv_len_th = 0.0; 65c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_isend_ct_th = 0.0; 66c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_irecv_ct_th = 0.0; 67c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_isend_len_th = 0.0; 68c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_irecv_len_th = 0.0; 69c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_wait_ct_th = 0.0; 70c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_wait_any_ct_th = 0.0; 71c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_wait_all_ct_th = 0.0; 72c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_sum_of_waits_ct_th = 0.0; 73c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_allreduce_ct_th = 0.0; 74c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gather_ct_th = 0.0; 75c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_scatter_ct_th = 0.0; 76c708d6e3SStefano Zampini 77bec0b493Shannah_mairs PetscLogDouble petsc_ctog_ct = 0.0; /* The total number of CPU to GPU copies */ 78bec0b493Shannah_mairs PetscLogDouble petsc_gtoc_ct = 0.0; /* The total number of GPU to CPU copies */ 79bec0b493Shannah_mairs PetscLogDouble petsc_ctog_sz = 0.0; /* The total size of CPU to GPU copies */ 80bec0b493Shannah_mairs PetscLogDouble petsc_gtoc_sz = 0.0; /* The total size of GPU to CPU copies */ 8145c4b7c1SBarry Smith PetscLogDouble petsc_ctog_ct_scalar = 0.0; /* The total number of CPU to GPU copies */ 8245c4b7c1SBarry Smith PetscLogDouble petsc_gtoc_ct_scalar = 0.0; /* The total number of GPU to CPU copies */ 8345c4b7c1SBarry Smith PetscLogDouble petsc_ctog_sz_scalar = 0.0; /* The total size of CPU to GPU copies */ 8445c4b7c1SBarry Smith PetscLogDouble petsc_gtoc_sz_scalar = 0.0; /* The total size of GPU to CPU copies */ 85958c4211Shannah_mairs PetscLogDouble petsc_gflops = 0.0; /* The flops done on a GPU */ 86958c4211Shannah_mairs PetscLogDouble petsc_gtime = 0.0; /* The time spent on a GPU */ 875268dc8aSHong Zhang PetscLogDouble petsc_genergy = 0.0; /* The energy (estimated with power*gtime) consumed on a GPU */ 885268dc8aSHong Zhang PetscLogDouble petsc_genergy_meter = 0.0; /* Readings from the energy meter on a GPU */ 89c708d6e3SStefano Zampini 90c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_ctog_ct_th = 0.0; 91c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gtoc_ct_th = 0.0; 92c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_ctog_sz_th = 0.0; 93c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gtoc_sz_th = 0.0; 94c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_ctog_ct_scalar_th = 0.0; 95c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gtoc_ct_scalar_th = 0.0; 96c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_ctog_sz_scalar_th = 0.0; 97c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gtoc_sz_scalar_th = 0.0; 98c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gflops_th = 0.0; 99c708d6e3SStefano Zampini PETSC_TLS PetscLogDouble petsc_gtime_th = 0.0; 1002611ad71SToby Isaac 1012611ad71SToby Isaac PetscBool PetscLogMemory = PETSC_FALSE; 1022611ad71SToby Isaac PetscBool PetscLogSyncOn = PETSC_FALSE; 1032611ad71SToby Isaac 1042611ad71SToby Isaac PetscBool PetscLogGpuTimeFlag = PETSC_FALSE; 1055268dc8aSHong Zhang PetscBool PetscLogGpuEnergyFlag = PETSC_FALSE; 1065268dc8aSHong Zhang PetscBool PetscLogGpuEnergyMeterFlag = PETSC_FALSE; 1072611ad71SToby Isaac 1080bc1c2e8SToby Isaac PetscInt PetscLogNumViewersCreated = 0; 1090bc1c2e8SToby Isaac PetscInt PetscLogNumViewersDestroyed = 0; 1100bc1c2e8SToby Isaac 1112611ad71SToby Isaac PetscLogState petsc_log_state = NULL; 1122611ad71SToby Isaac 11310dd146fSPierre Jolivet #define PETSC_LOG_HANDLER_HOT_BLANK {NULL, NULL, NULL, NULL, NULL, NULL} 1142611ad71SToby Isaac 1152611ad71SToby Isaac PetscLogHandlerHot PetscLogHandlers[PETSC_LOG_HANDLER_MAX] = { 1162611ad71SToby Isaac PETSC_LOG_HANDLER_HOT_BLANK, 1172611ad71SToby Isaac PETSC_LOG_HANDLER_HOT_BLANK, 1182611ad71SToby Isaac PETSC_LOG_HANDLER_HOT_BLANK, 1192611ad71SToby Isaac PETSC_LOG_HANDLER_HOT_BLANK, 1202611ad71SToby Isaac }; 1212611ad71SToby Isaac 1222611ad71SToby Isaac #undef PETSC_LOG_HANDLERS_HOT_BLANK 1232611ad71SToby Isaac 1242611ad71SToby Isaac #if defined(PETSC_USE_LOG) 1252611ad71SToby Isaac #include <../src/sys/logging/handler/impls/default/logdefault.h> 126c708d6e3SStefano Zampini 127c708d6e3SStefano Zampini #if defined(PETSC_HAVE_THREADSAFETY) 128c708d6e3SStefano Zampini PetscErrorCode PetscAddLogDouble(PetscLogDouble *tot, PetscLogDouble *tot_th, PetscLogDouble tmp) 129c708d6e3SStefano Zampini { 130c708d6e3SStefano Zampini *tot_th += tmp; 1313ba16761SJacob Faibussowitsch PetscCall(PetscSpinlockLock(&PetscLogSpinLock)); 132c708d6e3SStefano Zampini *tot += tmp; 1333ba16761SJacob Faibussowitsch PetscCall(PetscSpinlockUnlock(&PetscLogSpinLock)); 1343ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 135c708d6e3SStefano Zampini } 136c708d6e3SStefano Zampini 137c708d6e3SStefano Zampini PetscErrorCode PetscAddLogDoubleCnt(PetscLogDouble *cnt, PetscLogDouble *tot, PetscLogDouble *cnt_th, PetscLogDouble *tot_th, PetscLogDouble tmp) 138c708d6e3SStefano Zampini { 139c708d6e3SStefano Zampini *cnt_th = *cnt_th + 1; 140c708d6e3SStefano Zampini *tot_th += tmp; 1413ba16761SJacob Faibussowitsch PetscCall(PetscSpinlockLock(&PetscLogSpinLock)); 14257508eceSPierre Jolivet *tot += (PetscLogDouble)tmp; 143c708d6e3SStefano Zampini *cnt += *cnt + 1; 1443ba16761SJacob Faibussowitsch PetscCall(PetscSpinlockUnlock(&PetscLogSpinLock)); 1453ba16761SJacob Faibussowitsch return PETSC_SUCCESS; 146c708d6e3SStefano Zampini } 147c708d6e3SStefano Zampini 148bec0b493Shannah_mairs #endif 1495c6c1daeSBarry Smith 15053e0a2f3SToby Isaac static PetscErrorCode PetscLogTryGetHandler(PetscLogHandlerType type, PetscLogHandler *handler) 15153e0a2f3SToby Isaac { 15253e0a2f3SToby Isaac PetscFunctionBegin; 15353e0a2f3SToby Isaac PetscAssertPointer(handler, 2); 15453e0a2f3SToby Isaac *handler = NULL; 15553e0a2f3SToby Isaac for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 15653e0a2f3SToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 15753e0a2f3SToby Isaac if (h) { 15853e0a2f3SToby Isaac PetscBool match; 15953e0a2f3SToby Isaac 16053e0a2f3SToby Isaac PetscCall(PetscObjectTypeCompare((PetscObject)h, type, &match)); 16153e0a2f3SToby Isaac if (match) { 16253e0a2f3SToby Isaac *handler = PetscLogHandlers[i].handler; 16353e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 16453e0a2f3SToby Isaac } 16553e0a2f3SToby Isaac } 16653e0a2f3SToby Isaac } 16753e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 16853e0a2f3SToby Isaac } 16953e0a2f3SToby Isaac 17053e0a2f3SToby Isaac /*@ 171b665b14eSToby Isaac PetscLogGetDefaultHandler - Get the default log handler if it is running. 172b665b14eSToby Isaac 173b665b14eSToby Isaac Not collective 174b665b14eSToby Isaac 175b665b14eSToby Isaac Output Parameter: 176b665b14eSToby Isaac . handler - the default `PetscLogHandler`, or `NULL` if it is not running. 177b665b14eSToby Isaac 178b665b14eSToby Isaac Level: developer 179b665b14eSToby Isaac 180b665b14eSToby Isaac Notes: 181b665b14eSToby Isaac The default handler is started with `PetscLogDefaultBegin()`, 182b665b14eSToby Isaac if the options flags `-log_all` or `-log_view` is given without arguments, 183b665b14eSToby Isaac or for `-log_view :output:format` if `format` is not `ascii_xml` or `ascii_flamegraph`. 184b665b14eSToby Isaac 185b665b14eSToby Isaac .seealso: [](ch_profiling) 186b665b14eSToby Isaac @*/ 187b665b14eSToby Isaac PetscErrorCode PetscLogGetDefaultHandler(PetscLogHandler *handler) 188b665b14eSToby Isaac { 189b665b14eSToby Isaac PetscFunctionBegin; 190294de794SToby Isaac PetscCall(PetscLogTryGetHandler(PETSCLOGHANDLERDEFAULT, handler)); 191b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 192b665b14eSToby Isaac } 193b665b14eSToby Isaac 194b665b14eSToby Isaac static PetscErrorCode PetscLogGetHandler(PetscLogHandlerType type, PetscLogHandler *handler) 195b665b14eSToby Isaac { 196b665b14eSToby Isaac PetscFunctionBegin; 197b665b14eSToby Isaac PetscAssertPointer(handler, 2); 198b665b14eSToby Isaac PetscCall(PetscLogTryGetHandler(type, handler)); 1991943a749SToby Isaac PetscCheck(*handler != NULL, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "A PetscLogHandler of type %s has not been started.", type); 200b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 201b665b14eSToby Isaac } 202b665b14eSToby Isaac 203b665b14eSToby Isaac /*@ 20453e0a2f3SToby Isaac PetscLogGetState - Get the `PetscLogState` for PETSc's global logging, used 20553e0a2f3SToby Isaac by all default log handlers (`PetscLogDefaultBegin()`, 20653e0a2f3SToby Isaac `PetscLogNestedBegin()`, `PetscLogTraceBegin()`, `PetscLogMPEBegin()`, 20753e0a2f3SToby Isaac `PetscLogPerfstubsBegin()`). 20853e0a2f3SToby Isaac 20953e0a2f3SToby Isaac Collective on `PETSC_COMM_WORLD` 21053e0a2f3SToby Isaac 21153e0a2f3SToby Isaac Output Parameter: 212b665b14eSToby Isaac . state - The `PetscLogState` changed by registrations (such as 213b665b14eSToby Isaac `PetscLogEventRegister()`) and actions (such as `PetscLogEventBegin()` or 214b8004f34SBarry Smith `PetscLogStagePush()`), or `NULL` if logging is not active 21553e0a2f3SToby Isaac 21653e0a2f3SToby Isaac Level: developer 21753e0a2f3SToby Isaac 21853e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogState` 21953e0a2f3SToby Isaac @*/ 22053e0a2f3SToby Isaac PetscErrorCode PetscLogGetState(PetscLogState *state) 22153e0a2f3SToby Isaac { 22253e0a2f3SToby Isaac PetscFunctionBegin; 22353e0a2f3SToby Isaac PetscAssertPointer(state, 1); 22453e0a2f3SToby Isaac *state = petsc_log_state; 22553e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 22653e0a2f3SToby Isaac } 22753e0a2f3SToby Isaac 22853e0a2f3SToby Isaac static PetscErrorCode PetscLogHandlerCopyToHot(PetscLogHandler h, PetscLogHandlerHot *hot) 22953e0a2f3SToby Isaac { 23053e0a2f3SToby Isaac PetscFunctionBegin; 23153e0a2f3SToby Isaac hot->handler = h; 23253e0a2f3SToby Isaac hot->eventBegin = h->ops->eventbegin; 23353e0a2f3SToby Isaac hot->eventEnd = h->ops->eventend; 23453e0a2f3SToby Isaac hot->eventSync = h->ops->eventsync; 23553e0a2f3SToby Isaac hot->objectCreate = h->ops->objectcreate; 23653e0a2f3SToby Isaac hot->objectDestroy = h->ops->objectdestroy; 23753e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 23853e0a2f3SToby Isaac } 23953e0a2f3SToby Isaac 24053e0a2f3SToby Isaac /*@ 24153e0a2f3SToby Isaac PetscLogHandlerStart - Connect a log handler to PETSc's global logging stream and state. 24253e0a2f3SToby Isaac 24353e0a2f3SToby Isaac Logically collective 24453e0a2f3SToby Isaac 24553e0a2f3SToby Isaac Input Parameters: 24653e0a2f3SToby Isaac . h - a `PetscLogHandler` 24753e0a2f3SToby Isaac 24853e0a2f3SToby Isaac Level: developer 24953e0a2f3SToby Isaac 25053e0a2f3SToby Isaac Notes: 25153e0a2f3SToby Isaac Users should only need this if they create their own log handlers: handlers that are started 25253e0a2f3SToby Isaac from the command line (such as `-log_view` and `-log_trace`) or from a function like 25353e0a2f3SToby Isaac `PetscLogNestedBegin()` will automatically be started. 25453e0a2f3SToby Isaac 25553e0a2f3SToby Isaac There is a limit of `PESC_LOG_HANDLER_MAX` handlers that can be active at one time. 25653e0a2f3SToby Isaac 25753e0a2f3SToby Isaac To disconnect a handler from the global stream call `PetscLogHandlerStop()`. 25853e0a2f3SToby Isaac 25953e0a2f3SToby Isaac When a log handler is started, stages that have already been pushed with `PetscLogStagePush()`, 26053e0a2f3SToby Isaac will be pushed for the new log handler, but it will not be informed of any events that are 26153e0a2f3SToby Isaac in progress. It is recommended to start any user-defined log handlers immediately following 262b8004f34SBarry Smith `PetscInitialize()` before any user-defined stages are pushed. 26353e0a2f3SToby Isaac 264b8004f34SBarry Smith .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogState`, `PetscLogHandlerStop()`, `PetscInitialize()` 26553e0a2f3SToby Isaac @*/ 26653e0a2f3SToby Isaac PetscErrorCode PetscLogHandlerStart(PetscLogHandler h) 26753e0a2f3SToby Isaac { 26853e0a2f3SToby Isaac PetscFunctionBegin; 26953e0a2f3SToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 27053e0a2f3SToby Isaac if (PetscLogHandlers[i].handler == h) PetscFunctionReturn(PETSC_SUCCESS); 27153e0a2f3SToby Isaac } 27253e0a2f3SToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 27353e0a2f3SToby Isaac if (PetscLogHandlers[i].handler == NULL) { 27453e0a2f3SToby Isaac PetscCall(PetscObjectReference((PetscObject)h)); 27553e0a2f3SToby Isaac PetscCall(PetscLogHandlerCopyToHot(h, &PetscLogHandlers[i])); 27653e0a2f3SToby Isaac if (petsc_log_state) { 27753e0a2f3SToby Isaac PetscLogStage stack_height; 27853e0a2f3SToby Isaac PetscIntStack orig_stack, temp_stack; 27953e0a2f3SToby Isaac 28053e0a2f3SToby Isaac PetscCall(PetscLogHandlerSetState(h, petsc_log_state)); 28153e0a2f3SToby Isaac stack_height = petsc_log_state->stage_stack->top + 1; 28253e0a2f3SToby Isaac PetscCall(PetscIntStackCreate(&temp_stack)); 28353e0a2f3SToby Isaac orig_stack = petsc_log_state->stage_stack; 28453e0a2f3SToby Isaac petsc_log_state->stage_stack = temp_stack; 28553e0a2f3SToby Isaac petsc_log_state->current_stage = -1; 28653e0a2f3SToby Isaac for (int s = 0; s < stack_height; s++) { 287835f2295SStefano Zampini PetscLogStage stage = orig_stack->stack[s]; 28853e0a2f3SToby Isaac PetscCall(PetscLogHandlerStagePush(h, stage)); 28953e0a2f3SToby Isaac PetscCall(PetscIntStackPush(temp_stack, stage)); 29053e0a2f3SToby Isaac petsc_log_state->current_stage = stage; 29153e0a2f3SToby Isaac } 29253e0a2f3SToby Isaac PetscCall(PetscIntStackDestroy(temp_stack)); 29353e0a2f3SToby Isaac petsc_log_state->stage_stack = orig_stack; 29453e0a2f3SToby Isaac } 29553e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 29653e0a2f3SToby Isaac } 29753e0a2f3SToby Isaac } 29853e0a2f3SToby Isaac SETERRQ(PetscObjectComm((PetscObject)h), PETSC_ERR_ARG_WRONGSTATE, "%d log handlers already started, cannot start another", PETSC_LOG_HANDLER_MAX); 29953e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 30053e0a2f3SToby Isaac } 30153e0a2f3SToby Isaac 30253e0a2f3SToby Isaac /*@ 30353e0a2f3SToby Isaac PetscLogHandlerStop - Disconnect a log handler from PETSc's global logging stream. 30453e0a2f3SToby Isaac 30553e0a2f3SToby Isaac Logically collective 30653e0a2f3SToby Isaac 30753e0a2f3SToby Isaac Input Parameters: 30853e0a2f3SToby Isaac . h - a `PetscLogHandler` 30953e0a2f3SToby Isaac 31053e0a2f3SToby Isaac Level: developer 31153e0a2f3SToby Isaac 31253e0a2f3SToby Isaac Note: 31353e0a2f3SToby Isaac After `PetscLogHandlerStop()`, the handler can still access the global logging state 31453e0a2f3SToby Isaac with `PetscLogHandlerGetState()`, so that it can access the registry when post-processing 31553e0a2f3SToby Isaac (for instance, in `PetscLogHandlerView()`), 31653e0a2f3SToby Isaac 31753e0a2f3SToby Isaac When a log handler is stopped, the remaining stages will be popped before it is 31853e0a2f3SToby Isaac disconnected from the log stream. 31953e0a2f3SToby Isaac 32053e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogState`, `PetscLogHandlerStart()` 32153e0a2f3SToby Isaac @*/ 32253e0a2f3SToby Isaac PetscErrorCode PetscLogHandlerStop(PetscLogHandler h) 32353e0a2f3SToby Isaac { 32453e0a2f3SToby Isaac PetscFunctionBegin; 32553e0a2f3SToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 32653e0a2f3SToby Isaac if (PetscLogHandlers[i].handler == h) { 32753e0a2f3SToby Isaac if (petsc_log_state) { 32853e0a2f3SToby Isaac PetscLogState state; 32953e0a2f3SToby Isaac PetscLogStage stack_height; 33053e0a2f3SToby Isaac PetscIntStack orig_stack, temp_stack; 33153e0a2f3SToby Isaac 33253e0a2f3SToby Isaac PetscCall(PetscLogHandlerGetState(h, &state)); 33353e0a2f3SToby Isaac PetscCheck(state == petsc_log_state, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONGSTATE, "Called PetscLogHandlerStop() for a PetscLogHander that was not started."); 33453e0a2f3SToby Isaac stack_height = petsc_log_state->stage_stack->top + 1; 33553e0a2f3SToby Isaac PetscCall(PetscIntStackCreate(&temp_stack)); 33653e0a2f3SToby Isaac orig_stack = petsc_log_state->stage_stack; 33753e0a2f3SToby Isaac petsc_log_state->stage_stack = temp_stack; 33853e0a2f3SToby Isaac for (int s = 0; s < stack_height; s++) { 339835f2295SStefano Zampini PetscLogStage stage = orig_stack->stack[s]; 34053e0a2f3SToby Isaac 34153e0a2f3SToby Isaac PetscCall(PetscIntStackPush(temp_stack, stage)); 34253e0a2f3SToby Isaac } 34353e0a2f3SToby Isaac for (int s = 0; s < stack_height; s++) { 34453e0a2f3SToby Isaac PetscLogStage stage; 34553e0a2f3SToby Isaac PetscBool empty; 34653e0a2f3SToby Isaac 34753e0a2f3SToby Isaac PetscCall(PetscIntStackPop(temp_stack, &stage)); 34853e0a2f3SToby Isaac PetscCall(PetscIntStackEmpty(temp_stack, &empty)); 349ac530a7eSPierre Jolivet if (!empty) PetscCall(PetscIntStackTop(temp_stack, &petsc_log_state->current_stage)); 350ac530a7eSPierre Jolivet else petsc_log_state->current_stage = -1; 35153e0a2f3SToby Isaac PetscCall(PetscLogHandlerStagePop(h, stage)); 35253e0a2f3SToby Isaac } 35353e0a2f3SToby Isaac PetscCall(PetscIntStackDestroy(temp_stack)); 35453e0a2f3SToby Isaac petsc_log_state->stage_stack = orig_stack; 35553e0a2f3SToby Isaac PetscCall(PetscIntStackTop(petsc_log_state->stage_stack, &petsc_log_state->current_stage)); 35653e0a2f3SToby Isaac } 35753e0a2f3SToby Isaac PetscCall(PetscArrayzero(&PetscLogHandlers[i], 1)); 35853e0a2f3SToby Isaac PetscCall(PetscObjectDereference((PetscObject)h)); 35953e0a2f3SToby Isaac } 36053e0a2f3SToby Isaac } 36153e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 36253e0a2f3SToby Isaac } 3635c6c1daeSBarry Smith 364cc4c1da9SBarry Smith /*@ 3650b4b7b1cSBarry Smith PetscLogIsActive - Check if logging (profiling) is currently in progress. 3664dd65854SConnor Ward 3674dd65854SConnor Ward Not Collective 3684dd65854SConnor Ward 3694dd65854SConnor Ward Output Parameter: 370811af0c4SBarry Smith . isActive - `PETSC_TRUE` if logging is in progress, `PETSC_FALSE` otherwise 3714dd65854SConnor Ward 3724dd65854SConnor Ward Level: beginner 3734dd65854SConnor Ward 374b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogDefaultBegin()` 3754dd65854SConnor Ward @*/ 376d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogIsActive(PetscBool *isActive) 377d71ae5a4SJacob Faibussowitsch { 3784dd65854SConnor Ward PetscFunctionBegin; 379b665b14eSToby Isaac *isActive = PETSC_FALSE; 380b665b14eSToby Isaac if (petsc_log_state) { 381b665b14eSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 382b665b14eSToby Isaac if (PetscLogHandlers[i].handler) { 383b665b14eSToby Isaac *isActive = PETSC_TRUE; 384b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 385b665b14eSToby Isaac } 386b665b14eSToby Isaac } 387b665b14eSToby Isaac } 388b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 389b665b14eSToby Isaac } 390b665b14eSToby Isaac 391b665b14eSToby Isaac PETSC_UNUSED static PetscErrorCode PetscLogEventBeginIsActive(PetscBool *isActive) 392b665b14eSToby Isaac { 393b665b14eSToby Isaac PetscFunctionBegin; 394b665b14eSToby Isaac *isActive = PETSC_FALSE; 395b665b14eSToby Isaac if (petsc_log_state) { 396b665b14eSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 397b665b14eSToby Isaac if (PetscLogHandlers[i].eventBegin) { 398b665b14eSToby Isaac *isActive = PETSC_TRUE; 399b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 400b665b14eSToby Isaac } 401b665b14eSToby Isaac } 402b665b14eSToby Isaac } 403b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 404b665b14eSToby Isaac } 405b665b14eSToby Isaac 406b665b14eSToby Isaac PETSC_UNUSED static PetscErrorCode PetscLogEventEndIsActive(PetscBool *isActive) 407b665b14eSToby Isaac { 408b665b14eSToby Isaac PetscFunctionBegin; 409b665b14eSToby Isaac *isActive = PETSC_FALSE; 410b665b14eSToby Isaac if (petsc_log_state) { 411b665b14eSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 412b665b14eSToby Isaac if (PetscLogHandlers[i].eventEnd) { 413b665b14eSToby Isaac *isActive = PETSC_TRUE; 414b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 415b665b14eSToby Isaac } 416b665b14eSToby Isaac } 417b665b14eSToby Isaac } 4183ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 4194dd65854SConnor Ward } 4204dd65854SConnor Ward 42161cc7448SToby Isaac PETSC_INTERN PetscErrorCode PetscLogTypeBegin(PetscLogHandlerType type) 42253e0a2f3SToby Isaac { 42353e0a2f3SToby Isaac PetscLogHandler handler; 42453e0a2f3SToby Isaac 42553e0a2f3SToby Isaac PetscFunctionBegin; 42653e0a2f3SToby Isaac PetscCall(PetscLogTryGetHandler(type, &handler)); 42753e0a2f3SToby Isaac if (handler) PetscFunctionReturn(PETSC_SUCCESS); 42853e0a2f3SToby Isaac PetscCall(PetscLogHandlerCreate(PETSC_COMM_WORLD, &handler)); 42953e0a2f3SToby Isaac PetscCall(PetscLogHandlerSetType(handler, type)); 43053e0a2f3SToby Isaac PetscCall(PetscLogHandlerStart(handler)); 43153e0a2f3SToby Isaac PetscCall(PetscLogHandlerDestroy(&handler)); 43253e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 43353e0a2f3SToby Isaac } 43453e0a2f3SToby Isaac 435cc4c1da9SBarry Smith /*@ 4360b4b7b1cSBarry Smith PetscLogDefaultBegin - Turns on logging (profiling) of PETSc code using the default log handler (profiler). This logs time, flop 4370b4b7b1cSBarry Smith rates, and object creation and should not slow programs down too much. 4385c6c1daeSBarry Smith 4398f14a041SBarry Smith Logically Collective on `PETSC_COMM_WORLD` 4405c6c1daeSBarry Smith 441811af0c4SBarry Smith Options Database Key: 4420b4b7b1cSBarry Smith . -log_view [viewertype:filename:viewerformat] - Prints summary of flop and timing (profiling) information to the 4430b4b7b1cSBarry Smith screen (for PETSc configured with `--with-log=1` (which is the default)). 4440b4b7b1cSBarry Smith This option must be provided before `PetscInitialize()`. 4455c6c1daeSBarry Smith 44610450e9eSJacob Faibussowitsch Example Usage: 4475c6c1daeSBarry Smith .vb 4485c6c1daeSBarry Smith PetscInitialize(...); 449bb1d7374SBarry Smith PetscLogDefaultBegin(); 4505c6c1daeSBarry Smith ... code ... 4515c6c1daeSBarry Smith PetscLogView(viewer); or PetscLogDump(); 4525c6c1daeSBarry Smith PetscFinalize(); 4535c6c1daeSBarry Smith .ve 4545c6c1daeSBarry Smith 455d1f92df0SBarry Smith Level: advanced 456d1f92df0SBarry Smith 4570b4b7b1cSBarry Smith Notes: 458811af0c4SBarry Smith `PetscLogView()` or `PetscLogDump()` actually cause the printing of 4595c6c1daeSBarry Smith the logging information. 4605c6c1daeSBarry Smith 4610b4b7b1cSBarry Smith This routine may be called more than once. 4620b4b7b1cSBarry Smith 4630b4b7b1cSBarry Smith To provide the `-log_view` option in your source code you must call PetscCall(PetscOptionsSetValue(NULL, "-log_view", NULL)); 4640b4b7b1cSBarry Smith before you call `PetscInitialize()` 4650b4b7b1cSBarry Smith 466b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogDump()`, `PetscLogView()`, `PetscLogTraceBegin()` 4675c6c1daeSBarry Smith @*/ 468d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogDefaultBegin(void) 469d71ae5a4SJacob Faibussowitsch { 4705c6c1daeSBarry Smith PetscFunctionBegin; 471294de794SToby Isaac PetscCall(PetscLogTypeBegin(PETSCLOGHANDLERDEFAULT)); 4723ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 4735c6c1daeSBarry Smith } 4745c6c1daeSBarry Smith 4755c6c1daeSBarry Smith /*@C 476b665b14eSToby Isaac PetscLogTraceBegin - Begins trace logging. Every time a PETSc event 4775c6c1daeSBarry Smith begins or ends, the event name is printed. 4785c6c1daeSBarry Smith 479cc4c1da9SBarry Smith Logically Collective on `PETSC_COMM_WORLD`, No Fortran Support 4805c6c1daeSBarry Smith 4815c6c1daeSBarry Smith Input Parameter: 4825c6c1daeSBarry Smith . file - The file to print trace in (e.g. stdout) 4835c6c1daeSBarry Smith 4845c6c1daeSBarry Smith Options Database Key: 485b665b14eSToby Isaac . -log_trace [filename] - Begins `PetscLogTraceBegin()` 4865c6c1daeSBarry Smith 487d1f92df0SBarry Smith Level: intermediate 488d1f92df0SBarry Smith 4895c6c1daeSBarry Smith Notes: 490811af0c4SBarry Smith `PetscLogTraceBegin()` prints the processor number, the execution time (sec), 4915c6c1daeSBarry Smith then "Event begin:" or "Event end:" followed by the event name. 4925c6c1daeSBarry Smith 493811af0c4SBarry Smith `PetscLogTraceBegin()` allows tracing of all PETSc calls, which is useful 4945c6c1daeSBarry Smith to determine where a program is hanging without running in the 4955c6c1daeSBarry Smith debugger. Can be used in conjunction with the -info option. 4965c6c1daeSBarry Smith 497b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogDump()`, `PetscLogView()`, `PetscLogDefaultBegin()` 4985c6c1daeSBarry Smith @*/ 499d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogTraceBegin(FILE *file) 500d71ae5a4SJacob Faibussowitsch { 501b665b14eSToby Isaac PetscLogHandler handler; 5024d86920dSPierre Jolivet 5035c6c1daeSBarry Smith PetscFunctionBegin; 504294de794SToby Isaac PetscCall(PetscLogTryGetHandler(PETSCLOGHANDLERTRACE, &handler)); 505b665b14eSToby Isaac if (handler) PetscFunctionReturn(PETSC_SUCCESS); 506b665b14eSToby Isaac PetscCall(PetscLogHandlerCreateTrace(PETSC_COMM_WORLD, file, &handler)); 507b665b14eSToby Isaac PetscCall(PetscLogHandlerStart(handler)); 508b665b14eSToby Isaac PetscCall(PetscLogHandlerDestroy(&handler)); 509b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 510b665b14eSToby Isaac } 511a297a907SKarl Rupp 512b665b14eSToby Isaac PETSC_INTERN PetscErrorCode PetscLogHandlerCreate_Nested(MPI_Comm, PetscLogHandler *); 513b665b14eSToby Isaac 514cc4c1da9SBarry Smith /*@ 515b665b14eSToby Isaac PetscLogNestedBegin - Turns on nested logging of objects and events. This logs flop 516b665b14eSToby Isaac rates and object creation and should not slow programs down too much. 517b665b14eSToby Isaac 518cc4c1da9SBarry Smith Logically Collective on `PETSC_COMM_WORLD`, No Fortran Support 519b665b14eSToby Isaac 520b665b14eSToby Isaac Options Database Keys: 521b665b14eSToby Isaac . -log_view :filename.xml:ascii_xml - Prints an XML summary of flop and timing information to the file 522b665b14eSToby Isaac 523b665b14eSToby Isaac Example Usage: 524b665b14eSToby Isaac .vb 525b665b14eSToby Isaac PetscInitialize(...); 526b665b14eSToby Isaac PetscLogNestedBegin(); 527b665b14eSToby Isaac ... code ... 528b665b14eSToby Isaac PetscLogView(viewer); 529b665b14eSToby Isaac PetscFinalize(); 530b665b14eSToby Isaac .ve 531b665b14eSToby Isaac 532b665b14eSToby Isaac Level: advanced 533b665b14eSToby Isaac 534b665b14eSToby Isaac .seealso: `PetscLogDump()`, `PetscLogView()`, `PetscLogTraceBegin()`, `PetscLogDefaultBegin()` 535b665b14eSToby Isaac @*/ 536b665b14eSToby Isaac PetscErrorCode PetscLogNestedBegin(void) 537b665b14eSToby Isaac { 538b665b14eSToby Isaac PetscFunctionBegin; 539294de794SToby Isaac PetscCall(PetscLogTypeBegin(PETSCLOGHANDLERNESTED)); 5403ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 5415c6c1daeSBarry Smith } 5425c6c1daeSBarry Smith 54353e0a2f3SToby Isaac /*@C 54453e0a2f3SToby Isaac PetscLogLegacyCallbacksBegin - Create and start a log handler from callbacks 54553e0a2f3SToby Isaac matching the now deprecated function pointers `PetscLogPLB`, `PetscLogPLE`, 54653e0a2f3SToby Isaac `PetscLogPHC`, `PetscLogPHD`. 54753e0a2f3SToby Isaac 5488f14a041SBarry Smith Logically Collective on `PETSC_COMM_WORLD` 54953e0a2f3SToby Isaac 55053e0a2f3SToby Isaac Input Parameters: 55153e0a2f3SToby Isaac + PetscLogPLB - A callback that will be executed by `PetscLogEventBegin()` (or `NULL`) 55253e0a2f3SToby Isaac . PetscLogPLE - A callback that will be executed by `PetscLogEventEnd()` (or `NULL`) 55353e0a2f3SToby Isaac . PetscLogPHC - A callback that will be executed by `PetscLogObjectCreate()` (or `NULL`) 55453e0a2f3SToby Isaac - PetscLogPHD - A callback that will be executed by `PetscLogObjectCreate()` (or `NULL`) 55553e0a2f3SToby Isaac 55653e0a2f3SToby Isaac Calling sequence of `PetscLogPLB`: 55753e0a2f3SToby Isaac + e - a `PetscLogEvent` that is beginning 55853e0a2f3SToby Isaac . _i - deprecated, unused 55953e0a2f3SToby Isaac . o1 - a `PetscObject` associated with `e` (or `NULL`) 56053e0a2f3SToby Isaac . o2 - a `PetscObject` associated with `e` (or `NULL`) 56153e0a2f3SToby Isaac . o3 - a `PetscObject` associated with `e` (or `NULL`) 56253e0a2f3SToby Isaac - o4 - a `PetscObject` associated with `e` (or `NULL`) 56353e0a2f3SToby Isaac 56453e0a2f3SToby Isaac Calling sequence of `PetscLogPLE`: 56553e0a2f3SToby Isaac + e - a `PetscLogEvent` that is beginning 56653e0a2f3SToby Isaac . _i - deprecated, unused 56753e0a2f3SToby Isaac . o1 - a `PetscObject` associated with `e` (or `NULL`) 56853e0a2f3SToby Isaac . o2 - a `PetscObject` associated with `e` (or `NULL`) 56953e0a2f3SToby Isaac . o3 - a `PetscObject` associated with `e` (or `NULL`) 57053e0a2f3SToby Isaac - o4 - a `PetscObject` associated with `e` (or `NULL`) 57153e0a2f3SToby Isaac 57253e0a2f3SToby Isaac Calling sequence of `PetscLogPHC`: 57353e0a2f3SToby Isaac . o - a `PetscObject` that has just been created 57453e0a2f3SToby Isaac 57553e0a2f3SToby Isaac Calling sequence of `PetscLogPHD`: 57653e0a2f3SToby Isaac . o - a `PetscObject` that is about to be destroyed 57753e0a2f3SToby Isaac 57853e0a2f3SToby Isaac Level: advanced 57953e0a2f3SToby Isaac 58053e0a2f3SToby Isaac Notes: 58153e0a2f3SToby Isaac This is for transitioning from the deprecated function `PetscLogSet()` and should not be used in new code. 58253e0a2f3SToby Isaac 58353e0a2f3SToby Isaac This should help migrate external log handlers to use `PetscLogHandler`, but 58453e0a2f3SToby Isaac callbacks that depend on the deprecated `PetscLogStage` datatype will have to be 58553e0a2f3SToby Isaac updated. 58653e0a2f3SToby Isaac 58753e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerStart()`, `PetscLogState` 58853e0a2f3SToby Isaac @*/ 58953e0a2f3SToby Isaac PetscErrorCode PetscLogLegacyCallbacksBegin(PetscErrorCode (*PetscLogPLB)(PetscLogEvent e, int _i, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4), PetscErrorCode (*PetscLogPLE)(PetscLogEvent e, int _i, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4), PetscErrorCode (*PetscLogPHC)(PetscObject o), PetscErrorCode (*PetscLogPHD)(PetscObject o)) 59053e0a2f3SToby Isaac { 59153e0a2f3SToby Isaac PetscLogHandler handler; 59253e0a2f3SToby Isaac 59353e0a2f3SToby Isaac PetscFunctionBegin; 59453e0a2f3SToby Isaac PetscCall(PetscLogHandlerCreateLegacy(PETSC_COMM_WORLD, PetscLogPLB, PetscLogPLE, PetscLogPHC, PetscLogPHD, &handler)); 59553e0a2f3SToby Isaac PetscCall(PetscLogHandlerStart(handler)); 59653e0a2f3SToby Isaac PetscCall(PetscLogHandlerDestroy(&handler)); 59753e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 59853e0a2f3SToby Isaac } 59953e0a2f3SToby Isaac 6002611ad71SToby Isaac #if defined(PETSC_HAVE_MPE) 6012611ad71SToby Isaac #include <mpe.h> 6022611ad71SToby Isaac static PetscBool PetscBeganMPE = PETSC_FALSE; 6032611ad71SToby Isaac #endif 6042611ad71SToby Isaac 6052611ad71SToby Isaac /*@C 6062611ad71SToby Isaac PetscLogMPEBegin - Turns on MPE logging of events. This creates large log files and slows the 6072611ad71SToby Isaac program down. 6082611ad71SToby Isaac 609cc4c1da9SBarry Smith Collective on `PETSC_COMM_WORLD`, No Fortran Support 6102611ad71SToby Isaac 6112611ad71SToby Isaac Options Database Key: 6122611ad71SToby Isaac . -log_mpe - Prints extensive log information 6132611ad71SToby Isaac 6142611ad71SToby Isaac Level: advanced 6152611ad71SToby Isaac 6162611ad71SToby Isaac Note: 6172611ad71SToby Isaac A related routine is `PetscLogDefaultBegin()` (with the options key `-log_view`), which is 6182611ad71SToby Isaac intended for production runs since it logs only flop rates and object creation (and should 6192611ad71SToby Isaac not significantly slow the programs). 6202611ad71SToby Isaac 621b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogDump()`, `PetscLogDefaultBegin()`, `PetscLogEventActivate()`, 6222611ad71SToby Isaac `PetscLogEventDeactivate()` 6232611ad71SToby Isaac @*/ 6242611ad71SToby Isaac PetscErrorCode PetscLogMPEBegin(void) 6252611ad71SToby Isaac { 6262611ad71SToby Isaac PetscFunctionBegin; 6272611ad71SToby Isaac #if defined(PETSC_HAVE_MPE) 6282611ad71SToby Isaac /* Do MPE initialization */ 6292611ad71SToby Isaac if (!MPE_Initialized_logging()) { /* This function exists in mpich 1.1.2 and higher */ 6302611ad71SToby Isaac PetscCall(PetscInfo(0, "Initializing MPE.\n")); 6312611ad71SToby Isaac PetscCall(MPE_Init_log()); 6322611ad71SToby Isaac 6332611ad71SToby Isaac PetscBeganMPE = PETSC_TRUE; 6342611ad71SToby Isaac } else { 6352611ad71SToby Isaac PetscCall(PetscInfo(0, "MPE already initialized. Not attempting to reinitialize.\n")); 6362611ad71SToby Isaac } 637294de794SToby Isaac PetscCall(PetscLogTypeBegin(PETSCLOGHANDLERMPE)); 6382611ad71SToby Isaac #else 6392611ad71SToby Isaac SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP_SYS, "PETSc was configured without MPE support, reconfigure with --with-mpe or --download-mpe"); 6402611ad71SToby Isaac #endif 6412611ad71SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 6422611ad71SToby Isaac } 6432611ad71SToby Isaac 64453e0a2f3SToby Isaac #if defined(PETSC_HAVE_TAU_PERFSTUBS) 64553e0a2f3SToby Isaac #include <../src/sys/perfstubs/timer.h> 64653e0a2f3SToby Isaac #endif 64753e0a2f3SToby Isaac 64853e0a2f3SToby Isaac /*@C 64953e0a2f3SToby Isaac PetscLogPerfstubsBegin - Turns on logging of events using the perfstubs interface. 65053e0a2f3SToby Isaac 651cc4c1da9SBarry Smith Collective on `PETSC_COMM_WORLD`, No Fortran Support 65253e0a2f3SToby Isaac 65353e0a2f3SToby Isaac Options Database Key: 65453e0a2f3SToby Isaac . -log_perfstubs - use an external log handler through the perfstubs interface 65553e0a2f3SToby Isaac 65653e0a2f3SToby Isaac Level: advanced 65753e0a2f3SToby Isaac 65853e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogDefaultBegin()`, `PetscLogEventActivate()` 65953e0a2f3SToby Isaac @*/ 66053e0a2f3SToby Isaac PetscErrorCode PetscLogPerfstubsBegin(void) 66153e0a2f3SToby Isaac { 66253e0a2f3SToby Isaac PetscFunctionBegin; 66353e0a2f3SToby Isaac #if defined(PETSC_HAVE_TAU_PERFSTUBS) 664294de794SToby Isaac PetscCall(PetscLogTypeBegin(PETSCLOGHANDLERPERFSTUBS)); 66553e0a2f3SToby Isaac #else 66653e0a2f3SToby Isaac SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP_SYS, "PETSc was configured without perfstubs support, reconfigure with --with-tau-perfstubs"); 66753e0a2f3SToby Isaac #endif 66853e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 66953e0a2f3SToby Isaac } 67053e0a2f3SToby Isaac 6715c6c1daeSBarry Smith /*@ 672b665b14eSToby Isaac PetscLogActions - Determines whether actions are logged for the default log handler. 6735c6c1daeSBarry Smith 6745c6c1daeSBarry Smith Not Collective 6755c6c1daeSBarry Smith 6765c6c1daeSBarry Smith Input Parameter: 677811af0c4SBarry Smith . flag - `PETSC_TRUE` if actions are to be logged 678811af0c4SBarry Smith 679811af0c4SBarry Smith Options Database Key: 680b665b14eSToby Isaac + -log_exclude_actions - (deprecated) Does nothing 681b665b14eSToby Isaac - -log_include_actions - Turn on action logging 6825c6c1daeSBarry Smith 6835c6c1daeSBarry Smith Level: intermediate 6845c6c1daeSBarry Smith 685811af0c4SBarry Smith Note: 686811af0c4SBarry Smith Logging of actions continues to consume more memory as the program 6875c6c1daeSBarry Smith runs. Long running programs should consider turning this feature off. 688aec76313SJacob Faibussowitsch 689b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogGetDefaultHandler()` 6905c6c1daeSBarry Smith @*/ 691d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogActions(PetscBool flag) 692d71ae5a4SJacob Faibussowitsch { 6935c6c1daeSBarry Smith PetscFunctionBegin; 694dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 695dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 696dff009beSToby Isaac 697dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerSetLogActions(h, flag)); 698dff009beSToby Isaac } 6993ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 7005c6c1daeSBarry Smith } 7015c6c1daeSBarry Smith 7025c6c1daeSBarry Smith /*@ 7035c6c1daeSBarry Smith PetscLogObjects - Determines whether objects are logged for the graphical viewer. 7045c6c1daeSBarry Smith 7055c6c1daeSBarry Smith Not Collective 7065c6c1daeSBarry Smith 7075c6c1daeSBarry Smith Input Parameter: 708811af0c4SBarry Smith . flag - `PETSC_TRUE` if objects are to be logged 709811af0c4SBarry Smith 710811af0c4SBarry Smith Options Database Key: 711b665b14eSToby Isaac + -log_exclude_objects - (deprecated) Does nothing 712b665b14eSToby Isaac - -log_include_objects - Turns on object logging 7135c6c1daeSBarry Smith 7145c6c1daeSBarry Smith Level: intermediate 7155c6c1daeSBarry Smith 716811af0c4SBarry Smith Note: 717811af0c4SBarry Smith Logging of objects continues to consume more memory as the program 7185c6c1daeSBarry Smith runs. Long running programs should consider turning this feature off. 7195c6c1daeSBarry Smith 720b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogGetDefaultHandler()` 7215c6c1daeSBarry Smith @*/ 722d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogObjects(PetscBool flag) 723d71ae5a4SJacob Faibussowitsch { 7245c6c1daeSBarry Smith PetscFunctionBegin; 725dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 726dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 727dff009beSToby Isaac 728dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerSetLogObjects(h, flag)); 729dff009beSToby Isaac } 7303ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 7315c6c1daeSBarry Smith } 7325c6c1daeSBarry Smith 7335c6c1daeSBarry Smith /*------------------------------------------------ Stage Functions --------------------------------------------------*/ 734cc4c1da9SBarry Smith /*@ 73574c0405dSRichard Tran Mills PetscLogStageRegister - Attaches a character string name to a logging stage. 7365c6c1daeSBarry Smith 7375c6c1daeSBarry Smith Not Collective 7385c6c1daeSBarry Smith 7395c6c1daeSBarry Smith Input Parameter: 7405c6c1daeSBarry Smith . sname - The name to associate with that stage 7415c6c1daeSBarry Smith 7425c6c1daeSBarry Smith Output Parameter: 743b665b14eSToby Isaac . stage - The stage number or -1 if logging is not active (`PetscLogIsActive()`). 7445c6c1daeSBarry Smith 7455c6c1daeSBarry Smith Level: intermediate 7465c6c1daeSBarry Smith 747d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStagePush()`, `PetscLogStagePop()` 7485c6c1daeSBarry Smith @*/ 749d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStageRegister(const char sname[], PetscLogStage *stage) 750d71ae5a4SJacob Faibussowitsch { 751b665b14eSToby Isaac PetscLogState state; 7525c6c1daeSBarry Smith 7535c6c1daeSBarry Smith PetscFunctionBegin; 754b665b14eSToby Isaac *stage = -1; 755b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 756b665b14eSToby Isaac if (state) PetscCall(PetscLogStateStageRegister(state, sname, stage)); 7573ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 7585c6c1daeSBarry Smith } 7595c6c1daeSBarry Smith 760cc4c1da9SBarry Smith /*@ 761811af0c4SBarry Smith PetscLogStagePush - This function pushes a stage on the logging stack. Events started and stopped until `PetscLogStagePop()` will be associated with the stage 7625c6c1daeSBarry Smith 7635c6c1daeSBarry Smith Not Collective 7645c6c1daeSBarry Smith 7655c6c1daeSBarry Smith Input Parameter: 7665c6c1daeSBarry Smith . stage - The stage on which to log 7675c6c1daeSBarry Smith 76810450e9eSJacob Faibussowitsch Example Usage: 769811af0c4SBarry Smith If the option -log_view is used to run the program containing the 7705c6c1daeSBarry Smith following code, then 2 sets of summary data will be printed during 7715c6c1daeSBarry Smith PetscFinalize(). 7725c6c1daeSBarry Smith .vb 7735c6c1daeSBarry Smith PetscInitialize(int *argc,char ***args,0,0); 7745c6c1daeSBarry Smith [stage 0 of code] 7755c6c1daeSBarry Smith PetscLogStagePush(1); 7765c6c1daeSBarry Smith [stage 1 of code] 7775c6c1daeSBarry Smith PetscLogStagePop(); 7785c6c1daeSBarry Smith PetscBarrier(...); 7795c6c1daeSBarry Smith [more stage 0 of code] 7805c6c1daeSBarry Smith PetscFinalize(); 7815c6c1daeSBarry Smith .ve 7825c6c1daeSBarry Smith 783d1f92df0SBarry Smith Level: intermediate 784d1f92df0SBarry Smith 785811af0c4SBarry Smith Note: 786811af0c4SBarry Smith Use `PetscLogStageRegister()` to register a stage. 7875c6c1daeSBarry Smith 788d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStagePop()`, `PetscLogStageRegister()`, `PetscBarrier()` 7895c6c1daeSBarry Smith @*/ 790d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStagePush(PetscLogStage stage) 791d71ae5a4SJacob Faibussowitsch { 792b665b14eSToby Isaac PetscLogState state; 7935c6c1daeSBarry Smith 7945c6c1daeSBarry Smith PetscFunctionBegin; 795b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 796b665b14eSToby Isaac if (!state) PetscFunctionReturn(PETSC_SUCCESS); 797b665b14eSToby Isaac for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 798b665b14eSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 799b665b14eSToby Isaac if (h) PetscCall(PetscLogHandlerStagePush(h, stage)); 800b665b14eSToby Isaac } 801b665b14eSToby Isaac PetscCall(PetscLogStateStagePush(state, stage)); 8023ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 8035c6c1daeSBarry Smith } 8045c6c1daeSBarry Smith 805cc4c1da9SBarry Smith /*@ 806811af0c4SBarry Smith PetscLogStagePop - This function pops a stage from the logging stack that was pushed with `PetscLogStagePush()` 8075c6c1daeSBarry Smith 8085c6c1daeSBarry Smith Not Collective 8095c6c1daeSBarry Smith 81010450e9eSJacob Faibussowitsch Example Usage: 811811af0c4SBarry Smith If the option -log_view is used to run the program containing the 8125c6c1daeSBarry Smith following code, then 2 sets of summary data will be printed during 8135c6c1daeSBarry Smith PetscFinalize(). 8145c6c1daeSBarry Smith .vb 8155c6c1daeSBarry Smith PetscInitialize(int *argc,char ***args,0,0); 8165c6c1daeSBarry Smith [stage 0 of code] 8175c6c1daeSBarry Smith PetscLogStagePush(1); 8185c6c1daeSBarry Smith [stage 1 of code] 8195c6c1daeSBarry Smith PetscLogStagePop(); 8205c6c1daeSBarry Smith PetscBarrier(...); 8215c6c1daeSBarry Smith [more stage 0 of code] 8225c6c1daeSBarry Smith PetscFinalize(); 8235c6c1daeSBarry Smith .ve 8245c6c1daeSBarry Smith 8255c6c1daeSBarry Smith Level: intermediate 8265c6c1daeSBarry Smith 827d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStagePush()`, `PetscLogStageRegister()`, `PetscBarrier()` 8285c6c1daeSBarry Smith @*/ 829d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStagePop(void) 830d71ae5a4SJacob Faibussowitsch { 831b665b14eSToby Isaac PetscLogState state; 832b665b14eSToby Isaac PetscLogStage current_stage; 8335c6c1daeSBarry Smith 8345c6c1daeSBarry Smith PetscFunctionBegin; 835b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 836b665b14eSToby Isaac if (!state) PetscFunctionReturn(PETSC_SUCCESS); 837b665b14eSToby Isaac current_stage = state->current_stage; 838b665b14eSToby Isaac PetscCall(PetscLogStateStagePop(state)); 839b665b14eSToby Isaac for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 840b665b14eSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 841b665b14eSToby Isaac if (h) PetscCall(PetscLogHandlerStagePop(h, current_stage)); 842b665b14eSToby Isaac } 8433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 8445c6c1daeSBarry Smith } 8455c6c1daeSBarry Smith 8465c6c1daeSBarry Smith /*@ 847811af0c4SBarry Smith PetscLogStageSetActive - Sets if a stage is used for `PetscLogEventBegin()` and `PetscLogEventEnd()`. 8485c6c1daeSBarry Smith 8495c6c1daeSBarry Smith Not Collective 8505c6c1daeSBarry Smith 8515c6c1daeSBarry Smith Input Parameters: 8525c6c1daeSBarry Smith + stage - The stage 853811af0c4SBarry Smith - isActive - The activity flag, `PETSC_TRUE` for logging, else `PETSC_FALSE` (defaults to `PETSC_TRUE`) 8545c6c1daeSBarry Smith 8555c6c1daeSBarry Smith Level: intermediate 8565c6c1daeSBarry Smith 857811af0c4SBarry Smith Note: 858811af0c4SBarry Smith If this is set to `PETSC_FALSE` the logging acts as if the stage did not exist 859811af0c4SBarry Smith 860d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()`, `PetscPreLoadStage()` 8615c6c1daeSBarry Smith @*/ 862d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStageSetActive(PetscLogStage stage, PetscBool isActive) 863d71ae5a4SJacob Faibussowitsch { 864b665b14eSToby Isaac PetscLogState state; 8655c6c1daeSBarry Smith 8665c6c1daeSBarry Smith PetscFunctionBegin; 867b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 868b665b14eSToby Isaac if (state) PetscCall(PetscLogStateStageSetActive(state, stage, isActive)); 8693ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 8705c6c1daeSBarry Smith } 8715c6c1daeSBarry Smith 8725c6c1daeSBarry Smith /*@ 873811af0c4SBarry Smith PetscLogStageGetActive - Checks if a stage is used for `PetscLogEventBegin()` and `PetscLogEventEnd()`. 8745c6c1daeSBarry Smith 8755c6c1daeSBarry Smith Not Collective 8765c6c1daeSBarry Smith 8775c6c1daeSBarry Smith Input Parameter: 8785c6c1daeSBarry Smith . stage - The stage 8795c6c1daeSBarry Smith 8805c6c1daeSBarry Smith Output Parameter: 881811af0c4SBarry Smith . isActive - The activity flag, `PETSC_TRUE` for logging, else `PETSC_FALSE` (defaults to `PETSC_TRUE`) 8825c6c1daeSBarry Smith 8835c6c1daeSBarry Smith Level: intermediate 8845c6c1daeSBarry Smith 885d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()`, `PetscPreLoadStage()` 8865c6c1daeSBarry Smith @*/ 887d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStageGetActive(PetscLogStage stage, PetscBool *isActive) 888d71ae5a4SJacob Faibussowitsch { 889b665b14eSToby Isaac PetscLogState state; 8905c6c1daeSBarry Smith 8915c6c1daeSBarry Smith PetscFunctionBegin; 892b665b14eSToby Isaac *isActive = PETSC_FALSE; 893b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 894b665b14eSToby Isaac if (state) PetscCall(PetscLogStateStageGetActive(state, stage, isActive)); 8953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 8965c6c1daeSBarry Smith } 8975c6c1daeSBarry Smith 8985c6c1daeSBarry Smith /*@ 899811af0c4SBarry Smith PetscLogStageSetVisible - Determines stage visibility in `PetscLogView()` 9005c6c1daeSBarry Smith 9015c6c1daeSBarry Smith Not Collective 9025c6c1daeSBarry Smith 9035c6c1daeSBarry Smith Input Parameters: 9045c6c1daeSBarry Smith + stage - The stage 905811af0c4SBarry Smith - isVisible - The visibility flag, `PETSC_TRUE` to print, else `PETSC_FALSE` (defaults to `PETSC_TRUE`) 9065c6c1daeSBarry Smith 9075c6c1daeSBarry Smith Level: intermediate 9085c6c1daeSBarry Smith 909aec76313SJacob Faibussowitsch Developer Notes: 910b665b14eSToby Isaac Visibility only affects the default log handler in `PetscLogView()`: stages that are 911b665b14eSToby Isaac set to invisible are suppressed from output. 912811af0c4SBarry Smith 913b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogStageGetVisible()`, `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogView()`, `PetscLogGetDefaultHandler()` 9145c6c1daeSBarry Smith @*/ 915d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStageSetVisible(PetscLogStage stage, PetscBool isVisible) 916dff009beSToby Isaac { 9175c6c1daeSBarry Smith PetscFunctionBegin; 918dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 919dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 920dff009beSToby Isaac 921dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerStageSetVisible(h, stage, isVisible)); 922dff009beSToby Isaac } 9233ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 9245c6c1daeSBarry Smith } 9255c6c1daeSBarry Smith 9265c6c1daeSBarry Smith /*@ 927811af0c4SBarry Smith PetscLogStageGetVisible - Returns stage visibility in `PetscLogView()` 9285c6c1daeSBarry Smith 9295c6c1daeSBarry Smith Not Collective 9305c6c1daeSBarry Smith 9315c6c1daeSBarry Smith Input Parameter: 9325c6c1daeSBarry Smith . stage - The stage 9335c6c1daeSBarry Smith 9345c6c1daeSBarry Smith Output Parameter: 935811af0c4SBarry Smith . isVisible - The visibility flag, `PETSC_TRUE` to print, else `PETSC_FALSE` (defaults to `PETSC_TRUE`) 9365c6c1daeSBarry Smith 9375c6c1daeSBarry Smith Level: intermediate 9385c6c1daeSBarry Smith 939b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogStageSetVisible()`, `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogView()`, `PetscLogGetDefaultHandler()` 9405c6c1daeSBarry Smith @*/ 941d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStageGetVisible(PetscLogStage stage, PetscBool *isVisible) 942d71ae5a4SJacob Faibussowitsch { 943b665b14eSToby Isaac PetscLogHandler handler; 9445c6c1daeSBarry Smith 9455c6c1daeSBarry Smith PetscFunctionBegin; 946b665b14eSToby Isaac *isVisible = PETSC_FALSE; 947294de794SToby Isaac PetscCall(PetscLogTryGetHandler(PETSCLOGHANDLERDEFAULT, &handler)); 9483a7d0413SPierre Jolivet if (handler) PetscCall(PetscLogHandlerStageGetVisible(handler, stage, isVisible)); 9493ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 9505c6c1daeSBarry Smith } 9515c6c1daeSBarry Smith 952cc4c1da9SBarry Smith /*@ 9535c6c1daeSBarry Smith PetscLogStageGetId - Returns the stage id when given the stage name. 9545c6c1daeSBarry Smith 9555c6c1daeSBarry Smith Not Collective 9565c6c1daeSBarry Smith 9575c6c1daeSBarry Smith Input Parameter: 9585c6c1daeSBarry Smith . name - The stage name 9595c6c1daeSBarry Smith 9605c6c1daeSBarry Smith Output Parameter: 9615a4a3fabSBarry Smith . stage - The stage, , or -1 if no stage with that name exists 9625c6c1daeSBarry Smith 9635c6c1daeSBarry Smith Level: intermediate 9645c6c1daeSBarry Smith 965d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()`, `PetscPreLoadStage()` 9665c6c1daeSBarry Smith @*/ 967d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogStageGetId(const char name[], PetscLogStage *stage) 968d71ae5a4SJacob Faibussowitsch { 969b665b14eSToby Isaac PetscLogState state; 9705c6c1daeSBarry Smith 9715c6c1daeSBarry Smith PetscFunctionBegin; 972b665b14eSToby Isaac *stage = -1; 973b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 974b665b14eSToby Isaac if (state) PetscCall(PetscLogStateGetStageFromName(state, name, stage)); 9753ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 9765c6c1daeSBarry Smith } 9775c6c1daeSBarry Smith 978cc4c1da9SBarry Smith /*@ 97953e0a2f3SToby Isaac PetscLogStageGetName - Returns the stage name when given the stage id. 98053e0a2f3SToby Isaac 98153e0a2f3SToby Isaac Not Collective 98253e0a2f3SToby Isaac 98353e0a2f3SToby Isaac Input Parameter: 98453e0a2f3SToby Isaac . stage - The stage 98553e0a2f3SToby Isaac 98653e0a2f3SToby Isaac Output Parameter: 98753e0a2f3SToby Isaac . name - The stage name 98853e0a2f3SToby Isaac 98953e0a2f3SToby Isaac Level: intermediate 99053e0a2f3SToby Isaac 99153e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()`, `PetscPreLoadStage()` 99253e0a2f3SToby Isaac @*/ 993cc4c1da9SBarry Smith PetscErrorCode PetscLogStageGetName(PetscLogStage stage, const char *name[]) 99453e0a2f3SToby Isaac { 99553e0a2f3SToby Isaac PetscLogStageInfo stage_info; 99653e0a2f3SToby Isaac PetscLogState state; 99753e0a2f3SToby Isaac 99853e0a2f3SToby Isaac PetscFunctionBegin; 999b665b14eSToby Isaac *name = NULL; 100053e0a2f3SToby Isaac PetscCall(PetscLogGetState(&state)); 1001b665b14eSToby Isaac if (!state) PetscFunctionReturn(PETSC_SUCCESS); 100253e0a2f3SToby Isaac PetscCall(PetscLogStateStageGetInfo(state, stage, &stage_info)); 100353e0a2f3SToby Isaac *name = stage_info.name; 100453e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 100553e0a2f3SToby Isaac } 100653e0a2f3SToby Isaac 10075c6c1daeSBarry Smith /*------------------------------------------------ Event Functions --------------------------------------------------*/ 10087a101e5eSJacob Faibussowitsch 1009cc4c1da9SBarry Smith /*@ 1010811af0c4SBarry Smith PetscLogEventRegister - Registers an event name for logging operations 10115c6c1daeSBarry Smith 10125c6c1daeSBarry Smith Not Collective 10135c6c1daeSBarry Smith 1014d8d19677SJose E. Roman Input Parameters: 10155c6c1daeSBarry Smith + name - The name associated with the event 10165c6c1daeSBarry Smith - classid - The classid associated to the class for this event, obtain either with 1017811af0c4SBarry Smith `PetscClassIdRegister()` or use a predefined one such as `KSP_CLASSID`, `SNES_CLASSID`, the predefined ones 10185c6c1daeSBarry Smith are only available in C code 10195c6c1daeSBarry Smith 10205c6c1daeSBarry Smith Output Parameter: 1021811af0c4SBarry Smith . event - The event id for use with `PetscLogEventBegin()` and `PetscLogEventEnd()`. 10225c6c1daeSBarry Smith 102310450e9eSJacob Faibussowitsch Example Usage: 10245c6c1daeSBarry Smith .vb 10255c6c1daeSBarry Smith PetscLogEvent USER_EVENT; 10265c6c1daeSBarry Smith PetscClassId classid; 10275c6c1daeSBarry Smith PetscLogDouble user_event_flops; 10285c6c1daeSBarry Smith PetscClassIdRegister("class name",&classid); 10295c6c1daeSBarry Smith PetscLogEventRegister("User event name",classid,&USER_EVENT); 10305c6c1daeSBarry Smith PetscLogEventBegin(USER_EVENT,0,0,0,0); 10315c6c1daeSBarry Smith [code segment to monitor] 10325c6c1daeSBarry Smith PetscLogFlops(user_event_flops); 10335c6c1daeSBarry Smith PetscLogEventEnd(USER_EVENT,0,0,0,0); 10345c6c1daeSBarry Smith .ve 10355c6c1daeSBarry Smith 1036d1f92df0SBarry Smith Level: intermediate 1037d1f92df0SBarry Smith 10385c6c1daeSBarry Smith Notes: 10395c6c1daeSBarry Smith PETSc automatically logs library events if the code has been 1040a2553e36SBarry Smith configured with --with-log (which is the default) and 1041811af0c4SBarry Smith -log_view or -log_all is specified. `PetscLogEventRegister()` is 10425c6c1daeSBarry Smith intended for logging user events to supplement this PETSc 10435c6c1daeSBarry Smith information. 10445c6c1daeSBarry Smith 1045495fc317SBarry Smith PETSc can gather data for use with the utilities Jumpshot 10465c6c1daeSBarry Smith (part of the MPICH distribution). If PETSc has been compiled 10475c6c1daeSBarry Smith with flag -DPETSC_HAVE_MPE (MPE is an additional utility within 10485c6c1daeSBarry Smith MPICH), the user can employ another command line option, -log_mpe, 10495c6c1daeSBarry Smith to create a logfile, "mpe.log", which can be visualized 1050495fc317SBarry Smith Jumpshot. 10515c6c1daeSBarry Smith 10525c6c1daeSBarry Smith The classid is associated with each event so that classes of events 10535c6c1daeSBarry Smith can be disabled simultaneously, such as all matrix events. The user 1054811af0c4SBarry Smith can either use an existing classid, such as `MAT_CLASSID`, or create 10555c6c1daeSBarry Smith their own as shown in the example. 10565c6c1daeSBarry Smith 1057c5deb1d5SJed Brown If an existing event with the same name exists, its event handle is 1058c5deb1d5SJed Brown returned instead of creating a new event. 1059c5deb1d5SJed Brown 1060d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogFlops()`, 1061db781477SPatrick Sanan `PetscLogEventActivate()`, `PetscLogEventDeactivate()`, `PetscClassIdRegister()` 10625c6c1daeSBarry Smith @*/ 1063d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventRegister(const char name[], PetscClassId classid, PetscLogEvent *event) 1064d71ae5a4SJacob Faibussowitsch { 1065b665b14eSToby Isaac PetscLogState state; 10665c6c1daeSBarry Smith 10675c6c1daeSBarry Smith PetscFunctionBegin; 1068b665b14eSToby Isaac *event = -1; 1069b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1070b665b14eSToby Isaac if (state) PetscCall(PetscLogStateEventRegister(state, name, classid, event)); 10713ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 10725c6c1daeSBarry Smith } 10735c6c1daeSBarry Smith 10745c6c1daeSBarry Smith /*@ 1075217044c2SLisandro Dalcin PetscLogEventSetCollective - Indicates that a particular event is collective. 1076217044c2SLisandro Dalcin 10775aefd447SStefano Zampini Logically Collective 1078217044c2SLisandro Dalcin 1079d8d19677SJose E. Roman Input Parameters: 1080217044c2SLisandro Dalcin + event - The event id 1081ffbd2f08SBarry Smith - collective - `PetscBool` indicating whether a particular event is collective 1082217044c2SLisandro Dalcin 1083d1f92df0SBarry Smith Level: developer 1084d1f92df0SBarry Smith 1085811af0c4SBarry Smith Notes: 1086811af0c4SBarry Smith New events returned from `PetscLogEventRegister()` are collective by default. 1087811af0c4SBarry Smith 1088ffbd2f08SBarry Smith Collective events are handled specially if the command line option `-log_sync` is used. In that case the logging saves information about 1089811af0c4SBarry Smith two parts of the event; the time for all the MPI ranks to synchronize and then the time for the actual computation/communication 10905aefd447SStefano Zampini to be performed. This option is useful to debug imbalance within the computations or communications. 1091217044c2SLisandro Dalcin 1092d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogEventRegister()` 1093217044c2SLisandro Dalcin @*/ 1094d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventSetCollective(PetscLogEvent event, PetscBool collective) 1095d71ae5a4SJacob Faibussowitsch { 1096b665b14eSToby Isaac PetscLogState state; 1097217044c2SLisandro Dalcin 1098217044c2SLisandro Dalcin PetscFunctionBegin; 1099b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1100b665b14eSToby Isaac if (state) PetscCall(PetscLogStateEventSetCollective(state, event, collective)); 1101b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 1102b665b14eSToby Isaac } 1103b665b14eSToby Isaac 1104b665b14eSToby Isaac /* 1105b665b14eSToby Isaac PetscLogClassSetActiveAll - Activate or inactivate logging for all events associated with a PETSc object class in every stage. 1106b665b14eSToby Isaac 1107b665b14eSToby Isaac Not Collective 1108b665b14eSToby Isaac 1109b665b14eSToby Isaac Input Parameters: 1110b665b14eSToby Isaac + classid - The object class, for example `MAT_CLASSID`, `SNES_CLASSID`, etc. 1111b665b14eSToby Isaac - isActive - if `PETSC_FALSE`, events associated with this class will not be send to log handlers. 1112b665b14eSToby Isaac 1113b665b14eSToby Isaac Level: developer 1114b665b14eSToby Isaac 1115b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventActivate()`, `PetscLogEventActivateAll()`, `PetscLogStageSetActive()`, `PetscLogEventActivateClass()` 1116b665b14eSToby Isaac */ 1117b665b14eSToby Isaac static PetscErrorCode PetscLogClassSetActiveAll(PetscClassId classid, PetscBool isActive) 1118b665b14eSToby Isaac { 1119b665b14eSToby Isaac PetscLogState state; 1120b665b14eSToby Isaac 1121b665b14eSToby Isaac PetscFunctionBegin; 1122b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1123b665b14eSToby Isaac if (state) PetscCall(PetscLogStateClassSetActiveAll(state, classid, isActive)); 11243ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1125217044c2SLisandro Dalcin } 1126217044c2SLisandro Dalcin 1127217044c2SLisandro Dalcin /*@ 1128fa2bb9feSLisandro Dalcin PetscLogEventIncludeClass - Activates event logging for a PETSc object class in every stage. 1129fa2bb9feSLisandro Dalcin 1130fa2bb9feSLisandro Dalcin Not Collective 1131fa2bb9feSLisandro Dalcin 1132fa2bb9feSLisandro Dalcin Input Parameter: 1133811af0c4SBarry Smith . classid - The object class, for example `MAT_CLASSID`, `SNES_CLASSID`, etc. 1134fa2bb9feSLisandro Dalcin 1135fa2bb9feSLisandro Dalcin Level: developer 1136fa2bb9feSLisandro Dalcin 1137d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventActivateClass()`, `PetscLogEventDeactivateClass()`, `PetscLogEventActivate()`, `PetscLogEventDeactivate()` 1138fa2bb9feSLisandro Dalcin @*/ 1139d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventIncludeClass(PetscClassId classid) 1140d71ae5a4SJacob Faibussowitsch { 1141fa2bb9feSLisandro Dalcin PetscFunctionBegin; 1142b665b14eSToby Isaac PetscCall(PetscLogClassSetActiveAll(classid, PETSC_TRUE)); 11433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1144fa2bb9feSLisandro Dalcin } 1145fa2bb9feSLisandro Dalcin 1146fa2bb9feSLisandro Dalcin /*@ 1147fa2bb9feSLisandro Dalcin PetscLogEventExcludeClass - Deactivates event logging for a PETSc object class in every stage. 1148fa2bb9feSLisandro Dalcin 1149fa2bb9feSLisandro Dalcin Not Collective 1150fa2bb9feSLisandro Dalcin 1151fa2bb9feSLisandro Dalcin Input Parameter: 1152811af0c4SBarry Smith . classid - The object class, for example `MAT_CLASSID`, `SNES_CLASSID`, etc. 1153fa2bb9feSLisandro Dalcin 1154fa2bb9feSLisandro Dalcin Level: developer 1155fa2bb9feSLisandro Dalcin 1156811af0c4SBarry Smith Note: 1157811af0c4SBarry Smith If a class is excluded then events associated with that class are not logged. 1158811af0c4SBarry Smith 1159d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventDeactivateClass()`, `PetscLogEventActivateClass()`, `PetscLogEventDeactivate()`, `PetscLogEventActivate()` 1160fa2bb9feSLisandro Dalcin @*/ 1161d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventExcludeClass(PetscClassId classid) 1162d71ae5a4SJacob Faibussowitsch { 1163b665b14eSToby Isaac PetscFunctionBegin; 1164b665b14eSToby Isaac PetscCall(PetscLogClassSetActiveAll(classid, PETSC_FALSE)); 1165b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 1166b665b14eSToby Isaac } 1167b665b14eSToby Isaac 1168b665b14eSToby Isaac /* 1169b665b14eSToby Isaac PetscLogEventSetActive - Activate or inactivate logging for an event in a given stage 1170b665b14eSToby Isaac 1171b665b14eSToby Isaac Not Collective 1172b665b14eSToby Isaac 1173b665b14eSToby Isaac Input Parameters: 1174b665b14eSToby Isaac + stage - A registered `PetscLogStage` (or `PETSC_DEFAULT` for the current stage) 1175b665b14eSToby Isaac . event - A `PetscLogEvent` 1176b665b14eSToby Isaac - isActive - If `PETSC_FALSE`, activity from this event (`PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogEventSync()`) will not be sent to log handlers during this stage 1177b665b14eSToby Isaac 1178b665b14eSToby Isaac Usage: 1179b665b14eSToby Isaac .vb 1180b665b14eSToby Isaac PetscLogEventSetActive(VEC_SetValues, PETSC_FALSE); 1181b665b14eSToby Isaac [code where you do not want to log VecSetValues()] 1182b665b14eSToby Isaac PetscLogEventSetActive(VEC_SetValues, PETSC_TRUE); 1183b665b14eSToby Isaac [code where you do want to log VecSetValues()] 1184b665b14eSToby Isaac .ve 1185b665b14eSToby Isaac 1186b665b14eSToby Isaac Level: advanced 1187b665b14eSToby Isaac 1188b665b14eSToby Isaac Note: 1189b665b14eSToby Isaac The event may be either a pre-defined PETSc event (found in include/petsclog.h) 1190b665b14eSToby Isaac or an event number obtained with `PetscLogEventRegister()`. 1191b665b14eSToby Isaac 1192b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventDeactivatePush()`, `PetscLogEventDeactivatePop()` 1193b665b14eSToby Isaac */ 1194b665b14eSToby Isaac static PetscErrorCode PetscLogEventSetActive(PetscLogStage stage, PetscLogEvent event, PetscBool isActive) 1195b665b14eSToby Isaac { 1196b665b14eSToby Isaac PetscLogState state; 1197fa2bb9feSLisandro Dalcin 1198fa2bb9feSLisandro Dalcin PetscFunctionBegin; 1199b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1200b665b14eSToby Isaac if (state) PetscCall(PetscLogStateEventSetActive(state, stage, event, isActive)); 12013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1202fa2bb9feSLisandro Dalcin } 1203fa2bb9feSLisandro Dalcin 1204fa2bb9feSLisandro Dalcin /*@ 12055c6c1daeSBarry Smith PetscLogEventActivate - Indicates that a particular event should be logged. 12065c6c1daeSBarry Smith 12075c6c1daeSBarry Smith Not Collective 12085c6c1daeSBarry Smith 12095c6c1daeSBarry Smith Input Parameter: 12105c6c1daeSBarry Smith . event - The event id 12115c6c1daeSBarry Smith 121210450e9eSJacob Faibussowitsch Example Usage: 12135c6c1daeSBarry Smith .vb 12145c6c1daeSBarry Smith PetscLogEventDeactivate(VEC_SetValues); 12155c6c1daeSBarry Smith [code where you do not want to log VecSetValues()] 12165c6c1daeSBarry Smith PetscLogEventActivate(VEC_SetValues); 12175c6c1daeSBarry Smith [code where you do want to log VecSetValues()] 12185c6c1daeSBarry Smith .ve 12195c6c1daeSBarry Smith 1220d1f92df0SBarry Smith Level: advanced 1221d1f92df0SBarry Smith 12225c6c1daeSBarry Smith Note: 12235c6c1daeSBarry Smith The event may be either a pre-defined PETSc event (found in include/petsclog.h) 1224811af0c4SBarry Smith or an event number obtained with `PetscLogEventRegister()`. 12255c6c1daeSBarry Smith 1226b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventDeactivate()`, `PetscLogEventDeactivatePush()`, `PetscLogEventDeactivatePop()` 12275c6c1daeSBarry Smith @*/ 1228d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventActivate(PetscLogEvent event) 1229d71ae5a4SJacob Faibussowitsch { 12305c6c1daeSBarry Smith PetscFunctionBegin; 1231b665b14eSToby Isaac PetscCall(PetscLogEventSetActive(PETSC_DEFAULT, event, PETSC_TRUE)); 12323ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 12335c6c1daeSBarry Smith } 12345c6c1daeSBarry Smith 12355c6c1daeSBarry Smith /*@ 12365c6c1daeSBarry Smith PetscLogEventDeactivate - Indicates that a particular event should not be logged. 12375c6c1daeSBarry Smith 12385c6c1daeSBarry Smith Not Collective 12395c6c1daeSBarry Smith 12405c6c1daeSBarry Smith Input Parameter: 12415c6c1daeSBarry Smith . event - The event id 12425c6c1daeSBarry Smith 124310450e9eSJacob Faibussowitsch Example Usage: 12445c6c1daeSBarry Smith .vb 12455c6c1daeSBarry Smith PetscLogEventDeactivate(VEC_SetValues); 12465c6c1daeSBarry Smith [code where you do not want to log VecSetValues()] 12475c6c1daeSBarry Smith PetscLogEventActivate(VEC_SetValues); 12485c6c1daeSBarry Smith [code where you do want to log VecSetValues()] 12495c6c1daeSBarry Smith .ve 12505c6c1daeSBarry Smith 1251d1f92df0SBarry Smith Level: advanced 1252d1f92df0SBarry Smith 12535c6c1daeSBarry Smith Note: 12545c6c1daeSBarry Smith The event may be either a pre-defined PETSc event (found in 1255811af0c4SBarry Smith include/petsclog.h) or an event number obtained with `PetscLogEventRegister()`). 12565c6c1daeSBarry Smith 1257d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventActivate()`, `PetscLogEventDeactivatePush()`, `PetscLogEventDeactivatePop()` 12585c6c1daeSBarry Smith @*/ 1259d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventDeactivate(PetscLogEvent event) 1260d71ae5a4SJacob Faibussowitsch { 12615c6c1daeSBarry Smith PetscFunctionBegin; 1262b665b14eSToby Isaac PetscCall(PetscLogEventSetActive(PETSC_DEFAULT, event, PETSC_FALSE)); 12633ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 12645c6c1daeSBarry Smith } 12655c6c1daeSBarry Smith 12665c6c1daeSBarry Smith /*@ 1267811af0c4SBarry Smith PetscLogEventDeactivatePush - Indicates that a particular event should not be logged until `PetscLogEventDeactivatePop()` is called 1268c00cb57fSBarry Smith 1269c00cb57fSBarry Smith Not Collective 1270c00cb57fSBarry Smith 1271c00cb57fSBarry Smith Input Parameter: 1272c00cb57fSBarry Smith . event - The event id 1273c00cb57fSBarry Smith 127410450e9eSJacob Faibussowitsch Example Usage: 1275c00cb57fSBarry Smith .vb 1276c00cb57fSBarry Smith PetscLogEventDeactivatePush(VEC_SetValues); 1277c00cb57fSBarry Smith [code where you do not want to log VecSetValues()] 1278c00cb57fSBarry Smith PetscLogEventDeactivatePop(VEC_SetValues); 1279c00cb57fSBarry Smith [code where you do want to log VecSetValues()] 1280c00cb57fSBarry Smith .ve 1281c00cb57fSBarry Smith 1282d1f92df0SBarry Smith Level: advanced 1283d1f92df0SBarry Smith 1284c00cb57fSBarry Smith Note: 1285c00cb57fSBarry Smith The event may be either a pre-defined PETSc event (found in 1286811af0c4SBarry Smith include/petsclog.h) or an event number obtained with `PetscLogEventRegister()`). 1287c00cb57fSBarry Smith 1288baca6076SPierre Jolivet PETSc's default log handler (`PetscLogDefaultBegin()`) respects this function because it can make the output of `PetscLogView()` easier to interpret, but other handlers (such as the nested handler, `PetscLogNestedBegin()`) ignore it because suppressing events is not helpful in their output formats. 1289b665b14eSToby Isaac 12904b7c4d4dSPierre Jolivet .seealso: [](ch_profiling), `PetscLogEventActivate()`, `PetscLogEventDeactivate()`, `PetscLogEventDeactivatePop()` 1291c00cb57fSBarry Smith @*/ 1292d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent event) 1293d71ae5a4SJacob Faibussowitsch { 1294c00cb57fSBarry Smith PetscFunctionBegin; 1295dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 1296dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 1297dff009beSToby Isaac 1298dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerEventDeactivatePush(h, PETSC_DEFAULT, event)); 1299dff009beSToby Isaac } 13003ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1301c00cb57fSBarry Smith } 1302c00cb57fSBarry Smith 1303c00cb57fSBarry Smith /*@ 1304811af0c4SBarry Smith PetscLogEventDeactivatePop - Indicates that a particular event should again be logged after the logging was turned off with `PetscLogEventDeactivatePush()` 1305c00cb57fSBarry Smith 1306c00cb57fSBarry Smith Not Collective 1307c00cb57fSBarry Smith 1308c00cb57fSBarry Smith Input Parameter: 1309c00cb57fSBarry Smith . event - The event id 1310c00cb57fSBarry Smith 131110450e9eSJacob Faibussowitsch Example Usage: 1312c00cb57fSBarry Smith .vb 1313c00cb57fSBarry Smith PetscLogEventDeactivatePush(VEC_SetValues); 1314c00cb57fSBarry Smith [code where you do not want to log VecSetValues()] 1315c00cb57fSBarry Smith PetscLogEventDeactivatePop(VEC_SetValues); 1316c00cb57fSBarry Smith [code where you do want to log VecSetValues()] 1317c00cb57fSBarry Smith .ve 1318c00cb57fSBarry Smith 1319d1f92df0SBarry Smith Level: advanced 1320d1f92df0SBarry Smith 1321c00cb57fSBarry Smith Note: 1322c00cb57fSBarry Smith The event may be either a pre-defined PETSc event (found in 1323811af0c4SBarry Smith include/petsclog.h) or an event number obtained with `PetscLogEventRegister()`). 1324c00cb57fSBarry Smith 1325d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventActivate()`, `PetscLogEventDeactivatePush()` 1326c00cb57fSBarry Smith @*/ 1327d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent event) 1328d71ae5a4SJacob Faibussowitsch { 1329c00cb57fSBarry Smith PetscFunctionBegin; 1330dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 1331dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 1332dff009beSToby Isaac 1333dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerEventDeactivatePop(h, PETSC_DEFAULT, event)); 1334dff009beSToby Isaac } 13353ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 1336c00cb57fSBarry Smith } 1337c00cb57fSBarry Smith 1338c00cb57fSBarry Smith /*@ 1339811af0c4SBarry Smith PetscLogEventSetActiveAll - Turns on logging of all events 13405c6c1daeSBarry Smith 13415c6c1daeSBarry Smith Not Collective 13425c6c1daeSBarry Smith 13435c6c1daeSBarry Smith Input Parameters: 13445c6c1daeSBarry Smith + event - The event id 13455c6c1daeSBarry Smith - isActive - The activity flag determining whether the event is logged 13465c6c1daeSBarry Smith 13475c6c1daeSBarry Smith Level: advanced 13485c6c1daeSBarry Smith 1349b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventActivate()`, `PetscLogEventDeactivate()` 13505c6c1daeSBarry Smith @*/ 1351d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent event, PetscBool isActive) 1352d71ae5a4SJacob Faibussowitsch { 1353b665b14eSToby Isaac PetscLogState state; 13545c6c1daeSBarry Smith 13555c6c1daeSBarry Smith PetscFunctionBegin; 1356b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1357b665b14eSToby Isaac if (state) PetscCall(PetscLogStateEventSetActiveAll(state, event, isActive)); 1358b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 13595c6c1daeSBarry Smith } 1360b665b14eSToby Isaac 1361b665b14eSToby Isaac /* 1362b665b14eSToby Isaac PetscLogClassSetActive - Activates event logging for a PETSc object class for the current stage 1363b665b14eSToby Isaac 1364b665b14eSToby Isaac Not Collective 1365b665b14eSToby Isaac 1366b665b14eSToby Isaac Input Parameters: 1367b665b14eSToby Isaac + stage - A registered `PetscLogStage` (or `PETSC_DEFAULT` for the current stage) 1368b665b14eSToby Isaac . classid - The event class, for example `MAT_CLASSID`, `SNES_CLASSID`, etc. 1369b665b14eSToby Isaac - isActive - If `PETSC_FALSE`, events associated with this class are not sent to log handlers. 1370b665b14eSToby Isaac 1371b665b14eSToby Isaac Level: developer 1372b665b14eSToby Isaac 1373b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventIncludeClass()`, `PetscLogEventActivate()`, `PetscLogEventActivateAll()`, `PetscLogStageSetActive()` 1374b665b14eSToby Isaac */ 1375b665b14eSToby Isaac static PetscErrorCode PetscLogClassSetActive(PetscLogStage stage, PetscClassId classid, PetscBool isActive) 1376b665b14eSToby Isaac { 1377b665b14eSToby Isaac PetscLogState state; 1378b665b14eSToby Isaac 1379b665b14eSToby Isaac PetscFunctionBegin; 1380b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1381b665b14eSToby Isaac if (state) PetscCall(PetscLogStateClassSetActive(state, stage, classid, isActive)); 13823ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 13835c6c1daeSBarry Smith } 13845c6c1daeSBarry Smith 13855c6c1daeSBarry Smith /*@ 1386811af0c4SBarry Smith PetscLogEventActivateClass - Activates event logging for a PETSc object class for the current stage 13875c6c1daeSBarry Smith 13885c6c1daeSBarry Smith Not Collective 13895c6c1daeSBarry Smith 13905c6c1daeSBarry Smith Input Parameter: 1391811af0c4SBarry Smith . classid - The event class, for example `MAT_CLASSID`, `SNES_CLASSID`, etc. 13925c6c1daeSBarry Smith 13935c6c1daeSBarry Smith Level: developer 13945c6c1daeSBarry Smith 1395d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventIncludeClass()`, `PetscLogEventExcludeClass()`, `PetscLogEventDeactivateClass()`, `PetscLogEventActivate()`, `PetscLogEventDeactivate()` 13965c6c1daeSBarry Smith @*/ 1397d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventActivateClass(PetscClassId classid) 1398d71ae5a4SJacob Faibussowitsch { 13995c6c1daeSBarry Smith PetscFunctionBegin; 1400b665b14eSToby Isaac PetscCall(PetscLogClassSetActive(PETSC_DEFAULT, classid, PETSC_TRUE)); 14013ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 14025c6c1daeSBarry Smith } 14035c6c1daeSBarry Smith 14045c6c1daeSBarry Smith /*@ 1405811af0c4SBarry Smith PetscLogEventDeactivateClass - Deactivates event logging for a PETSc object class for the current stage 14065c6c1daeSBarry Smith 14075c6c1daeSBarry Smith Not Collective 14085c6c1daeSBarry Smith 14095c6c1daeSBarry Smith Input Parameter: 1410811af0c4SBarry Smith . classid - The event class, for example `MAT_CLASSID`, `SNES_CLASSID`, etc. 14115c6c1daeSBarry Smith 14125c6c1daeSBarry Smith Level: developer 14135c6c1daeSBarry Smith 1414d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventIncludeClass()`, `PetscLogEventExcludeClass()`, `PetscLogEventActivateClass()`, `PetscLogEventActivate()`, `PetscLogEventDeactivate()` 14155c6c1daeSBarry Smith @*/ 1416d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventDeactivateClass(PetscClassId classid) 1417d71ae5a4SJacob Faibussowitsch { 14185c6c1daeSBarry Smith PetscFunctionBegin; 1419b665b14eSToby Isaac PetscCall(PetscLogClassSetActive(PETSC_DEFAULT, classid, PETSC_FALSE)); 14203ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 14215c6c1daeSBarry Smith } 14225c6c1daeSBarry Smith 14235c6c1daeSBarry Smith /*MC 142462872c28SLisandro Dalcin PetscLogEventSync - Synchronizes the beginning of a user event. 142562872c28SLisandro Dalcin 142662872c28SLisandro Dalcin Synopsis: 142762872c28SLisandro Dalcin #include <petsclog.h> 1428b665b14eSToby Isaac PetscErrorCode PetscLogEventSync(PetscLogEvent e, MPI_Comm comm) 142962872c28SLisandro Dalcin 143062872c28SLisandro Dalcin Collective 143162872c28SLisandro Dalcin 143262872c28SLisandro Dalcin Input Parameters: 1433b665b14eSToby Isaac + e - `PetscLogEvent` obtained from `PetscLogEventRegister()` 143462872c28SLisandro Dalcin - comm - an MPI communicator 143562872c28SLisandro Dalcin 143610450e9eSJacob Faibussowitsch Example Usage: 143762872c28SLisandro Dalcin .vb 143862872c28SLisandro Dalcin PetscLogEvent USER_EVENT; 143910450e9eSJacob Faibussowitsch 144062872c28SLisandro Dalcin PetscLogEventRegister("User event", 0, &USER_EVENT); 144162872c28SLisandro Dalcin PetscLogEventSync(USER_EVENT, PETSC_COMM_WORLD); 144262872c28SLisandro Dalcin PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0); 144362872c28SLisandro Dalcin [code segment to monitor] 144462872c28SLisandro Dalcin PetscLogEventEnd(USER_EVENT, 0, 0, 0 , 0); 144562872c28SLisandro Dalcin .ve 144662872c28SLisandro Dalcin 1447d1f92df0SBarry Smith Level: developer 1448d1f92df0SBarry Smith 1449811af0c4SBarry Smith Note: 145010450e9eSJacob Faibussowitsch This routine should be called only if there is not a `PetscObject` available to pass to 145110450e9eSJacob Faibussowitsch `PetscLogEventBegin()`. 145262872c28SLisandro Dalcin 1453d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` 145462872c28SLisandro Dalcin M*/ 145562872c28SLisandro Dalcin 145662872c28SLisandro Dalcin /*MC 14575c6c1daeSBarry Smith PetscLogEventBegin - Logs the beginning of a user event. 14585c6c1daeSBarry Smith 14595c6c1daeSBarry Smith Synopsis: 1460aaa7dc30SBarry Smith #include <petsclog.h> 1461b665b14eSToby Isaac PetscErrorCode PetscLogEventBegin(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4) 14625c6c1daeSBarry Smith 14635c6c1daeSBarry Smith Not Collective 14645c6c1daeSBarry Smith 14655c6c1daeSBarry Smith Input Parameters: 1466b665b14eSToby Isaac + e - `PetscLogEvent` obtained from `PetscLogEventRegister()` 1467baca6076SPierre Jolivet . o1 - object associated with the event, or `NULL` 1468baca6076SPierre Jolivet . o2 - object associated with the event, or `NULL` 1469baca6076SPierre Jolivet . o3 - object associated with the event, or `NULL` 1470baca6076SPierre Jolivet - o4 - object associated with the event, or `NULL` 14715c6c1daeSBarry Smith 14725c6c1daeSBarry Smith Fortran Synopsis: 14735c6c1daeSBarry Smith void PetscLogEventBegin(int e, PetscErrorCode ierr) 14745c6c1daeSBarry Smith 147510450e9eSJacob Faibussowitsch Example Usage: 14765c6c1daeSBarry Smith .vb 14775c6c1daeSBarry Smith PetscLogEvent USER_EVENT; 147810450e9eSJacob Faibussowitsch 14795c6c1daeSBarry Smith PetscLogDouble user_event_flops; 14805c6c1daeSBarry Smith PetscLogEventRegister("User event",0, &USER_EVENT); 14815c6c1daeSBarry Smith PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0); 14825c6c1daeSBarry Smith [code segment to monitor] 14835c6c1daeSBarry Smith PetscLogFlops(user_event_flops); 14845c6c1daeSBarry Smith PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0); 14855c6c1daeSBarry Smith .ve 14865c6c1daeSBarry Smith 1487d1f92df0SBarry Smith Level: intermediate 1488d1f92df0SBarry Smith 1489811af0c4SBarry Smith Developer Note: 149010450e9eSJacob Faibussowitsch `PetscLogEventBegin()` and `PetscLogEventBegin()` return error codes instead of explicitly 149110450e9eSJacob Faibussowitsch handling the errors that occur in the macro directly because other packages that use this 149210450e9eSJacob Faibussowitsch macros have used them in their own functions or methods that do not return error codes and it 149310450e9eSJacob Faibussowitsch would be disruptive to change the current behavior. 1494d0609cedSBarry Smith 1495d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventEnd()`, `PetscLogFlops()` 14965c6c1daeSBarry Smith M*/ 14975c6c1daeSBarry Smith 14985c6c1daeSBarry Smith /*MC 14995c6c1daeSBarry Smith PetscLogEventEnd - Log the end of a user event. 15005c6c1daeSBarry Smith 15015c6c1daeSBarry Smith Synopsis: 1502aaa7dc30SBarry Smith #include <petsclog.h> 1503b665b14eSToby Isaac PetscErrorCode PetscLogEventEnd(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4) 15045c6c1daeSBarry Smith 15055c6c1daeSBarry Smith Not Collective 15065c6c1daeSBarry Smith 15075c6c1daeSBarry Smith Input Parameters: 1508b665b14eSToby Isaac + e - `PetscLogEvent` obtained from `PetscLogEventRegister()` 1509baca6076SPierre Jolivet . o1 - object associated with the event, or `NULL` 1510baca6076SPierre Jolivet . o2 - object associated with the event, or `NULL` 1511baca6076SPierre Jolivet . o3 - object associated with the event, or `NULL` 1512baca6076SPierre Jolivet - o4 - object associated with the event, or `NULL` 15135c6c1daeSBarry Smith 15145c6c1daeSBarry Smith Fortran Synopsis: 15155c6c1daeSBarry Smith void PetscLogEventEnd(int e, PetscErrorCode ierr) 15165c6c1daeSBarry Smith 151710450e9eSJacob Faibussowitsch Example Usage: 15185c6c1daeSBarry Smith .vb 15195c6c1daeSBarry Smith PetscLogEvent USER_EVENT; 152010450e9eSJacob Faibussowitsch 15215c6c1daeSBarry Smith PetscLogDouble user_event_flops; 152210450e9eSJacob Faibussowitsch PetscLogEventRegister("User event", 0, &USER_EVENT); 15235c6c1daeSBarry Smith PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0); 15245c6c1daeSBarry Smith [code segment to monitor] 15255c6c1daeSBarry Smith PetscLogFlops(user_event_flops); 15265c6c1daeSBarry Smith PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0); 15275c6c1daeSBarry Smith .ve 15285c6c1daeSBarry Smith 15295c6c1daeSBarry Smith Level: intermediate 15305c6c1daeSBarry Smith 1531d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogFlops()` 15325c6c1daeSBarry Smith M*/ 15335c6c1daeSBarry Smith 15345c6c1daeSBarry Smith /*@C 15358b08f494SToby Isaac PetscLogStageGetPerfInfo - Return the performance information about the given stage 15368b08f494SToby Isaac 1537cc4c1da9SBarry Smith No Fortran Support 1538cc4c1da9SBarry Smith 15398b08f494SToby Isaac Input Parameters: 15408b08f494SToby Isaac . stage - The stage number or `PETSC_DETERMINE` for the current stage 15418b08f494SToby Isaac 15428b08f494SToby Isaac Output Parameter: 15438b08f494SToby Isaac . info - This structure is filled with the performance information 15448b08f494SToby Isaac 15458b08f494SToby Isaac Level: intermediate 15468b08f494SToby Isaac 15478b08f494SToby Isaac Notes: 15488b08f494SToby Isaac This is a low level routine used by the logging functions in PETSc. 15498b08f494SToby Isaac 15508b08f494SToby Isaac A `PETSCLOGHANDLERDEFAULT` must be running for this to work, having been started either with 15515804573cSPierre Jolivet `PetscLogDefaultBegin()` or from the command line with `-log_view`. If it was not started, 15520ba5dad9SToby Isaac all performance statistics in `info` will be zeroed. 15538b08f494SToby Isaac 15548b08f494SToby Isaac .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogGetDefaultHandler()` 15558b08f494SToby Isaac @*/ 15568b08f494SToby Isaac PetscErrorCode PetscLogStageGetPerfInfo(PetscLogStage stage, PetscEventPerfInfo *info) 15578b08f494SToby Isaac { 15588b08f494SToby Isaac PetscLogHandler handler; 15598b08f494SToby Isaac PetscEventPerfInfo *event_info; 15608b08f494SToby Isaac 15618b08f494SToby Isaac PetscFunctionBegin; 15628b08f494SToby Isaac PetscAssertPointer(info, 2); 15630ba5dad9SToby Isaac PetscCall(PetscLogTryGetHandler(PETSCLOGHANDLERDEFAULT, &handler)); 15640ba5dad9SToby Isaac if (handler) { 15658b08f494SToby Isaac PetscCall(PetscLogHandlerGetStagePerfInfo(handler, stage, &event_info)); 15668b08f494SToby Isaac *info = *event_info; 15670ba5dad9SToby Isaac } else { 15680ba5dad9SToby Isaac PetscCall(PetscInfo(NULL, "Default log handler is not running, PetscLogStageGetPerfInfo() returning zeros\n")); 15690ba5dad9SToby Isaac PetscCall(PetscMemzero(info, sizeof(*info))); 15700ba5dad9SToby Isaac } 15718b08f494SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 15728b08f494SToby Isaac } 15738b08f494SToby Isaac 15748b08f494SToby Isaac /*@C 1575b665b14eSToby Isaac PetscLogEventGetPerfInfo - Return the performance information about the given event in the given stage 1576b665b14eSToby Isaac 1577cc4c1da9SBarry Smith No Fortran Support 1578cc4c1da9SBarry Smith 1579b665b14eSToby Isaac Input Parameters: 1580b665b14eSToby Isaac + stage - The stage number or `PETSC_DETERMINE` for the current stage 1581b665b14eSToby Isaac - event - The event number 1582b665b14eSToby Isaac 1583b665b14eSToby Isaac Output Parameter: 1584b665b14eSToby Isaac . info - This structure is filled with the performance information 1585b665b14eSToby Isaac 1586b665b14eSToby Isaac Level: intermediate 1587b665b14eSToby Isaac 1588b665b14eSToby Isaac Note: 1589b665b14eSToby Isaac This is a low level routine used by the logging functions in PETSc 1590b665b14eSToby Isaac 15910ba5dad9SToby Isaac A `PETSCLOGHANDLERDEFAULT` must be running for this to work, having been started either with 15925804573cSPierre Jolivet `PetscLogDefaultBegin()` or from the command line with `-log_view`. If it was not started, 15930ba5dad9SToby Isaac all performance statistics in `info` will be zeroed. 15940ba5dad9SToby Isaac 1595b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogGetDefaultHandler()` 1596b665b14eSToby Isaac @*/ 1597b665b14eSToby Isaac PetscErrorCode PetscLogEventGetPerfInfo(PetscLogStage stage, PetscLogEvent event, PetscEventPerfInfo *info) 1598b665b14eSToby Isaac { 1599b665b14eSToby Isaac PetscLogHandler handler; 1600b665b14eSToby Isaac PetscEventPerfInfo *event_info; 1601b665b14eSToby Isaac 1602b665b14eSToby Isaac PetscFunctionBegin; 1603b665b14eSToby Isaac PetscAssertPointer(info, 3); 16040ba5dad9SToby Isaac PetscCall(PetscLogTryGetHandler(PETSCLOGHANDLERDEFAULT, &handler)); 16050ba5dad9SToby Isaac if (handler) { 1606dff009beSToby Isaac PetscCall(PetscLogHandlerGetEventPerfInfo(handler, stage, event, &event_info)); 1607b665b14eSToby Isaac *info = *event_info; 16080ba5dad9SToby Isaac } else { 16090ba5dad9SToby Isaac PetscCall(PetscInfo(NULL, "Default log handler is not running, PetscLogEventGetPerfInfo() returning zeros\n")); 16100ba5dad9SToby Isaac PetscCall(PetscMemzero(info, sizeof(*info))); 16110ba5dad9SToby Isaac } 1612b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 1613b665b14eSToby Isaac } 1614b665b14eSToby Isaac 1615cc4c1da9SBarry Smith /*@ 1616b665b14eSToby Isaac PetscLogEventSetDof - Set the nth number of degrees of freedom of a numerical problem associated with this event 1617b665b14eSToby Isaac 1618b665b14eSToby Isaac Not Collective 1619b665b14eSToby Isaac 1620b665b14eSToby Isaac Input Parameters: 1621b665b14eSToby Isaac + event - The event id to log 1622b665b14eSToby Isaac . n - The dof index, in [0, 8) 1623b665b14eSToby Isaac - dof - The number of dofs 1624b665b14eSToby Isaac 1625b665b14eSToby Isaac Options Database Key: 1626b665b14eSToby Isaac . -log_view - Activates log summary 1627b665b14eSToby Isaac 1628b665b14eSToby Isaac Level: developer 1629b665b14eSToby Isaac 1630b665b14eSToby Isaac Note: 1631b665b14eSToby Isaac This is to enable logging of convergence 1632b665b14eSToby Isaac 1633b665b14eSToby Isaac .seealso: `PetscLogEventSetError()`, `PetscLogEventRegister()`, `PetscLogGetDefaultHandler()` 1634b665b14eSToby Isaac @*/ 1635b665b14eSToby Isaac PetscErrorCode PetscLogEventSetDof(PetscLogEvent event, PetscInt n, PetscLogDouble dof) 1636b665b14eSToby Isaac { 1637b665b14eSToby Isaac PetscFunctionBegin; 1638b665b14eSToby Isaac PetscCheck(!(n < 0) && !(n > 7), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Error index %" PetscInt_FMT " is not in [0, 8)", n); 1639dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 1640dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 1641dff009beSToby Isaac 1642dff009beSToby Isaac if (h) { 1643dff009beSToby Isaac PetscEventPerfInfo *event_info; 1644dff009beSToby Isaac 1645dff009beSToby Isaac PetscCall(PetscLogHandlerGetEventPerfInfo(h, PETSC_DEFAULT, event, &event_info)); 1646dff009beSToby Isaac if (event_info) event_info->dof[n] = dof; 1647dff009beSToby Isaac } 1648b665b14eSToby Isaac } 1649b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 1650b665b14eSToby Isaac } 1651b665b14eSToby Isaac 1652cc4c1da9SBarry Smith /*@ 1653b665b14eSToby Isaac PetscLogEventSetError - Set the nth error associated with a numerical problem associated with this event 1654b665b14eSToby Isaac 1655b665b14eSToby Isaac Not Collective 1656b665b14eSToby Isaac 1657b665b14eSToby Isaac Input Parameters: 1658b665b14eSToby Isaac + event - The event id to log 1659b665b14eSToby Isaac . n - The error index, in [0, 8) 1660b665b14eSToby Isaac - error - The error 1661b665b14eSToby Isaac 1662b665b14eSToby Isaac Options Database Key: 1663b665b14eSToby Isaac . -log_view - Activates log summary 1664b665b14eSToby Isaac 1665b665b14eSToby Isaac Level: developer 1666b665b14eSToby Isaac 1667b665b14eSToby Isaac Notes: 1668b665b14eSToby Isaac This is to enable logging of convergence, and enable users to interpret the errors as they wish. For example, 1669b665b14eSToby Isaac as different norms, or as errors for different fields 1670b665b14eSToby Isaac 1671b665b14eSToby Isaac This is a low level routine used by the logging functions in PETSc 1672b665b14eSToby Isaac 1673b665b14eSToby Isaac .seealso: `PetscLogEventSetDof()`, `PetscLogEventRegister()`, `PetscLogGetDefaultHandler()` 1674b665b14eSToby Isaac @*/ 1675b665b14eSToby Isaac PetscErrorCode PetscLogEventSetError(PetscLogEvent event, PetscInt n, PetscLogDouble error) 1676b665b14eSToby Isaac { 1677b665b14eSToby Isaac PetscFunctionBegin; 1678b665b14eSToby Isaac PetscCheck(!(n < 0) && !(n > 7), PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Error index %" PetscInt_FMT " is not in [0, 8)", n); 1679dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 1680dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 1681dff009beSToby Isaac 1682dff009beSToby Isaac if (h) { 1683dff009beSToby Isaac PetscEventPerfInfo *event_info; 1684dff009beSToby Isaac 1685dff009beSToby Isaac PetscCall(PetscLogHandlerGetEventPerfInfo(h, PETSC_DEFAULT, event, &event_info)); 1686dff009beSToby Isaac if (event_info) event_info->errors[n] = error; 1687dff009beSToby Isaac } 1688b665b14eSToby Isaac } 1689b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 1690b665b14eSToby Isaac } 1691b665b14eSToby Isaac 1692cc4c1da9SBarry Smith /*@ 16935c6c1daeSBarry Smith PetscLogEventGetId - Returns the event id when given the event name. 16945c6c1daeSBarry Smith 16955c6c1daeSBarry Smith Not Collective 16965c6c1daeSBarry Smith 16975c6c1daeSBarry Smith Input Parameter: 16985c6c1daeSBarry Smith . name - The event name 16995c6c1daeSBarry Smith 17005c6c1daeSBarry Smith Output Parameter: 1701c5deb1d5SJed Brown . event - The event, or -1 if no event with that name exists 17025c6c1daeSBarry Smith 17035c6c1daeSBarry Smith Level: intermediate 17045c6c1daeSBarry Smith 1705d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogStageGetId()` 17065c6c1daeSBarry Smith @*/ 1707d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogEventGetId(const char name[], PetscLogEvent *event) 1708d71ae5a4SJacob Faibussowitsch { 1709b665b14eSToby Isaac PetscLogState state; 17105c6c1daeSBarry Smith 17115c6c1daeSBarry Smith PetscFunctionBegin; 1712b665b14eSToby Isaac *event = -1; 1713b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 1714b665b14eSToby Isaac if (state) PetscCall(PetscLogStateGetEventFromName(state, name, event)); 17153ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 17165c6c1daeSBarry Smith } 17175c6c1daeSBarry Smith 1718cc4c1da9SBarry Smith /*@ 171953e0a2f3SToby Isaac PetscLogEventGetName - Returns the event name when given the event id. 172053e0a2f3SToby Isaac 172153e0a2f3SToby Isaac Not Collective 172253e0a2f3SToby Isaac 172353e0a2f3SToby Isaac Input Parameter: 172453e0a2f3SToby Isaac . event - The event 172553e0a2f3SToby Isaac 172653e0a2f3SToby Isaac Output Parameter: 172753e0a2f3SToby Isaac . name - The event name 172853e0a2f3SToby Isaac 172953e0a2f3SToby Isaac Level: intermediate 173053e0a2f3SToby Isaac 173153e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()`, `PetscPreLoadStage()` 173253e0a2f3SToby Isaac @*/ 1733cc4c1da9SBarry Smith PetscErrorCode PetscLogEventGetName(PetscLogEvent event, const char *name[]) 173453e0a2f3SToby Isaac { 173553e0a2f3SToby Isaac PetscLogEventInfo event_info; 173653e0a2f3SToby Isaac PetscLogState state; 173753e0a2f3SToby Isaac 173853e0a2f3SToby Isaac PetscFunctionBegin; 1739b665b14eSToby Isaac *name = NULL; 174053e0a2f3SToby Isaac PetscCall(PetscLogGetState(&state)); 1741b665b14eSToby Isaac if (!state) PetscFunctionReturn(PETSC_SUCCESS); 174253e0a2f3SToby Isaac PetscCall(PetscLogStateEventGetInfo(state, event, &event_info)); 174353e0a2f3SToby Isaac *name = event_info.name; 174453e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 174553e0a2f3SToby Isaac } 174653e0a2f3SToby Isaac 174753e0a2f3SToby Isaac /*@ 174853e0a2f3SToby Isaac PetscLogEventsPause - Put event logging into "paused" mode: timers and counters for in-progress events are paused, and any events that happen before logging is resumed with `PetscLogEventsResume()` are logged in the "Main Stage" of execution. 174953e0a2f3SToby Isaac 175053e0a2f3SToby Isaac Not collective 175153e0a2f3SToby Isaac 175253e0a2f3SToby Isaac Level: advanced 175353e0a2f3SToby Isaac 175453e0a2f3SToby Isaac Notes: 175553e0a2f3SToby Isaac When an external library or runtime has is initialized it can involve lots of setup time that skews the statistics of any unrelated running events: this function is intended to isolate such calls in the default log summary (`PetscLogDefaultBegin()`, `PetscLogView()`). 175653e0a2f3SToby Isaac 175753e0a2f3SToby Isaac Other log handlers (such as the nested handler, `PetscLogNestedBegin()`) will ignore this function. 175853e0a2f3SToby Isaac 1759b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventDeactivatePush()`, `PetscLogEventDeactivatePop()`, `PetscLogEventsResume()`, `PetscLogGetDefaultHandler()` 176053e0a2f3SToby Isaac @*/ 176153e0a2f3SToby Isaac PetscErrorCode PetscLogEventsPause(void) 176253e0a2f3SToby Isaac { 176353e0a2f3SToby Isaac PetscFunctionBegin; 1764dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 1765dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 1766dff009beSToby Isaac 1767dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerEventsPause(h)); 1768dff009beSToby Isaac } 176953e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 177053e0a2f3SToby Isaac } 177153e0a2f3SToby Isaac 177253e0a2f3SToby Isaac /*@ 177353e0a2f3SToby Isaac PetscLogEventsResume - Return logging to normal behavior after it was paused with `PetscLogEventsPause()`. 177453e0a2f3SToby Isaac 177553e0a2f3SToby Isaac Not collective 177653e0a2f3SToby Isaac 177753e0a2f3SToby Isaac Level: advanced 177853e0a2f3SToby Isaac 1779b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventDeactivatePush()`, `PetscLogEventDeactivatePop()`, `PetscLogEventsPause()`, `PetscLogGetDefaultHandler()` 178053e0a2f3SToby Isaac @*/ 178153e0a2f3SToby Isaac PetscErrorCode PetscLogEventsResume(void) 178253e0a2f3SToby Isaac { 178353e0a2f3SToby Isaac PetscFunctionBegin; 1784dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 1785dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 1786dff009beSToby Isaac 1787dff009beSToby Isaac if (h) PetscCall(PetscLogHandlerEventsResume(h)); 1788dff009beSToby Isaac } 178953e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 179053e0a2f3SToby Isaac } 179153e0a2f3SToby Isaac 17921c1ad86eSToby Isaac /*------------------------------------------------ Class Functions --------------------------------------------------*/ 17931c1ad86eSToby Isaac 17941c1ad86eSToby Isaac /*MC 17951c1ad86eSToby Isaac PetscLogObjectCreate - Log the creation of a `PetscObject` 17961c1ad86eSToby Isaac 17971c1ad86eSToby Isaac Synopsis: 17981c1ad86eSToby Isaac #include <petsclog.h> 17991c1ad86eSToby Isaac PetscErrorCode PetscLogObjectCreate(PetscObject h) 18001c1ad86eSToby Isaac 18011c1ad86eSToby Isaac Not Collective 18021c1ad86eSToby Isaac 18031c1ad86eSToby Isaac Input Parameters: 18041c1ad86eSToby Isaac . h - A `PetscObject` 18051c1ad86eSToby Isaac 18061c1ad86eSToby Isaac Level: developer 18071c1ad86eSToby Isaac 18081c1ad86eSToby Isaac Developer Note: 18091c1ad86eSToby Isaac Called internally by PETSc when creating objects: users do not need to call this directly. 1810b665b14eSToby Isaac Notification of the object creation is sent to each `PetscLogHandler` that is running. 18111c1ad86eSToby Isaac 1812b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogObjectDestroy()` 18131c1ad86eSToby Isaac M*/ 18141c1ad86eSToby Isaac 18151c1ad86eSToby Isaac /*MC 18161c1ad86eSToby Isaac PetscLogObjectDestroy - Logs the destruction of a `PetscObject` 18171c1ad86eSToby Isaac 18181c1ad86eSToby Isaac Synopsis: 18191c1ad86eSToby Isaac #include <petsclog.h> 18201c1ad86eSToby Isaac PetscErrorCode PetscLogObjectDestroy(PetscObject h) 18211c1ad86eSToby Isaac 18221c1ad86eSToby Isaac Not Collective 18231c1ad86eSToby Isaac 18241c1ad86eSToby Isaac Input Parameters: 18251c1ad86eSToby Isaac . h - A `PetscObject` 18261c1ad86eSToby Isaac 18271c1ad86eSToby Isaac Level: developer 18281c1ad86eSToby Isaac 18291c1ad86eSToby Isaac Developer Note: 18301c1ad86eSToby Isaac Called internally by PETSc when destroying objects: users do not need to call this directly. 1831b665b14eSToby Isaac Notification of the object creation is sent to each `PetscLogHandler` that is running. 18321c1ad86eSToby Isaac 1833b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogObjectCreate()` 18341c1ad86eSToby Isaac M*/ 18351c1ad86eSToby Isaac 1836cc4c1da9SBarry Smith /*@ 183753e0a2f3SToby Isaac PetscLogClassGetClassId - Returns the `PetscClassId` when given the class name. 183853e0a2f3SToby Isaac 183953e0a2f3SToby Isaac Not Collective 184053e0a2f3SToby Isaac 184153e0a2f3SToby Isaac Input Parameter: 184253e0a2f3SToby Isaac . name - The class name 184353e0a2f3SToby Isaac 184453e0a2f3SToby Isaac Output Parameter: 184553e0a2f3SToby Isaac . classid - The `PetscClassId` id, or -1 if no class with that name exists 184653e0a2f3SToby Isaac 184753e0a2f3SToby Isaac Level: intermediate 184853e0a2f3SToby Isaac 184953e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogStageGetId()` 185053e0a2f3SToby Isaac @*/ 185153e0a2f3SToby Isaac PetscErrorCode PetscLogClassGetClassId(const char name[], PetscClassId *classid) 185253e0a2f3SToby Isaac { 185353e0a2f3SToby Isaac PetscLogClass log_class; 185453e0a2f3SToby Isaac PetscLogClassInfo class_info; 185553e0a2f3SToby Isaac PetscLogState state; 185653e0a2f3SToby Isaac 185753e0a2f3SToby Isaac PetscFunctionBegin; 1858b665b14eSToby Isaac *classid = -1; 185953e0a2f3SToby Isaac PetscCall(PetscLogGetState(&state)); 1860b665b14eSToby Isaac if (!state) PetscFunctionReturn(PETSC_SUCCESS); 186153e0a2f3SToby Isaac PetscCall(PetscLogStateGetClassFromName(state, name, &log_class)); 186253e0a2f3SToby Isaac if (log_class < 0) { 186353e0a2f3SToby Isaac *classid = -1; 186453e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 186553e0a2f3SToby Isaac } 186653e0a2f3SToby Isaac PetscCall(PetscLogStateClassGetInfo(state, log_class, &class_info)); 186753e0a2f3SToby Isaac *classid = class_info.classid; 186853e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 186953e0a2f3SToby Isaac } 187053e0a2f3SToby Isaac 187153e0a2f3SToby Isaac /*@C 187253e0a2f3SToby Isaac PetscLogClassIdGetName - Returns a `PetscClassId`'s name. 187353e0a2f3SToby Isaac 187453e0a2f3SToby Isaac Not Collective 187553e0a2f3SToby Isaac 187653e0a2f3SToby Isaac Input Parameter: 187753e0a2f3SToby Isaac . classid - A `PetscClassId` 187853e0a2f3SToby Isaac 187953e0a2f3SToby Isaac Output Parameter: 188053e0a2f3SToby Isaac . name - The class name 188153e0a2f3SToby Isaac 188253e0a2f3SToby Isaac Level: intermediate 188353e0a2f3SToby Isaac 188453e0a2f3SToby Isaac .seealso: [](ch_profiling), `PetscLogClassRegister()`, `PetscLogClassBegin()`, `PetscLogClassEnd()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()`, `PetscPreLoadClass()` 188553e0a2f3SToby Isaac @*/ 188653e0a2f3SToby Isaac PetscErrorCode PetscLogClassIdGetName(PetscClassId classid, const char **name) 188753e0a2f3SToby Isaac { 188853e0a2f3SToby Isaac PetscLogClass log_class; 188953e0a2f3SToby Isaac PetscLogClassInfo class_info; 189053e0a2f3SToby Isaac PetscLogState state; 189153e0a2f3SToby Isaac 189253e0a2f3SToby Isaac PetscFunctionBegin; 189353e0a2f3SToby Isaac PetscCall(PetscLogGetState(&state)); 189453e0a2f3SToby Isaac PetscCall(PetscLogStateGetClassFromClassId(state, classid, &log_class)); 189553e0a2f3SToby Isaac PetscCall(PetscLogStateClassGetInfo(state, log_class, &class_info)); 189653e0a2f3SToby Isaac *name = class_info.name; 189753e0a2f3SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 189853e0a2f3SToby Isaac } 189953e0a2f3SToby Isaac 19005c6c1daeSBarry Smith /*------------------------------------------------ Output Functions -------------------------------------------------*/ 1901cc4c1da9SBarry Smith /*@ 19025c6c1daeSBarry Smith PetscLogDump - Dumps logs of objects to a file. This file is intended to 19035c6c1daeSBarry Smith be read by bin/petscview. This program no longer exists. 19045c6c1daeSBarry Smith 1905811af0c4SBarry Smith Collective on `PETSC_COMM_WORLD` 19065c6c1daeSBarry Smith 19075c6c1daeSBarry Smith Input Parameter: 1908aec76313SJacob Faibussowitsch . sname - an optional file name 19095c6c1daeSBarry Smith 191010450e9eSJacob Faibussowitsch Example Usage: 19115c6c1daeSBarry Smith .vb 19125c6c1daeSBarry Smith PetscInitialize(...); 1913b665b14eSToby Isaac PetscLogDefaultBegin(); 1914b665b14eSToby Isaac // ... code ... 19155c6c1daeSBarry Smith PetscLogDump(filename); 19165c6c1daeSBarry Smith PetscFinalize(); 19175c6c1daeSBarry Smith .ve 19185c6c1daeSBarry Smith 1919d1f92df0SBarry Smith Level: advanced 1920d1f92df0SBarry Smith 1921811af0c4SBarry Smith Note: 192237fdd005SBarry Smith The default file name is Log.<rank> where <rank> is the MPI process rank. If no name is specified, 19235c6c1daeSBarry Smith this file will be used. 19245c6c1daeSBarry Smith 1925b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogDefaultBegin()`, `PetscLogView()`, `PetscLogGetDefaultHandler()` 19265c6c1daeSBarry Smith @*/ 1927d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogDump(const char sname[]) 1928d71ae5a4SJacob Faibussowitsch { 1929b665b14eSToby Isaac PetscLogHandler handler; 19305c6c1daeSBarry Smith 19315c6c1daeSBarry Smith PetscFunctionBegin; 1932294de794SToby Isaac PetscCall(PetscLogGetHandler(PETSCLOGHANDLERDEFAULT, &handler)); 1933dff009beSToby Isaac PetscCall(PetscLogHandlerDump(handler, sname)); 1934b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 19355c6c1daeSBarry Smith } 1936b665b14eSToby Isaac 1937cc4c1da9SBarry Smith /*@ 1938b665b14eSToby Isaac PetscLogMPEDump - Dumps the MPE logging info to file for later use with Jumpshot. 1939b665b14eSToby Isaac 19408f14a041SBarry Smith Collective on `PETSC_COMM_WORLD` 1941b665b14eSToby Isaac 1942b665b14eSToby Isaac Input Parameter: 1943b665b14eSToby Isaac . sname - filename for the MPE logfile 1944b665b14eSToby Isaac 1945b665b14eSToby Isaac Level: advanced 1946b665b14eSToby Isaac 1947b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogDump()`, `PetscLogMPEBegin()` 1948b665b14eSToby Isaac @*/ 1949b665b14eSToby Isaac PetscErrorCode PetscLogMPEDump(const char sname[]) 1950b665b14eSToby Isaac { 1951b665b14eSToby Isaac PetscFunctionBegin; 1952b665b14eSToby Isaac #if defined(PETSC_HAVE_MPE) 1953b665b14eSToby Isaac if (PetscBeganMPE) { 1954b665b14eSToby Isaac char name[PETSC_MAX_PATH_LEN]; 1955b665b14eSToby Isaac 1956b665b14eSToby Isaac PetscCall(PetscInfo(0, "Finalizing MPE.\n")); 1957b665b14eSToby Isaac if (sname) { 1958b665b14eSToby Isaac PetscCall(PetscStrncpy(name, sname, sizeof(name))); 19595c6c1daeSBarry Smith } else { 1960b665b14eSToby Isaac PetscCall(PetscGetProgramName(name, sizeof(name))); 19615c6c1daeSBarry Smith } 1962b665b14eSToby Isaac PetscCall(MPE_Finish_log(name)); 19635c6c1daeSBarry Smith } else { 1964b665b14eSToby Isaac PetscCall(PetscInfo(0, "Not finalizing MPE (not started by PETSc).\n")); 19655c6c1daeSBarry Smith } 1966c2a741eeSJunchao Zhang #else 1967b665b14eSToby Isaac SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP_SYS, "PETSc was configured without MPE support, reconfigure with --with-mpe or --download-mpe"); 1968c2a741eeSJunchao Zhang #endif 19693ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 19705c6c1daeSBarry Smith } 19715c6c1daeSBarry Smith 1972ffeef943SBarry Smith /*@ 19737d6c928cSSatish Balay PetscLogView - Prints a summary of the logging. 19745c6c1daeSBarry Smith 19758f14a041SBarry Smith Collective 19765c6c1daeSBarry Smith 19775c6c1daeSBarry Smith Input Parameter: 1978f14045dbSBarry Smith . viewer - an ASCII viewer 19795c6c1daeSBarry Smith 19805c6c1daeSBarry Smith Options Database Keys: 1981bb1d7374SBarry Smith + -log_view [:filename] - Prints summary of log information 1982bb1d7374SBarry Smith . -log_view :filename.py:ascii_info_detail - Saves logging information from each process as a Python file 1983607d249eSBarry Smith . -log_view :filename.xml:ascii_xml - Saves a summary of the logging information in a nested format (see below for how to view it) 1984d0a29bd7SConnor Ward . -log_view :filename.txt:ascii_flamegraph - Saves logging information in a format suitable for visualising as a Flame Graph (see below for how to view it) 1985156b51fbSBarry Smith . -log_view_memory - Also display memory usage in each event 1986156b51fbSBarry Smith . -log_view_gpu_time - Also display time in each event for GPU kernels (Note this may slow the computation) 19875268dc8aSHong Zhang . -log_view_gpu_energy - Also display energy (estimated with power*gtime) in Joules for GPU kernels 19885268dc8aSHong Zhang . -log_view_gpu_energy_meter - [Experimental] Also display energy (readings from energy meters) in Joules for GPU kernels. This option is ignored if -log_view_gpu_energy is provided. 1989811af0c4SBarry Smith . -log_all - Saves a file Log.rank for each MPI rank with details of each step of the computation 1990bb1d7374SBarry Smith - -log_trace [filename] - Displays a trace of what each process is doing 19915c6c1daeSBarry Smith 1992d1f92df0SBarry Smith Level: beginner 1993d1f92df0SBarry Smith 19945c6c1daeSBarry Smith Notes: 1995da81f932SPierre Jolivet It is possible to control the logging programmatically but we recommend using the options database approach whenever possible 19965c6c1daeSBarry Smith By default the summary is printed to stdout. 19975c6c1daeSBarry Smith 1998bb1d7374SBarry Smith Before calling this routine you must have called either PetscLogDefaultBegin() or PetscLogNestedBegin() 1999bb1d7374SBarry Smith 2000bb1d7374SBarry Smith If PETSc is configured with --with-logging=0 then this functionality is not available 2001bb1d7374SBarry Smith 2002607d249eSBarry Smith To view the nested XML format filename.xml first copy ${PETSC_DIR}/share/petsc/xml/performance_xml2html.xsl to the current 2003607d249eSBarry Smith directory then open filename.xml with your browser. Specific notes for certain browsers 20041d27aa22SBarry Smith .vb 20051d27aa22SBarry Smith Firefox and Internet explorer - simply open the file 20061d27aa22SBarry Smith Google Chrome - you must start up Chrome with the option --allow-file-access-from-files 20071d27aa22SBarry Smith Safari - see https://ccm.net/faq/36342-safari-how-to-enable-local-file-access 20081d27aa22SBarry Smith .ve 20091d27aa22SBarry Smith or one can use the package <http://xmlsoft.org/XSLT/xsltproc2.html> to translate the xml file to html and then open it with 2010607d249eSBarry Smith your browser. 20112add09c0SLisandro Dalcin Alternatively, use the script ${PETSC_DIR}/lib/petsc/bin/petsc-performance-view to automatically open a new browser 20122add09c0SLisandro Dalcin window and render the XML log file contents. 2013607d249eSBarry Smith 2014bb1d7374SBarry Smith The nested XML format was kindly donated by Koos Huijssen and Christiaan M. Klaij MARITIME RESEARCH INSTITUTE NETHERLANDS 2015bb1d7374SBarry Smith 20161d27aa22SBarry Smith The Flame Graph output can be visualised using either the original Flame Graph script <https://github.com/brendangregg/FlameGraph> 20171d27aa22SBarry Smith or using speedscope <https://www.speedscope.app>. 2018d0a29bd7SConnor Ward Old XML profiles may be converted into this format using the script ${PETSC_DIR}/lib/petsc/bin/xml2flamegraph.py. 2019d0a29bd7SConnor Ward 2020d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogDefaultBegin()`, `PetscLogDump()` 20215c6c1daeSBarry Smith @*/ 2022d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogView(PetscViewer viewer) 2023d71ae5a4SJacob Faibussowitsch { 2024f14045dbSBarry Smith PetscBool isascii; 2025f14045dbSBarry Smith PetscViewerFormat format; 2026b665b14eSToby Isaac int stage; 2027b665b14eSToby Isaac PetscLogState state; 2028b665b14eSToby Isaac PetscIntStack temp_stack; 2029b665b14eSToby Isaac PetscLogHandler handler; 2030b665b14eSToby Isaac PetscBool is_empty; 20315c6c1daeSBarry Smith 20325c6c1daeSBarry Smith PetscFunctionBegin; 2033b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 203437b78d16SBarry Smith /* Pop off any stages the user forgot to remove */ 2035b665b14eSToby Isaac PetscCall(PetscIntStackCreate(&temp_stack)); 2036b665b14eSToby Isaac PetscCall(PetscLogStateGetCurrentStage(state, &stage)); 203737b78d16SBarry Smith while (stage >= 0) { 2038b665b14eSToby Isaac PetscCall(PetscLogStagePop()); 2039b665b14eSToby Isaac PetscCall(PetscIntStackPush(temp_stack, stage)); 2040b665b14eSToby Isaac PetscCall(PetscLogStateGetCurrentStage(state, &stage)); 204137b78d16SBarry Smith } 20429566063dSJacob Faibussowitsch PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 204328b400f6SJacob Faibussowitsch PetscCheck(isascii, PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Currently can only view logging to ASCII"); 20449566063dSJacob Faibussowitsch PetscCall(PetscViewerGetFormat(viewer, &format)); 2045b665b14eSToby Isaac if (format == PETSC_VIEWER_ASCII_XML || format == PETSC_VIEWER_ASCII_FLAMEGRAPH) { 2046294de794SToby Isaac PetscCall(PetscLogGetHandler(PETSCLOGHANDLERNESTED, &handler)); 2047b665b14eSToby Isaac PetscCall(PetscLogHandlerView(handler, viewer)); 2048b665b14eSToby Isaac } else { 2049294de794SToby Isaac PetscCall(PetscLogGetHandler(PETSCLOGHANDLERDEFAULT, &handler)); 2050b665b14eSToby Isaac PetscCall(PetscLogHandlerView(handler, viewer)); 20515c6c1daeSBarry Smith } 2052b665b14eSToby Isaac PetscCall(PetscIntStackEmpty(temp_stack, &is_empty)); 2053b665b14eSToby Isaac while (!is_empty) { 2054b665b14eSToby Isaac PetscCall(PetscIntStackPop(temp_stack, &stage)); 2055b665b14eSToby Isaac PetscCall(PetscLogStagePush(stage)); 2056b665b14eSToby Isaac PetscCall(PetscIntStackEmpty(temp_stack, &is_empty)); 2057b665b14eSToby Isaac } 2058b665b14eSToby Isaac PetscCall(PetscIntStackDestroy(temp_stack)); 20593ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 20605c6c1daeSBarry Smith } 20615c6c1daeSBarry Smith 2062f14045dbSBarry Smith /*@C 2063811af0c4SBarry Smith PetscLogViewFromOptions - Processes command line options to determine if/how a `PetscLog` is to be viewed. 2064f14045dbSBarry Smith 2065811af0c4SBarry Smith Collective on `PETSC_COMM_WORLD` 2066f14045dbSBarry Smith 2067811af0c4SBarry Smith Level: developer 2068f14045dbSBarry Smith 2069d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogView()` 2070f14045dbSBarry Smith @*/ 2071d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogViewFromOptions(void) 2072d71ae5a4SJacob Faibussowitsch { 2073ad2e3d55SToby Isaac PetscInt n_max = PETSC_LOG_VIEW_FROM_OPTIONS_MAX; 2074ad2e3d55SToby Isaac PetscViewer viewers[PETSC_LOG_VIEW_FROM_OPTIONS_MAX]; 2075ad2e3d55SToby Isaac PetscViewerFormat formats[PETSC_LOG_VIEW_FROM_OPTIONS_MAX]; 2076f14045dbSBarry Smith PetscBool flg; 2077f14045dbSBarry Smith 2078f14045dbSBarry Smith PetscFunctionBegin; 2079648c30bcSBarry Smith PetscCall(PetscOptionsCreateViewers(PETSC_COMM_WORLD, NULL, NULL, "-log_view", &n_max, viewers, formats, &flg)); 20800bc1c2e8SToby Isaac /* 20810bc1c2e8SToby Isaac PetscLogHandlerView_Default_Info() wants to be sure that the only objects still around are these viewers, so keep track of how many there are 20820bc1c2e8SToby Isaac */ 20830bc1c2e8SToby Isaac PetscLogNumViewersCreated = n_max; 2084ad2e3d55SToby Isaac for (PetscInt i = 0; i < n_max; i++) { 20850bc1c2e8SToby Isaac PetscInt refct; 20860bc1c2e8SToby Isaac 2087ad2e3d55SToby Isaac PetscCall(PetscViewerPushFormat(viewers[i], formats[i])); 2088ad2e3d55SToby Isaac PetscCall(PetscLogView(viewers[i])); 2089ad2e3d55SToby Isaac PetscCall(PetscViewerPopFormat(viewers[i])); 20900bc1c2e8SToby Isaac PetscCall(PetscObjectGetReference((PetscObject)viewers[i], &refct)); 2091648c30bcSBarry Smith PetscCall(PetscViewerDestroy(&viewers[i])); 20920bc1c2e8SToby Isaac if (refct == 1) PetscLogNumViewersDestroyed++; 2093f14045dbSBarry Smith } 2094a0449d98SPierre Jolivet PetscLogNumViewersDestroyed = 0; 20953ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 2096f14045dbSBarry Smith } 2097f14045dbSBarry Smith 2098b665b14eSToby Isaac PETSC_INTERN PetscErrorCode PetscLogHandlerNestedSetThreshold(PetscLogHandler, PetscLogDouble, PetscLogDouble *); 2099b665b14eSToby Isaac 2100b665b14eSToby Isaac /*@ 2101b665b14eSToby Isaac PetscLogSetThreshold - Set the threshold time for logging the events; this is a percentage out of 100, so 1. means any event 2102b665b14eSToby Isaac that takes 1 or more percent of the time. 2103b665b14eSToby Isaac 21048f14a041SBarry Smith Logically Collective on `PETSC_COMM_WORLD` 2105b665b14eSToby Isaac 2106b665b14eSToby Isaac Input Parameter: 2107b665b14eSToby Isaac . newThresh - the threshold to use 2108b665b14eSToby Isaac 2109b665b14eSToby Isaac Output Parameter: 2110b665b14eSToby Isaac . oldThresh - the previously set threshold value 2111b665b14eSToby Isaac 2112b665b14eSToby Isaac Options Database Keys: 2113b665b14eSToby Isaac . -log_view :filename.xml:ascii_xml - Prints an XML summary of flop and timing information to the file 2114b665b14eSToby Isaac 2115b665b14eSToby Isaac Example Usage: 2116b665b14eSToby Isaac .vb 2117b665b14eSToby Isaac PetscInitialize(...); 2118b665b14eSToby Isaac PetscLogNestedBegin(); 2119b665b14eSToby Isaac PetscLogSetThreshold(0.1,&oldthresh); 2120b665b14eSToby Isaac // ... code ... 2121b665b14eSToby Isaac PetscLogView(viewer); 2122b665b14eSToby Isaac PetscFinalize(); 2123b665b14eSToby Isaac .ve 2124b665b14eSToby Isaac 2125b665b14eSToby Isaac Level: advanced 2126b665b14eSToby Isaac 2127b665b14eSToby Isaac Note: 2128b665b14eSToby Isaac This threshold is only used by the nested log handler 2129b665b14eSToby Isaac 2130b665b14eSToby Isaac .seealso: `PetscLogDump()`, `PetscLogView()`, `PetscLogTraceBegin()`, `PetscLogDefaultBegin()`, 2131b665b14eSToby Isaac `PetscLogNestedBegin()` 2132b665b14eSToby Isaac @*/ 2133b665b14eSToby Isaac PetscErrorCode PetscLogSetThreshold(PetscLogDouble newThresh, PetscLogDouble *oldThresh) 2134b665b14eSToby Isaac { 2135b665b14eSToby Isaac PetscLogHandler handler; 2136b665b14eSToby Isaac 2137b665b14eSToby Isaac PetscFunctionBegin; 2138294de794SToby Isaac PetscCall(PetscLogTryGetHandler(PETSCLOGHANDLERNESTED, &handler)); 2139b665b14eSToby Isaac PetscCall(PetscLogHandlerNestedSetThreshold(handler, newThresh, oldThresh)); 2140b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 2141b665b14eSToby Isaac } 2142b665b14eSToby Isaac 21435c6c1daeSBarry Smith /*----------------------------------------------- Counter Functions -------------------------------------------------*/ 2144cc4c1da9SBarry Smith /*@ 21455c6c1daeSBarry Smith PetscGetFlops - Returns the number of flops used on this processor 21465c6c1daeSBarry Smith since the program began. 21475c6c1daeSBarry Smith 21485c6c1daeSBarry Smith Not Collective 21495c6c1daeSBarry Smith 21505c6c1daeSBarry Smith Output Parameter: 215110450e9eSJacob Faibussowitsch . flops - number of floating point operations 21525c6c1daeSBarry Smith 2153d1f92df0SBarry Smith Level: intermediate 2154d1f92df0SBarry Smith 21555c6c1daeSBarry Smith Notes: 21565c6c1daeSBarry Smith A global counter logs all PETSc flop counts. The user can use 2157811af0c4SBarry Smith `PetscLogFlops()` to increment this counter to include flops for the 21585c6c1daeSBarry Smith application code. 21595c6c1daeSBarry Smith 21604b7c4d4dSPierre Jolivet A separate counter `PetscLogGpuFlops()` logs the flops that occur on any GPU associated with this MPI rank 2161811af0c4SBarry Smith 21624b7c4d4dSPierre Jolivet .seealso: [](ch_profiling), `PetscLogGpuFlops()`, `PetscTime()`, `PetscLogFlops()` 21635c6c1daeSBarry Smith @*/ 2164d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscGetFlops(PetscLogDouble *flops) 2165d71ae5a4SJacob Faibussowitsch { 21665c6c1daeSBarry Smith PetscFunctionBegin; 21675c6c1daeSBarry Smith *flops = petsc_TotalFlops; 21683ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 21695c6c1daeSBarry Smith } 21705c6c1daeSBarry Smith 21711c1ad86eSToby Isaac /*@C 21721c1ad86eSToby Isaac PetscLogObjectState - Record information about an object with the default log handler 21731c1ad86eSToby Isaac 21741c1ad86eSToby Isaac Not Collective 21751c1ad86eSToby Isaac 21761c1ad86eSToby Isaac Input Parameters: 21771c1ad86eSToby Isaac + obj - the `PetscObject` 21781c1ad86eSToby Isaac . format - a printf-style format string 21791c1ad86eSToby Isaac - ... - printf arguments to format 21801c1ad86eSToby Isaac 21811c1ad86eSToby Isaac Level: developer 21821c1ad86eSToby Isaac 2183b665b14eSToby Isaac .seealso: [](ch_profiling), `PetscLogObjectCreate()`, `PetscLogObjectDestroy()`, `PetscLogGetDefaultHandler()` 21841c1ad86eSToby Isaac @*/ 2185d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogObjectState(PetscObject obj, const char format[], ...) 2186d71ae5a4SJacob Faibussowitsch { 21875c6c1daeSBarry Smith PetscFunctionBegin; 2188dff009beSToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 2189dff009beSToby Isaac PetscLogHandler h = PetscLogHandlers[i].handler; 2190dff009beSToby Isaac 2191dff009beSToby Isaac if (h) { 2192dff009beSToby Isaac va_list Argp; 21935c6c1daeSBarry Smith va_start(Argp, format); 2194dff009beSToby Isaac PetscCall(PetscLogHandlerLogObjectState_Internal(h, obj, format, Argp)); 21955c6c1daeSBarry Smith va_end(Argp); 2196b665b14eSToby Isaac } 2197dff009beSToby Isaac } 21983ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 21995c6c1daeSBarry Smith } 22005c6c1daeSBarry Smith 22015c6c1daeSBarry Smith /*MC 22025c6c1daeSBarry Smith PetscLogFlops - Adds floating point operations to the global counter. 22035c6c1daeSBarry Smith 22045c6c1daeSBarry Smith Synopsis: 2205aaa7dc30SBarry Smith #include <petsclog.h> 22065c6c1daeSBarry Smith PetscErrorCode PetscLogFlops(PetscLogDouble f) 22075c6c1daeSBarry Smith 22085c6c1daeSBarry Smith Not Collective 22095c6c1daeSBarry Smith 22105c6c1daeSBarry Smith Input Parameter: 22115c6c1daeSBarry Smith . f - flop counter 22125c6c1daeSBarry Smith 221310450e9eSJacob Faibussowitsch Example Usage: 22145c6c1daeSBarry Smith .vb 22155c6c1daeSBarry Smith PetscLogEvent USER_EVENT; 221610450e9eSJacob Faibussowitsch 22175c6c1daeSBarry Smith PetscLogEventRegister("User event", 0, &USER_EVENT); 22185c6c1daeSBarry Smith PetscLogEventBegin(USER_EVENT, 0, 0, 0, 0); 22195c6c1daeSBarry Smith [code segment to monitor] 22205c6c1daeSBarry Smith PetscLogFlops(user_flops) 22215c6c1daeSBarry Smith PetscLogEventEnd(USER_EVENT, 0, 0, 0, 0); 22225c6c1daeSBarry Smith .ve 22235c6c1daeSBarry Smith 2224d1f92df0SBarry Smith Level: intermediate 2225d1f92df0SBarry Smith 2226811af0c4SBarry Smith Note: 222710450e9eSJacob Faibussowitsch A global counter logs all PETSc flop counts. The user can use PetscLogFlops() to increment 222810450e9eSJacob Faibussowitsch this counter to include flops for the application code. 22295c6c1daeSBarry Smith 22304b7c4d4dSPierre Jolivet .seealso: [](ch_profiling), `PetscLogGpuFlops()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscGetFlops()` 22315c6c1daeSBarry Smith M*/ 22325c6c1daeSBarry Smith 22335c6c1daeSBarry Smith /*MC 223410450e9eSJacob Faibussowitsch PetscPreLoadBegin - Begin a segment of code that may be preloaded (run twice) to get accurate 223510450e9eSJacob Faibussowitsch timings 22365c6c1daeSBarry Smith 22375c6c1daeSBarry Smith Synopsis: 2238aaa7dc30SBarry Smith #include <petsclog.h> 22395c6c1daeSBarry Smith void PetscPreLoadBegin(PetscBool flag, char *name); 22405c6c1daeSBarry Smith 22415c6c1daeSBarry Smith Not Collective 22425c6c1daeSBarry Smith 2243d8d19677SJose E. Roman Input Parameters: 224410450e9eSJacob Faibussowitsch + flag - `PETSC_TRUE` to run twice, `PETSC_FALSE` to run once, may be overridden with command 224510450e9eSJacob Faibussowitsch line option `-preload true|false` 224610450e9eSJacob Faibussowitsch - name - name of first stage (lines of code timed separately with `-log_view`) to be preloaded 22475c6c1daeSBarry Smith 224810450e9eSJacob Faibussowitsch Example Usage: 22495c6c1daeSBarry Smith .vb 225010450e9eSJacob Faibussowitsch PetscPreLoadBegin(PETSC_TRUE, "first stage"); 225110450e9eSJacob Faibussowitsch // lines of code 22525c6c1daeSBarry Smith PetscPreLoadStage("second stage"); 225310450e9eSJacob Faibussowitsch // lines of code 22545c6c1daeSBarry Smith PetscPreLoadEnd(); 22555c6c1daeSBarry Smith .ve 22565c6c1daeSBarry Smith 2257d1f92df0SBarry Smith Level: intermediate 2258d1f92df0SBarry Smith 2259811af0c4SBarry Smith Note: 226095452b02SPatrick Sanan Only works in C/C++, not Fortran 22615c6c1daeSBarry Smith 226210450e9eSJacob Faibussowitsch Flags available within the macro\: 226310450e9eSJacob Faibussowitsch + PetscPreLoadingUsed - `PETSC_TRUE` if we are or have done preloading 226410450e9eSJacob Faibussowitsch . PetscPreLoadingOn - `PETSC_TRUE` if it is CURRENTLY doing preload 226510450e9eSJacob Faibussowitsch . PetscPreLoadIt - `0` for the first computation (with preloading turned off it is only 226610450e9eSJacob Faibussowitsch `0`) `1` for the second 226710450e9eSJacob Faibussowitsch - PetscPreLoadMax - number of times it will do the computation, only one when preloading is 226810450e9eSJacob Faibussowitsch turned on 226910450e9eSJacob Faibussowitsch 227010450e9eSJacob Faibussowitsch The first two variables are available throughout the program, the second two only between the 227110450e9eSJacob Faibussowitsch `PetscPreLoadBegin()` and `PetscPreLoadEnd()` 22725c6c1daeSBarry Smith 2273d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscPreLoadEnd()`, `PetscPreLoadStage()` 22745c6c1daeSBarry Smith M*/ 22755c6c1daeSBarry Smith 22765c6c1daeSBarry Smith /*MC 227710450e9eSJacob Faibussowitsch PetscPreLoadEnd - End a segment of code that may be preloaded (run twice) to get accurate 227810450e9eSJacob Faibussowitsch timings 22795c6c1daeSBarry Smith 22805c6c1daeSBarry Smith Synopsis: 2281aaa7dc30SBarry Smith #include <petsclog.h> 22825c6c1daeSBarry Smith void PetscPreLoadEnd(void); 22835c6c1daeSBarry Smith 22845c6c1daeSBarry Smith Not Collective 22855c6c1daeSBarry Smith 228610450e9eSJacob Faibussowitsch Example Usage: 22875c6c1daeSBarry Smith .vb 228810450e9eSJacob Faibussowitsch PetscPreLoadBegin(PETSC_TRUE, "first stage"); 228910450e9eSJacob Faibussowitsch // lines of code 22905c6c1daeSBarry Smith PetscPreLoadStage("second stage"); 229110450e9eSJacob Faibussowitsch // lines of code 22925c6c1daeSBarry Smith PetscPreLoadEnd(); 22935c6c1daeSBarry Smith .ve 22945c6c1daeSBarry Smith 2295d1f92df0SBarry Smith Level: intermediate 2296d1f92df0SBarry Smith 2297811af0c4SBarry Smith Note: 2298dd01b7e5SBarry Smith Only works in C/C++ not Fortran 22995c6c1daeSBarry Smith 2300d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscPreLoadBegin()`, `PetscPreLoadStage()` 23015c6c1daeSBarry Smith M*/ 23025c6c1daeSBarry Smith 23035c6c1daeSBarry Smith /*MC 230410450e9eSJacob Faibussowitsch PetscPreLoadStage - Start a new segment of code to be timed separately to get accurate timings 23055c6c1daeSBarry Smith 23065c6c1daeSBarry Smith Synopsis: 2307aaa7dc30SBarry Smith #include <petsclog.h> 23085c6c1daeSBarry Smith void PetscPreLoadStage(char *name); 23095c6c1daeSBarry Smith 23105c6c1daeSBarry Smith Not Collective 23115c6c1daeSBarry Smith 231210450e9eSJacob Faibussowitsch Example Usage: 23135c6c1daeSBarry Smith .vb 231410450e9eSJacob Faibussowitsch PetscPreLoadBegin(PETSC_TRUE,"first stage"); 231510450e9eSJacob Faibussowitsch // lines of code 23165c6c1daeSBarry Smith PetscPreLoadStage("second stage"); 231710450e9eSJacob Faibussowitsch // lines of code 23185c6c1daeSBarry Smith PetscPreLoadEnd(); 23195c6c1daeSBarry Smith .ve 23205c6c1daeSBarry Smith 2321d1f92df0SBarry Smith Level: intermediate 2322d1f92df0SBarry Smith 2323811af0c4SBarry Smith Note: 2324dd01b7e5SBarry Smith Only works in C/C++ not Fortran 23255c6c1daeSBarry Smith 2326d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscPreLoadBegin()`, `PetscPreLoadEnd()` 23275c6c1daeSBarry Smith M*/ 23285c6c1daeSBarry Smith 2329a4af0ceeSJacob Faibussowitsch #if PetscDefined(HAVE_DEVICE) 2330a4af0ceeSJacob Faibussowitsch #include <petsc/private/deviceimpl.h> 23319ffd0706SHong Zhang 2332cc4c1da9SBarry Smith /*@ 2333156b51fbSBarry Smith PetscLogGpuTime - turn on the logging of GPU time for GPU kernels 2334156b51fbSBarry Smith 2335811af0c4SBarry Smith Options Database Key: 2336efa05fe8SBarry Smith . -log_view_gpu_time - provide the GPU times for all events in the `-log_view` output 2337156b51fbSBarry Smith 2338d1f92df0SBarry Smith Level: advanced 2339d1f92df0SBarry Smith 2340156b51fbSBarry Smith Notes: 234110450e9eSJacob Faibussowitsch Turning on the timing of the GPU kernels can slow down the entire computation and should only 2342efa05fe8SBarry Smith be used when studying the performance of individual operations on GPU such as vector operations and 234310450e9eSJacob Faibussowitsch matrix-vector operations. 2344156b51fbSBarry Smith 2345*76c63389SBarry Smith If this option is not used then times for most of the events in the `-log_view` output will be listed as NaN, indicating the times are not available 2346efa05fe8SBarry Smith 234710450e9eSJacob Faibussowitsch This routine should only be called once near the beginning of the program. Once it is started 234810450e9eSJacob Faibussowitsch it cannot be turned off. 2349156b51fbSBarry Smith 2350d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`, `PetscLogGpuTimeEnd()`, `PetscLogGpuTimeBegin()` 2351156b51fbSBarry Smith @*/ 2352d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogGpuTime(void) 2353d71ae5a4SJacob Faibussowitsch { 2354473903fcSJunchao Zhang PetscFunctionBegin; 2355473903fcSJunchao Zhang PetscCheck(petsc_gtime == 0.0, PETSC_COMM_SELF, PETSC_ERR_SUP, "GPU logging has already been turned on"); 2356156b51fbSBarry Smith PetscLogGpuTimeFlag = PETSC_TRUE; 2357473903fcSJunchao Zhang PetscFunctionReturn(PETSC_SUCCESS); 2358156b51fbSBarry Smith } 2359156b51fbSBarry Smith 2360cc4c1da9SBarry Smith /*@ 23619ffd0706SHong Zhang PetscLogGpuTimeBegin - Start timer for device 23629ffd0706SHong Zhang 2363d1f92df0SBarry Smith Level: intermediate 2364d1f92df0SBarry Smith 23659ffd0706SHong Zhang Notes: 23667d766218SJunchao Zhang When GPU is enabled, the timer is run on the GPU, it is a separate logging of time 236710450e9eSJacob Faibussowitsch devoted to GPU computations (excluding kernel launch times). 2368811af0c4SBarry Smith 23697d766218SJunchao Zhang When GPU is not available, the timer is run on the CPU, it is a separate logging of 237010450e9eSJacob Faibussowitsch time devoted to GPU computations (including kernel launch times). 2371811af0c4SBarry Smith 237210450e9eSJacob Faibussowitsch There is no need to call WaitForCUDA() or WaitForHIP() between `PetscLogGpuTimeBegin()` and 237310450e9eSJacob Faibussowitsch `PetscLogGpuTimeEnd()` 2374811af0c4SBarry Smith 237510450e9eSJacob Faibussowitsch This timer should NOT include times for data transfers between the GPU and CPU, nor setup 237610450e9eSJacob Faibussowitsch actions such as allocating space. 2377811af0c4SBarry Smith 237810450e9eSJacob Faibussowitsch The regular logging captures the time for data transfers and any CPU activities during the 237910450e9eSJacob Faibussowitsch event. It is used to compute the flop rate on the GPU as it is actively engaged in running a 238010450e9eSJacob Faibussowitsch kernel. 23819ffd0706SHong Zhang 23829ffd0706SHong Zhang Developer Notes: 238310450e9eSJacob Faibussowitsch The GPU event timer captures the execution time of all the kernels launched in the default 238454c05997SPierre Jolivet stream by the CPU between `PetscLogGpuTimeBegin()` and `PetscLogGpuTimeEnd()`. 2385811af0c4SBarry Smith 238654c05997SPierre Jolivet `PetscLogGpuTimeBegin()` and `PetscLogGpuTimeEnd()` insert the begin and end events into the 238710450e9eSJacob Faibussowitsch default stream (stream 0). The device will record a time stamp for the event when it reaches 238810450e9eSJacob Faibussowitsch that event in the stream. The function xxxEventSynchronize() is called in 238954c05997SPierre Jolivet `PetscLogGpuTimeEnd()` to block CPU execution, but not continued GPU execution, until the 239010450e9eSJacob Faibussowitsch timer event is recorded. 23919ffd0706SHong Zhang 2392d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`, `PetscLogGpuTimeEnd()`, `PetscLogGpuTime()` 23939ffd0706SHong Zhang @*/ 2394d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogGpuTimeBegin(void) 2395d71ae5a4SJacob Faibussowitsch { 2396b665b14eSToby Isaac PetscBool isActive; 2397b665b14eSToby Isaac 23989ffd0706SHong Zhang PetscFunctionBegin; 2399b665b14eSToby Isaac PetscCall(PetscLogEventBeginIsActive(&isActive)); 2400b665b14eSToby Isaac if (!isActive || !PetscLogGpuTimeFlag) PetscFunctionReturn(PETSC_SUCCESS); 24015268dc8aSHong Zhang if (!PetscDefined(HAVE_KOKKOS_WITHOUT_GPU)) { 2402a4af0ceeSJacob Faibussowitsch PetscDeviceContext dctx; 2403a4af0ceeSJacob Faibussowitsch 24049566063dSJacob Faibussowitsch PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 24059566063dSJacob Faibussowitsch PetscCall(PetscDeviceContextBeginTimer_Internal(dctx)); 24065268dc8aSHong Zhang } else { 24077d766218SJunchao Zhang PetscCall(PetscTimeSubtract(&petsc_gtime)); 24085268dc8aSHong Zhang } 24093ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 24109ffd0706SHong Zhang } 24119ffd0706SHong Zhang 2412cc4c1da9SBarry Smith /*@ 24139ffd0706SHong Zhang PetscLogGpuTimeEnd - Stop timer for device 24149ffd0706SHong Zhang 24159ffd0706SHong Zhang Level: intermediate 24169ffd0706SHong Zhang 2417d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`, `PetscLogGpuTimeBegin()` 24189ffd0706SHong Zhang @*/ 2419d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscLogGpuTimeEnd(void) 2420d71ae5a4SJacob Faibussowitsch { 2421b665b14eSToby Isaac PetscBool isActive; 2422b665b14eSToby Isaac 24239ffd0706SHong Zhang PetscFunctionBegin; 2424b665b14eSToby Isaac PetscCall(PetscLogEventEndIsActive(&isActive)); 2425b665b14eSToby Isaac if (!isActive || !PetscLogGpuTimeFlag) PetscFunctionReturn(PETSC_SUCCESS); 24265268dc8aSHong Zhang if (!PetscDefined(HAVE_KOKKOS_WITHOUT_GPU)) { 2427a4af0ceeSJacob Faibussowitsch PetscDeviceContext dctx; 2428a4af0ceeSJacob Faibussowitsch PetscLogDouble elapsed; 2429a4af0ceeSJacob Faibussowitsch 24309566063dSJacob Faibussowitsch PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 24319566063dSJacob Faibussowitsch PetscCall(PetscDeviceContextEndTimer_Internal(dctx, &elapsed)); 2432a4af0ceeSJacob Faibussowitsch petsc_gtime += (elapsed / 1000.0); 24335268dc8aSHong Zhang #if PetscDefined(HAVE_CUDA_VERSION_12_2PLUS) 24345268dc8aSHong Zhang if (PetscLogGpuEnergyFlag) { 24355268dc8aSHong Zhang PetscLogDouble power; 24365268dc8aSHong Zhang PetscCall(PetscDeviceContextGetPower_Internal(dctx, &power)); 24375268dc8aSHong Zhang petsc_genergy += (power * elapsed / 1000000.0); // convert to Joules 2438a4af0ceeSJacob Faibussowitsch } 24397d766218SJunchao Zhang #endif 24405268dc8aSHong Zhang } else { 24415268dc8aSHong Zhang PetscCall(PetscTimeAdd(&petsc_gtime)); 24425268dc8aSHong Zhang } 24433ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 24449ffd0706SHong Zhang } 2445c708d6e3SStefano Zampini 24465268dc8aSHong Zhang /*@ 24475268dc8aSHong Zhang PetscLogGpuEnergy - turn on the logging of GPU energy (estimated with power*gtime) for GPU kernels 24485268dc8aSHong Zhang 24495268dc8aSHong Zhang Options Database Key: 24505268dc8aSHong Zhang . -log_view_gpu_energy - provide the GPU energy consumption (estimated with power*gtime) for all events in the `-log_view` output 24515268dc8aSHong Zhang 24525268dc8aSHong Zhang Level: advanced 24535268dc8aSHong Zhang 24545268dc8aSHong Zhang Note: 24555268dc8aSHong Zhang This option is mutually exclusive to `-log_view_gpu_energy_meter`. 24565268dc8aSHong Zhang 24575268dc8aSHong Zhang Developer Note: 24585268dc8aSHong Zhang This option turns on energy monitoring of GPU kernels and requires CUDA version >= 12.2. The energy consumption is estimated as 24595268dc8aSHong Zhang instant_power * gpu_kernel_time. Due to the delay in NVML power sampling, we read the instantaneous power draw at the end of each 24605268dc8aSHong Zhang event using `nvmlDeviceGetFieldValues()` with the field ID `NVML_FI_DEV_POWER_INSTANT`. 24615268dc8aSHong Zhang 24625268dc8aSHong Zhang .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuEnergyMeter()` 24635268dc8aSHong Zhang @*/ 24645268dc8aSHong Zhang PetscErrorCode PetscLogGpuEnergy(void) 24655268dc8aSHong Zhang { 24665268dc8aSHong Zhang PetscFunctionBegin; 24675268dc8aSHong Zhang PetscCheck(PetscDefined(HAVE_CUDA_VERSION_12_2PLUS), PETSC_COMM_WORLD, PETSC_ERR_SUP_SYS, "-log_view_gpu_energy requires CUDA version >= 12.2"); 24685268dc8aSHong Zhang PetscCheck(petsc_genergy == 0.0, PETSC_COMM_SELF, PETSC_ERR_SUP, "GPU energy logging has already been turned on"); 24695268dc8aSHong Zhang PetscLogGpuEnergyFlag = PETSC_TRUE; 24705268dc8aSHong Zhang PetscLogGpuEnergyMeterFlag = PETSC_FALSE; 24715268dc8aSHong Zhang PetscFunctionReturn(PETSC_SUCCESS); 24725268dc8aSHong Zhang } 24735268dc8aSHong Zhang 24745268dc8aSHong Zhang /*@ 24755268dc8aSHong Zhang PetscLogGpuEnergyMeter - turn on the logging of GPU energy (readings from energy meters) for GPU kernels 24765268dc8aSHong Zhang 24775268dc8aSHong Zhang Options Database Key: 24785268dc8aSHong Zhang . -log_view_gpu_energy_meter - provide the GPU energy (readings from energy meters) consumption for all events in the `-log_view` output 24795268dc8aSHong Zhang 24805268dc8aSHong Zhang Level: advanced 24815268dc8aSHong Zhang 24825268dc8aSHong Zhang Note: 24835268dc8aSHong Zhang This option is mutually exclusive to `-log_view_gpu_energy`. 24845268dc8aSHong Zhang 24855268dc8aSHong Zhang Developer Note: 24865268dc8aSHong Zhang This option turns on energy monitoring of GPU kernels. The energy consumption is measured directly using the NVML API 24875268dc8aSHong Zhang `nvmlDeviceGetTotalEnergyConsumption()`, which returns the total energy used by the GPU since the driver was last initialized. 24885268dc8aSHong Zhang For newer GPUs, energy readings are updated every 20-100ms, so this approach may be inaccurate for short-duration GPU events. 24895268dc8aSHong Zhang 24905268dc8aSHong Zhang @*/ 24915268dc8aSHong Zhang PetscErrorCode PetscLogGpuEnergyMeter(void) 24925268dc8aSHong Zhang { 24935268dc8aSHong Zhang PetscFunctionBegin; 24945268dc8aSHong Zhang PetscCheck(petsc_genergy == 0.0, PETSC_COMM_SELF, PETSC_ERR_SUP, "GPU energy logging has already been turned on"); 24955268dc8aSHong Zhang PetscLogGpuEnergyMeterFlag = PETSC_TRUE; 24965268dc8aSHong Zhang PetscLogGpuEnergyFlag = PETSC_FALSE; 24975268dc8aSHong Zhang PetscFunctionReturn(PETSC_SUCCESS); 24985268dc8aSHong Zhang } 24995268dc8aSHong Zhang 25005268dc8aSHong Zhang /*@ 25015268dc8aSHong Zhang PetscLogGpuEnergyMeterBegin - Start energy meter for device 25025268dc8aSHong Zhang 25035268dc8aSHong Zhang Level: intermediate 25045268dc8aSHong Zhang 25055268dc8aSHong Zhang Notes: 25065268dc8aSHong Zhang The GPU event energy meter captures the energy used by the GPU between `PetscLogGpuEnergyMeterBegin()` and `PetscLogGpuEnergyMeterEnd()`. 25075268dc8aSHong Zhang 25085268dc8aSHong Zhang `PetscLogGpuEnergyMeterBegin()` and `PetscLogGpuEnergyMeterEnd()` collect the energy readings using `nvmlDeviceGetTotalEnergyConsumption()`. 25095268dc8aSHong Zhang The function `cupmStreamSynchronize()` is called before the energy query to ensure completion. 25105268dc8aSHong Zhang 25115268dc8aSHong Zhang .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuEnergyMeterEnd()`, `PetscLogGpuEnergyMeter()` 25125268dc8aSHong Zhang @*/ 25135268dc8aSHong Zhang PetscErrorCode PetscLogGpuEnergyMeterBegin(void) 25145268dc8aSHong Zhang { 25155268dc8aSHong Zhang PetscBool isActive; 25165268dc8aSHong Zhang 25175268dc8aSHong Zhang PetscFunctionBegin; 25185268dc8aSHong Zhang PetscCall(PetscLogEventBeginIsActive(&isActive)); 25195268dc8aSHong Zhang if (!isActive || !PetscLogGpuEnergyMeterFlag) PetscFunctionReturn(PETSC_SUCCESS); 25205268dc8aSHong Zhang if (!PetscDefined(HAVE_KOKKOS_WITHOUT_GPU)) { 25215268dc8aSHong Zhang PetscDeviceContext dctx; 25225268dc8aSHong Zhang 25235268dc8aSHong Zhang PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 25245268dc8aSHong Zhang PetscCall(PetscDeviceContextBeginEnergyMeter_Internal(dctx)); 25255268dc8aSHong Zhang } 25265268dc8aSHong Zhang PetscFunctionReturn(PETSC_SUCCESS); 25275268dc8aSHong Zhang } 25285268dc8aSHong Zhang 25295268dc8aSHong Zhang /*@ 25305268dc8aSHong Zhang PetscLogGpuEnergyMeterEnd - Stop energy meter for device 25315268dc8aSHong Zhang 25325268dc8aSHong Zhang Level: intermediate 25335268dc8aSHong Zhang 25345268dc8aSHong Zhang .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuEnergyMeterBegin()` 25355268dc8aSHong Zhang @*/ 25365268dc8aSHong Zhang PetscErrorCode PetscLogGpuEnergyMeterEnd(void) 25375268dc8aSHong Zhang { 25385268dc8aSHong Zhang PetscBool isActive; 25395268dc8aSHong Zhang 25405268dc8aSHong Zhang PetscFunctionBegin; 25415268dc8aSHong Zhang PetscCall(PetscLogEventEndIsActive(&isActive)); 25425268dc8aSHong Zhang if (!isActive || !PetscLogGpuEnergyMeterFlag) PetscFunctionReturn(PETSC_SUCCESS); 25435268dc8aSHong Zhang if (!PetscDefined(HAVE_KOKKOS_WITHOUT_GPU)) { 25445268dc8aSHong Zhang PetscDeviceContext dctx; 25455268dc8aSHong Zhang PetscLogDouble energy; 25465268dc8aSHong Zhang 25475268dc8aSHong Zhang PetscCall(PetscDeviceContextGetCurrentContext(&dctx)); 25485268dc8aSHong Zhang PetscCall(PetscDeviceContextEndEnergyMeter_Internal(dctx, &energy)); 25495268dc8aSHong Zhang petsc_genergy_meter += (energy / 1000.0); // convert to Joules 25505268dc8aSHong Zhang } 25515268dc8aSHong Zhang PetscFunctionReturn(PETSC_SUCCESS); 25525268dc8aSHong Zhang } 25539ffd0706SHong Zhang #endif /* end of PETSC_HAVE_DEVICE */ 25549ffd0706SHong Zhang 2555cb9ef012SToby Isaac #endif /* PETSC_USE_LOG*/ 2556cb9ef012SToby Isaac 2557dd01b7e5SBarry Smith /* -- Utility functions for logging from Fortran -- */ 2558b665b14eSToby Isaac 2559b665b14eSToby Isaac PETSC_EXTERN PetscErrorCode PetscASend(int count, int datatype) 2560b665b14eSToby Isaac { 2561b665b14eSToby Isaac PetscFunctionBegin; 2562cb9ef012SToby Isaac #if PetscDefined(USE_LOG) 2563b665b14eSToby Isaac PetscCall(PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1)); 2564b665b14eSToby Isaac #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) 2565b665b14eSToby Isaac PetscCall(PetscMPITypeSize(count, MPI_Type_f2c((MPI_Fint)datatype), &petsc_send_len, &petsc_send_len_th)); 2566b665b14eSToby Isaac #endif 2567cb9ef012SToby Isaac #endif 2568b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 2569b665b14eSToby Isaac } 2570b665b14eSToby Isaac 2571b665b14eSToby Isaac PETSC_EXTERN PetscErrorCode PetscARecv(int count, int datatype) 2572b665b14eSToby Isaac { 2573b665b14eSToby Isaac PetscFunctionBegin; 2574cb9ef012SToby Isaac #if PetscDefined(USE_LOG) 2575b665b14eSToby Isaac PetscCall(PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1)); 2576b665b14eSToby Isaac #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) 2577b665b14eSToby Isaac PetscCall(PetscMPITypeSize(count, MPI_Type_f2c((MPI_Fint)datatype), &petsc_recv_len, &petsc_recv_len_th)); 2578b665b14eSToby Isaac #endif 2579cb9ef012SToby Isaac #endif 2580b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 2581b665b14eSToby Isaac } 2582b665b14eSToby Isaac 2583b665b14eSToby Isaac PETSC_EXTERN PetscErrorCode PetscAReduce(void) 2584b665b14eSToby Isaac { 2585b665b14eSToby Isaac PetscFunctionBegin; 2586cb9ef012SToby Isaac if (PetscDefined(USE_LOG)) PetscCall(PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, 1)); 2587b665b14eSToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 2588b665b14eSToby Isaac } 2589b665b14eSToby Isaac 25905c6c1daeSBarry Smith PetscClassId PETSC_LARGEST_CLASSID = PETSC_SMALLEST_CLASSID; 25915c6c1daeSBarry Smith PetscClassId PETSC_OBJECT_CLASSID = 0; 25925c6c1daeSBarry Smith 25932611ad71SToby Isaac static PetscBool PetscLogInitializeCalled = PETSC_FALSE; 25942611ad71SToby Isaac 25952611ad71SToby Isaac PETSC_INTERN PetscErrorCode PetscLogInitialize(void) 25962611ad71SToby Isaac { 25972611ad71SToby Isaac int stage; 25982611ad71SToby Isaac 25992611ad71SToby Isaac PetscFunctionBegin; 26002611ad71SToby Isaac if (PetscLogInitializeCalled) PetscFunctionReturn(PETSC_SUCCESS); 26012611ad71SToby Isaac PetscLogInitializeCalled = PETSC_TRUE; 26022611ad71SToby Isaac if (PetscDefined(USE_LOG)) { 26032611ad71SToby Isaac /* Setup default logging structures */ 26042611ad71SToby Isaac PetscCall(PetscLogStateCreate(&petsc_log_state)); 26052611ad71SToby Isaac for (PetscInt i = 0; i < PETSC_LOG_HANDLER_MAX; i++) { 26062611ad71SToby Isaac if (PetscLogHandlers[i].handler) PetscCall(PetscLogHandlerSetState(PetscLogHandlers[i].handler, petsc_log_state)); 26072611ad71SToby Isaac } 26082611ad71SToby Isaac PetscCall(PetscLogStateStageRegister(petsc_log_state, "Main Stage", &stage)); 26092611ad71SToby Isaac PetscCall(PetscSpinlockCreate(&PetscLogSpinLock)); 26102611ad71SToby Isaac #if defined(PETSC_HAVE_THREADSAFETY) 26112611ad71SToby Isaac petsc_log_tid = 0; 26122611ad71SToby Isaac petsc_log_gid = 0; 26132611ad71SToby Isaac #endif 26142611ad71SToby Isaac 26152611ad71SToby Isaac /* All processors sync here for more consistent logging */ 26162611ad71SToby Isaac PetscCallMPI(MPI_Barrier(PETSC_COMM_WORLD)); 26172611ad71SToby Isaac PetscCall(PetscTime(&petsc_BaseTime)); 26182611ad71SToby Isaac PetscCall(PetscLogStagePush(stage)); 26192611ad71SToby Isaac } 26202611ad71SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 26212611ad71SToby Isaac } 26222611ad71SToby Isaac 26232611ad71SToby Isaac PETSC_INTERN PetscErrorCode PetscLogFinalize(void) 26242611ad71SToby Isaac { 26252611ad71SToby Isaac PetscFunctionBegin; 26262611ad71SToby Isaac if (PetscDefined(USE_LOG)) { 2627b665b14eSToby Isaac /* Resetting phase */ 2628b665b14eSToby Isaac // pop remaining stages 2629b665b14eSToby Isaac if (petsc_log_state) { 26303a7d0413SPierre Jolivet while (petsc_log_state->current_stage >= 0) PetscCall(PetscLogStagePop()); 2631b665b14eSToby Isaac } 26322611ad71SToby Isaac for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) PetscCall(PetscLogHandlerDestroy(&PetscLogHandlers[i].handler)); 26332611ad71SToby Isaac PetscCall(PetscArrayzero(PetscLogHandlers, PETSC_LOG_HANDLER_MAX)); 26342611ad71SToby Isaac PetscCall(PetscLogStateDestroy(&petsc_log_state)); 26352611ad71SToby Isaac 26362611ad71SToby Isaac petsc_TotalFlops = 0.0; 26372611ad71SToby Isaac petsc_BaseTime = 0.0; 26382611ad71SToby Isaac petsc_TotalFlops = 0.0; 26392611ad71SToby Isaac petsc_send_ct = 0.0; 26402611ad71SToby Isaac petsc_recv_ct = 0.0; 26412611ad71SToby Isaac petsc_send_len = 0.0; 26422611ad71SToby Isaac petsc_recv_len = 0.0; 26432611ad71SToby Isaac petsc_isend_ct = 0.0; 26442611ad71SToby Isaac petsc_irecv_ct = 0.0; 26452611ad71SToby Isaac petsc_isend_len = 0.0; 26462611ad71SToby Isaac petsc_irecv_len = 0.0; 26472611ad71SToby Isaac petsc_wait_ct = 0.0; 26482611ad71SToby Isaac petsc_wait_any_ct = 0.0; 26492611ad71SToby Isaac petsc_wait_all_ct = 0.0; 26502611ad71SToby Isaac petsc_sum_of_waits_ct = 0.0; 26512611ad71SToby Isaac petsc_allreduce_ct = 0.0; 26522611ad71SToby Isaac petsc_gather_ct = 0.0; 26532611ad71SToby Isaac petsc_scatter_ct = 0.0; 26542611ad71SToby Isaac petsc_TotalFlops_th = 0.0; 26552611ad71SToby Isaac petsc_send_ct_th = 0.0; 26562611ad71SToby Isaac petsc_recv_ct_th = 0.0; 26572611ad71SToby Isaac petsc_send_len_th = 0.0; 26582611ad71SToby Isaac petsc_recv_len_th = 0.0; 26592611ad71SToby Isaac petsc_isend_ct_th = 0.0; 26602611ad71SToby Isaac petsc_irecv_ct_th = 0.0; 26612611ad71SToby Isaac petsc_isend_len_th = 0.0; 26622611ad71SToby Isaac petsc_irecv_len_th = 0.0; 26632611ad71SToby Isaac petsc_wait_ct_th = 0.0; 26642611ad71SToby Isaac petsc_wait_any_ct_th = 0.0; 26652611ad71SToby Isaac petsc_wait_all_ct_th = 0.0; 26662611ad71SToby Isaac petsc_sum_of_waits_ct_th = 0.0; 26672611ad71SToby Isaac petsc_allreduce_ct_th = 0.0; 26682611ad71SToby Isaac petsc_gather_ct_th = 0.0; 26692611ad71SToby Isaac petsc_scatter_ct_th = 0.0; 26702611ad71SToby Isaac 26712611ad71SToby Isaac petsc_ctog_ct = 0.0; 26722611ad71SToby Isaac petsc_gtoc_ct = 0.0; 26732611ad71SToby Isaac petsc_ctog_sz = 0.0; 26742611ad71SToby Isaac petsc_gtoc_sz = 0.0; 26752611ad71SToby Isaac petsc_gflops = 0.0; 26762611ad71SToby Isaac petsc_gtime = 0.0; 26775268dc8aSHong Zhang petsc_genergy = 0.0; 26785268dc8aSHong Zhang petsc_genergy_meter = 0.0; 26792611ad71SToby Isaac petsc_ctog_ct_th = 0.0; 26802611ad71SToby Isaac petsc_gtoc_ct_th = 0.0; 26812611ad71SToby Isaac petsc_ctog_sz_th = 0.0; 26822611ad71SToby Isaac petsc_gtoc_sz_th = 0.0; 26832611ad71SToby Isaac petsc_gflops_th = 0.0; 26842611ad71SToby Isaac petsc_gtime_th = 0.0; 26852611ad71SToby Isaac } 26862611ad71SToby Isaac PETSC_LARGEST_CLASSID = PETSC_SMALLEST_CLASSID; 26872611ad71SToby Isaac PETSC_OBJECT_CLASSID = 0; 26882611ad71SToby Isaac PetscLogInitializeCalled = PETSC_FALSE; 26892611ad71SToby Isaac PetscFunctionReturn(PETSC_SUCCESS); 26902611ad71SToby Isaac } 26912611ad71SToby Isaac 2692cc4c1da9SBarry Smith /*@ 26935c6c1daeSBarry Smith PetscClassIdRegister - Registers a new class name for objects and logging operations in an application code. 26945c6c1daeSBarry Smith 26955c6c1daeSBarry Smith Not Collective 26965c6c1daeSBarry Smith 26975c6c1daeSBarry Smith Input Parameter: 26985c6c1daeSBarry Smith . name - The class name 26995c6c1daeSBarry Smith 27005c6c1daeSBarry Smith Output Parameter: 27015c6c1daeSBarry Smith . oclass - The class id or classid 27025c6c1daeSBarry Smith 27035c6c1daeSBarry Smith Level: developer 27045c6c1daeSBarry Smith 2705d1f92df0SBarry Smith .seealso: [](ch_profiling), `PetscLogEventRegister()` 27065c6c1daeSBarry Smith @*/ 2707d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscClassIdRegister(const char name[], PetscClassId *oclass) 2708d71ae5a4SJacob Faibussowitsch { 27095c6c1daeSBarry Smith PetscFunctionBegin; 27105c6c1daeSBarry Smith *oclass = ++PETSC_LARGEST_CLASSID; 27115c6c1daeSBarry Smith #if defined(PETSC_USE_LOG) 2712b665b14eSToby Isaac { 2713b665b14eSToby Isaac PetscLogState state; 2714b665b14eSToby Isaac PetscLogClass logclass; 2715b665b14eSToby Isaac 2716b665b14eSToby Isaac PetscCall(PetscLogGetState(&state)); 2717b665b14eSToby Isaac if (state) PetscCall(PetscLogStateClassRegister(state, name, *oclass, &logclass)); 2718b665b14eSToby Isaac } 27195c6c1daeSBarry Smith #endif 27203ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 27215c6c1daeSBarry Smith } 2722