LCOV - code coverage report
Current view: top level - home/gitlab-runner/builds/q8svuz_Y/0/slepc/petsc/include - petsclog.h (source / functions) Hit Total Coverage
Test: SLEPc Lines: 26 26 100.0 %
Date: 2024-05-08 00:46:20 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :     Defines profile/logging in PETSc.
       3             : */
       4             : #pragma once
       5             : 
       6             : #include <petscsys.h>
       7             : #include <petsctime.h>
       8             : #include <petscbt.h>
       9             : #include <petsclogtypes.h>
      10             : 
      11             : /* SUBMANSEC = Profiling */
      12             : 
      13             : /* General logging of information; different from event logging */
      14             : PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[], PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(3, 4);
      15             : #if defined(PETSC_USE_INFO)
      16             :   #define PetscInfo(A, ...) PetscInfo_Private(PETSC_FUNCTION_NAME, ((PetscObject)A), __VA_ARGS__)
      17             : #else
      18             :   #define PetscInfo(A, ...) PETSC_SUCCESS
      19             : #endif
      20             : 
      21             : #define PetscInfo1(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      22             : #define PetscInfo2(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      23             : #define PetscInfo3(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      24             : #define PetscInfo4(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      25             : #define PetscInfo5(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      26             : #define PetscInfo6(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      27             : #define PetscInfo7(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      28             : #define PetscInfo8(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      29             : #define PetscInfo9(...) PETSC_DEPRECATED_MACRO(3, 17, 0, "PetscInfo()", ) PetscInfo(__VA_ARGS__)
      30             : 
      31             : /*E
      32             :   PetscInfoCommFlag - Describes the method by which to filter information displayed by `PetscInfo()` by communicator size
      33             : 
      34             :   Values:
      35             : + `PETSC_INFO_COMM_ALL`       - Default uninitialized value. `PetscInfo()` will not filter based on
      36             :                                 communicator size (i.e. will print for all communicators)
      37             : . `PETSC_INFO_COMM_NO_SELF`   - `PetscInfo()` will NOT print for communicators with size = 1 (i.e. *_COMM_SELF)
      38             : - `PETSC_INFO_COMM_ONLY_SELF` - `PetscInfo()` will ONLY print for communicators with size = 1
      39             : 
      40             :   Level: intermediate
      41             : 
      42             :   Note:
      43             :   Used as an input for `PetscInfoSetFilterCommSelf()`
      44             : 
      45             : .seealso: `PetscInfo()`, `PetscInfoSetFromOptions()`, `PetscInfoSetFilterCommSelf()`
      46             : E*/
      47             : typedef enum {
      48             :   PETSC_INFO_COMM_ALL       = -1,
      49             :   PETSC_INFO_COMM_NO_SELF   = 0,
      50             :   PETSC_INFO_COMM_ONLY_SELF = 1
      51             : } PetscInfoCommFlag;
      52             : 
      53             : PETSC_EXTERN const char *const PetscInfoCommFlags[];
      54             : PETSC_EXTERN PetscErrorCode    PetscInfoDeactivateClass(PetscClassId);
      55             : PETSC_EXTERN PetscErrorCode    PetscInfoActivateClass(PetscClassId);
      56             : PETSC_EXTERN PetscErrorCode    PetscInfoEnabled(PetscClassId, PetscBool *);
      57             : PETSC_EXTERN PetscErrorCode    PetscInfoAllow(PetscBool);
      58             : PETSC_EXTERN PetscErrorCode    PetscInfoSetFile(const char[], const char[]);
      59             : PETSC_EXTERN PetscErrorCode    PetscInfoGetFile(char **, FILE **);
      60             : PETSC_EXTERN PetscErrorCode    PetscInfoSetClasses(PetscBool, PetscInt, const char *const *);
      61             : PETSC_EXTERN PetscErrorCode    PetscInfoGetClass(const char *, PetscBool *);
      62             : PETSC_EXTERN PetscErrorCode    PetscInfoGetInfo(PetscBool *, PetscBool *, PetscBool *, PetscBool *, PetscInfoCommFlag *);
      63             : PETSC_EXTERN PetscErrorCode    PetscInfoProcessClass(const char[], PetscInt, const PetscClassId[]);
      64             : PETSC_EXTERN PetscErrorCode    PetscInfoSetFilterCommSelf(PetscInfoCommFlag);
      65             : PETSC_EXTERN PetscErrorCode    PetscInfoSetFromOptions(PetscOptions);
      66             : PETSC_EXTERN PetscErrorCode    PetscInfoDestroy(void);
      67             : PETSC_EXTERN PetscBool         PetscLogPrintInfo; /* if true, indicates PetscInfo() is turned on */
      68             : 
      69             : PETSC_EXTERN PetscErrorCode PetscIntStackCreate(PetscIntStack *);
      70             : PETSC_EXTERN PetscErrorCode PetscIntStackDestroy(PetscIntStack);
      71             : PETSC_EXTERN PetscErrorCode PetscIntStackPush(PetscIntStack, int);
      72             : PETSC_EXTERN PetscErrorCode PetscIntStackPop(PetscIntStack, int *);
      73             : PETSC_EXTERN PetscErrorCode PetscIntStackTop(PetscIntStack, int *);
      74             : PETSC_EXTERN PetscErrorCode PetscIntStackEmpty(PetscIntStack, PetscBool *);
      75             : 
      76             : PETSC_EXTERN PetscErrorCode PetscLogStateCreate(PetscLogState *);
      77             : PETSC_EXTERN PetscErrorCode PetscLogStateDestroy(PetscLogState *);
      78             : PETSC_EXTERN PetscErrorCode PetscLogStateGetRegistry(PetscLogState, PetscLogRegistry *);
      79             : 
      80             : PETSC_EXTERN PetscErrorCode PetscLogStateClassRegister(PetscLogState, const char[], PetscClassId, PetscLogStage *);
      81             : PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActive(PetscLogState, PetscLogStage, PetscClassId, PetscBool);
      82             : PETSC_EXTERN PetscErrorCode PetscLogStateClassSetActiveAll(PetscLogState, PetscClassId, PetscBool);
      83             : 
      84             : PETSC_EXTERN PetscErrorCode PetscLogStateStageRegister(PetscLogState, const char[], PetscLogStage *);
      85             : PETSC_EXTERN PetscErrorCode PetscLogStateStagePush(PetscLogState, PetscLogStage);
      86             : PETSC_EXTERN PetscErrorCode PetscLogStateStagePop(PetscLogState);
      87             : PETSC_EXTERN PetscErrorCode PetscLogStateStageSetActive(PetscLogState, PetscLogStage, PetscBool);
      88             : PETSC_EXTERN PetscErrorCode PetscLogStateStageGetActive(PetscLogState, PetscLogStage, PetscBool *);
      89             : PETSC_EXTERN PetscErrorCode PetscLogStateGetCurrentStage(PetscLogState, PetscLogStage *);
      90             : 
      91             : PETSC_EXTERN PetscErrorCode PetscLogStateEventRegister(PetscLogState, const char[], PetscClassId, PetscLogEvent *);
      92             : PETSC_EXTERN PetscErrorCode PetscLogStateEventSetCollective(PetscLogState, PetscLogEvent, PetscBool);
      93             : PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool);
      94             : PETSC_EXTERN PetscErrorCode PetscLogStateEventSetActiveAll(PetscLogState, PetscLogEvent, PetscBool);
      95             : PETSC_EXTERN PetscErrorCode PetscLogStateEventGetActive(PetscLogState, PetscLogStage, PetscLogEvent, PetscBool *);
      96             : 
      97             : PETSC_EXTERN PetscErrorCode PetscLogStateGetEventFromName(PetscLogState, const char[], PetscLogEvent *);
      98             : PETSC_EXTERN PetscErrorCode PetscLogStateGetStageFromName(PetscLogState, const char[], PetscLogStage *);
      99             : PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromName(PetscLogState, const char[], PetscLogClass *);
     100             : PETSC_EXTERN PetscErrorCode PetscLogStateGetClassFromClassId(PetscLogState, PetscClassId, PetscLogClass *);
     101             : PETSC_EXTERN PetscErrorCode PetscLogStateGetNumEvents(PetscLogState, PetscInt *);
     102             : PETSC_EXTERN PetscErrorCode PetscLogStateGetNumStages(PetscLogState, PetscInt *);
     103             : PETSC_EXTERN PetscErrorCode PetscLogStateGetNumClasses(PetscLogState, PetscInt *);
     104             : PETSC_EXTERN PetscErrorCode PetscLogStateEventGetInfo(PetscLogState, PetscLogEvent, PetscLogEventInfo *);
     105             : PETSC_EXTERN PetscErrorCode PetscLogStateStageGetInfo(PetscLogState, PetscLogStage, PetscLogStageInfo *);
     106             : PETSC_EXTERN PetscErrorCode PetscLogStateClassGetInfo(PetscLogState, PetscLogClass, PetscLogClassInfo *);
     107             : 
     108             : PETSC_EXTERN PetscClassId PETSCLOGHANDLER_CLASSID;
     109             : 
     110             : PETSC_EXTERN PetscFunctionList PetscLogHandlerList;
     111             : 
     112             : PETSC_EXTERN PetscErrorCode PetscLogHandlerRegister(const char[], PetscErrorCode (*)(PetscLogHandler));
     113             : PETSC_EXTERN PetscErrorCode PetscLogHandlerCreate(MPI_Comm, PetscLogHandler *);
     114             : PETSC_EXTERN PetscErrorCode PetscLogHandlerSetType(PetscLogHandler, PetscLogHandlerType);
     115             : PETSC_EXTERN PetscErrorCode PetscLogHandlerGetType(PetscLogHandler, PetscLogHandlerType *);
     116             : PETSC_EXTERN PetscErrorCode PetscLogHandlerDestroy(PetscLogHandler *);
     117             : PETSC_EXTERN PetscErrorCode PetscLogHandlerSetState(PetscLogHandler, PetscLogState);
     118             : PETSC_EXTERN PetscErrorCode PetscLogHandlerGetState(PetscLogHandler, PetscLogState *);
     119             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventBegin(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
     120             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventEnd(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
     121             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventSync(PetscLogHandler, PetscLogEvent, MPI_Comm);
     122             : PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectCreate(PetscLogHandler, PetscObject);
     123             : PETSC_EXTERN PetscErrorCode PetscLogHandlerObjectDestroy(PetscLogHandler, PetscObject);
     124             : PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePush(PetscLogHandler, PetscLogStage);
     125             : PETSC_EXTERN PetscErrorCode PetscLogHandlerStagePop(PetscLogHandler, PetscLogStage);
     126             : PETSC_EXTERN PetscErrorCode PetscLogHandlerView(PetscLogHandler, PetscViewer);
     127             : 
     128             : PETSC_EXTERN PetscErrorCode PetscLogHandlerGetEventPerfInfo(PetscLogHandler, PetscLogStage, PetscLogEvent, PetscEventPerfInfo **);
     129             : PETSC_EXTERN PetscErrorCode PetscLogHandlerGetStagePerfInfo(PetscLogHandler, PetscLogStage, PetscEventPerfInfo **);
     130             : PETSC_EXTERN PetscErrorCode PetscLogHandlerSetLogActions(PetscLogHandler, PetscBool);
     131             : PETSC_EXTERN PetscErrorCode PetscLogHandlerSetLogObjects(PetscLogHandler, PetscBool);
     132             : PETSC_EXTERN PetscErrorCode PetscLogHandlerLogObjectState(PetscLogHandler, PetscObject, const char[], ...);
     133             : PETSC_EXTERN PetscErrorCode PetscLogHandlerGetNumObjects(PetscLogHandler, PetscInt *);
     134             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventDeactivatePush(PetscLogHandler, PetscLogStage, PetscLogEvent);
     135             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventDeactivatePop(PetscLogHandler, PetscLogStage, PetscLogEvent);
     136             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventsPause(PetscLogHandler);
     137             : PETSC_EXTERN PetscErrorCode PetscLogHandlerEventsResume(PetscLogHandler);
     138             : PETSC_EXTERN PetscErrorCode PetscLogHandlerDump(PetscLogHandler, const char[]);
     139             : PETSC_EXTERN PetscErrorCode PetscLogHandlerStageSetVisible(PetscLogHandler, PetscLogStage, PetscBool);
     140             : PETSC_EXTERN PetscErrorCode PetscLogHandlerStageGetVisible(PetscLogHandler, PetscLogStage, PetscBool *);
     141             : 
     142             : PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateTrace(MPI_Comm, FILE *, PetscLogHandler *);
     143             : PETSC_EXTERN PetscErrorCode PetscLogHandlerCreateLegacy(MPI_Comm, PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscObject), PetscErrorCode (*)(PetscObject), PetscLogHandler *);
     144             : 
     145             : /* All events are inactive if an invalid stage is set, like if there have been more stage pops than stage pushes */
     146             : #define PetscLogStateStageEventIsActive(state, stage, event) ((stage >= 0) && PetscBTLookup((state)->active, (stage)) && PetscBTLookup((state)->active, (stage) + (event + 1) * (state)->bt_num_stages))
     147             : #define PetscLogStateEventCurrentlyActive(state, event)      ((state) && PetscLogStateStageEventIsActive(state, (state)->current_stage, event))
     148             : 
     149             : /* PetscLogHandler with critical methods exposed for speed */
     150             : typedef struct _n_PetscLogHandlerHot {
     151             :   PetscLogHandler handler;
     152             :   PetscErrorCode (*eventBegin)(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
     153             :   PetscErrorCode (*eventEnd)(PetscLogHandler, PetscLogEvent, PetscObject, PetscObject, PetscObject, PetscObject);
     154             :   PetscErrorCode (*eventSync)(PetscLogHandler, PetscLogEvent, MPI_Comm);
     155             :   PetscErrorCode (*objectCreate)(PetscLogHandler, PetscObject);
     156             :   PetscErrorCode (*objectDestroy)(PetscLogHandler, PetscObject);
     157             : } PetscLogHandlerHot;
     158             : 
     159             : /* Handle multithreading */
     160             : #if defined(PETSC_HAVE_THREADSAFETY)
     161             :   #if defined(__cplusplus)
     162             :     #define PETSC_TLS thread_local
     163             :   #else
     164             :     #define PETSC_TLS _Thread_local
     165             :   #endif
     166             :   #define PETSC_EXTERN_TLS extern PETSC_TLS PETSC_VISIBILITY_PUBLIC
     167             : PETSC_EXTERN PetscErrorCode PetscAddLogDouble(PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
     168             : PETSC_EXTERN PetscErrorCode PetscAddLogDoubleCnt(PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble *, PetscLogDouble);
     169             : #else
     170             :   #define PETSC_EXTERN_TLS PETSC_EXTERN
     171             :   #define PETSC_TLS
     172             :   #define PetscAddLogDouble(a, b, c)          ((PetscErrorCode)((*(a) += (c), PETSC_SUCCESS) || ((*(b) += (c)), PETSC_SUCCESS)))
     173             :   #define PetscAddLogDoubleCnt(a, b, c, d, e) ((PetscErrorCode)(PetscAddLogDouble(a, c, 1) || PetscAddLogDouble(b, d, e)))
     174             : #endif
     175             : 
     176             : PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectParent()", ) static inline PetscErrorCode PetscLogObjectParent(PetscObject o, PetscObject p)
     177             : {
     178             :   (void)o;
     179             :   (void)p;
     180             :   return PETSC_SUCCESS;
     181             : }
     182             : #define PetscLogObjectParents(p, n, d) PetscMacroReturnStandard(for (int _i = 0; _i < (n); ++_i) PetscCall(PetscLogObjectParent((PetscObject)(p), (PetscObject)(d)[_i]));)
     183             : 
     184             : PETSC_DEPRECATED_FUNCTION(3, 18, 0, "PetscLogObjectMemory()", ) static inline PetscErrorCode PetscLogObjectMemory(PetscObject o, PetscLogDouble m)
     185             : {
     186             :   (void)o;
     187             :   (void)m;
     188             :   return PETSC_SUCCESS;
     189             : }
     190             : 
     191             : /* Global flop counter */
     192             : PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
     193             : PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
     194             : PETSC_EXTERN PetscLogDouble petsc_isend_ct;
     195             : PETSC_EXTERN PetscLogDouble petsc_recv_ct;
     196             : PETSC_EXTERN PetscLogDouble petsc_send_ct;
     197             : PETSC_EXTERN PetscLogDouble petsc_irecv_len;
     198             : PETSC_EXTERN PetscLogDouble petsc_isend_len;
     199             : PETSC_EXTERN PetscLogDouble petsc_recv_len;
     200             : PETSC_EXTERN PetscLogDouble petsc_send_len;
     201             : PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
     202             : PETSC_EXTERN PetscLogDouble petsc_gather_ct;
     203             : PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
     204             : PETSC_EXTERN PetscLogDouble petsc_wait_ct;
     205             : PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
     206             : PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
     207             : PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;
     208             : 
     209             : /* Thread local storage */
     210             : PETSC_EXTERN_TLS PetscLogDouble petsc_TotalFlops_th;
     211             : PETSC_EXTERN_TLS PetscLogDouble petsc_irecv_ct_th;
     212             : PETSC_EXTERN_TLS PetscLogDouble petsc_isend_ct_th;
     213             : PETSC_EXTERN_TLS PetscLogDouble petsc_recv_ct_th;
     214             : PETSC_EXTERN_TLS PetscLogDouble petsc_send_ct_th;
     215             : PETSC_EXTERN_TLS PetscLogDouble petsc_irecv_len_th;
     216             : PETSC_EXTERN_TLS PetscLogDouble petsc_isend_len_th;
     217             : PETSC_EXTERN_TLS PetscLogDouble petsc_recv_len_th;
     218             : PETSC_EXTERN_TLS PetscLogDouble petsc_send_len_th;
     219             : PETSC_EXTERN_TLS PetscLogDouble petsc_allreduce_ct_th;
     220             : PETSC_EXTERN_TLS PetscLogDouble petsc_gather_ct_th;
     221             : PETSC_EXTERN_TLS PetscLogDouble petsc_scatter_ct_th;
     222             : PETSC_EXTERN_TLS PetscLogDouble petsc_wait_ct_th;
     223             : PETSC_EXTERN_TLS PetscLogDouble petsc_wait_any_ct_th;
     224             : PETSC_EXTERN_TLS PetscLogDouble petsc_wait_all_ct_th;
     225             : PETSC_EXTERN_TLS PetscLogDouble petsc_sum_of_waits_ct_th;
     226             : 
     227             : /* Global GPU counters */
     228             : PETSC_EXTERN PetscLogDouble petsc_ctog_ct;
     229             : PETSC_EXTERN PetscLogDouble petsc_gtoc_ct;
     230             : PETSC_EXTERN PetscLogDouble petsc_ctog_sz;
     231             : PETSC_EXTERN PetscLogDouble petsc_gtoc_sz;
     232             : PETSC_EXTERN PetscLogDouble petsc_ctog_ct_scalar;
     233             : PETSC_EXTERN PetscLogDouble petsc_gtoc_ct_scalar;
     234             : PETSC_EXTERN PetscLogDouble petsc_ctog_sz_scalar;
     235             : PETSC_EXTERN PetscLogDouble petsc_gtoc_sz_scalar;
     236             : PETSC_EXTERN PetscLogDouble petsc_gflops;
     237             : PETSC_EXTERN PetscLogDouble petsc_gtime;
     238             : 
     239             : /* Thread local storage */
     240             : PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_ct_th;
     241             : PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_ct_th;
     242             : PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_sz_th;
     243             : PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_sz_th;
     244             : PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_ct_scalar_th;
     245             : PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_ct_scalar_th;
     246             : PETSC_EXTERN_TLS PetscLogDouble petsc_ctog_sz_scalar_th;
     247             : PETSC_EXTERN_TLS PetscLogDouble petsc_gtoc_sz_scalar_th;
     248             : PETSC_EXTERN_TLS PetscLogDouble petsc_gflops_th;
     249             : PETSC_EXTERN_TLS PetscLogDouble petsc_gtime_th;
     250             : 
     251             : PETSC_EXTERN PetscBool PetscLogMemory;
     252             : PETSC_EXTERN PetscBool PetscLogSyncOn; /* true if logging synchronization is enabled */
     253             : 
     254             : PETSC_EXTERN PetscLogState petsc_log_state;
     255             : 
     256             : #define PETSC_LOG_HANDLER_MAX 4
     257             : PETSC_EXTERN PetscLogHandlerHot PetscLogHandlers[PETSC_LOG_HANDLER_MAX];
     258             : 
     259             : #if defined(PETSC_USE_LOG) /* --- Logging is turned on --------------------------------*/
     260             : PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
     261             : 
     262             : PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...) PETSC_ATTRIBUTE_FORMAT(2, 3);
     263             : 
     264             : /* Initialization functions */
     265             : PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
     266             : PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
     267             : PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
     268             : PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
     269             : PETSC_EXTERN PetscErrorCode PetscLogPerfstubsBegin(void);
     270             : PETSC_EXTERN PetscErrorCode PetscLogLegacyCallbacksBegin(PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject), PetscErrorCode (*)(PetscObject), PetscErrorCode (*)(PetscObject));
     271             : PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
     272             : PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
     273             : PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble, PetscLogDouble *);
     274             : 
     275             : /* Output functions */
     276             : PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
     277             : PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
     278             : PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);
     279             : PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
     280             : 
     281             : PETSC_EXTERN PetscErrorCode PetscLogGetState(PetscLogState *);
     282             : PETSC_EXTERN PetscErrorCode PetscLogGetDefaultHandler(PetscLogHandler *);
     283             : PETSC_EXTERN PetscErrorCode PetscLogHandlerStart(PetscLogHandler);
     284             : PETSC_EXTERN PetscErrorCode PetscLogHandlerStop(PetscLogHandler);
     285             : 
     286             : /* Status checking functions */
     287             : PETSC_EXTERN PetscErrorCode PetscLogIsActive(PetscBool *);
     288             : 
     289             : /* Stage functions */
     290             : PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[], PetscLogStage *);
     291             : PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
     292             : PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
     293             : PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage, PetscBool);
     294             : PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage, PetscBool *);
     295             : PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage, PetscBool);
     296             : PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage, PetscBool *);
     297             : PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[], PetscLogStage *);
     298             : PETSC_EXTERN PetscErrorCode PetscLogStageGetName(PetscLogEvent, const char **);
     299             : PETSC_EXTERN PetscErrorCode PetscLogStageGetPerfInfo(PetscLogStage, PetscEventPerfInfo *);
     300             : 
     301             : /* Event functions */
     302             : PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[], PetscClassId, PetscLogEvent *);
     303             : PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent, PetscBool);
     304             : PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
     305             : PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
     306             : PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
     307             : PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
     308             : PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePush(PetscLogEvent);
     309             : PETSC_EXTERN PetscErrorCode PetscLogEventDeactivatePop(PetscLogEvent);
     310             : PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent, PetscBool);
     311             : PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
     312             : PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
     313             : PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[], PetscLogEvent *);
     314             : PETSC_EXTERN PetscErrorCode PetscLogEventGetName(PetscLogEvent, const char **);
     315             : PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(PetscLogStage, PetscLogEvent, PetscEventPerfInfo *);
     316             : PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
     317             : PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);
     318             : PETSC_EXTERN PetscErrorCode PetscLogEventsPause(void);
     319             : PETSC_EXTERN PetscErrorCode PetscLogEventsResume(void);
     320             : 
     321             : /* Class functions */
     322             : PETSC_EXTERN PetscErrorCode PetscLogClassGetClassId(const char[], PetscClassId *);
     323             : PETSC_EXTERN PetscErrorCode PetscLogClassIdGetName(PetscClassId, const char **);
     324             : 
     325             : static inline PETSC_UNUSED PetscErrorCode PetscLogEventSync(PetscLogEvent e, MPI_Comm comm)
     326             : {
     327             :   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
     328             :     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
     329             :       PetscLogHandlerHot *h = &PetscLogHandlers[i];
     330             :       if (h->eventSync) {
     331             :         PetscErrorCode err = (*h->eventSync)(h->handler, e, comm);
     332             :         if (err != PETSC_SUCCESS) return err;
     333             :       }
     334             :     }
     335             :   }
     336             :   return PETSC_SUCCESS;
     337             : }
     338             : 
     339     2445432 : static inline PETSC_UNUSED PetscErrorCode PetscLogEventBegin_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
     340             : {
     341     2445432 :   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
     342    12166375 :     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
     343     9733100 :       PetscLogHandlerHot *h = &PetscLogHandlers[i];
     344     9733100 :       if (h->eventBegin) {
     345     2431386 :         PetscErrorCode err = (*h->eventBegin)(h->handler, e, o1, o2, o3, o4);
     346     2431386 :         if (err != PETSC_SUCCESS) return err;
     347             :       }
     348             :     }
     349             :   }
     350             :   return PETSC_SUCCESS;
     351             : }
     352             :   #define PetscLogEventBegin(e, o1, o2, o3, o4) PetscLogEventBegin_Internal(e, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))
     353             : 
     354     2445432 : static inline PETSC_UNUSED PetscErrorCode PetscLogEventEnd_Internal(PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
     355             : {
     356     2445432 :   if (PetscLogStateEventCurrentlyActive(petsc_log_state, e)) {
     357    12166375 :     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
     358     9733100 :       PetscLogHandlerHot *h = &PetscLogHandlers[i];
     359     9733100 :       if (h->eventEnd) {
     360     2431386 :         PetscErrorCode err = (*h->eventEnd)(h->handler, e, o1, o2, o3, o4);
     361     2431386 :         if (err != PETSC_SUCCESS) return err;
     362             :       }
     363             :     }
     364             :   }
     365             :   return PETSC_SUCCESS;
     366             : }
     367             :   #define PetscLogEventEnd(e, o1, o2, o3, o4) PetscLogEventEnd_Internal(e, (PetscObject)(o1), (PetscObject)(o2), (PetscObject)(o3), (PetscObject)(o4))
     368             : 
     369             : /* Object functions */
     370             : static inline PETSC_UNUSED PetscErrorCode PetscLogObjectCreate(PetscObject o)
     371             : {
     372             :   if (petsc_log_state) {
     373             :     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
     374             :       PetscLogHandlerHot *h = &PetscLogHandlers[i];
     375             :       if (h->objectCreate) {
     376             :         PetscErrorCode err = (*h->objectCreate)(h->handler, o);
     377             :         if (err != PETSC_SUCCESS) return err;
     378             :       }
     379             :     }
     380             :   }
     381             :   return PETSC_SUCCESS;
     382             : }
     383             : 
     384             : static inline PETSC_UNUSED PetscErrorCode PetscLogObjectDestroy(PetscObject o)
     385             : {
     386             :   if (petsc_log_state) {
     387             :     for (int i = 0; i < PETSC_LOG_HANDLER_MAX; i++) {
     388             :       PetscLogHandlerHot *h = &PetscLogHandlers[i];
     389             :       if (h->objectDestroy) {
     390             :         PetscErrorCode err = (*h->objectDestroy)(h->handler, o);
     391             :         if (err != PETSC_SUCCESS) return err;
     392             :       }
     393             :     }
     394             :   }
     395             :   return PETSC_SUCCESS;
     396             : }
     397             : 
     398             : /*
     399             :    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
     400             : 
     401             :    For the complex numbers version, note that
     402             :        1 complex addition = 2 flops
     403             :        1 complex multiplication = 6 flops,
     404             :    where we define 1 flop as that for a double precision scalar.  We roughly approximate
     405             :    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
     406             :    to the assumption that we're counting mostly additions and multiplications -- and
     407             :    roughly the same number of each.  More accurate counting could be done by distinguishing
     408             :    among the various arithmetic operations.
     409             :  */
     410             : 
     411             :   #if defined(PETSC_USE_COMPLEX)
     412             :     #define PETSC_FLOPS_PER_OP 4.0
     413             :   #else
     414             :     #define PETSC_FLOPS_PER_OP 1.0
     415             :   #endif
     416             : 
     417             : /*@C
     418             :    PetscLogFlops - Log how many flops are performed in a calculation
     419             : 
     420             :    Input Parameter:
     421             : .   flops - the number of flops
     422             : 
     423             :    Level: intermediate
     424             : 
     425             :    Note:
     426             :    To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double,
     427             :    not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n)
     428             : 
     429             :    Developer Note:
     430             :    Currently Fortran stub generator cannot run through files in include
     431             : 
     432             : .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogGpuFlops()`
     433             : @*/
     434     3170520 : static inline PetscErrorCode PetscLogFlops(PetscLogDouble n)
     435             : {
     436     3170520 :   PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
     437     3170520 :   return PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n);
     438             : }
     439             : 
     440             :   /*
     441             :      These are used internally in the PETSc routines to keep a count of MPI messages and
     442             :    their sizes.
     443             : 
     444             :      This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file
     445             :    uses macros to defined the MPI operations.
     446             : 
     447             :      It does not work correctly from HP-UX because it processes the
     448             :    macros in a way that sometimes it double counts, hence
     449             :    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
     450             : 
     451             :      It does not work with Windows because winmpich lacks MPI_Type_size()
     452             : */
     453             :   #if !defined(MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO)
     454             : /*
     455             :    Logging of MPI activities
     456             : */
     457         180 : static inline PetscErrorCode PetscMPITypeSize(PetscInt count, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
     458             : {
     459         180 :   PetscMPIInt typesize;
     460             : 
     461         180 :   if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
     462         180 :   PetscCallMPI(MPI_Type_size(type, &typesize));
     463         180 :   return PetscAddLogDouble(length, length_th, (PetscLogDouble)(count * typesize));
     464             : }
     465             : 
     466             : static inline PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, const PetscMPIInt *counts, MPI_Datatype type, PetscLogDouble *length, PetscLogDouble *length_th)
     467             : {
     468             :   PetscMPIInt    typesize, size, p;
     469             :   PetscLogDouble l;
     470             : 
     471             :   if (type == MPI_DATATYPE_NULL) return PETSC_SUCCESS;
     472             :   PetscCallMPI(MPI_Comm_size(comm, &size));
     473             :   PetscCallMPI(MPI_Type_size(type, &typesize));
     474             :   for (p = 0, l = 0.0; p < size; ++p) l += (PetscLogDouble)(counts[p] * typesize);
     475             :   return PetscAddLogDouble(length, length_th, l);
     476             : }
     477             : 
     478             : /*
     479             :     Returns 1 if the communicator is parallel else zero
     480             : */
     481    27654668 : static inline int PetscMPIParallelComm(MPI_Comm comm)
     482             : {
     483    27654668 :   PetscMPIInt size;
     484    27653374 :   MPI_Comm_size(comm, &size);
     485    27653374 :   return size > 1;
     486             : }
     487             : 
     488             :     #define MPI_Irecv(buf, count, datatype, source, tag, comm, request) \
     489             :       (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)))
     490             : 
     491             :     #define MPI_Irecv_c(buf, count, datatype, source, tag, comm, request) \
     492             :       (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)))
     493             : 
     494             :     #define MPI_Isend(buf, count, datatype, dest, tag, comm, request) \
     495             :       (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)))
     496             : 
     497             :     #define MPI_Isend_c(buf, count, datatype, dest, tag, comm, request) \
     498             :       (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)))
     499             : 
     500             :     #define MPI_Startall_irecv(count, datatype, number, requests) \
     501             :       (PetscAddLogDouble(&petsc_irecv_ct, &petsc_irecv_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_irecv_len), &(petsc_irecv_len_th)) || ((number) && MPI_Startall((number), (requests))))
     502             : 
     503             :     #define MPI_Startall_isend(count, datatype, number, requests) \
     504             :       (PetscAddLogDouble(&petsc_isend_ct, &petsc_isend_ct_th, number) || PetscMPITypeSize((count), (datatype), &(petsc_isend_len), &(petsc_isend_len_th)) || ((number) && MPI_Startall((number), (requests))))
     505             : 
     506             :     #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))
     507             : 
     508             :     #define MPI_Recv(buf, count, datatype, source, tag, comm, status) \
     509             :       (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)))
     510             : 
     511             :     #define MPI_Recv_c(buf, count, datatype, source, tag, comm, status) \
     512             :       (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)))
     513             : 
     514             :     #define MPI_Send(buf, count, datatype, dest, tag, comm) \
     515             :       (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)))
     516             : 
     517             :     #define MPI_Send_c(buf, count, datatype, dest, tag, comm) \
     518             :       (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)))
     519             : 
     520             :     #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)))
     521             : 
     522             :     #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)))
     523             : 
     524             :     #define MPI_Waitall(count, array_of_requests, array_of_statuses) \
     525             :       (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)))
     526             : 
     527             :     #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)))
     528             : 
     529             :     #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)))
     530             : 
     531             :     #define MPI_Reduce_scatter_block(sendbuf, recvbuf, recvcount, datatype, op, comm) \
     532             :       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPI_Reduce_scatter_block((sendbuf), (recvbuf), (recvcount), (datatype), (op), (comm)))
     533             : 
     534             :     #define MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
     535             :       (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)))
     536             : 
     537             :     #define MPI_Alltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm) \
     538             :       (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)))
     539             : 
     540             :     #define MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm) \
     541             :       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm)))
     542             : 
     543             :     #define MPI_Allgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm) \
     544             :       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Allgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm)))
     545             : 
     546             :     #define MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
     547             :       (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)))
     548             : 
     549             :     #define MPI_Gatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm) \
     550             :       (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)))
     551             : 
     552             :     #define MPI_Scatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm) \
     553             :       (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)))
     554             : 
     555             :     #define MPI_Scatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm) \
     556             :       (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)))
     557             : 
     558             :     #define MPI_Ialltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
     559             :       (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)))
     560             : 
     561             :     #define MPI_Ialltoallv(sendbuf, sendcnts, sdispls, sendtype, recvbuf, recvcnts, rdispls, recvtype, comm, request) \
     562             :       (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)))
     563             : 
     564             :     #define MPI_Iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request) \
     565             :       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgather((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (recvtype), (comm), (request)))
     566             : 
     567             :     #define MPI_Iallgatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, comm, request) \
     568             :       (PetscAddLogDouble(&petsc_gather_ct, &petsc_gather_ct_th, PetscMPIParallelComm(comm)) || MPI_Iallgatherv((sendbuf), (sendcount), (sendtype), (recvbuf), (recvcount), (displs), (recvtype), (comm), (request)))
     569             : 
     570             :     #define MPI_Igather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
     571             :       (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)))
     572             : 
     573             :     #define MPI_Igatherv(sendbuf, sendcount, sendtype, recvbuf, recvcount, displs, recvtype, root, comm, request) \
     574             :       (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)))
     575             : 
     576             :     #define MPI_Iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
     577             :       (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)))
     578             : 
     579             :     #define MPI_Iscatterv(sendbuf, sendcount, displs, sendtype, recvbuf, recvcount, recvtype, root, comm, request) \
     580             :       (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)))
     581             : 
     582             :     #define MPIX_Send_enqueue(buf, count, datatype, dest, tag, comm) \
     583             :       (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)))
     584             : 
     585             :     #define MPIX_Recv_enqueue(buf, count, datatype, source, tag, comm, status) \
     586             :       (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)))
     587             : 
     588             :     #define MPIX_Isend_enqueue(buf, count, datatype, dest, tag, comm, request) \
     589             :       (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)))
     590             : 
     591             :     #define MPIX_Irecv_enqueue(buf, count, datatype, source, tag, comm, request) \
     592             :       (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)))
     593             : 
     594             :     #define MPIX_Allreduce_enqueue(sendbuf, recvbuf, count, datatype, op, comm) \
     595             :       (PetscAddLogDouble(&petsc_allreduce_ct, &petsc_allreduce_ct_th, PetscMPIParallelComm(comm)) || MPIX_Allreduce_enqueue((sendbuf), (recvbuf), (count), (datatype), (op), (comm)))
     596             : 
     597             :     #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)))
     598             : 
     599             :     #define MPIX_Waitall_enqueue(count, array_of_requests, array_of_statuses) \
     600             :       (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)))
     601             :   #else
     602             : 
     603             :     #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests)))
     604             : 
     605             :     #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall((number), (requests)))
     606             : 
     607             :     #define MPI_Start_isend(count, datatype, requests) (MPI_Start(requests))
     608             : 
     609             :   #endif /* !MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
     610             : 
     611             : #else /* ---Logging is turned off --------------------------------------------*/
     612             : 
     613             :   #define PetscLogGetState(a)          (*(a) = NULL, PETSC_SUCCESS)
     614             :   #define PetscLogGetDefaultHandler(a) (*(a) = NULL, PETSC_SUCCESS)
     615             :   #define PetscLogHandlerStart(a)      ((void)(a), PETSC_SUCCESS)
     616             :   #define PetscLogHandlerStop(a)       ((void)(a), PETSC_SUCCESS)
     617             : 
     618             :   #define PetscLogFlops(n) ((void)(n), PETSC_SUCCESS)
     619             :   #define PetscGetFlops(a) (*(a) = 0.0, PETSC_SUCCESS)
     620             : 
     621             :   #define PetscLogStageRegister(a, b)    ((void)(a), *(b) = -1, PETSC_SUCCESS)
     622             :   #define PetscLogStagePush(a)           ((void)(a), PETSC_SUCCESS)
     623             :   #define PetscLogStagePop()             PETSC_SUCCESS
     624             :   #define PetscLogStageSetActive(a, b)   ((void)(a), (void)(b), PETSC_SUCCESS)
     625             :   #define PetscLogStageGetActive(a, b)   ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
     626             :   #define PetscLogStageGetVisible(a, b)  ((void)(a), *(b) = PETSC_FALSE, PETSC_SUCCESS)
     627             :   #define PetscLogStageSetVisible(a, b)  ((void)(a), (void)(b), PETSC_SUCCESS)
     628             :   #define PetscLogStageGetId(a, b)       ((void)(a), *(b) = -1, PETSC_SUCCESS)
     629             :   #define PetscLogStageGetName(a, b)     ((void)(a), *(b) = NULL, PETSC_SUCCESS)
     630             :   #define PetscLogStageGetPerfInfo(a, b) ((void)(a), *(b) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)
     631             : 
     632             :   #define PetscLogEventRegister(a, b, c)    ((void)(a), (void)(b), *(c) = -1, PETSC_SUCCESS)
     633             :   #define PetscLogEventSetCollective(a, b)  ((void)(a), (void)(b), PETSC_SUCCESS)
     634             :   #define PetscLogEventIncludeClass(a)      ((void)(a), PETSC_SUCCESS)
     635             :   #define PetscLogEventExcludeClass(a)      ((void)(a), PETSC_SUCCESS)
     636             :   #define PetscLogEventActivate(a)          ((void)(a), PETSC_SUCCESS)
     637             :   #define PetscLogEventDeactivate(a)        ((void)(a), PETSC_SUCCESS)
     638             :   #define PetscLogEventDeactivatePush(a)    ((void)(a), PETSC_SUCCESS)
     639             :   #define PetscLogEventDeactivatePop(a)     ((void)(a), PETSC_SUCCESS)
     640             :   #define PetscLogEventActivateClass(a)     ((void)(a), PETSC_SUCCESS)
     641             :   #define PetscLogEventDeactivateClass(a)   ((void)(a), PETSC_SUCCESS)
     642             :   #define PetscLogEventSetActiveAll(a, b)   ((void)(a), PETSC_SUCCESS)
     643             :   #define PetscLogEventGetId(a, b)          ((void)(a), *(b) = -1, PETSC_SUCCESS)
     644             :   #define PetscLogEventGetName(a, b)        ((void)(a), *(b) = NULL, PETSC_SUCCESS)
     645             :   #define PetscLogEventGetPerfInfo(a, b, c) ((void)(a), (void)(b), *(c) = (const PetscEventPerfInfo){0}, PETSC_SUCCESS)
     646             : 
     647             :   #define PetscLogEventSetDof(a, b, c)   ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
     648             :   #define PetscLogEventSetError(a, b, c) ((void)(a), (void)(b), (void)(c), PETSC_SUCCESS)
     649             :   #define PetscLogEventsPause()          PETSC_SUCCESS
     650             :   #define PetscLogEventsResume()         PETSC_SUCCESS
     651             : 
     652             :   #define PetscLogClassGetClassId(a, b) (*(b) = -1, PETSC_SUCCESS)
     653             :   #define PetscLogClassIdGetName(a, b)  (*(b) = NULL, PETSC_SUCCESS)
     654             : 
     655             :   #define PetscLogObjectCreate(h)        ((void)(h), PETSC_SUCCESS)
     656             :   #define PetscLogObjectDestroy(h)       ((void)(h), PETSC_SUCCESS)
     657             :   #define PetscLogObjectState(h, c, ...) ((void)(h), (void)(c), PETSC_SUCCESS)
     658             : 
     659             :   #define PetscLogDefaultBegin()                   PETSC_SUCCESS
     660             :   #define PetscLogNestedBegin()                    PETSC_SUCCESS
     661             :   #define PetscLogTraceBegin(file)                 ((void)(file), PETSC_SUCCESS)
     662             :   #define PetscLogMPEBegin()                       PETSC_SUCCESS
     663             :   #define PetscLogPerfstubsBegin()                 PETSC_SUCCESS
     664             :   #define PetscLogLegacyCallbacksBegin(a, b, c, d) ((void)(a), (void)(b), (void)(c), (void)(d), PETSC_SUCCESS)
     665             :   #define PetscLogActions(a)                       ((void)(a), PETSC_SUCCESS)
     666             :   #define PetscLogObjects(a)                       ((void)(a), PETSC_SUCCESS)
     667             :   #define PetscLogSetThreshold(a, b)               ((void)(a), (void)(b), PETSC_SUCCESS)
     668             : 
     669             :   #define PetscLogIsActive(flag) (*(flag) = PETSC_FALSE, PETSC_SUCCESS)
     670             : 
     671             :   #define PetscLogView(viewer)      ((void)(viewer), PETSC_SUCCESS)
     672             :   #define PetscLogViewFromOptions() PETSC_SUCCESS
     673             :   #define PetscLogDump(c)           ((void)(c), PETSC_SUCCESS)
     674             :   #define PetscLogMPEDump(c)        ((void)(c), PETSC_SUCCESS)
     675             : 
     676             :   #define PetscLogEventSync(e, comm)                            ((void)(e), (void)(comm), PETSC_SUCCESS)
     677             :   #define PetscLogEventBegin(e, o1, o2, o3, o4)                 ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)
     678             :   #define PetscLogEventEnd(e, o1, o2, o3, o4)                   ((void)(e), (void)(o1), (void)(o2), (void)(o3), PETSC_SUCCESS)
     679             : 
     680             :   /* If PETSC_USE_LOG is NOT defined, these still need to be! */
     681             :   #define MPI_Startall_irecv(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
     682             :   #define MPI_Startall_isend(count, datatype, number, requests) ((number) && MPI_Startall(number, requests))
     683             :   #define MPI_Start_isend(count, datatype, requests)            MPI_Start(requests)
     684             : 
     685             : #endif /* PETSC_USE_LOG */
     686             : 
     687             : #define PetscPreLoadBegin(flag, name) \
     688             :   do { \
     689             :     PetscBool     PetscPreLoading = flag; \
     690             :     int           PetscPreLoadMax, PetscPreLoadIt; \
     691             :     PetscLogStage _stageNum; \
     692             :     PetscCall(PetscOptionsGetBool(NULL, NULL, "-preload", &PetscPreLoading, NULL)); \
     693             :     PetscPreLoadMax     = (int)(PetscPreLoading); \
     694             :     PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed; \
     695             :     PetscCall(PetscLogStageGetId(name, &_stageNum)); \
     696             :     for (PetscPreLoadIt = (_stageNum == -1) ? 0 : PetscPreLoadMax; PetscPreLoadIt <= PetscPreLoadMax; PetscPreLoadIt++) { \
     697             :       PetscPreLoadingOn = (PetscBool)(PetscPreLoadIt < PetscPreLoadMax); \
     698             :       PetscCall(PetscBarrier(NULL)); \
     699             :       if (_stageNum == -1) PetscCall(PetscLogStageRegister(name, &_stageNum)); \
     700             :       PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(PetscPreLoadIt == PetscPreLoadMax))); \
     701             :       PetscCall(PetscLogStagePush(_stageNum))
     702             : 
     703             : #define PetscPreLoadEnd() \
     704             :   PetscCall(PetscLogStagePop()); \
     705             :   } \
     706             :   } \
     707             :   while (0)
     708             : 
     709             : #define PetscPreLoadStage(name) \
     710             :   do { \
     711             :     PetscCall(PetscLogStagePop()); \
     712             :     PetscCall(PetscLogStageGetId(name, &_stageNum)); \
     713             :     if (_stageNum == -1) PetscCall(PetscLogStageRegister(name, &_stageNum)); \
     714             :     PetscCall(PetscLogStageSetActive(_stageNum, (PetscBool)(!PetscPreLoadMax || PetscPreLoadIt))); \
     715             :     PetscCall(PetscLogStagePush(_stageNum)); \
     716             :   } while (0)
     717             : 
     718             : /* some vars for logging */
     719             : PETSC_EXTERN PetscBool PetscPreLoadingUsed; /* true if we are or have done preloading */
     720             : PETSC_EXTERN PetscBool PetscPreLoadingOn;   /* true if we are currently in a preloading calculation */
     721             : 
     722             : #if defined(PETSC_USE_LOG) && defined(PETSC_HAVE_DEVICE)
     723             : 
     724             : PETSC_EXTERN PetscErrorCode PetscLogGpuTime(void);
     725             : PETSC_EXTERN PetscErrorCode PetscLogGpuTimeBegin(void);
     726             : PETSC_EXTERN PetscErrorCode PetscLogGpuTimeEnd(void);
     727             : 
     728             : /*@
     729             :    PetscLogGpuFlops - Log how many flops are performed in a calculation on the device
     730             : 
     731             :    Input Parameter:
     732             : .  flops - the number of flops
     733             : 
     734             :    Level: intermediate
     735             : 
     736             :    Notes:
     737             :    To limit the chance of integer overflow when multiplying by a constant, represent the constant as a double,
     738             :    not an integer. Use `PetscLogFlops`(4.0*n) not `PetscLogFlops`(4*n)
     739             : 
     740             :    The values are also added to the total flop count for the MPI rank that is set with `PetscLogFlops()`; hence the number of flops
     741             :    just on the CPU would be the value from set from `PetscLogFlops()` minus the value set from `PetscLogGpuFlops()`
     742             : 
     743             :    Developer Note:
     744             :    Currently Fortran stub generator cannot run through files in include
     745             : 
     746             : .seealso: [](ch_profiling), `PetscLogView()`, `PetscLogFlops()`, `PetscLogGpuTimeBegin()`, `PetscLogGpuTimeEnd()`
     747             : @*/
     748             : static inline PetscErrorCode PetscLogGpuFlops(PetscLogDouble n)
     749             : {
     750             :   PetscAssert(n >= 0, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Cannot log negative flops");
     751             :   PetscCall(PetscAddLogDouble(&petsc_TotalFlops, &petsc_TotalFlops_th, PETSC_FLOPS_PER_OP * n));
     752             :   PetscCall(PetscAddLogDouble(&petsc_gflops, &petsc_gflops_th, PETSC_FLOPS_PER_OP * n));
     753             :   return PETSC_SUCCESS;
     754             : }
     755             : 
     756             : static inline PetscErrorCode PetscLogGpuTimeAdd(PetscLogDouble t)
     757             : {
     758             :   return PetscAddLogDouble(&petsc_gtime, &petsc_gtime_th, t);
     759             : }
     760             : 
     761             : static inline PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size)
     762             : {
     763             :   return PetscAddLogDoubleCnt(&petsc_ctog_ct, &petsc_ctog_sz, &petsc_ctog_ct_th, &petsc_ctog_sz_th, size);
     764             : }
     765             : 
     766             : static inline PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size)
     767             : {
     768             :   return PetscAddLogDoubleCnt(&petsc_gtoc_ct, &petsc_gtoc_sz, &petsc_gtoc_ct_th, &petsc_gtoc_sz_th, size);
     769             : }
     770             : 
     771             : static inline PetscErrorCode PetscLogCpuToGpuScalar(PetscLogDouble size)
     772             : {
     773             :   return PetscAddLogDoubleCnt(&petsc_ctog_ct_scalar, &petsc_ctog_sz_scalar, &petsc_ctog_ct_scalar_th, &petsc_ctog_sz_scalar_th, size);
     774             : }
     775             : 
     776             : static inline PetscErrorCode PetscLogGpuToCpuScalar(PetscLogDouble size)
     777             : {
     778             :   return PetscAddLogDoubleCnt(&petsc_gtoc_ct_scalar, &petsc_gtoc_sz_scalar, &petsc_gtoc_ct_scalar_th, &petsc_gtoc_sz_scalar_th, size);
     779             : }
     780             : #else
     781             : 
     782             :   #define PetscLogCpuToGpu(a)       PETSC_SUCCESS
     783             :   #define PetscLogGpuToCpu(a)       PETSC_SUCCESS
     784             :   #define PetscLogCpuToGpuScalar(a) PETSC_SUCCESS
     785             :   #define PetscLogGpuToCpuScalar(a) PETSC_SUCCESS
     786             :   #define PetscLogGpuFlops(a)       PETSC_SUCCESS
     787             :   #define PetscLogGpuTime()         PETSC_SUCCESS
     788             :   #define PetscLogGpuTimeAdd(a)     PETSC_SUCCESS
     789             :   #define PetscLogGpuTimeBegin()    PETSC_SUCCESS
     790             :   #define PetscLogGpuTimeEnd()      PETSC_SUCCESS
     791             : 
     792             : #endif /* PETSC_USE_LOG && PETSC_HAVE_DEVICE */
     793             : 
     794             : /* remove TLS defines */
     795             : #undef PETSC_EXTERN_TLS
     796             : #undef PETSC_TLS
     797             : 
     798             : #include <petsclogdeprecated.h>

Generated by: LCOV version 1.14