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: #if PetscDefined(HAVE_THREADSAFETY) && PetscDefined(USE_LOG)
199: PETSC_EXTERN PetscErrorCode PetscAddLogDouble(PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
200: PETSC_EXTERN PetscErrorCode PetscAddLogDoubleCnt(PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
201: #else
202:   #define PetscAddLogDouble(a, b, c)          ((PetscErrorCode)((*(a) += (c), PETSC_SUCCESS) || ((*(b) += (c)), PETSC_SUCCESS)))
203:   #define PetscAddLogDoubleCnt(a, b, c, d, e) ((PetscErrorCode)(PetscAddLogDouble(a, c, 1) || PetscAddLogDouble(b, d, e)))
204: #endif

206: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectParent()", ) static inline PetscErrorCode PetscLogObjectParent(PetscObject o, PetscObject p)
207: {
208:   (void)o;
209:   (void)p;
210:   return PETSC_SUCCESS;
211: }
212: /*MC
213:   PetscLogObjectParents - Record a parent/child relationship between a `PetscObject` and an array of `PetscObject`s for performance logging

215:   Synopsis:
216: #include <petsclog.h>
217:   PetscErrorCode PetscLogObjectParents(PetscObject p, int n, PetscObject d[])

219:   Not Collective; No Fortran Support

221:   Input Parameters:
222: + p - the parent `PetscObject`
223: . n - the number of child objects
224: - d - array of child `PetscObject`s

226:   Level: developer

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

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

235: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectMemory()", ) static inline PetscErrorCode PetscLogObjectMemory(PetscObject o, PetscLogDouble m)
236: {
237:   (void)o;
238:   (void)m;
239:   return PETSC_SUCCESS;
240: }

242: /* Global flop counter */
243: PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
244: PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
245: PETSC_EXTERN PetscLogDouble petsc_isend_ct;
246: PETSC_EXTERN PetscLogDouble petsc_recv_ct;
247: PETSC_EXTERN PetscLogDouble petsc_send_ct;
248: PETSC_EXTERN PetscLogDouble petsc_irecv_len;
249: PETSC_EXTERN PetscLogDouble petsc_isend_len;
250: PETSC_EXTERN PetscLogDouble petsc_recv_len;
251: PETSC_EXTERN PetscLogDouble petsc_send_len;
252: PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
253: PETSC_EXTERN PetscLogDouble petsc_gather_ct;
254: PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
255: PETSC_EXTERN PetscLogDouble petsc_wait_ct;
256: PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
257: PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
258: PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;

260: /* Thread local storage */
261: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_TotalFlops_th;
262: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_irecv_ct_th;
263: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_isend_ct_th;
264: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_recv_ct_th;
265: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_send_ct_th;
266: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_irecv_len_th;
267: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_isend_len_th;
268: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_recv_len_th;
269: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_send_len_th;
270: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_allreduce_ct_th;
271: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gather_ct_th;
272: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_scatter_ct_th;
273: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_wait_ct_th;
274: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_wait_any_ct_th;
275: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_wait_all_ct_th;
276: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_sum_of_waits_ct_th;

278: /* Global GPU counters */
279: PETSC_EXTERN PetscLogDouble petsc_ctog_ct;
280: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct;
281: PETSC_EXTERN PetscLogDouble petsc_ctog_sz;
282: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz;
283: PETSC_EXTERN PetscLogDouble petsc_ctog_ct_scalar;
284: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct_scalar;
285: PETSC_EXTERN PetscLogDouble petsc_ctog_sz_scalar;
286: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz_scalar;
287: PETSC_EXTERN PetscLogDouble petsc_gflops;
288: PETSC_EXTERN PetscLogDouble petsc_gtime;
289: PETSC_EXTERN PetscLogDouble petsc_genergy;
290: PETSC_EXTERN PetscLogDouble petsc_genergy_meter;

292: /* Thread local storage */
293: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_ct_th;
294: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_ct_th;
295: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_sz_th;
296: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_sz_th;
297: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_ct_scalar_th;
298: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_ct_scalar_th;
299: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_sz_scalar_th;
300: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_sz_scalar_th;
301: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gflops_th;
302: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtime_th;

304: PETSC_EXTERN PetscBool PetscLogMemory;
305: PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */

307: PETSC_EXTERN PetscLogState petsc_log_state;

309: #define PETSC_LOG_HANDLER_MAX 4
310: PETSC_EXTERN PetscLogHandlerHot PetscLogHandlers[PETSC_LOG_HANDLER_MAX];

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

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

317: /* Initialization functions */
318: PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
319: PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
320: PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
321: PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
322: PETSC_EXTERN PetscErrorCode PetscLogPerfstubsBegin(void);
323: PETSC_EXTERN PetscErrorCode PetscLogLegacyCallbacksBegin(PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscObject), PetscErrorCode (*)(PetscObject));
324: PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
325: PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
326: PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble, PetscLogDouble *);

