Actual source code: petsclog.h

  1: /*
  2:     Defines profile/logging in PETSc.
  3: */
  4: #pragma once

  6: #include <petscsys.h>
  7: #include <petsctime.h>
  8: #include <petscbt.h>
  9: #include <petsclogtypes.h>

 11: /* MANSEC = Sys */
 12: /* SUBMANSEC = Log */

 14: /* General logging of information; different from event logging */
 15: PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[], PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
 16: #if PetscDefined(USE_INFO)
 17:   #define PetscInfo(A, ...) PetscInfo_Private(PETSC_FUNCTION_NAME, ((PetscObject)A), __VA_ARGS__)
 18: #else
 19:   #define PetscInfo(A, ...) PETSC_SUCCESS
 20: #endif

 22: #define PetscInfo1(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 23: #define PetscInfo2(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 24: #define PetscInfo3(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 25: #define PetscInfo4(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 26: #define PetscInfo5(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 27: #define PetscInfo6(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 28: #define PetscInfo7(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 29: #define PetscInfo8(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
 30: #define PetscInfo9(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)

 32: /*E
 33:   PetscInfoCommFlag - Describes the method by which to filter information displayed by `PetscInfo()` by communicator size

 35:   Values:
 36: + `PETSC_INFO_COMM_ALL`       - Default uninitialized value. `PetscInfo()` will not filter based on
 37:                                 communicator size (i.e. will print for all communicators)
 38: . `PETSC_INFO_COMM_NO_SELF`   - `PetscInfo()` will NOT print for communicators with size = 1 (i.e. *_COMM_SELF)
 39: - `PETSC_INFO_COMM_ONLY_SELF` - `PetscInfo()` will ONLY print for communicators with size = 1

 41:   Level: intermediate

 43:   Note:
 44:   Used as an input for `PetscInfoSetFilterCommSelf()`

 46: .seealso: `PetscInfo()`, `PetscInfoSetFromOptions()`, `PetscInfoSetFilterCommSelf()`
 47: E*/
 48: typedef enum {
 49:   PETSC_INFO_COMM_ALL       = -1,
 50:   PETSC_INFO_COMM_NO_SELF   = 0,
 51:   PETSC_INFO_COMM_ONLY_SELF = 1
 52: } PetscInfoCommFlag;

 54: PETSC_EXTERN const char *const PetscInfoCommFlags[];
 55: PETSC_EXTERN PetscErrorCode    PetscInfoDeactivateClass(PetscClassId);
 56: PETSC_EXTERN PetscErrorCode    PetscInfoActivateClass(PetscClassId);
 57: PETSC_EXTERN PetscErrorCode    PetscInfoEnabled(PetscClassId, PetscBool *);
 58: PETSC_EXTERN PetscErrorCode    PetscInfoAllow(PetscBool);
 59: PETSC_EXTERN PetscErrorCode    PetscInfoSetFile(const char[], const char[]);
 60: PETSC_EXTERN PetscErrorCode    PetscInfoGetFile(char **, FILE **);
 61: PETSC_EXTERN PetscErrorCode    PetscInfoSetClasses(PetscBool, PetscInt, const char *const *);
 62: PETSC_EXTERN PetscErrorCode    PetscInfoGetClass(const char *, PetscBool *);
 63: PETSC_EXTERN PetscErrorCode    PetscInfoGetInfo(PetscBool *, PetscBool *, PetscBool *, PetscBool *, PetscInfoCommFlag *);
 64: PETSC_EXTERN PetscErrorCode    PetscInfoProcessClass(const char[], PetscInt, const PetscClassId[]);
 65: PETSC_EXTERN PetscErrorCode    PetscInfoSetFilterCommSelf(PetscInfoCommFlag);
 66: PETSC_EXTERN PetscErrorCode    PetscInfoSetFromOptions(PetscOptions);
 67: PETSC_EXTERN PetscErrorCode    PetscInfoDestroy(void);
 68: PETSC_EXTERN PetscBool         PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */

 70: PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *);
 71: PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack);
 72: PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int);
 73: PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *);
 74: PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *);
 75: PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *);

 77: PETSC_EXTERN PetscErrorCode PetscLogStateCreate(PetscLogState *);
 78: PETSC_EXTERN PetscErrorCode PetscLogStateDestroy(PetscLogState *);

 80: PETSC_EXTERN PetscErrorCode PetscLogStateClassRegister(PetscLogState, const char[], PetscClassId, PetscLogStage *);
 81: PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActive(PetscLogState, PetscLogStage, PetscClassId, PetscBool);
 82: PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState, PetscClassId, PetscBool);

 84: PETSC_EXTERN PetscErrorCode PetscLogStateStageRegister(PetscLogState, const char[], PetscLogStage *);
 85: PETSC_EXTERN PetscErrorCode PetscLogStateStagePush(PetscLogState, PetscLogStage);
 86: PETSC_EXTERN PetscErrorCode PetscLogStateStagePop(PetscLogState);
 87: PETSC_EXTERN PetscErrorCode PetscLogStateStageSetActive(PetscLogState, PetscLogStage, PetscBool);
 88: PETSC_EXTERN PetscErrorCode PetscLogStateStageGetActive(PetscLogState, PetscLogStage, PetscBool *);
 89: PETSC_EXTERN PetscErrorCode PetscLogStateGetCurrentStage(PetscLogState, PetscLogStage *);

 91: PETSC_EXTERN PetscErrorCode PetscLogStateEventRegister(PetscLogState, const char[], PetscClassId, PetscLogEvent *);
 92: PETSC_EXTERN PetscErrorCode PetscLogStateEventSetCollective(PetscLogState, PetscLogEvent, PetscBool);
 93: PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool);
 94: PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActiveAll(PetscLogState, PetscLogEvent, PetscBool);
 95: PETSC_EXTERN PetscErrorCode PetscLogStateEventGetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool *);

 97: PETSC_EXTERN PetscErrorCode PetscLogStateGetEventFromName(PetscLogState, const char[], PetscLogEvent *);
 98: PETSC_EXTERN PetscErrorCode PetscLogStateGetStageFromName(PetscLogState, const char[], PetscLogStage *);
 99: PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromName(PetscLogState, const char[], PetscLogClass *);
100: PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState, PetscClassId, PetscLogClass *);
101: PETSC_EXTERN PetscErrorCode PetscLogStateGetNumEvents(PetscLogState, PetscInt *);
102: PETSC_EXTERN PetscErrorCode PetscLogStateGetNumStages(PetscLogState, PetscInt *);
103: PETSC_EXTERN PetscErrorCode PetscLogStateGetNumClasses(PetscLogState, PetscInt *);
104: PETSC_EXTERN PetscErrorCode PetscLogStateEventGetInfo(PetscLogState, PetscLogEvent, PetscLogEventInfo *);
105: PETSC_EXTERN PetscErrorCode PetscLogStateStageGetInfo(PetscLogState, PetscLogStage, PetscLogStageInfo *);
106: PETSC_EXTERN PetscErrorCode PetscLogStateClassGetInfo(PetscLogState, PetscLogClass, PetscLogClassInfo *);

