xref: /petsc/include/petsclogtypes.h (revision 5fa70555f2cfa5f8527759fb2fd8b5523acdf153)
1a4963045SJacob Faibussowitsch #pragma once
21c1ad86eSToby Isaac #include <petscsystypes.h>
31c1ad86eSToby Isaac 
4ce78bad3SBarry Smith /* MANSEC = Sys */
5ce78bad3SBarry Smith /* SUBMANSEC = Log */
61c1ad86eSToby Isaac 
71c1ad86eSToby Isaac /*S
81c1ad86eSToby Isaac   PetscEventPerfInfo - statistics on how many times the event is used, how much time it takes, etc.
91c1ad86eSToby Isaac 
101c1ad86eSToby Isaac   Level: advanced
111c1ad86eSToby Isaac 
121c1ad86eSToby Isaac   Note:
131c1ad86eSToby Isaac   This is the data structure that describes profiling statsitics collected for an event from
141c1ad86eSToby Isaac   the default log handler (`PetscLogDefaultBegin()`) using `PetscLogEventGetPerfInfo()`.
151c1ad86eSToby Isaac 
161c1ad86eSToby Isaac .seealso(): [](ch_profiling)
171c1ad86eSToby Isaac S*/
181c1ad86eSToby Isaac typedef struct {
191c1ad86eSToby Isaac   int            id;                  /* The integer identifying this event / stage */
201c1ad86eSToby Isaac   PetscBool      active;              /* Deprecated */
211c1ad86eSToby Isaac   PetscBool      visible;             /* The flag to print info in summary */
221c1ad86eSToby Isaac   int            depth;               /* The nesting depth of the event call */
231c1ad86eSToby Isaac   int            count;               /* The number of times this event was executed */
241c1ad86eSToby Isaac   PetscLogDouble flops;               /* The flops used in this event */
251c1ad86eSToby Isaac   PetscLogDouble flops2;              /* The square of flops used in this event */
261c1ad86eSToby Isaac   PetscLogDouble flopsTmp;            /* The accumulator for flops used in this event */
271c1ad86eSToby Isaac   PetscLogDouble time;                /* The time taken for this event */
281c1ad86eSToby Isaac   PetscLogDouble time2;               /* The square of time taken for this event */
291c1ad86eSToby Isaac   PetscLogDouble timeTmp;             /* The accumulator for time taken for this event */
301c1ad86eSToby Isaac   PetscLogDouble syncTime;            /* The synchronization barrier time */
311c1ad86eSToby Isaac   PetscLogDouble dof[8];              /* The number of degrees of freedom associated with this event */
321c1ad86eSToby Isaac   PetscLogDouble errors[8];           /* The errors (user-defined) associated with this event */
331c1ad86eSToby Isaac   PetscLogDouble numMessages;         /* The number of messages in this event */
341c1ad86eSToby Isaac   PetscLogDouble messageLength;       /* The total message lengths in this event */
351c1ad86eSToby Isaac   PetscLogDouble numReductions;       /* The number of reductions in this event */
361c1ad86eSToby Isaac   PetscLogDouble memIncrease;         /* How much the resident memory has increased in this event */
371c1ad86eSToby Isaac   PetscLogDouble mallocIncrease;      /* How much the maximum malloced space has increased in this event */
381c1ad86eSToby Isaac   PetscLogDouble mallocSpace;         /* How much the space was malloced and kept during this event */
391c1ad86eSToby Isaac   PetscLogDouble mallocIncreaseEvent; /* Maximum of the high water mark with in event minus memory available at the end of the event */
401c1ad86eSToby Isaac #if defined(PETSC_HAVE_DEVICE)
411c1ad86eSToby Isaac   PetscLogDouble CpuToGpuCount; /* The total number of CPU to GPU copies */
421c1ad86eSToby Isaac   PetscLogDouble GpuToCpuCount; /* The total number of GPU to CPU copies */
431c1ad86eSToby Isaac   PetscLogDouble CpuToGpuSize;  /* The total size of CPU to GPU copies */
441c1ad86eSToby Isaac   PetscLogDouble GpuToCpuSize;  /* The total size of GPU to CPU copies */
451c1ad86eSToby Isaac   PetscLogDouble GpuFlops;      /* The flops done on a GPU in this event */
461c1ad86eSToby Isaac   PetscLogDouble GpuTime;       /* The time spent on a GPU in this event */
47*5268dc8aSHong Zhang   PetscLogDouble GpuEnergy;     /* The energy consumed on a GPU in this event */
481c1ad86eSToby Isaac #endif
491c1ad86eSToby Isaac } PetscEventPerfInfo;
501c1ad86eSToby Isaac 
511c1ad86eSToby Isaac typedef struct _n_PetscIntStack *PetscIntStack;
521c1ad86eSToby Isaac 
531c1ad86eSToby Isaac /*MC
541c1ad86eSToby Isaac     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
551c1ad86eSToby Isaac     code.
561c1ad86eSToby Isaac 
571c1ad86eSToby Isaac     Level: intermediate
581c1ad86eSToby Isaac 
591c1ad86eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogStage`
601c1ad86eSToby Isaac M*/
611c1ad86eSToby Isaac typedef int PetscLogEvent;
621c1ad86eSToby Isaac 
631c1ad86eSToby Isaac /*MC
641c1ad86eSToby Isaac     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
651c1ad86eSToby Isaac 
661c1ad86eSToby Isaac     Level: intermediate
671c1ad86eSToby Isaac 
681c1ad86eSToby Isaac .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogEvent`
691c1ad86eSToby Isaac M*/
701c1ad86eSToby Isaac typedef int PetscLogStage;
711c1ad86eSToby Isaac 
726873511fSToby Isaac /*MC
736873511fSToby Isaac     PetscLogClass - id used to identify classes for logging purposes only.  It
746873511fSToby Isaac     is not equal to its `PetscClassId`, which is the identifier used for other
756873511fSToby Isaac     purposes.
766873511fSToby Isaac 
776873511fSToby Isaac     Level: developer
786873511fSToby Isaac 
796873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogStateClassRegister()`
806873511fSToby Isaac M*/
816873511fSToby Isaac typedef int PetscLogClass;
826873511fSToby Isaac 
8319ef957cSToby Isaac /*S
8419ef957cSToby Isaac   PetscLogHandler - Interface for performance logging.  A log handler receives a `PetscLogState` that has
8519ef957cSToby Isaac   information about the events (`PetscLogEvent`) and stages (`PetscLogStage`) in the logging environment.
86b665b14eSToby Isaac   When a handler is connected to PETSc's global logging stream (`PetscLogHandlerStart()`), it receives
87b665b14eSToby Isaac   updates about events (`PetscLogEventBegin()` / `PetscLogEventEnd()`), stages (`PetscLogStagePush()` /
88b665b14eSToby Isaac   `PetscLogStagePop()`), and objects (`PetscLogObjectCreate()` / `PetscLogObjectDestroy()`).  After
89b665b14eSToby Isaac   collecting information the logger can summarize its data with `PetscLogHandlerView()`.
9019ef957cSToby Isaac 
9119ef957cSToby Isaac   Example Usage:
9219ef957cSToby Isaac .vb
9319ef957cSToby Isaac #include <petscsys.h>
9419ef957cSToby Isaac 
9519ef957cSToby Isaac int main() {
9619ef957cSToby Isaac   UserCtx             ctx;
9719ef957cSToby Isaac   PetscLogHandlerType handler_type;
9819ef957cSToby Isaac 
9919ef957cSToby Isaac   PetscInitialize(...);
10019ef957cSToby Isaac   // ... fill in ctx
10119ef957cSToby Isaac   PetscLogHandlerCreate(PETSC_COMM_WORLD, &handler);
10219ef957cSToby Isaac   PetscLogHandlerSetType(handler, handler_type);
10319ef957cSToby Isaac   PetscLogHandlerStart(handler); // connect your handler to global logging state
10419ef957cSToby Isaac   // ... run code to be profiled
10519ef957cSToby Isaac   PetscLogHandlerStop(handler); // disconnect your handler from the global logging state
10619ef957cSToby Isaac   PetscLogHandlerView(handler, PETSC_VIEWER_STDOUT_WORLD); // view the results
10719ef957cSToby Isaac   PetscLogHandlerDestroy(&handler);
10819ef957cSToby Isaac   PetscFinalize();
10919ef957cSToby Isaac }
11019ef957cSToby Isaac .ve
11119ef957cSToby Isaac 
11219ef957cSToby Isaac   Level: developer
11319ef957cSToby Isaac 
11419ef957cSToby Isaac .seealso: [](ch_profiling),
11519ef957cSToby Isaac           `PetscLogHandlerCreate()`,
11619ef957cSToby Isaac           `PetscLogHandlerStart()`, `PetscLogHandlerStop()`,
11719ef957cSToby Isaac           `PetscLogHandlerSetType()`, `PetscLogHandlerGetType()`,
11819ef957cSToby Isaac           `PetscLogHandlerSetState()`, `PetscLogHandlerGetState()`,
11919ef957cSToby Isaac           `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`,
12019ef957cSToby Isaac           `PetscLogHandlerEventSync()`,
12119ef957cSToby Isaac           `PetscLogHandlerObjectCreate()`, `PetscLogHandlerObjectDestroy()`,
12219ef957cSToby Isaac           `PetscLogHandlerStagePush()`, `PetscLogHandlerStagePop()`,
12319ef957cSToby Isaac           `PetscLogHandlerView()`,
12419ef957cSToby Isaac           `PetscLogHandlerDestroy()`,
12519ef957cSToby Isaac S*/
12619ef957cSToby Isaac typedef struct _p_PetscLogHandler *PetscLogHandler;
12719ef957cSToby Isaac 
12819ef957cSToby Isaac /*J
12919ef957cSToby Isaac   PetscLogHandlerType - String with the name of a `PetscLogHandler` type
13019ef957cSToby Isaac 
13119ef957cSToby Isaac   Level: Developer
13219ef957cSToby Isaac 
13319ef957cSToby Isaac   Note:
13419ef957cSToby Isaac   Implementations included with PETSc include\:
135294de794SToby Isaac + `PETSCLOGHANDLERDEFAULT` (`PetscLogDefaultBegin()`)        - formats data for PETSc's default summary (`PetscLogView()`) and data-dump (`PetscLogDump()`) formats.
136294de794SToby Isaac . `PETSCLOGHANDLERNESTED` (`PetscLogNestedBegin()`)          - formats data for XML or flamegraph output
137294de794SToby Isaac . `PETSCLOGHANDLERTRACE` (`PetscLogTraceBegin()`)            - traces profiling events in an output stream
138294de794SToby Isaac . `PETSCLOGHANDLERMPE` (`PetscLogMPEBegin()`)                - outputs parallel performance visualization using MPE
139294de794SToby Isaac . `PETSCLOGHANDLERPERFSTUBS` (`PetscLogPerfstubsBegin()`)    - outputs instrumentation data for PerfStubs/TAU
14061cc7448SToby Isaac . `PETSCLOGHANDLERLEGACY` (`PetscLogLegacyCallbacksBegin()`) - adapts legacy callbacks to the `PetscLogHandler` interface
14161cc7448SToby Isaac - `PETSCLOGHANDLERNVTX`                                      - creates NVTX ranges for events that are visible in Nsight
14256a72328SZach Atkins - `PETSCLOGHANDLERROCTX`                                     - creates ROCTx ranges for events that are visible in rocprof
14319ef957cSToby Isaac 
14419ef957cSToby Isaac .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerSetType()`, `PetscLogHandlerGetType()`
14519ef957cSToby Isaac J*/
14619ef957cSToby Isaac typedef const char *PetscLogHandlerType;
14719ef957cSToby Isaac 
148294de794SToby Isaac #define PETSCLOGHANDLERDEFAULT   "default"
149294de794SToby Isaac #define PETSCLOGHANDLERNESTED    "nested"
150294de794SToby Isaac #define PETSCLOGHANDLERTRACE     "trace"
151294de794SToby Isaac #define PETSCLOGHANDLERMPE       "mpe"
152294de794SToby Isaac #define PETSCLOGHANDLERPERFSTUBS "perfstubs"
153294de794SToby Isaac #define PETSCLOGHANDLERLEGACY    "legacy"
15461cc7448SToby Isaac #define PETSCLOGHANDLERNVTX      "nvtx"
15556a72328SZach Atkins #define PETSCLOGHANDLERROCTX     "roctx"
15678f1b9b4SToby Isaac 
1576873511fSToby Isaac typedef struct _n_PetscLogRegistry *PetscLogRegistry;
1586873511fSToby Isaac 
1596873511fSToby Isaac /*S
1602965abd2SToby Isaac    PetscLogState - Interface for the shared state information used by `PetscLogHandler`s.
1616873511fSToby Isaac 
162b665b14eSToby Isaac    Most users will not need to reference a `PetscLogState` directly: global logging routines
163b665b14eSToby Isaac    like `PetscLogEventRegister()`  and `PetscLogStagePush()` implicitly manipulate PETSc's global
164b665b14eSToby Isaac    logging state, `PetscLogGetState()`.
165b665b14eSToby Isaac 
1666873511fSToby Isaac    Level: developer
1676873511fSToby Isaac 
1682965abd2SToby Isaac    Notes:
1692965abd2SToby Isaac    `PetscLogState` holds a registry of events (`PetscLogStateEventRegister()`), stages
1702965abd2SToby Isaac    (`PetscLogStateStageRegister()`), and classes (`PetscLogStateClassRegister()`).
1712965abd2SToby Isaac    It keeps track of when the user has activated events (`PetscLogStateEventSetActive()`) and
1722965abd2SToby Isaac    stages (`PetscLogStateStageSetActive()`).  It also keeps a stack of running stages
1732965abd2SToby Isaac    (`PetscLogStateStagePush()`, `PetscLogStateStagePop()`).
1742965abd2SToby Isaac 
1756873511fSToby Isaac    The struct defining `PetscLogState` is in a public header so that `PetscLogEventBegin()`,
1766873511fSToby Isaac    `PetscLogEventEnd()`, `PetscLogObjectCreate()`, and `PetscLogObjectDestroy()` can be defined
1776873511fSToby Isaac    as macros rather than function calls, but users are discouraged from directly accessing
1786873511fSToby Isaac    the struct's fields, which are subject to change.
1796873511fSToby Isaac 
1806873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogStateCreate()`, `PetscLogStateDestroy()`
1816873511fSToby Isaac S*/
1826873511fSToby Isaac typedef struct _n_PetscLogState *PetscLogState;
1836873511fSToby Isaac struct _n_PetscLogState {
1846873511fSToby Isaac   PetscLogRegistry registry;
1856873511fSToby Isaac   PetscBT          active;
1866873511fSToby Isaac   PetscIntStack    stage_stack;
1876873511fSToby Isaac   int              current_stage;
1886873511fSToby Isaac   int              bt_num_stages;
1896873511fSToby Isaac   int              bt_num_events;
1906873511fSToby Isaac   int              refct;
1916873511fSToby Isaac };
1926873511fSToby Isaac 
1936873511fSToby Isaac /*S
1946873511fSToby Isaac   PetscLogEventInfo - A registry entry about a logging event for `PetscLogState`.
1956873511fSToby Isaac 
1966873511fSToby Isaac   Level: developer
1976873511fSToby Isaac 
1986873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogEvent`, `PetscLogState`, `PetscLogStateEventGetInfo()`
1996873511fSToby Isaac S*/
2006873511fSToby Isaac typedef struct {
2016873511fSToby Isaac   char        *name;       /* The name of this event */
2026873511fSToby Isaac   PetscClassId classid;    /* The class the event is associated with */
2036873511fSToby Isaac   PetscBool    collective; /* Flag this event as collective */
2046873511fSToby Isaac } PetscLogEventInfo;
2056873511fSToby Isaac 
2066873511fSToby Isaac /*S
2076873511fSToby Isaac   PetscLogClassInfo - A registry entry about a class for `PetscLogState`.
2086873511fSToby Isaac 
2096873511fSToby Isaac   Level: developer
2106873511fSToby Isaac 
2116873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogClass`, `PetscLogState`, `PetscLogStateStageGetInfo()`
2126873511fSToby Isaac S*/
2136873511fSToby Isaac typedef struct {
2146873511fSToby Isaac   char        *name;    /* The class name */
2156873511fSToby Isaac   PetscClassId classid; /* The integer identifying this class */
2166873511fSToby Isaac } PetscLogClassInfo;
2176873511fSToby Isaac 
2186873511fSToby Isaac /*S
2196873511fSToby Isaac   PetscLogStageInfo - A registry entry about a class for `PetscLogState`.
2206873511fSToby Isaac 
2216873511fSToby Isaac   Level: developer
2226873511fSToby Isaac 
2236873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogStage`, `PetscLogState`, `PetscLogStateClassGetInfo()`
2246873511fSToby Isaac S*/
225ce78bad3SBarry Smith typedef struct {
2266873511fSToby Isaac   char *name; /* The stage name */
2276873511fSToby Isaac } PetscLogStageInfo;
228