328: /* Output functions */
329: PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
330: PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
331: PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);
332: PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);

334: PETSC_EXTERN PetscErrorCode PetscLogGetState(PetscLogState *);
335: PETSC_EXTERN PetscErrorCode PetscLogGetDefaultHandler(PetscLogHandler *);
336: PETSC_EXTERN PetscErrorCode PetscLogHandlerStart(PetscLogHandler);
337: PETSC_EXTERN PetscErrorCode PetscLogHandlerStop(PetscLogHandler);

339: /* Status checking functions */
340: PETSC_EXTERN PetscErrorCode PetscLogIsActive(PetscBool *);

342: /* Stage functions */
343: PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[], PetscLogStage *);
344: PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
345: PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
346: PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool);
347: PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *);
348: PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool);
349: PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *);
350: PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[], PetscLogStage *);
351: PETSC_EXTERN PetscErrorCode PetscLogStageGetName(PetscLogEvent, const char *[]);
352: PETSC_EXTERN PetscErrorCode PetscLogStageGetPerfInfo(PetscLogStage, PetscEventPerfInfo *);

354: /* Event functions */
355: PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId, PetscLogEvent *);
356: PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent, PetscBool);
357: PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
358: PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
359: PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
360: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
361: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent);
362: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent);
363: PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool);
364: PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
365: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
366: PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[], PetscLogEvent *);
367: PETSC_EXTERN PetscErrorCode PetscLogEventGetName(PetscLogEvent, const char *[]);
368: PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(PetscLogStage, PetscLogEvent, PetscEventPerfInfo *);
369: PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
370: PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);
371: PETSC_EXTERN PetscErrorCode PetscLogEventsPause(void);
372: PETSC_EXTERN PetscErrorCode PetscLogEventsResume(void);

374: /* Class functions */
375: PETSC_EXTERN PetscErrorCode PetscLogClassGetClassId(const char[], PetscClassId *);
376: PETSC_EXTERN PetscErrorCode PetscLogClassIdGetName(PetscClassId, const char *[]);

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

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

383:   Input Parameters:
384: + e    - the `PetscLogEvent` to associate with the synchronization
385: - comm - the `MPI_Comm` whose ranks are synchronized

387:   Level: developer

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

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