108: PETSC_EXTERN PetscClassId PETSCLOGHANDLER_CLASSID;

110: PETSC_EXTERN PetscFunctionList PetscLogHandlerList;

112: PETSC_EXTERN PetscErrorCode PetscLogHandlerRegister(const char[], PetscErrorCode (*)(PetscLogHandler));
113: PETSC_EXTERN PetscErrorCode PetscLogHandlerCreate(MPI_Comm, PetscLogHandler *);
114: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetType(PetscLogHandler, PetscLogHandlerType);
115: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetType(PetscLogHandler, PetscLogHandlerType *);
116: PETSC_EXTERN PetscErrorCode PetscLogHandlerDestroy(PetscLogHandler *);
117: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetState(PetscLogHandler, PetscLogState);
118: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetState(PetscLogHandler, PetscLogState *);
119: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventBegin(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
120: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventEnd(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
121: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventSync(PetscLogHandler, PetscLogEvent, MPI_Comm);
122: PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectCreate(PetscLogHandler, PetscObject);
123: PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectDestroy(PetscLogHandler, PetscObject);
124: PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePush(PetscLogHandler, PetscLogStage);
125: PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePop(PetscLogHandler, PetscLogStage);
126: PETSC_EXTERN PetscErrorCode PetscLogHandlerView(PetscLogHandler, PetscViewer);

128: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetEventPerfInfo(PetscLogHandler, PetscLogStage, PetscLogEvent, PetscEventPerfInfo **);
129: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetStagePerfInfo(PetscLogHandler, PetscLogStage, PetscEventPerfInfo **);
130: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetLogActions(PetscLogHandler, PetscBool);
131: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetLogObjects(PetscLogHandler, PetscBool);
132: PETSC_EXTERN PetscErrorCode PetscLogHandlerLogObjectState(PetscLogHandler, PetscObject, const char[], ...);
133: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetNumObjects(PetscLogHandler, PetscInt *);
134: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventDeactivatePush(PetscLogHandler, PetscLogStage, PetscLogEvent);
135: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventDeactivatePop(PetscLogHandler, PetscLogStage, PetscLogEvent);
136: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventsPause(PetscLogHandler);
137: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventsResume(PetscLogHandler);
138: PETSC_EXTERN PetscErrorCode PetscLogHandlerDump(PetscLogHandler, const char[]);
139: PETSC_EXTERN PetscErrorCode PetscLogHandlerStageSetVisible(PetscLogHandler, PetscLogStage, PetscBool);
140: PETSC_EXTERN PetscErrorCode PetscLogHandlerStageGetVisible(PetscLogHandler, PetscLogStage, PetscBool *);

142: PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateTrace(MPI_Comm, FILE *, PetscLogHandler *);
143: PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateLegacy(MPI_Comm, PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscObject), PetscErrorCode (*)(PetscObject), PetscLogHandler *);

145: /*MC
146:   PetscLogStateStageEventIsActive - Returns whether a specific `PetscLogEvent` is active in a specific stage of a `PetscLogState`

148:   Synopsis:
149: #include <petsclog.h>
150:   PetscBool PetscLogStateStageEventIsActive(PetscLogState state, PetscLogStage stage, PetscLogEvent event)

152:   Not Collective; No Fortran Support

154:   Input Parameters:
155: + state - the `PetscLogState`
156: . stage - the stage index
157: - event - the event index

159:   Level: developer

161:   Note:
162:   Returns `PETSC_FALSE` when `stage` is negative, which indicates that there have been more stage pops than pushes.

164: .seealso: `PetscLogState`, `PetscLogStage`, `PetscLogEvent`, `PetscLogStateEventCurrentlyActive()`, `PetscLogStateStageGetActive()`
165: M*/
166: /* All events are inactive if an invalid stage is set, like if there have been more stage pops than stage pushes */
167: #define PetscLogStateStageEventIsActive(state, stage, event) ((stage >= 0) && PetscBTLookup((state)->active, (stage)) && PetscBTLookup((state)->active, (stage) + (event + 1) * (state)->bt_num_stages))

169: /*MC
170:   PetscLogStateEventCurrentlyActive - Returns whether a specific `PetscLogEvent` is active in the currently active stage of a `PetscLogState`

172:   Synopsis:
173: #include <petsclog.h>
174:   PetscBool PetscLogStateEventCurrentlyActive(PetscLogState state, PetscLogEvent event)

176:   Not Collective; No Fortran Support

178:   Input Parameters:
179: + state - the `PetscLogState` (may be `NULL`, in which case `PETSC_FALSE` is returned)
180: - event - the event index

182:   Level: developer

184: .seealso: `PetscLogState`, `PetscLogEvent`, `PetscLogStateStageEventIsActive()`
185: M*/
186: #define PetscLogStateEventCurrentlyActive(state, event) ((state) && PetscLogStateStageEventIsActive(state, (state)->current_stage, event))

188: /* PetscLogHandler with critical methods exposed for speed */
189: typedef struct _n_PetscLogHandlerHot {
190:   PetscLogHandler handler;
191:   PetscErrorCode (*eventBegin)(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
192:   PetscErrorCode (*eventEnd)(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
193:   PetscErrorCode (*eventSync)(PetscLogHandler, PetscLogEvent, MPI_Comm);
194:   PetscErrorCode (*objectCreate)(PetscLogHandler, PetscObject);
195:   PetscErrorCode (*objectDestroy)(PetscLogHandler, PetscObject);
196: } PetscLogHandlerHot;

198: /* Handle multithreading */
199: #if PetscDefined(HAVE_THREADSAFETY)
200:   #if defined(__cplusplus)
201:     #define PETSC_TLS thread_local
202:   #else
203:     #define PETSC_TLS _Thread_local
204:   #endif
205:   #define PETSC_EXTERN_TLS extern PETSC_TLS PETSC_VISIBILITY_PUBLIC
206: #else
207:   #define PETSC_EXTERN_TLS PETSC_EXTERN
208:   #define PETSC_TLS
209: #endif
210: #if PetscDefined(HAVE_THREADSAFETY) && PetscDefined(USE_LOG)
211: PETSC_EXTERN PetscErrorCode PetscAddLogDouble(PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
212: PETSC_EXTERN PetscErrorCode PetscAddLogDoubleCnt(PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
213: #else
214:   #define PetscAddLogDouble(a, b, c)          ((PetscErrorCode)((*(a) += (c), PETSC_SUCCESS) || ((*(b) += (c)), PETSC_SUCCESS)))
215:   #define PetscAddLogDoubleCnt(a, b, c, d, e) ((PetscErrorCode)(PetscAddLogDouble(a, c, 1) || PetscAddLogDouble(b, d, e)))
216: #endif

218: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectParent()", ) static inline PetscErrorCode PetscLogObjectParent(PetscObject o, PetscObject p)
219: {
220:   (void)o;
221:   (void)p;
222:   return PETSC_SUCCESS;
223: }
224: /*MC
225:   PetscLogObjectParents - Record a parent/child relationship between a `PetscObject` and an array of `PetscObject`s for performance logging

227:   Synopsis:
228: #include <petsclog.h>
229:   PetscErrorCode PetscLogObjectParents(PetscObject p, int n, PetscObject d[])

231:   Not Collective; No Fortran Support

233:   Input Parameters:
234: + p - the parent `PetscObject`
235: . n - the number of child objects
236: - d - array of child `PetscObject`s

238:   Level: developer

240:   Note:
241:   This routine is a no-op unless PETSc is configured with logging enabled.

243: .seealso: `PetscLogObjectParent()`, `PetscLogObjectCreate()`, `PetscLogObjectDestroy()`
244: M*/
245: #define PetscLogObjectParents(p, n, d) PetscMacroReturnStandard(for (int _i = 0; _i < (n); ++_i) PetscCall(PetscLogObjectParent((PetscObject)(p), (PetscObject)(d)[_i]));)

247: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectMemory()", ) static inline PetscErrorCode PetscLogObjectMemory(PetscObject o, PetscLogDouble m)
248: {
249:   (void)o;
250:   (void)m;
251:   return PETSC_SUCCESS;
252: }

254: /* Global flop counter */
255: PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
256: PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
257: PETSC_EXTERN PetscLogDouble petsc_isend_ct;
258: PETSC_EXTERN PetscLogDouble petsc_recv_ct;
259: PETSC_EXTERN PetscLogDouble petsc_send_ct;
260: PETSC_EXTERN PetscLogDouble petsc_irecv_len;
261: PETSC_EXTERN PetscLogDouble petsc_isend_len;
262: PETSC_EXTERN PetscLogDouble petsc_recv_len;
263: PETSC_EXTERN PetscLogDouble petsc_send_len;
264: PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
265: PETSC_EXTERN PetscLogDouble petsc_gather_ct;
266: PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
267: PETSC_EXTERN PetscLogDouble petsc_wait_ct;
268: PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
269: PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
270: PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;

272: /* Thread local storage */
273: PETSC_EXTERN_TLS PetscLogDouble petsc_TotalFlops_th;
274: PETSC_EXTERN_TLS PetscLogDouble petsc_irecv_ct_th;
275: PETSC_EXTERN_TLS PetscLogDouble petsc_isend_ct_th;
276: PETSC_EXTERN_TLS PetscLogDouble petsc_recv_ct_th;
277: PETSC_EXTERN_TLS PetscLogDouble petsc_send_ct_th;
278: PETSC_EXTERN_TLS PetscLogDouble petsc_irecv_len_th;
279: PETSC_EXTERN_TLS PetscLogDouble petsc_isend_len_th;
280: PETSC_EXTERN_TLS PetscLogDouble petsc_recv_len_th;
281: PETSC_EXTERN_TLS PetscLogDouble petsc_send_len_th;
282: PETSC_EXTERN_TLS PetscLogDouble petsc_allreduce_ct_th;
283: PETSC_EXTERN_TLS PetscLogDouble petsc_gather_ct_th;
284: PETSC_EXTERN_TLS PetscLogDouble petsc_scatter_ct_th;
285: PETSC_EXTERN_TLS PetscLogDouble petsc_wait_ct_th;
286: PETSC_EXTERN_TLS PetscLogDouble petsc_wait_any_ct_th;
287: PETSC_EXTERN_TLS PetscLogDouble petsc_wait_all_ct_th;
288: PETSC_EXTERN_TLS PetscLogDouble petsc_sum_of_waits_ct_th;

290: /* Global GPU counters */
291: PETSC_EXTERN PetscLogDouble petsc_ctog_ct;
292: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct;
293: PETSC_EXTERN PetscLogDouble petsc_ctog_sz;
294: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz;
295: PETSC_EXTERN PetscLogDouble petsc_ctog_ct_scalar;
296: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct_scalar;
297: PETSC_EXTERN PetscLogDouble petsc_ctog_sz_scalar;
298: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz_scalar;
299: PETSC_EXTERN PetscLogDouble petsc_gflops;
300: PETSC_EXTERN PetscLogDouble petsc_gtime;
301: PETSC_EXTERN PetscLogDouble petsc_genergy;
302: PETSC_EXTERN PetscLogDouble petsc_genergy_meter;

304: /* Thread local storage */
305: PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_ct_th;
306: PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_ct_th;
307: PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_sz_th;
308: PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_sz_th;
309: PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_ct_scalar_th;
310: PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_ct_scalar_th;
311: PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_sz_scalar_th;
312: PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_sz_scalar_th;
313: PETSC_EXTERN_TLS PetscLogDouble petsc_gflops_th;
314: PETSC_EXTERN_TLS PetscLogDouble petsc_gtime_th;

316: PETSC_EXTERN PetscBool PetscLogMemory;
317: PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */

319: PETSC_EXTERN PetscLogState petsc_log_state;

321: #define PETSC_LOG_HANDLER_MAX 4
322: PETSC_EXTERN PetscLogHandlerHot PetscLogHandlers[PETSC_LOG_HANDLER_MAX];

324: #if PetscDefined(USE_LOG) /* --- Logging is turned on --------------------------------*/
325: PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);

327: PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);

329: /* Initialization functions */
330: PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
331: PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
332: PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
333: PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
334: PETSC_EXTERN PetscErrorCode PetscLogPerfstubsBegin(void);
335: PETSC_EXTERN PetscErrorCode PetscLogLegacyCallbacksBegin(PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscObject), PetscErrorCode (*)(PetscObject));
336: PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
337: PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
338: PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble, PetscLogDouble *);

340: /* Output functions */
341: PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
342: PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
343: PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);
344: PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);

