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 defined(PETSC_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 *);
     79: PETSC_EXTERN PetscErrorCode PetscLogStateGetRegistry(PetscLogState, PetscLogRegistry *);

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

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

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

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

    109: PETSC_EXTERN PetscClassId PETSCLOGHANDLER_CLASSID;

    111: PETSC_EXTERN PetscFunctionList PetscLogHandlerList;

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

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

    143: PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateTrace(MPI_Comm, FILE *, PetscLogHandler *);
    144: 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 *);

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

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

    153:   Not Collective; No Fortran Support

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

    160:   Level: developer

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

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

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

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

    177:   Not Collective; No Fortran Support

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

    183:   Level: developer

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

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

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

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

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

    232:   Not Collective; No Fortran Support

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

    239:   Level: developer

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

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

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

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

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

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

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

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

    320: PETSC_EXTERN PetscLogState petsc_log_state;

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

    325: #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/
    326: PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);

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

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

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

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

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

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

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

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

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

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

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

    400:   Level: developer

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

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

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

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

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

    443:     Not Collective; No Fortran Support

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

    452:     Level: intermediate

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

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

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

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

    482:     Not Collective; No Fortran Support

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

    491:     Level: intermediate

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

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

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

    504:   Not Collective; No Fortran Support

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

    509:   Level: developer

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

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

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

    533:   Not Collective; No Fortran Support

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

    538:   Level: developer

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

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

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

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

    572:   #if defined(PETSC_USE_COMPLEX)
    573:     #define PETSC_FLOPS_PER_OP 4.0
    574:   #else
    575:     #define PETSC_FLOPS_PER_OP 1.0
    576:   #endif

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

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

    584:    Level: intermediate

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    757:     #define MPIX_Waitall_enqueue(count, array_of_requests, array_of_statuses) \
    758:       (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)))
    759:   #else

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    843: #endif /* PETSC_USE_LOG */

    845: /*MC
    846:   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

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

    852:   Not Collective; No Fortran Support

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

    858:   Level: intermediate

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

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

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

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

    895:   Not Collective; No Fortran Support

    897:   Level: intermediate

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

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

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

    914:   Not Collective; No Fortran Support

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

    919:   Level: intermediate

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

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

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

    940: #if defined(PETSC_USE_LOG) && defined(PETSC_HAVE_DEVICE)

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

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

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

    956:    Level: intermediate

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

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

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

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

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

    981:   Not Collective; No Fortran Support

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

    986:   Level: developer

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

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

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

    1001:   Not Collective; No Fortran Support

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

    1006:   Level: developer

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

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

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

    1021:   Not Collective; No Fortran Support

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

    1026:   Level: developer

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

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

    1038:   Not Collective; No Fortran Support

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

    1043:   Level: developer

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

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

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

    1058:   Not Collective; No Fortran Support

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

    1063:   Level: developer

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

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

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

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

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

    1094: #include <petsclogdeprecated.h>