394: .seealso: `PetscLogEvent`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogHandler`
395: @*/
396: static inline PetscErrorCode PetscLogEventSync(PetscLogEvent e, MPI_Comm comm)
397: {
398:   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
399:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
400:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
401:       if (h->eventSync) {
402:         PetscErrorCode err = (*h->eventSync)(h->handler, e, comm);
403:         if (err != PETSC_SUCCESS) return err;
404:       }
405:     }
406:   }
407:   return PETSC_SUCCESS;
408: }

410: static inline PetscErrorCode PetscLogEventBegin_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
411: {
412:   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
413:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
414:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
415:       if (h->eventBegin) {
416:         PetscErrorCode err = (*h->eventBegin)(h->handler, e, o1, o2, o3, o4);
417:         if (err != PETSC_SUCCESS) return err;
418:       }
419:     }
420:   }
421:   return PETSC_SUCCESS;
422: }
423:   /*MC
424:     PetscLogEventBegin - Log the start of an instance of a `PetscLogEvent`

426:     Synopsis:
427: #include <petsclog.h>
428:     PetscErrorCode PetscLogEventBegin(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)

430:     Not Collective; No Fortran Support

432:     Input Parameters:
433:   + e  - the `PetscLogEvent`
434:   . o1 - first object involved in the event (may be `NULL`)
435:   . o2 - second object involved in the event (may be `NULL`)
436:   . o3 - third object involved in the event (may be `NULL`)
437:   - o4 - fourth object involved in the event (may be `NULL`)

439:     Level: intermediate

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

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

449: static inline PetscErrorCode PetscLogEventEnd_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
450: {
451:   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
452:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
453:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
454:       if (h->eventEnd) {
455:         PetscErrorCode err = (*h->eventEnd)(h->handler, e, o1, o2, o3, o4);
456:         if (err != PETSC_SUCCESS) return err;
457:       }
458:     }
459:   }
460:   return PETSC_SUCCESS;
461: }
462:   /*MC
463:     PetscLogEventEnd - Log the end of an instance of a `PetscLogEvent`

465:     Synopsis:
466: #include <petsclog.h>
467:     PetscErrorCode PetscLogEventEnd(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)

469:     Not Collective; No Fortran Support

471:     Input Parameters:
472:   + e  - the `PetscLogEvent`
473:   . o1 - first object involved in the event (may be `NULL`)
474:   . o2 - second object involved in the event (may be `NULL`)
475:   . o3 - third object involved in the event (may be `NULL`)
476:   - o4 - fourth object involved in the event (may be `NULL`)

478:     Level: intermediate

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

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

487: /* Object functions */
488: /*@
489:   PetscLogObjectCreate - Notify the active `PetscLogHandler`s that a new `PetscObject` has been created

491:   Not Collective; No Fortran Support

493:   Input Parameter:
494: . o - the newly created `PetscObject`

496:   Level: developer

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

501: .seealso: `PetscLogObjectDestroy()`, `PetscLogHandler`, `PetscObject`
502: @*/
503: static inline PetscErrorCode PetscLogObjectCreate(PetscObject o)
504: {
505:   if (petsc_log_state) {
506:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
507:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
508:       if (h->objectCreate) {
509:         PetscErrorCode err = (*h->objectCreate)(h->handler, o);
510:         if (err != PETSC_SUCCESS) return err;
511:       }
512:     }
513:   }
514:   return PETSC_SUCCESS;
515: }

517: /*@
518:   PetscLogObjectDestroy - Notify the active `PetscLogHandler`s that a `PetscObject` is being destroyed

520:   Not Collective; No Fortran Support

522:   Input Parameter:
523: . o - the `PetscObject` that is being destroyed

525:   Level: developer

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

530: .seealso: `PetscLogObjectCreate()`, `PetscLogHandler`, `PetscObject`
531: @*/
532: static inline PetscErrorCode PetscLogObjectDestroy(PetscObject o)
533: {
534:   if (petsc_log_state) {
535:     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
536:       PetscLogHandlerHot *h = &PetscLogHandlers[i];
537:       if (h->objectDestroy) {
538:         PetscErrorCode err = (*h->objectDestroy)(h->handler, o);
539:         if (err != PETSC_SUCCESS) return err;
540:       }
541:     }
542:   }
543:   return PETSC_SUCCESS;
544: }

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

549:    For the complex numbers version, note that
550:        1 complex addition = 2 flops
551:        1 complex multiplication = 6 flops,
552:    where we define 1 flop as that for a double precision scalar.  We roughly approximate
553:    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
554:    to the assumption that we're counting mostly additions and multiplications -- and
555:    roughly the same number of each.  More accurate counting could be done by distinguishing
556:    among the various arithmetic operations.
557:  */

559:   #if PetscDefined(USE_COMPLEX)
560:     #define PETSC_FLOPS_PER_OP 4.0
561:   #else
562:     #define PETSC_FLOPS_PER_OP 1.0
563:   #endif

565: /*@
566:   PetscLogFlops - Log how many flops are performed in a calculation

568:   Not Collective

570:   Input Parameter:
571: . n - the number of flops

573:   Level: intermediate

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

579: .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`
580: @*/
581: static inline PetscErrorCode PetscLogFlops(PetscLogDouble n)
582: {
583:   PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
584:   return PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n);
585: }