346: PETSC_EXTERN PetscErrorCode PetscLogGetState(PetscLogState *);
347: PETSC_EXTERN PetscErrorCode PetscLogGetDefaultHandler(PetscLogHandler *);
348: PETSC_EXTERN PetscErrorCode PetscLogHandlerStart(PetscLogHandler);
349: PETSC_EXTERN PetscErrorCode PetscLogHandlerStop(PetscLogHandler);

351: /* Status checking functions */
352: PETSC_EXTERN PetscErrorCode PetscLogIsActive(PetscBool *);

354: /* Stage functions */
355: PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[], PetscLogStage *);
356: PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
357: PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
358: PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool);
359: PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *);
360: PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool);
361: PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *);
362: PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[], PetscLogStage *);
363: PETSC_EXTERN PetscErrorCode PetscLogStageGetName(PetscLogEvent, const char *[]);
364: PETSC_EXTERN PetscErrorCode PetscLogStageGetPerfInfo(PetscLogStage, PetscEventPerfInfo *);

366: /* Event functions */
367: PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId, PetscLogEvent *);
368: PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent, PetscBool);
369: PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
370: PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
371: PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
372: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
373: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent);
374: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent);
375: PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool);
376: PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
377: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
378: PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[], PetscLogEvent *);
379: PETSC_EXTERN PetscErrorCode PetscLogEventGetName(PetscLogEvent, const char *[]);
380: PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(PetscLogStage, PetscLogEvent, PetscEventPerfInfo *);
381: PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
382: PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);
383: PETSC_EXTERN PetscErrorCode PetscLogEventsPause(void);
384: PETSC_EXTERN PetscErrorCode PetscLogEventsResume(void);

