Actual source code: petsclog.h
1: /*
2: Defines profile/logging in PETSc.
3: */
4: #pragma once
6: #include <petscsystypes.h>
7: #include <petscerror.h>
8: #include <petscoptionstypes.h>
9: #include <petsctime.h>
10: #include <petscbt.h>
11: #include <petsclogtypes.h>
13: /* MANSEC = Sys */
14: /* SUBMANSEC = Log */
16: /* General logging of information; different from event logging */
17: PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[], PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
18: #if PetscDefined(USE_INFO)
19: #define PetscInfo(A, ...) PetscInfo_Private(PETSC_FUNCTION_NAME, ((PetscObject)(A)), __VA_ARGS__)
20: #else
21: #define PetscInfo(A, ...) PETSC_SUCCESS
22: #endif
24: #define PetscInfo1(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
25: #define PetscInfo2(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
26: #define PetscInfo3(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
27: #define PetscInfo4(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
28: #define PetscInfo5(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
29: #define PetscInfo6(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
30: #define PetscInfo7(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
31: #define PetscInfo8(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
32: #define PetscInfo9(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
34: PETSC_EXTERN const char *const PetscInfoCommFlags[];
35: PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId);
36: PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId);
37: PETSC_EXTERN PetscErrorCode PetscInfoEnabled(PetscClassId, PetscBool *);
38: PETSC_EXTERN PetscErrorCode PetscInfoAllow(PetscBool);
39: PETSC_EXTERN PetscErrorCode PetscInfoSetFile(const char[], const char[]);
40: PETSC_EXTERN PetscErrorCode PetscInfoGetFile(char **, FILE **);
41: PETSC_EXTERN PetscErrorCode PetscInfoSetClasses(PetscBool, PetscInt, const char *const *);
42: PETSC_EXTERN PetscErrorCode PetscInfoGetClass(const char *, PetscBool *);
43: PETSC_EXTERN PetscErrorCode PetscInfoGetInfo(PetscBool *, PetscBool *, PetscBool *, PetscBool *, PetscInfoCommFlag *);
44: PETSC_EXTERN PetscErrorCode PetscInfoProcessClass(const char[], PetscInt, const PetscClassId[]);
45: PETSC_EXTERN PetscErrorCode PetscInfoSetFilterCommSelf(PetscInfoCommFlag);
46: PETSC_EXTERN PetscErrorCode PetscInfoSetFromOptions(PetscOptions);
47: PETSC_EXTERN PetscErrorCode PetscInfoDestroy(void);
48: PETSC_EXTERN PetscBool PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */
50: PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *);
51: PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack);
52: PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int);
53: PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *);
54: PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *);
55: PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *);
57: PETSC_EXTERN PetscErrorCode PetscLogStateCreate(PetscLogState *);
58: PETSC_EXTERN PetscErrorCode PetscLogStateDestroy(PetscLogState *);
60: PETSC_EXTERN PetscErrorCode PetscLogStateClassRegister(PetscLogState, const char[], PetscClassId, PetscLogStage *);
61: PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActive(PetscLogState, PetscLogStage, PetscClassId, PetscBool);
62: PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState, PetscClassId, PetscBool);
64: PETSC_EXTERN PetscErrorCode PetscLogStateStageRegister(PetscLogState, const char[], PetscLogStage *);
65: PETSC_EXTERN PetscErrorCode PetscLogStateStagePush(PetscLogState, PetscLogStage);
66: PETSC_EXTERN PetscErrorCode PetscLogStateStagePop(PetscLogState);
67: PETSC_EXTERN PetscErrorCode PetscLogStateStageSetActive(PetscLogState, PetscLogStage, PetscBool);
68: PETSC_EXTERN PetscErrorCode PetscLogStateStageGetActive(PetscLogState, PetscLogStage, PetscBool *);
69: PETSC_EXTERN PetscErrorCode PetscLogStateGetCurrentStage(PetscLogState, PetscLogStage *);
71: PETSC_EXTERN PetscErrorCode PetscLogStateEventRegister(PetscLogState, const char[], PetscClassId, PetscLogEvent *);
72: PETSC_EXTERN PetscErrorCode PetscLogStateEventSetCollective(PetscLogState, PetscLogEvent, PetscBool);
73: PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool);
74: PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActiveAll(PetscLogState, PetscLogEvent, PetscBool);
75: PETSC_EXTERN PetscErrorCode PetscLogStateEventGetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool *);
77: PETSC_EXTERN PetscErrorCode PetscLogStateGetEventFromName(PetscLogState, const char[], PetscLogEvent *);
78: PETSC_EXTERN PetscErrorCode PetscLogStateGetStageFromName(PetscLogState, const char[], PetscLogStage *);
79: PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromName(PetscLogState, const char[], PetscLogClass *);
80: PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState, PetscClassId, PetscLogClass *);
81: PETSC_EXTERN PetscErrorCode PetscLogStateGetNumEvents(PetscLogState, PetscInt *);
82: PETSC_EXTERN PetscErrorCode PetscLogStateGetNumStages(PetscLogState, PetscInt *);
83: PETSC_EXTERN PetscErrorCode PetscLogStateGetNumClasses(PetscLogState, PetscInt *);
84: PETSC_EXTERN PetscErrorCode PetscLogStateEventGetInfo(PetscLogState, PetscLogEvent, PetscLogEventInfo *);
85: PETSC_EXTERN PetscErrorCode PetscLogStateStageGetInfo(PetscLogState, PetscLogStage, PetscLogStageInfo *);
86: PETSC_EXTERN PetscErrorCode PetscLogStateClassGetInfo(PetscLogState, PetscLogClass, PetscLogClassInfo *);
88: PETSC_EXTERN PetscClassId PETSCLOGHANDLER_CLASSID;
90: PETSC_EXTERN PetscFunctionList PetscLogHandlerList;
92: PETSC_EXTERN PetscErrorCode PetscLogHandlerRegister(const char[], PetscErrorCode (*)(PetscLogHandler));
93: PETSC_EXTERN PetscErrorCode PetscLogHandlerCreate(MPI_Comm, PetscLogHandler *);
94: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetType(PetscLogHandler, PetscLogHandlerType);
95: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetType(PetscLogHandler, PetscLogHandlerType *);
96: PETSC_EXTERN PetscErrorCode PetscLogHandlerDestroy(PetscLogHandler *);
97: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetState(PetscLogHandler, PetscLogState);
98: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetState(PetscLogHandler, PetscLogState *);
99: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventBegin(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
100: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventEnd(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
101: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventSync(PetscLogHandler, PetscLogEvent, MPI_Comm);
102: PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectCreate(PetscLogHandler, PetscObject);
103: PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectDestroy(PetscLogHandler, PetscObject);
104: PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePush(PetscLogHandler, PetscLogStage);
105: PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePop(PetscLogHandler, PetscLogStage);
106: PETSC_EXTERN PetscErrorCode PetscLogHandlerView(PetscLogHandler, PetscViewer);
108: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetEventPerfInfo(PetscLogHandler, PetscLogStage, PetscLogEvent, PetscEventPerfInfo **);
109: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetStagePerfInfo(PetscLogHandler, PetscLogStage, PetscEventPerfInfo **);
110: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetLogActions(PetscLogHandler, PetscBool);
111: PETSC_EXTERN PetscErrorCode PetscLogHandlerSetLogObjects(PetscLogHandler, PetscBool);
112: PETSC_EXTERN PetscErrorCode PetscLogHandlerLogObjectState(PetscLogHandler, PetscObject, const char[], ...);
113: PETSC_EXTERN PetscErrorCode PetscLogHandlerGetNumObjects(PetscLogHandler, PetscInt *);
114: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventDeactivatePush(PetscLogHandler, PetscLogStage, PetscLogEvent);
115: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventDeactivatePop(PetscLogHandler, PetscLogStage, PetscLogEvent);
116: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventsPause(PetscLogHandler);
117: PETSC_EXTERN PetscErrorCode PetscLogHandlerEventsResume(PetscLogHandler);
118: PETSC_EXTERN PetscErrorCode PetscLogHandlerDump(PetscLogHandler, const char[]);
119: PETSC_EXTERN PetscErrorCode PetscLogHandlerStageSetVisible(PetscLogHandler, PetscLogStage, PetscBool);
120: PETSC_EXTERN PetscErrorCode PetscLogHandlerStageGetVisible(PetscLogHandler, PetscLogStage, PetscBool *);
122: PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateTrace(MPI_Comm, FILE *, PetscLogHandler *);
123: 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 *);
125: /*MC
126: PetscLogStateStageEventIsActive - Returns whether a specific `PetscLogEvent` is active in a specific stage of a `PetscLogState`
128: Synopsis:
129: #include <petsclog.h>
130: PetscBool PetscLogStateStageEventIsActive(PetscLogState state, PetscLogStage stage, PetscLogEvent event)
132: Not Collective; No Fortran Support
134: Input Parameters:
135: + state - the `PetscLogState`
136: . stage - the stage index
137: - event - the event index
139: Level: developer
141: Note:
142: Returns `PETSC_FALSE` when `stage` is negative, which indicates that there have been more stage pops than pushes.
144: .seealso: `PetscLogState`, `PetscLogStage`, `PetscLogEvent`, `PetscLogStateEventCurrentlyActive()`, `PetscLogStateStageGetActive()`
145: M*/
146: /* All events are inactive if an invalid stage is set, like if there have been more stage pops than stage pushes */
147: #define PetscLogStateStageEventIsActive(state, stage, event) (((stage) >= 0) && PetscBTLookup((state)->active, (stage)) && PetscBTLookup((state)->active, (stage) + ((event) + 1) * (state)->bt_num_stages))
149: /*MC
150: PetscLogStateEventCurrentlyActive - Returns whether a specific `PetscLogEvent` is active in the currently active stage of a `PetscLogState`
152: Synopsis:
153: #include <petsclog.h>
154: PetscBool PetscLogStateEventCurrentlyActive(PetscLogState state, PetscLogEvent event)
156: Not Collective; No Fortran Support
158: Input Parameters:
159: + state - the `PetscLogState` (may be `NULL`, in which case `PETSC_FALSE` is returned)
160: - event - the event index
162: Level: developer
164: .seealso: `PetscLogState`, `PetscLogEvent`, `PetscLogStateStageEventIsActive()`
165: M*/
166: #define PetscLogStateEventCurrentlyActive(state, event) ((state) && PetscLogStateStageEventIsActive(state, (state)->current_stage, event))
168: /* PetscLogHandler with critical methods exposed for speed */
169: typedef struct _n_PetscLogHandlerHot {
170: PetscLogHandler handler;
171: PetscErrorCode (*eventBegin)(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
172: PetscErrorCode (*eventEnd)(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
173: PetscErrorCode (*eventSync)(PetscLogHandler, PetscLogEvent, MPI_Comm);
174: PetscErrorCode (*objectCreate)(PetscLogHandler, PetscObject);
175: PetscErrorCode (*objectDestroy)(PetscLogHandler, PetscObject);
176: } PetscLogHandlerHot;
178: #if PetscDefined(HAVE_THREADSAFETY) && PetscDefined(USE_LOG)
179: PETSC_EXTERN PetscErrorCode PetscAddLogDouble(PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
180: PETSC_EXTERN PetscErrorCode PetscAddLogDoubleCnt(PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
181: #else
182: #define PetscAddLogDouble(a, b, c) ((PetscErrorCode)((*(a) += (c), PETSC_SUCCESS) || ((*(b) += (c)), PETSC_SUCCESS)))
183: #define PetscAddLogDoubleCnt(a, b, c, d, e) ((PetscErrorCode)(PetscAddLogDouble(a, c, 1) || PetscAddLogDouble(b, d, e)))
184: #endif
186: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectParent()", ) static inline PetscErrorCode PetscLogObjectParent(PetscObject o, PetscObject p)
187: {
188: (void)o;
189: (void)p;
190: return PETSC_SUCCESS;
191: }
192: /*MC
193: PetscLogObjectParents - Record a parent/child relationship between a `PetscObject` and an array of `PetscObject`s for performance logging
195: Synopsis:
196: #include <petsclog.h>
197: PetscErrorCode PetscLogObjectParents(PetscObject p, int n, PetscObject d[])
199: Not Collective; No Fortran Support
201: Input Parameters:
202: + p - the parent `PetscObject`
203: . n - the number of child objects
204: - d - array of child `PetscObject`s
206: Level: developer
208: Note:
209: This routine is a no-op unless PETSc is configured with logging enabled.
211: .seealso: `PetscLogObjectParent()`, `PetscLogObjectCreate()`, `PetscLogObjectDestroy()`
212: M*/
213: #define PetscLogObjectParents(p, n, d) PetscMacroReturnStandard(for (int _i = 0; _i < (n); ++_i) PetscCall(PetscLogObjectParent((PetscObject)(p), (PetscObject)(d)[_i]));)
215: PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectMemory()", ) static inline PetscErrorCode PetscLogObjectMemory(PetscObject o, PetscLogDouble m)
216: {
217: (void)o;
218: (void)m;
219: return PETSC_SUCCESS;
220: }
222: /* Global flop counter */
223: PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
224: PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
225: PETSC_EXTERN PetscLogDouble petsc_isend_ct;
226: PETSC_EXTERN PetscLogDouble petsc_recv_ct;
227: PETSC_EXTERN PetscLogDouble petsc_send_ct;
228: PETSC_EXTERN PetscLogDouble petsc_irecv_len;
229: PETSC_EXTERN PetscLogDouble petsc_isend_len;
230: PETSC_EXTERN PetscLogDouble petsc_recv_len;
231: PETSC_EXTERN PetscLogDouble petsc_send_len;
232: PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
233: PETSC_EXTERN PetscLogDouble petsc_gather_ct;
234: PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
235: PETSC_EXTERN PetscLogDouble petsc_wait_ct;
236: PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
237: PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
238: PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;
240: /* Thread local storage */
241: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_TotalFlops_th;
242: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_irecv_ct_th;
243: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_isend_ct_th;
244: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_recv_ct_th;
245: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_send_ct_th;
246: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_irecv_len_th;
247: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_isend_len_th;
248: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_recv_len_th;
249: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_send_len_th;
250: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_allreduce_ct_th;
251: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gather_ct_th;
252: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_scatter_ct_th;
253: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_wait_ct_th;
254: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_wait_any_ct_th;
255: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_wait_all_ct_th;
256: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_sum_of_waits_ct_th;
258: /* Global GPU counters */
259: PETSC_EXTERN PetscLogDouble petsc_ctog_ct;
260: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct;
261: PETSC_EXTERN PetscLogDouble petsc_ctog_sz;
262: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz;
263: PETSC_EXTERN PetscLogDouble petsc_ctog_ct_scalar;
264: PETSC_EXTERN PetscLogDouble petsc_gtoc_ct_scalar;
265: PETSC_EXTERN PetscLogDouble petsc_ctog_sz_scalar;
266: PETSC_EXTERN PetscLogDouble petsc_gtoc_sz_scalar;
267: PETSC_EXTERN PetscLogDouble petsc_gflops;
268: PETSC_EXTERN PetscLogDouble petsc_gtime;
269: PETSC_EXTERN PetscLogDouble petsc_genergy;
270: PETSC_EXTERN PetscLogDouble petsc_genergy_meter;
272: /* Thread local storage */
273: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_ct_th;
274: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_ct_th;
275: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_sz_th;
276: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_sz_th;
277: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_ct_scalar_th;
278: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_ct_scalar_th;
279: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_ctog_sz_scalar_th;
280: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtoc_sz_scalar_th;
281: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gflops_th;
282: PETSC_EXTERN PETSC_TLS PetscLogDouble petsc_gtime_th;
284: PETSC_EXTERN PetscBool PetscLogMemory;
285: PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */
287: PETSC_EXTERN PetscLogState petsc_log_state;
289: #define PETSC_LOG_HANDLER_MAX 4
290: PETSC_EXTERN PetscLogHandlerHot PetscLogHandlers[PETSC_LOG_HANDLER_MAX];
292: #if PetscDefined(USE_LOG) /* --- Logging is turned on --------------------------------*/
293: PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
295: PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
297: /* Initialization functions */
298: PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
299: PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
300: PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
301: PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
302: PETSC_EXTERN PetscErrorCode PetscLogPerfstubsBegin(void);
303: PETSC_EXTERN PetscErrorCode PetscLogLegacyCallbacksBegin(PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscObject), PetscErrorCode (*)(PetscObject));
304: PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
305: PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
306: PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble, PetscLogDouble *);
308: /* Output functions */
309: PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
310: PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
311: PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);
312: PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
314: PETSC_EXTERN PetscErrorCode PetscLogGetState(PetscLogState *);
315: PETSC_EXTERN PetscErrorCode PetscLogGetDefaultHandler(PetscLogHandler *);
316: PETSC_EXTERN PetscErrorCode PetscLogHandlerStart(PetscLogHandler);
317: PETSC_EXTERN PetscErrorCode PetscLogHandlerStop(PetscLogHandler);
319: /* Status checking functions */
320: PETSC_EXTERN PetscErrorCode PetscLogIsActive(PetscBool *);
322: /* Stage functions */
323: PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[], PetscLogStage *);
324: PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
325: PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
326: PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool);
327: PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *);
328: PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool);
329: PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *);
330: PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[], PetscLogStage *);
331: PETSC_EXTERN PetscErrorCode PetscLogStageGetName(PetscLogEvent, const char *[]);
332: PETSC_EXTERN PetscErrorCode PetscLogStageGetPerfInfo(PetscLogStage, PetscEventPerfInfo *);
334: /* Event functions */
335: PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId, PetscLogEvent *);
336: PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent, PetscBool);
337: PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
338: PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
339: PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
340: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
341: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent);
342: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent);
343: PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool);
344: PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
345: PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
346: PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[], PetscLogEvent *);
347: PETSC_EXTERN PetscErrorCode PetscLogEventGetName(PetscLogEvent, const char *[]);
348: PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(PetscLogStage, PetscLogEvent, PetscEventPerfInfo *);
349: PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
350: PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);
351: PETSC_EXTERN PetscErrorCode PetscLogEventsPause(void);
352: PETSC_EXTERN PetscErrorCode PetscLogEventsResume(void);
354: /* Class functions */
355: PETSC_EXTERN PetscErrorCode PetscLogClassGetClassId(const char[], PetscClassId *);
356: PETSC_EXTERN PetscErrorCode PetscLogClassIdGetName(PetscClassId, const char *[]);
358: /*@
359: PetscLogEventSync - Synchronize an `MPI_Comm` so that the wall-clock time spent waiting at the implicit barrier is not attributed to a subsequent event
361: Logically Collective on `comm`; No Fortran Support
363: Input Parameters:
364: + e - the `PetscLogEvent` to associate with the synchronization
365: - comm - the `MPI_Comm` whose ranks are synchronized
367: Level: developer
369: Notes:
370: Forwards the call to every active `PetscLogHandler` that implements an `eventSync` method.
372: Has no effect when logging is not active or when the event is not active in the current stage.
374: .seealso: `PetscLogEvent`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogHandler`
375: @*/
376: static inline PetscErrorCode PetscLogEventSync(PetscLogEvent e, MPI_Comm comm)
377: {
378: if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
379: for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
380: PetscLogHandlerHot *h = &PetscLogHandlers[i];
381: if (h->eventSync) {
382: PetscErrorCode err = (*h->eventSync)(h->handler, e, comm);
383: if (err != PETSC_SUCCESS) return err;
384: }
385: }
386: }
387: return PETSC_SUCCESS;
388: }
390: static inline PetscErrorCode PetscLogEventBegin_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
391: {
392: if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
393: for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
394: PetscLogHandlerHot *h = &PetscLogHandlers[i];
395: if (h->eventBegin) {
396: PetscErrorCode err = (*h->eventBegin)(h->handler, e, o1, o2, o3, o4);
397: if (err != PETSC_SUCCESS) return err;
398: }
399: }
400: }
401: return PETSC_SUCCESS;
402: }
403: /*MC
404: PetscLogEventBegin - Log the start of an instance of a `PetscLogEvent`
406: Synopsis:
407: #include <petsclog.h>
408: PetscErrorCode PetscLogEventBegin(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
410: Not Collective; No Fortran Support
412: Input Parameters:
413: + e - the `PetscLogEvent`
414: . o1 - first object involved in the event (may be `NULL`)
415: . o2 - second object involved in the event (may be `NULL`)
416: . o3 - third object involved in the event (may be `NULL`)
417: - o4 - fourth object involved in the event (may be `NULL`)
419: Level: intermediate
421: Note:
422: Forwards the call to every active `PetscLogHandler` that implements an `eventBegin` method. Use
423: `PetscLogEventEnd()` to log the end of the same event.
425: .seealso: `PetscLogEvent`, `PetscLogEventRegister()`, `PetscLogEventEnd()`, `PetscLogEventSync()`
426: M*/
427: #define PetscLogEventBegin(e, o1, o2, o3, o4) PetscLogEventBegin_Internal(e, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))
429: static inline PetscErrorCode PetscLogEventEnd_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
430: {
431: if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
432: for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
433: PetscLogHandlerHot *h = &PetscLogHandlers[i];
434: if (h->eventEnd) {
435: PetscErrorCode err = (*h->eventEnd)(h->handler, e, o1, o2, o3, o4);
436: if (err != PETSC_SUCCESS) return err;
437: }
438: }
439: }
440: return PETSC_SUCCESS;
441: }
442: /*MC
443: PetscLogEventEnd - Log the end of an instance of a `PetscLogEvent`
445: Synopsis:
446: #include <petsclog.h>
447: PetscErrorCode PetscLogEventEnd(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
449: Not Collective; No Fortran Support
451: Input Parameters:
452: + e - the `PetscLogEvent`
453: . o1 - first object involved in the event (may be `NULL`)
454: . o2 - second object involved in the event (may be `NULL`)
455: . o3 - third object involved in the event (may be `NULL`)
456: - o4 - fourth object involved in the event (may be `NULL`)
458: Level: intermediate
460: Note:
461: Must be paired with a prior `PetscLogEventBegin()` for the same event.
463: .seealso: `PetscLogEvent`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventSync()`
464: M*/
465: #define PetscLogEventEnd(e, o1, o2, o3, o4) PetscLogEventEnd_Internal(e, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))
467: /* Object functions */
468: /*@
469: PetscLogObjectCreate - Notify the active `PetscLogHandler`s that a new `PetscObject` has been created
471: Not Collective; No Fortran Support
473: Input Parameter:
474: . o - the newly created `PetscObject`
476: Level: developer
478: Note:
479: Called internally by PETSc object constructors; users normally do not need to call this directly.
481: .seealso: `PetscLogObjectDestroy()`, `PetscLogHandler`, `PetscObject`
482: @*/
483: static inline PetscErrorCode PetscLogObjectCreate(PetscObject o)
484: {
485: if (petsc_log_state) {
486: for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
487: PetscLogHandlerHot *h = &PetscLogHandlers[i];
488: if (h->objectCreate) {
489: PetscErrorCode err = (*h->objectCreate)(h->handler, o);
490: if (err != PETSC_SUCCESS) return err;
491: }
492: }
493: }
494: return PETSC_SUCCESS;
495: }
497: /*@
498: PetscLogObjectDestroy - Notify the active `PetscLogHandler`s that a `PetscObject` is being destroyed
500: Not Collective; No Fortran Support
502: Input Parameter:
503: . o - the `PetscObject` that is being destroyed
505: Level: developer
507: Note:
508: Called internally by PETSc object destructors; users normally do not need to call this directly.
510: .seealso: `PetscLogObjectCreate()`, `PetscLogHandler`, `PetscObject`
511: @*/
512: static inline PetscErrorCode PetscLogObjectDestroy(PetscObject o)
513: {
514: if (petsc_log_state) {
515: for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
516: PetscLogHandlerHot *h = &PetscLogHandlers[i];
517: if (h->objectDestroy) {
518: PetscErrorCode err = (*h->objectDestroy)(h->handler, o);
519: if (err != PETSC_SUCCESS) return err;
520: }
521: }
522: }
523: return PETSC_SUCCESS;
524: }
526: /*
527: Flop counting: We count each arithmetic operation (e.g., addition, multiplication) separately.
529: For the complex numbers version, note that
530: 1 complex addition = 2 flops
531: 1 complex multiplication = 6 flops,
532: where we define 1 flop as that for a double precision scalar. We roughly approximate
533: flop counting for complex numbers by multiplying the total flops by 4; this corresponds
534: to the assumption that we're counting mostly additions and multiplications -- and
535: roughly the same number of each. More accurate counting could be done by distinguishing
536: among the various arithmetic operations.
537: */
539: #if PetscDefined(USE_COMPLEX)
540: #define PETSC_FLOPS_PER_OP 4.0
541: #else
542: #define PETSC_FLOPS_PER_OP 1.0
543: #endif
545: /*@
546: PetscLogFlops - Log how many flops are performed in a calculation
548: Not Collective
550: Input Parameter:
551: . n - the number of flops
553: Level: intermediate
555: Note:
556: To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double,
557: not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n)
559: .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`
560: @*/
561: static inline PetscErrorCode PetscLogFlops(PetscLogDouble n)
562: {
563: PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
564: return PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n);
565: }
567: /*
568: These are used internally in the PETSc routines to keep a count of MPI messages and
569: their sizes.
571: This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file
572: uses macros to defined the MPI operations.
574: It does not work correctly from HP-UX because it processes the
575: macros in a way that sometimes it double counts, hence
576: PETSC_HAVE_BROKEN_RECURSIVE_MACRO
578: It does not work with Windows because winmpich lacks MPI_Type_size()
579: */
580: #if !defined(MPIUNI_H) && !PetscDefined(HAVE_BROKEN_RECURSIVE_MACRO)
581: /*
582: Logging of MPI activities
583: */
584: /*@
585: PetscMPITypeSize - Atomically add a `PetscLogDouble` value to both a global counter and its per-thread counterpart based on the
586: length of an `MPI_Datatype`
588: Not Collective; No Fortran Support
590: Input Parameters:
591: + count - the length of the array containing a specific `MPI_Datatype`
592: . type - the `MPI_Datatype`
593: . length - pointer to the global counter to update
594: - length_th - pointer to the per-thread counter to update
596: Level: developer
598: Note:
599: When PETSc is built without thread safety this is a fast routine that performs the same update without locking.
601: Developer Note:
602: This should have a better name related to its functionality
604: .seealso: `PetscAddLogDouble()`, `PetscAddLogDoubleCnt()`, `PetscLogFlops()`, `PetscLogDouble`, `PetscMPITypeSizeComm()`
605: @*/
606: static inline PetscErrorCode PetscMPITypeSize(PetscCount count, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
607: {
608: PetscMPIInt typesize;
610: if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
611: PetscCallMPI(MPI_Type_size(type, &typesize));
612: return PetscAddLogDouble(length, length_th, (PetscLogDouble)(count * typesize));
613: }
615: /*@
616: PetscMPITypeSizeComm - Atomically add a `PetscLogDouble` value to both a global counter and its per-thread counterpart based on the
617: length of an `MPI_Datatype`
619: Not Collective; No Fortran Support
621: Input Parameters:
622: + comm - the `MPI_Comm` that shared the communication of the `MPI_Datatype`
623: . counts - the length of the array containing a specific `MPI_Datatype` being sent to each MPI process
624: . type - the `MPI_Datatype`
625: . length - pointer to the global counter to update
626: - length_th - pointer to the per-thread counter to update
628: Level: developer
630: Note:
631: When PETSc is built without thread safety this is a fast routine that performs the same update without locking.
633: Developer Note:
634: This should have a better name related to its functionality
636: .seealso: `PetscAddLogDouble()`, `PetscAddLogDoubleCnt()`, `PetscLogFlops()`, `PetscLogDouble`, `PetscMPITypeSize()`
637: @*/
638: static inline PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, const PetscMPIInt *counts, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
639: {
640: PetscMPIInt typesize, size, p;
641: PetscLogDouble l;
643: if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
644: PetscCallMPI(MPI_Comm_size(comm, &size));
645: PetscCallMPI(MPI_Type_size(type, &typesize));
646: for (p = 0, l = 0.0; p < size; ++p) l += (PetscLogDouble)(counts[p] * typesize);
647: return PetscAddLogDouble(length, length_th, l);
648: }
650: /*
651: Returns 1 if the communicator is parallel else zero
652: */
653: static inline int PetscMPIParallelComm(MPI_Comm comm)
654: {
655: PetscMPIInt size;
656: MPI_Comm_size(comm, &size);
657: return size > 1;
658: }
660: #define MPI_Irecv(buf, count, datatype, source, tag, comm, request) \
661: (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)))
663: #define MPI_Irecv_c(buf, count, datatype, source, tag, comm, request) \
664: (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)))
666: #define MPI_Isend(buf, count, datatype, dest, tag, comm, request) \
667: (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)))
669: #define MPI_Isend_c(buf, count, datatype, dest, tag, comm, request) \
670: (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)))
672: #define MPI_Startall_irecv(count, datatype, number, requests) \
673: (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || ((number) && MPI_Startall((number), (requests))))
675: #define MPI_Startall_isend(count, datatype, number, requests) \
676: (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || ((number) && MPI_Startall((number), (requests))))
678: #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))
680: #define MPI_Recv(buf, count, datatype, source, tag, comm, status) \
681: (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)))
683: #define MPI_Recv_c(buf, count, datatype, source, tag, comm, status) \
684: (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)))
686: #define MPI_Send(buf, count, datatype, dest, tag, comm) \
687: (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)))
689: #define MPI_Send_c(buf, count, datatype, dest, tag, comm) \
690: (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)))
692: #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)))
694: #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)))
696: #define MPI_Waitall(count, array_of_requests, array_of_statuses) \
697: (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)))
699: #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)))
701: #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)))
703: #define MPI_Reduce_scatter_block(sendbuf, recvbuf, recvcount, datatype, op, comm) \
704: (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Reduce_scatter_block((sendbuf), (recvbuf), (recvcount), (datatype), (op), (comm)))
706: #define MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
707: (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)))
709: #define MPI_Alltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm) \
710: (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)))
712: #define MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
713: (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm)))
715: #define MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm) \
716: (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm)))
718: #define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
719: (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)))
721: #define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm) \
722: (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)))
724: #define MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
725: (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)))
727: #define MPI_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
728: (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)))
730: #define MPI_Ialltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
731: (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)))
733: #define MPI_Ialltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm, request) \
734: (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)))
736: #define MPI_Iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
737: (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm), (request)))
739: #define MPI_Iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm, request) \
740: (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm), (request)))
742: #define MPI_Igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
743: (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)))
745: #define MPI_Igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm, request) \
746: (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)))
748: #define MPI_Iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
749: (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)))
751: #define MPI_Iscatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
752: (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)))
754: #define MPIX_Send_enqueue(buf, count, datatype, dest, tag, comm) \
755: (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)))
757: #define MPIX_Recv_enqueue(buf, count, datatype, source, tag, comm, status) \
758: (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)))
760: #define MPIX_Isend_enqueue(buf, count, datatype, dest, tag, comm, request) \
761: (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)))
763: #define MPIX_Irecv_enqueue(buf, count, datatype, source, tag, comm, request) \
764: (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)))
766: #define MPIX_Allreduce_enqueue(sendbuf, recvbuf, count, datatype, op, comm) \
767: (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPIX_Allreduce_enqueue((sendbuf), (recvbuf), (count), (datatype), (op), (comm)))
769: #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)))
771: #define MPIX_Waitall_enqueue(count, array_of_requests, array_of_statuses) \
772: (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)))
773: #else
775: #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests)))
777: #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests)))
779: #define MPI_Start_isend(count, datatype, requests) (MPI_Start(requests))
781: #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
783: #else /* ---Logging is turned off --------------------------------------------*/
785: #define PetscLogGetState(a) (*(a) = NULL, PETSC_SUCCESS)
786: #define PetscLogGetDefaultHandler(a) (*(a) = NULL, PETSC_SUCCESS)
787: #define PetscLogHandlerStart(a) ((void)(a), PETSC_SUCCESS)
788: #define PetscLogHandlerStop(a) ((void)(a), PETSC_SUCCESS)
790: #define PetscLogFlops(n) ((void)(n), PETSC_SUCCESS)
791: #define PetscGetFlops(a) (*(a) = 0.0, PETSC_SUCCESS)
793: #define PetscLogStageRegister(a, b) ((void)(a), *(b) = -1, PETSC_SUCCESS)
794: #define PetscLogStagePush(a) ((void)(a), PETSC_SUCCESS)
795: #define PetscLogStagePop() PETSC_SUCCESS
796: #define PetscLogStageSetActive(a, b) ((void)(a), (void)(b), PETSC_SUCCESS)
797: #define PetscLogStageGetActive(a, b) ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
798: #define PetscLogStageGetVisible(a, b) ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
799: #define PetscLogStageSetVisible(a, b) ((void)(a), (void)(b), PETSC_SUCCESS)
800: #define PetscLogStageGetId(a, b) ((void)(a), *(b) = -1, PETSC_SUCCESS)
801: #define PetscLogStageGetName(a, b) ((void)(a), *(b) = NULL, PETSC_SUCCESS)
802: #define PetscLogStageGetPerfInfo(a, b) ((void)(a), *(b) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)
804: #define PetscLogEventRegister(a, b, c) ((void)(a), (void)(b), *(c) = -1, PETSC_SUCCESS)
805: #define PetscLogEventSetCollective(a, b) ((void)(a), (void)(b), PETSC_SUCCESS)
806: #define PetscLogEventIncludeClass(a) ((void)(a), PETSC_SUCCESS)
807: #define PetscLogEventExcludeClass(a) ((void)(a), PETSC_SUCCESS)
808: #define PetscLogEventActivate(a) ((void)(a), PETSC_SUCCESS)
809: #define PetscLogEventDeactivate(a) ((void)(a), PETSC_SUCCESS)
810: #define PetscLogEventDeactivatePush(a) ((void)(a), PETSC_SUCCESS)
811: #define PetscLogEventDeactivatePop(a) ((void)(a), PETSC_SUCCESS)
812: #define PetscLogEventActivateClass(a) ((void)(a), PETSC_SUCCESS)
813: #define PetscLogEventDeactivateClass(a) ((void)(a), PETSC_SUCCESS)
814: #define PetscLogEventSetActiveAll(a, b) ((void)(a), PETSC_SUCCESS)
815: #define PetscLogEventGetId(a, b) ((void)(a), *(b) = -1, PETSC_SUCCESS)
816: #define PetscLogEventGetName(a, b) ((void)(a), *(b) = NULL, PETSC_SUCCESS)
817: #define PetscLogEventGetPerfInfo(a, b, c) ((void)(a), (void)(b), *(c) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)
819: #define PetscLogEventSetDof(a, b, c) ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
820: #define PetscLogEventSetError(a, b, c) ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
821: #define PetscLogEventsPause() PETSC_SUCCESS
822: #define PetscLogEventsResume() PETSC_SUCCESS
824: #define PetscLogClassGetClassId(a, b) (*(b) = -1, PETSC_SUCCESS)
825: #define PetscLogClassIdGetName(a, b) (*(b) = NULL, PETSC_SUCCESS)
827: #define PetscLogObjectCreate(h) ((void)(h), PETSC_SUCCESS)
828: #define PetscLogObjectDestroy(h) ((void)(h), PETSC_SUCCESS)
829: #define PetscLogObjectState(h, c, ...) ((void)(h), (void)(c), PETSC_SUCCESS)
831: #define PetscLogDefaultBegin() PETSC_SUCCESS
832: #define PetscLogNestedBegin() PETSC_SUCCESS
833: #define PetscLogTraceBegin(file) ((void)(file), PETSC_SUCCESS)
834: #define PetscLogMPEBegin() PETSC_SUCCESS
835: #define PetscLogPerfstubsBegin() PETSC_SUCCESS
836: #define PetscLogLegacyCallbacksBegin(a, b, c, d) ((void)(a), (void)(b), (void)(c), (void)(d), PETSC_SUCCESS)
837: #define PetscLogActions(a) ((void)(a), PETSC_SUCCESS)
838: #define PetscLogObjects(a) ((void)(a), PETSC_SUCCESS)
839: #define PetscLogSetThreshold(a, b) ((void)(a), (void)(b), PETSC_SUCCESS)
841: #define PetscLogIsActive(flag) (*(flag) = PETSC_FALSE, PETSC_SUCCESS)
843: #define PetscLogView(viewer) ((void)(viewer), PETSC_SUCCESS)
844: #define PetscLogViewFromOptions() PETSC_SUCCESS
845: #define PetscLogDump(c) ((void)(c), PETSC_SUCCESS)
846: #define PetscLogMPEDump(c) ((void)(c), PETSC_SUCCESS)
848: #define PetscLogEventSync(e, comm) ((void)(e), (void)(comm), PETSC_SUCCESS)
849: #define PetscLogEventBegin(e, o1, o2, o3, o4) ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)
850: #define PetscLogEventEnd(e, o1, o2, o3, o4) ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)
852: /* If PETSC_USE_LOG is NOT defined, these still need to be! */
853: #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
854: #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
855: #define MPI_Start_isend(count, datatype, requests) MPI_Start(requests)
857: #endif /* PETSC_USE_LOG */
859: #if PetscDefined(USE_LOG) && PetscDefined(HAVE_DEVICE)
861: PETSC_EXTERN PetscErrorCode PetscLogGpuTime(void);
862: PETSC_EXTERN PetscErrorCode PetscLogGpuTimeBegin(void);
863: PETSC_EXTERN PetscErrorCode PetscLogGpuTimeEnd(void);
864: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergy(void);
865: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeter(void);
866: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeterBegin(void);
867: PETSC_EXTERN PetscErrorCode PetscLogGpuEnergyMeterEnd(void);
869: /*@
870: PetscLogGpuFlops - Log how many flops are performed in a calculation on the device
872: Not Collective
874: Input Parameter:
875: . n - the number of flops
877: Level: intermediate
879: Notes:
880: To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double,
881: not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n)
883: The values are also added to the total flop count for the MPI rank that is set with `PetscLogFlops()`; hence the number of flops
884: just on the CPU would be the value from set from `PetscLogFlops()` minus the value set from `PetscLogGpuFlops()`
886: .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogFlops()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`
887: @*/
888: static inline PetscErrorCode PetscLogGpuFlops(PetscLogDouble n)
889: {
890: PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
891: PetscCall(PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n));
892: PetscCall(PetscAddLogDouble(&petsc_gflops, &petsc_gflops_th, PETSC_FLOPS_PER_OP * n));
893: return PETSC_SUCCESS;
894: }
896: /*@
897: PetscLogGpuTimeAdd - Add elapsed GPU computation time to PETSc's GPU time counter
899: Not Collective; No Fortran Support
901: Input Parameter:
902: . t - the elapsed time, in seconds, to add to the GPU time counter
904: Level: developer
906: Note:
907: Used internally by GPU backends to report the time spent in a kernel or library call.
909: .seealso: `PetscLogGpuTime()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`, `PetscLogGpuFlops()`
910: @*/
911: static inline PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t)
912: {
913: return PetscAddLogDouble(&petsc_gtime, &petsc_gtime_th, t);
914: }
916: /*@
917: PetscLogCpuToGpu - Log a CPU-to-GPU memory transfer for performance reporting
919: Not Collective; No Fortran Support
921: Input Parameter:
922: . size - number of bytes transferred from CPU to GPU
924: Level: developer
926: Note:
927: Updates both the transfer-count and transfer-size counters used by `PetscLogView()`.
929: .seealso: `PetscLogGpuToCpu()`, `PetscLogCpuToGpuScalar()`, `PetscLogGpuFlops()`
930: @*/
931: static inline PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size)
932: {
933: return PetscAddLogDoubleCnt(&petsc_ctog_ct, &petsc_ctog_sz, &petsc_ctog_ct_th, &petsc_ctog_sz_th, size);
934: }
936: /*@
937: PetscLogGpuToCpu - Log a GPU-to-CPU memory transfer for performance reporting
939: Not Collective; No Fortran Support
941: Input Parameter:
942: . size - number of bytes transferred from GPU to CPU
944: Level: developer
946: .seealso: `PetscLogCpuToGpu()`, `PetscLogGpuToCpuScalar()`, `PetscLogGpuFlops()`
947: @*/
948: static inline PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size)
949: {
950: return PetscAddLogDoubleCnt(&petsc_gtoc_ct, &petsc_gtoc_sz, &petsc_gtoc_ct_th, &petsc_gtoc_sz_th, size);
951: }
953: /*@
954: PetscLogCpuToGpuScalar - Log a CPU-to-GPU memory transfer of `PetscScalar` data for performance reporting
956: Not Collective; No Fortran Support
958: Input Parameter:
959: . size - number of bytes of scalar data transferred from CPU to GPU
961: Level: developer
963: Note:
964: Tracks scalar-only transfers separately from generic byte counters tracked by `PetscLogCpuToGpu()`.
966: .seealso: `PetscLogCpuToGpu()`, `PetscLogGpuToCpuScalar()`
967: @*/
968: static inline PetscErrorCode PetscLogCpuToGpuScalar(PetscLogDouble size)
969: {
970: return PetscAddLogDoubleCnt(&petsc_ctog_ct_scalar, &petsc_ctog_sz_scalar, &petsc_ctog_ct_scalar_th, &petsc_ctog_sz_scalar_th, size);
971: }
973: /*@
974: PetscLogGpuToCpuScalar - Log a GPU-to-CPU memory transfer of `PetscScalar` data for performance reporting
976: Not Collective; No Fortran Support
978: Input Parameter:
979: . size - number of bytes of scalar data transferred from GPU to CPU
981: Level: developer
983: .seealso: `PetscLogGpuToCpu()`, `PetscLogCpuToGpuScalar()`
984: @*/
985: static inline PetscErrorCode PetscLogGpuToCpuScalar(PetscLogDouble size)
986: {
987: return PetscAddLogDoubleCnt(&petsc_gtoc_ct_scalar, &petsc_gtoc_sz_scalar, &petsc_gtoc_ct_scalar_th, &petsc_gtoc_sz_scalar_th, size);
988: }
989: #else
991: #define PetscLogCpuToGpu(a) ((void)(a), PETSC_SUCCESS)
992: #define PetscLogGpuToCpu(a) ((void)(a), PETSC_SUCCESS)
993: #define PetscLogCpuToGpuScalar(a) ((void)(a), PETSC_SUCCESS)
994: #define PetscLogGpuToCpuScalar(a) ((void)(a), PETSC_SUCCESS)
995: #define PetscLogGpuFlops(a) ((void)(a), PETSC_SUCCESS)
996: #define PetscLogGpuTimeAdd(a) ((void)(a), PETSC_SUCCESS)
997: #define PetscLogGpuTime() PETSC_SUCCESS
998: #define PetscLogGpuTimeBegin() PETSC_SUCCESS
999: #define PetscLogGpuTimeEnd() PETSC_SUCCESS
1001: #define PetscLogGpuEnergy() PETSC_SUCCESS
1002: #define PetscLogGpuEnergyMeter() PETSC_SUCCESS
1003: #define PetscLogGpuEnergyMeterBegin() PETSC_SUCCESS
1004: #define PetscLogGpuEnergyMeterEnd() PETSC_SUCCESS
1006: #endif /* PETSC_USE_LOG && PETSC_HAVE_DEVICE */
1008: #include <petsclogdeprecated.h>