587:   /*
588:      These are used internally in the PETSc routines to keep a count of MPI messages and
589:    their sizes.

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

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

598:      It does not work with Windows because winmpich lacks MPI_Type_size()
599: */
600:   #if !defined(MPIUNI_H) && !PetscDefined(HAVE_BROKEN_RECURSIVE_MACRO)
601: /*
602:    Logging of MPI activities
603: */
604: /*@
605:   PetscMPITypeSize - Atomically add a `PetscLogDouble` value to both a global counter and its per-thread counterpart based on the
606:   length of an `MPI_Datatype`

608:   Not Collective; No Fortran Support

610:   Input Parameters:
611: + count     - the length of the array containing a specific `MPI_Datatype`
612: . type      - the `MPI_Datatype`
613: . length    - pointer to the global counter to update
614: - length_th - pointer to the per-thread counter to update

616:   Level: developer

618:   Note:
619:   When PETSc is built without thread safety this is a fast routine that performs the same update without locking.

621:   Developer Note:
622:   This should have a better name related to its functionality

624: .seealso: `PetscAddLogDouble()`, `PetscAddLogDoubleCnt()`, `PetscLogFlops()`, `PetscLogDouble`, `PetscMPITypeSizeComm()`
625: @*/
626: static inline PetscErrorCode PetscMPITypeSize(PetscCount count, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
627: {
628:   PetscMPIInt typesize;

630:   if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
631:   PetscCallMPI(MPI_Type_size(type, &typesize));
632:   return PetscAddLogDouble(length, length_th, (PetscLogDouble)(count * typesize));
633: }

635: /*@
636:   PetscMPITypeSizeComm - Atomically add a `PetscLogDouble` value to both a global counter and its per-thread counterpart based on the
637:   length of an `MPI_Datatype`

639:   Not Collective; No Fortran Support

641:   Input Parameters:
642: + comm      - the `MPI_Comm` that shared the communication of the `MPI_Datatype`
643: . counts    - the length of the array containing a specific `MPI_Datatype` being sent to each MPI process
644: . type      - the `MPI_Datatype`
645: . length    - pointer to the global counter to update
646: - length_th - pointer to the per-thread counter to update

648:   Level: developer

650:   Note:
651:   When PETSc is built without thread safety this is a fast routine that performs the same update without locking.

653:   Developer Note:
654:   This should have a better name related to its functionality

656: .seealso: `PetscAddLogDouble()`, `PetscAddLogDoubleCnt()`, `PetscLogFlops()`, `PetscLogDouble`, `PetscMPITypeSize()`
657: @*/
658: static inline PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, const PetscMPIInt *counts, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
659: {
660:   PetscMPIInt    typesize, size, p;
661:   PetscLogDouble l;

663:   if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
664:   PetscCallMPI(MPI_Comm_size(comm, &size));
665:   PetscCallMPI(MPI_Type_size(type, &typesize));
666:   for (p = 0, l = 0.0; p < size; ++p) l += (PetscLogDouble)(counts[p] * typesize);
667:   return PetscAddLogDouble(length, length_th, l);
668: }

670: /*
671:     Returns 1 if the communicator is parallel else zero
672: */
673: static inline int PetscMPIParallelComm(MPI_Comm comm)
674: {
675:   PetscMPIInt size;
676:   MPI_Comm_size(comm, &size);
677:   return size > 1;
678: }

680:     #define MPI_Irecv(buf, count, datatype, source, tag, comm, request) \
681:       (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)))

683:     #define MPI_Irecv_c(buf, count, datatype, source, tag, comm, request) \
684:       (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)))

686:     #define MPI_Isend(buf, count, datatype, dest, tag, comm, request) \
687:       (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)))

689:     #define MPI_Isend_c(buf, count, datatype, dest, tag, comm, request) \
690:       (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)))

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

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

698:     #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))