386: /* Class functions */
387: PETSC_EXTERN PetscErrorCode PetscLogClassGetClassId(const char[], PetscClassId *);
388: PETSC_EXTERN PetscErrorCode PetscLogClassIdGetName(PetscClassId, const char *[]);

390: /*@C
391:   PetscLogEventSync - Synchronize an `MPI_Comm` so that the wall-clock time spent waiting at the implicit barrier is not attributed to a subsequent event

393:   Logically Collective on `comm`; No Fortran Support

395:   Input Parameters:
396: + e    - the `PetscLogEvent` to associate with the synchronization
397: - comm - the `MPI_Comm` whose ranks are synchronized

399:   Level: developer

401:   Notes:
402:   Forwards the call to every active `PetscLogHandler` that implements an `eventSync` method.

404:   Has no effect when logging is not active or when the event is not active in the current stage.

406: .seealso: `PetscLogEvent`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogHandler`
407: @*/
408: static inline PetscErrorCode PetscLogEventSync(PetscLogEvent e, MPI_Comm comm)
409: {
410:   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
411:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
412:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
413:       if (h->eventSync) {
414:         PetscErrorCode err = (*h->eventSync)(h->handler, e, comm);
415:         if (err != PETSC_SUCCESS) return err;
416:       }
417:     }
418:   }
419:   return PETSC_SUCCESS;
420: }

422: static inline PetscErrorCode PetscLogEventBegin_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
423: {
424:   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
425:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
426:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
427:       if (h->eventBegin) {
428:         PetscErrorCode err = (*h->eventBegin)(h->handler, e, o1, o2, o3, o4);
429:         if (err != PETSC_SUCCESS) return err;
430:       }
431:     }
432:   }
433:   return PETSC_SUCCESS;
434: }
435:   /*MC
436:     PetscLogEventBegin - Log the start of an instance of a `PetscLogEvent`

438:     Synopsis:
439: #include <petsclog.h>
440:     PetscErrorCode PetscLogEventBegin(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)

442:     Not Collective; No Fortran Support

444:     Input Parameters:
445:   + e  - the `PetscLogEvent`
446:   . o1 - first object involved in the event (may be `NULL`)
447:   . o2 - second object involved in the event (may be `NULL`)
448:   . o3 - third object involved in the event (may be `NULL`)
449:   - o4 - fourth object involved in the event (may be `NULL`)

451:     Level: intermediate

453:     Note:
454:     Forwards the call to every active `PetscLogHandler` that implements an `eventBegin` method. Use
455:     `PetscLogEventEnd()` to log the end of the same event.

457: .seealso: `PetscLogEvent`, `PetscLogEventRegister()`, `PetscLogEventEnd()`, `PetscLogEventSync()`
458: M*/
459:   #define PetscLogEventBegin(e, o1, o2, o3, o4) PetscLogEventBegin_Internal(e, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))

461: static inline PetscErrorCode PetscLogEventEnd_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
462: {
463:   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
464:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
465:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
466:       if (h->eventEnd) {
467:         PetscErrorCode err = (*h->eventEnd)(h->handler, e, o1, o2, o3, o4);
468:         if (err != PETSC_SUCCESS) return err;
469:       }
470:     }
471:   }
472:   return PETSC_SUCCESS;
473: }
474:   /*MC
475:     PetscLogEventEnd - Log the end of an instance of a `PetscLogEvent`

477:     Synopsis:
478: #include <petsclog.h>
479:     PetscErrorCode PetscLogEventEnd(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)

481:     Not Collective; No Fortran Support

483:     Input Parameters:
484:   + e  - the `PetscLogEvent`
485:   . o1 - first object involved in the event (may be `NULL`)
486:   . o2 - second object involved in the event (may be `NULL`)
487:   . o3 - third object involved in the event (may be `NULL`)
488:   - o4 - fourth object involved in the event (may be `NULL`)

490:     Level: intermediate

492:     Note:
493:     Must be paired with a prior `PetscLogEventBegin()` for the same event.

495: .seealso: `PetscLogEvent`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventSync()`
496: M*/
497:   #define PetscLogEventEnd(e, o1, o2, o3, o4) PetscLogEventEnd_Internal(e, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))

499: /* Object functions */
500: /*@C
501:   PetscLogObjectCreate - Notify the active `PetscLogHandler`s that a new `PetscObject` has been created

503:   Not Collective; No Fortran Support

505:   Input Parameter:
506: . o - the newly created `PetscObject`

508:   Level: developer

510:   Note:
511:   Called internally by PETSc object constructors; users normally do not need to call this directly.

513: .seealso: `PetscLogObjectDestroy()`, `PetscLogHandler`, `PetscObject`
514: @*/
515: static inline PetscErrorCode PetscLogObjectCreate(PetscObject o)
516: {
517:   if (petsc_log_state) {
518:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
519:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
520:       if (h->objectCreate) {
521:         PetscErrorCode err = (*h->objectCreate)(h->handler, o);
522:         if (err != PETSC_SUCCESS) return err;
523:       }
524:     }
525:   }
526:   return PETSC_SUCCESS;
527: }

529: /*@C
530:   PetscLogObjectDestroy - Notify the active `PetscLogHandler`s that a `PetscObject` is being destroyed

532:   Not Collective; No Fortran Support

534:   Input Parameter:
535: . o - the `PetscObject` that is being destroyed

537:   Level: developer

539:   Note:
540:   Called internally by PETSc object destructors; users normally do not need to call this directly.

542: .seealso: `PetscLogObjectCreate()`, `PetscLogHandler`, `PetscObject`
543: @*/
544: static inline PetscErrorCode PetscLogObjectDestroy(PetscObject o)
545: {
546:   if (petsc_log_state) {
547:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
548:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
549:       if (h->objectDestroy) {
550:         PetscErrorCode err = (*h->objectDestroy)(h->handler, o);
551:         if (err != PETSC_SUCCESS) return err;
552:       }
553:     }
554:   }
555:   return PETSC_SUCCESS;
556: }

558: /*
559:    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.

561:    For the complex numbers version, note that
562:        1 complex addition = 2 flops
563:        1 complex multiplication = 6 flops,
564:    where we define 1 flop as that for a double precision scalar.  We roughly approximate
565:    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
566:    to the assumption that we're counting mostly additions and multiplications -- and
567:    roughly the same number of each.  More accurate counting could be done by distinguishing
568:    among the various arithmetic operations.
569:  */

571:   #if PetscDefined(USE_COMPLEX)
572:     #define PETSC_FLOPS_PER_OP 4.0
573:   #else
574:     #define PETSC_FLOPS_PER_OP 1.0
575:   #endif

577: /*@
578:    PetscLogFlops - Log how many flops are performed in a calculation

580:    Input Parameter:
581: .   flops - the number of flops

583:    Level: intermediate

585:    Note:
586:    To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double,
587:    not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n)

589: .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`
590: @*/
591: static inline PetscErrorCode PetscLogFlops(PetscLogDouble n)
592: {
593:   PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
594:   return PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n);
595: }

597:   /*
598:      These are used internally in the PETSc routines to keep a count of MPI messages and
599:    their sizes.

601:      This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file
602:    uses macros to defined the MPI operations.

604:      It does not work correctly from HP-UX because it processes the
605:    macros in a way that sometimes it double counts, hence
606:    PETSC_HAVE_BROKEN_RECURSIVE_MACRO

608:      It does not work with Windows because winmpich lacks MPI_Type_size()
609: */
610:   #if !defined(MPIUNI_H) && !PetscDefined(HAVE_BROKEN_RECURSIVE_MACRO)
611: /*
612:    Logging of MPI activities
613: */
614: static inline PetscErrorCode PetscMPITypeSize(PetscCount count, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
615: {
616:   PetscMPIInt typesize;

618:   if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
619:   PetscCallMPI(MPI_Type_size(type, &typesize));
620:   return PetscAddLogDouble(length, length_th, (PetscLogDouble)(count * typesize));
621: }

623: static inline PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, const PetscMPIInt *counts, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
624: {
625:   PetscMPIInt    typesize, size, p;
626:   PetscLogDouble l;

628:   if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
629:   PetscCallMPI(MPI_Comm_size(comm, &size));
630:   PetscCallMPI(MPI_Type_size(type, &typesize));
631:   for (p = 0, l = 0.0; p < size; ++p) l += (PetscLogDouble)(counts[p] * typesize);
632:   return PetscAddLogDouble(length, length_th, l);
633: }

635: /*
636:     Returns 1 if the communicator is parallel else zero
637: */
638: static inline int PetscMPIParallelComm(MPI_Comm comm)
639: {
640:   PetscMPIInt size;
641:   MPI_Comm_size(comm, &size);
642:   return size > 1;
643: }

645:     #define MPI_Irecv(buf, count, datatype, source, tag, comm, request) \
646:       (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || MPI_Irecv((buf), (count), (datatype), (source), (tag), (comm), (request)))

648:     #define MPI_Irecv_c(buf, count, datatype, source, tag, comm, request) \
649:       (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || MPI_Irecv_c((buf), (count), (datatype), (source), (tag), (comm), (request)))

651:     #define MPI_Isend(buf, count, datatype, dest, tag, comm, request) \
652:       (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || MPI_Isend((buf), (count), (datatype), (dest), (tag), (comm), (request)))

654:     #define MPI_Isend_c(buf, count, datatype, dest, tag, comm, request) \
655:       (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || MPI_Isend_c((buf), (count), (datatype), (dest), (tag), (comm), (request)))

657:     #define MPI_Startall_irecv(count, datatype, number, requests) \
658:       (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || ((number) && MPI_Startall((number), (requests))))

660:     #define MPI_Startall_isend(count, datatype, number, requests) \
661:       (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || ((number) && MPI_Startall((number), (requests))))

663:     #define MPI_Start_isend(count, datatype, requests) (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_isend_len), (&petsc_isend_len_th)) || MPI_Start(requests))

665:     #define MPI_Recv(buf, count, datatype, source, tag, comm, status) \
666:       (PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPI_Recv((buf), (count), (datatype), (source), (tag), (comm), (status)))

668:     #define MPI_Recv_c(buf, count, datatype, source, tag, comm, status) \
669:       (PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_recv_len), &(petsc_recv_len_th)) || MPI_Recv_c((buf), (count), (datatype), (source), (tag), (comm), (status)))

671:     #define MPI_Send(buf, count, datatype, dest, tag, comm) \
672:       (PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Send((buf), (count), (datatype), (dest), (tag), (comm)))

674:     #define MPI_Send_c(buf, count, datatype, dest, tag, comm) \
675:       (PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Send_c((buf), (count), (datatype), (dest), (tag), (comm)))

677:     #define MPI_Wait(request, status) (PetscAddLogDouble(&petsc_wait_ct, &petsc_wait_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, 1) || MPI_Wait((request), (status)))

679:     #define MPI_Waitany(a, b, c, d) (PetscAddLogDouble(&petsc_wait_any_ct, &petsc_wait_any_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, 1) || MPI_Waitany((a), (b), (c), (d)))

681:     #define MPI_Waitall(count, array_of_requests, array_of_statuses) \
682:       (PetscAddLogDouble(&petsc_wait_all_ct, &petsc_wait_all_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, count) || MPI_Waitall((count), (array_of_requests), (array_of_statuses)))

684:     #define MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm) (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Allreduce((sendbuf), (recvbuf), (count), (datatype), (op), (comm)))

686:     #define MPI_Bcast(buffer, count, datatype, root, comm) (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Bcast((buffer), (count), (datatype), (root), (comm)))

688:     #define MPI_Reduce_scatter_block(sendbuf, recvbuf, recvcount, datatype, op, comm) \
689:       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Reduce_scatter_block((sendbuf), (recvbuf), (recvcount), (datatype), (op), (comm)))

691:     #define MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
692:       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Alltoall((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm)))

694:     #define MPI_Alltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm) \
695:       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSizeComm((comm), (sendcnts), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Alltoallv((sendbuf), (sendcnts), (sdispls), (sendtype), (recvbuf), (recvcnts), (rdispls), (recvtype), (comm)))

697:     #define MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
698:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm)))

700:     #define MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm) \
701:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm)))

703:     #define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
704:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Gather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm)))

706:     #define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm) \
707:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Gatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (root), (comm)))

709:     #define MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
710:       (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), &(petsc_recv_len_th)) || MPI_Scatter((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm)))

712:     #define MPI_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
713:       (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), &(petsc_recv_len_th)) || MPI_Scatterv((sendbuf), (sendcount), (displs), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm)))