700:     #define MPI_Recv(buf, count, datatype, source, tag, comm, status) \
701:       (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)))

703:     #define MPI_Recv_c(buf, count, datatype, source, tag, comm, status) \
704:       (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)))

706:     #define MPI_Send(buf, count, datatype, dest, tag, comm) \
707:       (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)))

709:     #define MPI_Send_c(buf, count, datatype, dest, tag, comm) \
710:       (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)))

712:     #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)))

714:     #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)))

716:     #define MPI_Waitall(count, array_of_requests, array_of_statuses) \
717:       (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)))

719:     #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)))

721:     #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)))

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

726:     #define MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
727:       (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)))

729:     #define MPI_Alltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm) \
730:       (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)))

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

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

738:     #define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
739:       (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)))

741:     #define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm) \
742:       (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)))

744:     #define MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
745:       (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)))

747:     #define MPI_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
748:       (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)))

750:     #define MPI_Ialltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
751:       (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)))

753:     #define MPI_Ialltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm, request) \
754:       (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)))

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

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

762:     #define MPI_Igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
763:       (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)))

765:     #define MPI_Igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm, request) \
766:       (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)))

768:     #define MPI_Iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
769:       (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)))

771:     #define MPI_Iscatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
772:       (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)))

774:     #define MPIX_Send_enqueue(buf, count, datatype, dest, tag, comm) \
775:       (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)))

777:     #define MPIX_Recv_enqueue(buf, count, datatype, source, tag, comm, status) \
778:       (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)))

780:     #define MPIX_Isend_enqueue(buf, count, datatype, dest, tag, comm, request) \
781:       (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)))

783:     #define MPIX_Irecv_enqueue(buf, count, datatype, source, tag, comm, request) \
784:       (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)))

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

789:     #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)))

791:     #define MPIX_Waitall_enqueue(count, array_of_requests, array_of_statuses) \
792:       (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)))
793:   #else

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

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

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

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

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

805:   #define PetscLogGetState(a)          (*(a) = NULL, PETSC_SUCCESS)
806:   #define PetscLogGetDefaultHandler(a) (*(a) = NULL, PETSC_SUCCESS)
807:   #define PetscLogHandlerStart(a)      ((void)(a), PETSC_SUCCESS)
808:   #define PetscLogHandlerStop(a)       ((void)(a), PETSC_SUCCESS)

810:   #define PetscLogFlops(n) ((void)(n), PETSC_SUCCESS)
811:   #define PetscGetFlops(a) (*(a) = 0.0, PETSC_SUCCESS)

813:   #define PetscLogStageRegister(a, b)    ((void)(a), *(b) = -1, PETSC_SUCCESS)
814:   #define PetscLogStagePush(a)           ((void)(a), PETSC_SUCCESS)
815:   #define PetscLogStagePop()             PETSC_SUCCESS
816:   #define PetscLogStageSetActive(a, b)   ((void)(a), (void)(b), PETSC_SUCCESS)
817:   #define PetscLogStageGetActive(a, b)   ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
818:   #define PetscLogStageGetVisible(a, b)  ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
819:   #define PetscLogStageSetVisible(a, b)  ((void)(a), (void)(b), PETSC_SUCCESS)
820:   #define PetscLogStageGetId(a, b)       ((void)(a), *(b) = -1, PETSC_SUCCESS)
821:   #define PetscLogStageGetName(a, b)     ((void)(a), *(b) = NULL, PETSC_SUCCESS)
822:   #define PetscLogStageGetPerfInfo(a, b) ((void)(a), *(b) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)