715:     #define MPI_Ialltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
716:       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Ialltoall((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm), (request)))

718:     #define MPI_Ialltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm, request) \
719:       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || PetscMPITypeSizeComm((comm), (sendcnts), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Ialltoallv((sendbuf), (sendcnts), (sdispls), (sendtype), (recvbuf), (recvcnts), (rdispls), (recvtype), (comm), (request)))

721:     #define MPI_Iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
722:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm), (request)))

724:     #define MPI_Iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm, request) \
725:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm), (request)))

727:     #define MPI_Igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
728:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Igather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm), (request)))

730:     #define MPI_Igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm, request) \
731:       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, 1) || PetscMPITypeSize((sendcount), (sendtype), (&petsc_send_len), (&petsc_send_len_th)) || MPI_Igatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (root), (comm), (request)))

733:     #define MPI_Iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
734:       (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPI_Iscatter((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm), (request)))

736:     #define MPI_Iscatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
737:       (PetscAddLogDouble(&petsc_scatter_ct, &petsc_scatter_ct_th, 1) || PetscMPITypeSize((recvcount), (recvtype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPI_Iscatterv((sendbuf), (sendcount), (displs), (sendtype), (recvbuf), (recvcount), (recvtype), (root), (comm), (request)))

739:     #define MPIX_Send_enqueue(buf, count, datatype, dest, tag, comm) \
740:       (PetscAddLogDouble(&petsc_send_ct, &petsc_send_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_send_len), (&petsc_send_len_th)) || MPIX_Send_enqueue((buf), (count), (datatype), (dest), (tag), (comm)))

742:     #define MPIX_Recv_enqueue(buf, count, datatype, source, tag, comm, status) \
743:       (PetscAddLogDouble(&petsc_recv_ct, &petsc_recv_ct_th, 1) || PetscMPITypeSize((count), (datatype), (&petsc_recv_len), (&petsc_recv_len_th)) || MPIX_Recv_enqueue((buf), (count), (datatype), (source), (tag), (comm), (status)))

745:     #define MPIX_Isend_enqueue(buf, count, datatype, dest, tag, comm, request) \
746:       (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || MPIX_Isend_enqueue((buf), (count), (datatype), (dest), (tag), (comm), (request)))

748:     #define MPIX_Irecv_enqueue(buf, count, datatype, source, tag, comm, request) \
749:       (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, 1) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || MPIX_Irecv_enqueue((buf), (count), (datatype), (source), (tag), (comm), (request)))

751:     #define MPIX_Allreduce_enqueue(sendbuf, recvbuf, count, datatype, op, comm) \
752:       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPIX_Allreduce_enqueue((sendbuf), (recvbuf), (count), (datatype), (op), (comm)))

754:     #define MPIX_Wait_enqueue(request, status) (PetscAddLogDouble(&petsc_wait_ct, &petsc_wait_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, 1) || MPIX_Wait_enqueue((request), (status)))

756:     #define MPIX_Waitall_enqueue(count, array_of_requests, array_of_statuses) \
757:       (PetscAddLogDouble(&petsc_wait_all_ct, &petsc_wait_all_ct_th, 1) || PetscAddLogDouble(&petsc_sum_of_waits_ct, &petsc_sum_of_waits_ct_th, count) || MPIX_Waitall_enqueue((count), (array_of_requests), (array_of_statuses)))
758:   #else

760:     #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests)))

762:     #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests)))

764:     #define MPI_Start_isend(count, datatype, requests) (MPI_Start(requests))

766:   #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */

768: #else /* ---Logging is turned off --------------------------------------------*/

770:   #define PetscLogGetState(a)          (*(a) = NULL, PETSC_SUCCESS)
771:   #define PetscLogGetDefaultHandler(a) (*(a) = NULL, PETSC_SUCCESS)
772:   #define PetscLogHandlerStart(a)      ((void)(a), PETSC_SUCCESS)
773:   #define PetscLogHandlerStop(a)       ((void)(a), PETSC_SUCCESS)

775:   #define PetscLogFlops(n) ((void)(n), PETSC_SUCCESS)
776:   #define PetscGetFlops(a) (*(a) = 0.0, PETSC_SUCCESS)

778:   #define PetscLogStageRegister(a, b)    ((void)(a), *(b) = -1, PETSC_SUCCESS)
779:   #define PetscLogStagePush(a)           ((void)(a), PETSC_SUCCESS)
780:   #define PetscLogStagePop()             PETSC_SUCCESS
781:   #define PetscLogStageSetActive(a, b)   ((void)(a), (void)(b), PETSC_SUCCESS)
782:   #define PetscLogStageGetActive(a, b)   ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
783:   #define PetscLogStageGetVisible(a, b)  ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
784:   #define PetscLogStageSetVisible(a, b)  ((void)(a), (void)(b), PETSC_SUCCESS)
785:   #define PetscLogStageGetId(a, b)       ((void)(a), *(b) = -1, PETSC_SUCCESS)
786:   #define PetscLogStageGetName(a, b)     ((void)(a), *(b) = NULL, PETSC_SUCCESS)
787:   #define PetscLogStageGetPerfInfo(a, b) ((void)(a), *(b) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)

789:   #define PetscLogEventRegister(a, b, c)    ((void)(a), (void)(b), *(c) = -1, PETSC_SUCCESS)
790:   #define PetscLogEventSetCollective(a, b)  ((void)(a), (void)(b), PETSC_SUCCESS)
791:   #define PetscLogEventIncludeClass(a)      ((void)(a), PETSC_SUCCESS)
792:   #define PetscLogEventExcludeClass(a)      ((void)(a), PETSC_SUCCESS)
793:   #define PetscLogEventActivate(a)          ((void)(a), PETSC_SUCCESS)
794:   #define PetscLogEventDeactivate(a)        ((void)(a), PETSC_SUCCESS)
795:   #define PetscLogEventDeactivatePush(a)    ((void)(a), PETSC_SUCCESS)
796:   #define PetscLogEventDeactivatePop(a)     ((void)(a), PETSC_SUCCESS)
797:   #define PetscLogEventActivateClass(a)     ((void)(a), PETSC_SUCCESS)
798:   #define PetscLogEventDeactivateClass(a)   ((void)(a), PETSC_SUCCESS)
799:   #define PetscLogEventSetActiveAll(a, b)   ((void)(a), PETSC_SUCCESS)
800:   #define PetscLogEventGetId(a, b)          ((void)(a), *(b) = -1, PETSC_SUCCESS)
801:   #define PetscLogEventGetName(a, b)        ((void)(a), *(b) = NULL, PETSC_SUCCESS)
802:   #define PetscLogEventGetPerfInfo(a, b, c) ((void)(a), (void)(b), *(c) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)

804:   #define PetscLogEventSetDof(a, b, c)   ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
805:   #define PetscLogEventSetError(a, b, c) ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
806:   #define PetscLogEventsPause()          PETSC_SUCCESS
807:   #define PetscLogEventsResume()         PETSC_SUCCESS