824:   #define PetscLogEventRegister(a, b, c)    ((void)(a), (void)(b), *(c) = -1, PETSC_SUCCESS)
825:   #define PetscLogEventSetCollective(a, b)  ((void)(a), (void)(b), PETSC_SUCCESS)
826:   #define PetscLogEventIncludeClass(a)      ((void)(a), PETSC_SUCCESS)
827:   #define PetscLogEventExcludeClass(a)      ((void)(a), PETSC_SUCCESS)
828:   #define PetscLogEventActivate(a)          ((void)(a), PETSC_SUCCESS)
829:   #define PetscLogEventDeactivate(a)        ((void)(a), PETSC_SUCCESS)
830:   #define PetscLogEventDeactivatePush(a)    ((void)(a), PETSC_SUCCESS)
831:   #define PetscLogEventDeactivatePop(a)     ((void)(a), PETSC_SUCCESS)
832:   #define PetscLogEventActivateClass(a)     ((void)(a), PETSC_SUCCESS)
833:   #define PetscLogEventDeactivateClass(a)   ((void)(a), PETSC_SUCCESS)
834:   #define PetscLogEventSetActiveAll(a, b)   ((void)(a), PETSC_SUCCESS)
835:   #define PetscLogEventGetId(a, b)          ((void)(a), *(b) = -1, PETSC_SUCCESS)
836:   #define PetscLogEventGetName(a, b)        ((void)(a), *(b) = NULL, PETSC_SUCCESS)
837:   #define PetscLogEventGetPerfInfo(a, b, c) ((void)(a), (void)(b), *(c) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)

839:   #define PetscLogEventSetDof(a, b, c)   ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
840:   #define PetscLogEventSetError(a, b, c) ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
841:   #define PetscLogEventsPause()          PETSC_SUCCESS
842:   #define PetscLogEventsResume()         PETSC_SUCCESS

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

847:   #define PetscLogObjectCreate(h)        ((void)(h), PETSC_SUCCESS)
848:   #define PetscLogObjectDestroy(h)       ((void)(h), PETSC_SUCCESS)
849:   #define PetscLogObjectState(h, c, ...) ((void)(h), (void)(c), PETSC_SUCCESS)

851:   #define PetscLogDefaultBegin()                   PETSC_SUCCESS
852:   #define PetscLogNestedBegin()                    PETSC_SUCCESS
853:   #define PetscLogTraceBegin(file)                 ((void)(file), PETSC_SUCCESS)
854:   #define PetscLogMPEBegin()                       PETSC_SUCCESS
855:   #define PetscLogPerfstubsBegin()                 PETSC_SUCCESS
856:   #define PetscLogLegacyCallbacksBegin(a, b, c, d) ((void)(a), (void)(b), (void)(c), (void)(d), PETSC_SUCCESS)
857:   #define PetscLogActions(a)                       ((void)(a), PETSC_SUCCESS)
858:   #define PetscLogObjects(a)                       ((void)(a), PETSC_SUCCESS)
859:   #define PetscLogSetThreshold(a, b)               ((void)(a), (void)(b), PETSC_SUCCESS)

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

863:   #define PetscLogView(viewer)      ((void)(viewer), PETSC_SUCCESS)
864:   #define PetscLogViewFromOptions() PETSC_SUCCESS
865:   #define PetscLogDump(c)           ((void)(c), PETSC_SUCCESS)
866:   #define PetscLogMPEDump(c)        ((void)(c), PETSC_SUCCESS)

868:   #define PetscLogEventSync(e, comm)                            ((void)(e), (void)(comm), PETSC_SUCCESS)
869:   #define PetscLogEventBegin(e, o1, o2, o3, o4)                 ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)
870:   #define PetscLogEventEnd(e, o1, o2, o3, o4)                   ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)

872:   /* If PETSC_USE_LOG is NOT defined, these still need to be! */
873:   #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
874:   #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
875:   #define MPI_Start_isend(count, datatype, requests)            MPI_Start(requests)

877: #endif /* PETSC_USE_LOG */