809:   #define PetscLogClassGetClassId(a, b) (*(b) = -1, PETSC_SUCCESS)
810:   #define PetscLogClassIdGetName(a, b)  (*(b) = NULL, PETSC_SUCCESS)

812:   #define PetscLogObjectCreate(h)        ((void)(h), PETSC_SUCCESS)
813:   #define PetscLogObjectDestroy(h)       ((void)(h), PETSC_SUCCESS)
814:   #define PetscLogObjectState(h, c, ...) ((void)(h), (void)(c), PETSC_SUCCESS)

816:   #define PetscLogDefaultBegin()                   PETSC_SUCCESS
817:   #define PetscLogNestedBegin()                    PETSC_SUCCESS
818:   #define PetscLogTraceBegin(file)                 ((void)(file), PETSC_SUCCESS)
819:   #define PetscLogMPEBegin()                       PETSC_SUCCESS
820:   #define PetscLogPerfstubsBegin()                 PETSC_SUCCESS
821:   #define PetscLogLegacyCallbacksBegin(a, b, c, d) ((void)(a), (void)(b), (void)(c), (void)(d), PETSC_SUCCESS)
822:   #define PetscLogActions(a)                       ((void)(a), PETSC_SUCCESS)
823:   #define PetscLogObjects(a)                       ((void)(a), PETSC_SUCCESS)
824:   #define PetscLogSetThreshold(a, b)               ((void)(a), (void)(b), PETSC_SUCCESS)

826:   #define PetscLogIsActive(flag) (*(flag) = PETSC_FALSE, PETSC_SUCCESS)

828:   #define PetscLogView(viewer)      ((void)(viewer), PETSC_SUCCESS)
829:   #define PetscLogViewFromOptions() PETSC_SUCCESS
830:   #define PetscLogDump(c)           ((void)(c), PETSC_SUCCESS)
831:   #define PetscLogMPEDump(c)        ((void)(c), PETSC_SUCCESS)

833:   #define PetscLogEventSync(e, comm)                            ((void)(e), (void)(comm), PETSC_SUCCESS)
834:   #define PetscLogEventBegin(e, o1, o2, o3, o4)                 ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)
835:   #define PetscLogEventEnd(e, o1, o2, o3, o4)                   ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)

837:   /* If PETSC_USE_LOG is NOT defined, these still need to be! */
838:   #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
839:   #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
840:   #define MPI_Start_isend(count, datatype, requests)            MPI_Start(requests)

842: #endif /* PETSC_USE_LOG */

844: /*MC
845:   PetscPreLoadBegin - Begin a block of code that is timed twice so that startup costs (such as JIT or first-touch allocation) are not attributed to the measured run

847:   Synopsis:
848: #include <petsclog.h>
849:   PetscPreLoadBegin(PetscBool flag, const char name[])

851:   Not Collective; No Fortran Support

853:   Input Parameters:
854: + flag - whether preloading is desired (may be overridden by the command-line option `-preload`)
855: - name - name to use for the `PetscLogStage` created for the measured run

857:   Level: intermediate

859:   Note:
860:   Use this macro in the form
861: .vb
862:     PetscPreLoadBegin(PETSC_TRUE, "Compute");
863:     // ... code to be timed
864:     PetscPreLoadEnd();
865: .ve
866:   It expands to a loop that runs the enclosed code twice when preloading is enabled and once otherwise.
867:   Pair with `PetscPreLoadEnd()`. Use `PetscPreLoadStage()` to advance to a new named stage between phases.

869: .seealso: `PetscPreLoadEnd`, `PetscPreLoadStage`, `PetscLogStageRegister()`, `PetscLogStagePush()`
870: M*/
871: #define PetscPreLoadBegin(flag, name) \
872:   do { \
873:     PetscBool     PetscPreLoading = flag; \
874:     int           PetscPreLoadMax, PetscPreLoadIt; \
875:     PetscLogStage _stageNum; \
876:     PetscCall(PetscOptionsGetBool(NULL, NULL, "-preload", &PetscPreLoading, NULL)); \
877:     PetscPreLoadMax     = (int)(PetscPreLoading); \
878:     PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed; \
879:     PetscCall(PetscLogStageGetId(name, &_stageNum)); \
880:     for (PetscPreLoadIt = (_stageNum == -1) ? 0 : PetscPreLoadMax; PetscPreLoadIt <= PetscPreLoadMax; PetscPreLoadIt++) { \
881:       PetscPreLoadingOn = (PetscBool)(PetscPreLoadIt < PetscPreLoadMax); \
882:       PetscCall(PetscBarrier(NULL)); \
883:       if (_stageNum == -1) PetscCall(PetscLogStageRegister(name, &_stageNum)); \
884:       PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(PetscPreLoadIt == PetscPreLoadMax))); \
885:       PetscCall(PetscLogStagePush(_stageNum))

887: /*MC
888:   PetscPreLoadEnd - Close a preload block started with `PetscPreLoadBegin()`

890:   Synopsis:
891: #include <petsclog.h>
892:   PetscPreLoadEnd()

894:   Not Collective; No Fortran Support

896:   Level: intermediate

898: .seealso: `PetscPreLoadBegin`, `PetscPreLoadStage`
899: M*/
900: #define PetscPreLoadEnd() \
901:   PetscCall(PetscLogStagePop()); \
902:   } \
903:   } \
904:   while (0)

906: /*MC
907:   PetscPreLoadStage - Advance to a new named stage inside a `PetscPreLoadBegin()` / `PetscPreLoadEnd()` block

909:   Synopsis:
910: #include <petsclog.h>
911:   PetscPreLoadStage(const char name[])

913:   Not Collective; No Fortran Support

915:   Input Parameter:
916: . name - name for the new `PetscLogStage`

918:   Level: intermediate

920:   Note:
921:   Pops the previous stage, registers (or reuses) the new stage, and pushes it. Only valid between
922:   `PetscPreLoadBegin()` and `PetscPreLoadEnd()`.

924: .seealso: `PetscPreLoadBegin`, `PetscPreLoadEnd`, `PetscLogStagePush()`, `PetscLogStagePop()`
925: M*/
926: #define PetscPreLoadStage(name) \
927:   do { \
928:     PetscCall(PetscLogStagePop()); \
929:     PetscCall(PetscLogStageGetId(name, &_stageNum)); \
930:     if (_stageNum == -1) PetscCall(PetscLogStageRegister(name, &_stageNum)); \
931:     PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(!PetscPreLoadMax || PetscPreLoadIt))); \
932:     PetscCall(PetscLogStagePush(_stageNum)); \
933:   } while (0)

935: /* some vars for logging */
936: PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */
937: PETSC_EXTERN PetscBool PetscPreLoadingOn;   /* true if we are currently in a preloading calculation */