879: /*MC
880:   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

882:   Synopsis:
883: #include <petsclog.h>
884:   PetscPreLoadBegin(PetscBool flag, const char name[])

886:   Not Collective; No Fortran Support

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

892:   Level: intermediate

894:   Note:
895:   Use this macro in the form
896: .vb
897:     PetscPreLoadBegin(PETSC_TRUE, "Compute");
898:     // ... code to be timed
899:     PetscPreLoadEnd();
900: .ve
901:   It expands to a loop that runs the enclosed code twice when preloading is enabled and once otherwise.
902:   Pair with `PetscPreLoadEnd()`. Use `PetscPreLoadStage()` to advance to a new named stage between phases.

904: .seealso: `PetscPreLoadEnd`, `PetscPreLoadStage`, `PetscLogStageRegister()`, `PetscLogStagePush()`
905: M*/
906: #define PetscPreLoadBegin(flag, name) \
907:   do { \
908:     PetscBool     PetscPreLoading = flag; \
909:     int           PetscPreLoadMax, PetscPreLoadIt; \
910:     PetscLogStage _stageNum; \
911:     PetscCall(PetscOptionsGetBool(NULL, NULL, "-preload", &PetscPreLoading, NULL)); \
912:     PetscPreLoadMax     = (int)(PetscPreLoading); \
913:     PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed; \
914:     PetscCall(PetscLogStageGetId(name, &_stageNum)); \
915:     for (PetscPreLoadIt = (_stageNum == -1) ? 0 : PetscPreLoadMax; PetscPreLoadIt <= PetscPreLoadMax; PetscPreLoadIt++) { \
916:       PetscPreLoadingOn = (PetscBool)(PetscPreLoadIt < PetscPreLoadMax); \
917:       PetscCall(PetscBarrier(NULL)); \
918:       if (_stageNum == -1) PetscCall(PetscLogStageRegister(name, &_stageNum)); \
919:       PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(PetscPreLoadIt == PetscPreLoadMax))); \
920:       PetscCall(PetscLogStagePush(_stageNum))

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

925:   Synopsis:
926: #include <petsclog.h>
927:   PetscPreLoadEnd()

929:   Not Collective; No Fortran Support

931:   Level: intermediate

933: .seealso: `PetscPreLoadBegin`, `PetscPreLoadStage`
934: M*/
935: #define PetscPreLoadEnd() \
936:   PetscCall(PetscLogStagePop()); \
937:   } \
938:   } \
939:   while (0)

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

944:   Synopsis:
945: #include <petsclog.h>
946:   PetscPreLoadStage(const char name[])

948:   Not Collective; No Fortran Support

950:   Input Parameter:
951: . name - name for the new `PetscLogStage`

953:   Level: intermediate

955:   Note:
956:   Pops the previous stage, registers (or reuses) the new stage, and pushes it. Only valid between
957:   `PetscPreLoadBegin()` and `PetscPreLoadEnd()`.

959: .seealso: `PetscPreLoadBegin`, `PetscPreLoadEnd`, `PetscLogStagePush()`, `PetscLogStagePop()`
960: M*/
961: #define PetscPreLoadStage(name) \
962:   do { \
963:     PetscCall(PetscLogStagePop()); \
964:     PetscCall(PetscLogStageGetId(name, &_stageNum)); \
965:     if (_stageNum == -1) PetscCall(PetscLogStageRegister(name, &_stageNum)); \
966:     PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(!PetscPreLoadMax || PetscPreLoadIt))); \
967:     PetscCall(PetscLogStagePush(_stageNum)); \
968:   } while (0)

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

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

976: PETSC_EXTERN PetscErrorCode PetscLogGpuTime(void);
977: PETSC_EXTERN PetscErrorCode PetscLogGpuTimeBegin(void);
978: PETSC_EXTERN PetscErrorCode PetscLogGpuTimeEnd(void);
979: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergy(void);
980: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeter(void);
981: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeterBegin(void);
982: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeterEnd(void);

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

987:   Not Collective

989:   Input Parameter:
990: . n - the number of flops

992:   Level: intermediate

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

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

1001: .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogFlops()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`
1002: @*/
1003: static inline PetscErrorCode PetscLogGpuFlops(PetscLogDouble n)
1004: {
1005:   PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
1006:   PetscCall(PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n));
1007:   PetscCall(PetscAddLogDouble(&petsc_gflops, &petsc_gflops_th, PETSC_FLOPS_PER_OP * n));
1008:   return PETSC_SUCCESS;
1009: }

1011: /*@
1012:   PetscLogGpuTimeAdd - Add elapsed GPU computation time to PETSc's GPU time counter

1014:   Not Collective; No Fortran Support

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

1019:   Level: developer

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

1024: .seealso: `PetscLogGpuTime()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`, `PetscLogGpuFlops()`
1025: @*/
1026: static inline PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t)
1027: {
1028:   return PetscAddLogDouble(&petsc_gtime, &petsc_gtime_th, t);
1029: }

1031: /*@
1032:   PetscLogCpuToGpu - Log a CPU-to-GPU memory transfer for performance reporting

1034:   Not Collective; No Fortran Support

1036:   Input Parameter:
1037: . size - number of bytes transferred from CPU to GPU

1039:   Level: developer

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

1044: .seealso: `PetscLogGpuToCpu()`, `PetscLogCpuToGpuScalar()`, `PetscLogGpuFlops()`
1045: @*/
1046: static inline PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size)
1047: {
1048:   return PetscAddLogDoubleCnt(&petsc_ctog_ct, &petsc_ctog_sz, &petsc_ctog_ct_th, &petsc_ctog_sz_th, size);
1049: }

1051: /*@
1052:   PetscLogGpuToCpu - Log a GPU-to-CPU memory transfer for performance reporting

1054:   Not Collective; No Fortran Support

1056:   Input Parameter:
1057: . size - number of bytes transferred from GPU to CPU

1059:   Level: developer

1061: .seealso: `PetscLogCpuToGpu()`, `PetscLogGpuToCpuScalar()`, `PetscLogGpuFlops()`
1062: @*/
1063: static inline PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size)
1064: {
1065:   return PetscAddLogDoubleCnt(&petsc_gtoc_ct, &petsc_gtoc_sz, &petsc_gtoc_ct_th, &petsc_gtoc_sz_th, size);
1066: }

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

1071:   Not Collective; No Fortran Support

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

1076:   Level: developer

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

1081: .seealso: `PetscLogCpuToGpu()`, `PetscLogGpuToCpuScalar()`
1082: @*/
1083: static inline PetscErrorCode PetscLogCpuToGpuScalar(PetscLogDouble size)
1084: {
1085:   return PetscAddLogDoubleCnt(&petsc_ctog_ct_scalar, &petsc_ctog_sz_scalar, &petsc_ctog_ct_scalar_th, &petsc_ctog_sz_scalar_th, size);
1086: }

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

1091:   Not Collective; No Fortran Support

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

1096:   Level: developer

1098: .seealso: `PetscLogGpuToCpu()`, `PetscLogCpuToGpuScalar()`
1099: @*/
1100: static inline PetscErrorCode PetscLogGpuToCpuScalar(PetscLogDouble size)
1101: {
1102:   return PetscAddLogDoubleCnt(&petsc_gtoc_ct_scalar, &petsc_gtoc_sz_scalar, &petsc_gtoc_ct_scalar_th, &petsc_gtoc_sz_scalar_th, size);
1103: }
1104: #else

1106:   #define PetscLogCpuToGpu(a)       ((void)(a), PETSC_SUCCESS)
1107:   #define PetscLogGpuToCpu(a)       ((void)(a), PETSC_SUCCESS)
1108:   #define PetscLogCpuToGpuScalar(a) ((void)(a), PETSC_SUCCESS)
1109:   #define PetscLogGpuToCpuScalar(a) ((void)(a), PETSC_SUCCESS)
1110:   #define PetscLogGpuFlops(a)       ((void)(a), PETSC_SUCCESS)
1111:   #define PetscLogGpuTimeAdd(a)     ((void)(a), PETSC_SUCCESS)
1112:   #define PetscLogGpuTime()         PETSC_SUCCESS
1113:   #define PetscLogGpuTimeBegin()    PETSC_SUCCESS
1114:   #define PetscLogGpuTimeEnd()      PETSC_SUCCESS

1116:   #define PetscLogGpuEnergy()           PETSC_SUCCESS
1117:   #define PetscLogGpuEnergyMeter()      PETSC_SUCCESS
1118:   #define PetscLogGpuEnergyMeterBegin() PETSC_SUCCESS
1119:   #define PetscLogGpuEnergyMeterEnd()   PETSC_SUCCESS

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

1123: #include <petsclogdeprecated.h>