939: #if PetscDefined(USE_LOG) && PetscDefined(HAVE_DEVICE)

941: PETSC_EXTERN PetscErrorCode PetscLogGpuTime(void);
942: PETSC_EXTERN PetscErrorCode PetscLogGpuTimeBegin(void);
943: PETSC_EXTERN PetscErrorCode PetscLogGpuTimeEnd(void);
944: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergy(void);
945: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeter(void);
946: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeterBegin(void);
947: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeterEnd(void);

949: /*@
950:    PetscLogGpuFlops - Log how many flops are performed in a calculation on the device

952:    Input Parameter:
953: .  flops - the number of flops

955:    Level: intermediate

957:    Notes:
958:    To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double,
959:    not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n)

961:    The values are also added to the total flop count for the MPI rank that is set with `PetscLogFlops()`; hence the number of flops
962:    just on the CPU would be the value from set from `PetscLogFlops()` minus the value set from `PetscLogGpuFlops()`

964:    Developer Note:
965:    Currently Fortran stub generator cannot run through files in include

967: .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogFlops()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`
968: @*/
969: static inline PetscErrorCode PetscLogGpuFlops(PetscLogDouble n)
970: {
971:   PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
972:   PetscCall(PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n));
973:   PetscCall(PetscAddLogDouble(&petsc_gflops, &petsc_gflops_th, PETSC_FLOPS_PER_OP * n));
974:   return PETSC_SUCCESS;
975: }

977: /*@C
978:   PetscLogGpuTimeAdd - Add elapsed GPU computation time to PETSc's GPU time counter

980:   Not Collective; No Fortran Support

982:   Input Parameter:
983: . t - the elapsed time, in seconds, to add to the GPU time counter

985:   Level: developer

987:   Note:
988:   Used internally by GPU backends to report the time spent in a kernel or library call.

990: .seealso: `PetscLogGpuTime()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`, `PetscLogGpuFlops()`
991: @*/
992: static inline PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t)
993: {
994:   return PetscAddLogDouble(&petsc_gtime, &petsc_gtime_th, t);
995: }

997: /*@C
998:   PetscLogCpuToGpu - Log a CPU-to-GPU memory transfer for performance reporting

1000:   Not Collective; No Fortran Support

1002:   Input Parameter:
1003: . size - number of bytes transferred from CPU to GPU

1005:   Level: developer

1007:   Note:
1008:   Updates both the transfer-count and transfer-size counters used by `PetscLogView()`.

1010: .seealso: `PetscLogGpuToCpu()`, `PetscLogCpuToGpuScalar()`, `PetscLogGpuFlops()`
1011: @*/
1012: static inline PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size)
1013: {
1014:   return PetscAddLogDoubleCnt(&petsc_ctog_ct, &petsc_ctog_sz, &petsc_ctog_ct_th, &petsc_ctog_sz_th, size);
1015: }

1017: /*@C
1018:   PetscLogGpuToCpu - Log a GPU-to-CPU memory transfer for performance reporting

1020:   Not Collective; No Fortran Support

1022:   Input Parameter:
1023: . size - number of bytes transferred from GPU to CPU

1025:   Level: developer

1027: .seealso: `PetscLogCpuToGpu()`, `PetscLogGpuToCpuScalar()`, `PetscLogGpuFlops()`
1028: @*/
1029: static inline PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size)
1030: {
1031:   return PetscAddLogDoubleCnt(&petsc_gtoc_ct, &petsc_gtoc_sz, &petsc_gtoc_ct_th, &petsc_gtoc_sz_th, size);
1032: }

1034: /*@C
1035:   PetscLogCpuToGpuScalar - Log a CPU-to-GPU memory transfer of `PetscScalar` data for performance reporting

1037:   Not Collective; No Fortran Support

1039:   Input Parameter:
1040: . size - number of bytes of scalar data transferred from CPU to GPU

1042:   Level: developer

1044:   Note:
1045:   Tracks scalar-only transfers separately from generic byte counters tracked by `PetscLogCpuToGpu()`.

1047: .seealso: `PetscLogCpuToGpu()`, `PetscLogGpuToCpuScalar()`
1048: @*/
1049: static inline PetscErrorCode PetscLogCpuToGpuScalar(PetscLogDouble size)
1050: {
1051:   return PetscAddLogDoubleCnt(&petsc_ctog_ct_scalar, &petsc_ctog_sz_scalar, &petsc_ctog_ct_scalar_th, &petsc_ctog_sz_scalar_th, size);
1052: }

1054: /*@C
1055:   PetscLogGpuToCpuScalar - Log a GPU-to-CPU memory transfer of `PetscScalar` data for performance reporting

1057:   Not Collective; No Fortran Support

1059:   Input Parameter:
1060: . size - number of bytes of scalar data transferred from GPU to CPU

1062:   Level: developer

1064: .seealso: `PetscLogGpuToCpu()`, `PetscLogCpuToGpuScalar()`
1065: @*/
1066: static inline PetscErrorCode PetscLogGpuToCpuScalar(PetscLogDouble size)
1067: {
1068:   return PetscAddLogDoubleCnt(&petsc_gtoc_ct_scalar, &petsc_gtoc_sz_scalar, &petsc_gtoc_ct_scalar_th, &petsc_gtoc_sz_scalar_th, size);
1069: }
1070: #else

1072:   #define PetscLogCpuToGpu(a)       ((void)(a), PETSC_SUCCESS)
1073:   #define PetscLogGpuToCpu(a)       ((void)(a), PETSC_SUCCESS)
1074:   #define PetscLogCpuToGpuScalar(a) ((void)(a), PETSC_SUCCESS)
1075:   #define PetscLogGpuToCpuScalar(a) ((void)(a), PETSC_SUCCESS)
1076:   #define PetscLogGpuFlops(a)       ((void)(a), PETSC_SUCCESS)
1077:   #define PetscLogGpuTimeAdd(a)     ((void)(a), PETSC_SUCCESS)
1078:   #define PetscLogGpuTime()         PETSC_SUCCESS
1079:   #define PetscLogGpuTimeBegin()    PETSC_SUCCESS
1080:   #define PetscLogGpuTimeEnd()      PETSC_SUCCESS

1082:   #define PetscLogGpuEnergy()           PETSC_SUCCESS
1083:   #define PetscLogGpuEnergyMeter()      PETSC_SUCCESS
1084:   #define PetscLogGpuEnergyMeterBegin() PETSC_SUCCESS
1085:   #define PetscLogGpuEnergyMeterEnd()   PETSC_SUCCESS

1087: #endif /* PETSC_USE_LOG && PETSC_HAVE_DEVICE */

1089: /* remove TLS defines */
1090: #undef PETSC_EXTERN_TLS
1091: #undef PETSC_TLS

1093: #include <petsclogdeprecated.h>