xref: /petsc/include/petsclogtypes.h (revision 2965abd2a23f5c1162fd500274ba2fe7bd846c8e)
11c1ad86eSToby Isaac #ifndef PETSCLOGTYPES_H
21c1ad86eSToby Isaac #define PETSCLOGTYPES_H
31c1ad86eSToby Isaac #include <petscsystypes.h>
41c1ad86eSToby Isaac 
51c1ad86eSToby Isaac /* SUBMANSEC = Profiling */
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 */
471c1ad86eSToby Isaac #endif
481c1ad86eSToby Isaac } PetscEventPerfInfo;
491c1ad86eSToby Isaac 
501c1ad86eSToby Isaac typedef struct _n_PetscIntStack *PetscIntStack;
511c1ad86eSToby Isaac 
521c1ad86eSToby Isaac /*MC
531c1ad86eSToby Isaac     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
541c1ad86eSToby Isaac      code.
551c1ad86eSToby Isaac 
561c1ad86eSToby Isaac     Level: intermediate
571c1ad86eSToby Isaac 
581c1ad86eSToby Isaac .seealso: [](ch_profiling), `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`, `PetscLogStage`
591c1ad86eSToby Isaac M*/
601c1ad86eSToby Isaac typedef int PetscLogEvent;
611c1ad86eSToby Isaac 
621c1ad86eSToby Isaac /*MC
631c1ad86eSToby Isaac     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
641c1ad86eSToby Isaac 
651c1ad86eSToby Isaac     Level: intermediate
661c1ad86eSToby Isaac 
671c1ad86eSToby Isaac .seealso: [](ch_profiling), `PetscLogStageRegister()`, `PetscLogStagePush()`, `PetscLogStagePop()`, `PetscLogEvent`
681c1ad86eSToby Isaac M*/
691c1ad86eSToby Isaac typedef int PetscLogStage;
701c1ad86eSToby Isaac 
716873511fSToby Isaac /*MC
726873511fSToby Isaac     PetscLogClass - id used to identify classes for logging purposes only.  It
736873511fSToby Isaac     is not equal to its `PetscClassId`, which is the identifier used for other
746873511fSToby Isaac     purposes.
756873511fSToby Isaac 
766873511fSToby Isaac     Level: developer
776873511fSToby Isaac 
786873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogStateClassRegister()`
796873511fSToby Isaac M*/
806873511fSToby Isaac typedef int PetscLogClass;
816873511fSToby Isaac 
8219ef957cSToby Isaac /*S
8319ef957cSToby Isaac   PetscLogHandler - Interface for performance logging.  A log handler receives a `PetscLogState` that has
8419ef957cSToby Isaac   information about the events (`PetscLogEvent`) and stages (`PetscLogStage`) in the logging environment.
85b665b14eSToby Isaac   When a handler is connected to PETSc's global logging stream (`PetscLogHandlerStart()`), it receives
86b665b14eSToby Isaac   updates about events (`PetscLogEventBegin()` / `PetscLogEventEnd()`), stages (`PetscLogStagePush()` /
87b665b14eSToby Isaac   `PetscLogStagePop()`), and objects (`PetscLogObjectCreate()` / `PetscLogObjectDestroy()`).  After
88b665b14eSToby Isaac   collecting information the logger can summarize its data with `PetscLogHandlerView()`.
8919ef957cSToby Isaac 
9019ef957cSToby Isaac   Example Usage:
9119ef957cSToby Isaac .vb
9219ef957cSToby Isaac #include <petscsys.h>
9319ef957cSToby Isaac 
9419ef957cSToby Isaac int main() {
9519ef957cSToby Isaac   UserCtx             ctx;
9619ef957cSToby Isaac   PetscLogHandlerType handler_type;
9719ef957cSToby Isaac 
9819ef957cSToby Isaac   PetscInitialize(...);
9919ef957cSToby Isaac   // ... fill in ctx
10019ef957cSToby Isaac   PetscLogHandlerCreate(PETSC_COMM_WORLD, &handler);
10119ef957cSToby Isaac   PetscLogHandlerSetType(handler, handler_type);
10219ef957cSToby Isaac   PetscLogHandlerStart(handler); // connect your handler to global logging state
10319ef957cSToby Isaac   // ... run code to be profiled
10419ef957cSToby Isaac   PetscLogHandlerStop(handler); // disconnect your handler from the global logging state
10519ef957cSToby Isaac   PetscLogHandlerView(handler, PETSC_VIEWER_STDOUT_WORLD); // view the results
10619ef957cSToby Isaac   PetscLogHandlerDestroy(&handler);
10719ef957cSToby Isaac   PetscFinalize();
10819ef957cSToby Isaac }
10919ef957cSToby Isaac .ve
11019ef957cSToby Isaac 
11119ef957cSToby Isaac   Level: developer
11219ef957cSToby Isaac 
11319ef957cSToby Isaac .seealso: [](ch_profiling),
11419ef957cSToby Isaac           `PetscLogHandlerCreate()`,
11519ef957cSToby Isaac           `PetscLogHandlerStart()`, `PetscLogHandlerStop()`,
11619ef957cSToby Isaac           `PetscLogHandlerSetType()`, `PetscLogHandlerGetType()`,
11719ef957cSToby Isaac           `PetscLogHandlerSetState()`, `PetscLogHandlerGetState()`,
11819ef957cSToby Isaac           `PetscLogHandlerEventBegin()`, `PetscLogHandlerEventEnd()`,
11919ef957cSToby Isaac           `PetscLogHandlerEventSync()`,
12019ef957cSToby Isaac           `PetscLogHandlerObjectCreate()`, `PetscLogHandlerObjectDestroy()`,
12119ef957cSToby Isaac           `PetscLogHandlerStagePush()`, `PetscLogHandlerStagePop()`,
12219ef957cSToby Isaac           `PetscLogHandlerView()`,
12319ef957cSToby Isaac           `PetscLogHandlerDestroy()`,
12419ef957cSToby Isaac S*/
12519ef957cSToby Isaac typedef struct _p_PetscLogHandler *PetscLogHandler;
12619ef957cSToby Isaac 
12719ef957cSToby Isaac /*J
12819ef957cSToby Isaac   PetscLogHandlerType - String with the name of a `PetscLogHandler` type
12919ef957cSToby Isaac 
13019ef957cSToby Isaac   Level: Developer
13119ef957cSToby Isaac 
13219ef957cSToby Isaac   Note:
13319ef957cSToby Isaac   Implementations included with PETSc include\:
134294de794SToby Isaac + `PETSCLOGHANDLERDEFAULT` (`PetscLogDefaultBegin()`)        - formats data for PETSc's default summary (`PetscLogView()`) and data-dump (`PetscLogDump()`) formats.
135294de794SToby Isaac . `PETSCLOGHANDLERNESTED` (`PetscLogNestedBegin()`)          - formats data for XML or flamegraph output
136294de794SToby Isaac . `PETSCLOGHANDLERTRACE` (`PetscLogTraceBegin()`)            - traces profiling events in an output stream
137294de794SToby Isaac . `PETSCLOGHANDLERMPE` (`PetscLogMPEBegin()`)                - outputs parallel performance visualization using MPE
138294de794SToby Isaac . `PETSCLOGHANDLERPERFSTUBS` (`PetscLogPerfstubsBegin()`)    - outputs instrumentation data for PerfStubs/TAU
139294de794SToby Isaac - `PETSCLOGHANDLERLEGACY` (`PetscLogLegacyCallbacksBegin()`) - adapts legacy callbacks to the `PetscLogHandler` interface
14019ef957cSToby Isaac 
14119ef957cSToby Isaac .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerSetType()`, `PetscLogHandlerGetType()`
14219ef957cSToby Isaac J*/
14319ef957cSToby Isaac typedef const char *PetscLogHandlerType;
14419ef957cSToby Isaac 
145294de794SToby Isaac #define PETSCLOGHANDLERDEFAULT   "default"
146294de794SToby Isaac #define PETSCLOGHANDLERNESTED    "nested"
147294de794SToby Isaac #define PETSCLOGHANDLERTRACE     "trace"
148294de794SToby Isaac #define PETSCLOGHANDLERMPE       "mpe"
149294de794SToby Isaac #define PETSCLOGHANDLERPERFSTUBS "perfstubs"
150294de794SToby Isaac #define PETSCLOGHANDLERLEGACY    "legacy"
15178f1b9b4SToby Isaac 
1526873511fSToby Isaac typedef struct _n_PetscLogRegistry *PetscLogRegistry;
1536873511fSToby Isaac 
1546873511fSToby Isaac /*S
155*2965abd2SToby Isaac    PetscLogState - Interface for the shared state information used by `PetscLogHandler`s.
1566873511fSToby Isaac 
157b665b14eSToby Isaac    Most users will not need to reference a `PetscLogState` directly: global logging routines
158b665b14eSToby Isaac    like `PetscLogEventRegister()`  and `PetscLogStagePush()` implicitly manipulate PETSc's global
159b665b14eSToby Isaac    logging state, `PetscLogGetState()`.
160b665b14eSToby Isaac 
1616873511fSToby Isaac    Level: developer
1626873511fSToby Isaac 
163*2965abd2SToby Isaac    Notes:
164*2965abd2SToby Isaac    `PetscLogState` holds a registry of events (`PetscLogStateEventRegister()`), stages
165*2965abd2SToby Isaac    (`PetscLogStateStageRegister()`), and classes (`PetscLogStateClassRegister()`).
166*2965abd2SToby Isaac    It keeps track of when the user has activated events (`PetscLogStateEventSetActive()`) and
167*2965abd2SToby Isaac    stages (`PetscLogStateStageSetActive()`).  It also keeps a stack of running stages
168*2965abd2SToby Isaac    (`PetscLogStateStagePush()`, `PetscLogStateStagePop()`).
169*2965abd2SToby Isaac 
1706873511fSToby Isaac    The struct defining `PetscLogState` is in a public header so that `PetscLogEventBegin()`,
1716873511fSToby Isaac    `PetscLogEventEnd()`, `PetscLogObjectCreate()`, and `PetscLogObjectDestroy()` can be defined
1726873511fSToby Isaac    as macros rather than function calls, but users are discouraged from directly accessing
1736873511fSToby Isaac    the struct's fields, which are subject to change.
1746873511fSToby Isaac 
1756873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogStateCreate()`, `PetscLogStateDestroy()`
1766873511fSToby Isaac S*/
1776873511fSToby Isaac typedef struct _n_PetscLogState *PetscLogState;
1786873511fSToby Isaac struct _n_PetscLogState {
1796873511fSToby Isaac   PetscLogRegistry registry;
1806873511fSToby Isaac   PetscBT          active;
1816873511fSToby Isaac   PetscIntStack    stage_stack;
1826873511fSToby Isaac   int              current_stage;
1836873511fSToby Isaac   int              bt_num_stages;
1846873511fSToby Isaac   int              bt_num_events;
1856873511fSToby Isaac   int              refct;
1866873511fSToby Isaac };
1876873511fSToby Isaac 
1886873511fSToby Isaac /*S
1896873511fSToby Isaac   PetscLogEventInfo - A registry entry about a logging event for `PetscLogState`.
1906873511fSToby Isaac 
1916873511fSToby Isaac   Level: developer
1926873511fSToby Isaac 
1936873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogEvent`, `PetscLogState`, `PetscLogStateEventGetInfo()`
1946873511fSToby Isaac S*/
1956873511fSToby Isaac typedef struct {
1966873511fSToby Isaac   char        *name;       /* The name of this event */
1976873511fSToby Isaac   PetscClassId classid;    /* The class the event is associated with */
1986873511fSToby Isaac   PetscBool    collective; /* Flag this event as collective */
1996873511fSToby Isaac } PetscLogEventInfo;
2006873511fSToby Isaac 
2016873511fSToby Isaac /*S
2026873511fSToby Isaac   PetscLogClassInfo - A registry entry about a class for `PetscLogState`.
2036873511fSToby Isaac 
2046873511fSToby Isaac   Level: developer
2056873511fSToby Isaac 
2066873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogClass`, `PetscLogState`, `PetscLogStateStageGetInfo()`
2076873511fSToby Isaac S*/
2086873511fSToby Isaac typedef struct {
2096873511fSToby Isaac   char        *name;    /* The class name */
2106873511fSToby Isaac   PetscClassId classid; /* The integer identifying this class */
2116873511fSToby Isaac } PetscLogClassInfo;
2126873511fSToby Isaac 
2136873511fSToby Isaac /*S
2146873511fSToby Isaac   PetscLogStageInfo - A registry entry about a class for `PetscLogState`.
2156873511fSToby Isaac 
2166873511fSToby Isaac   Level: developer
2176873511fSToby Isaac 
2186873511fSToby Isaac .seealso: [](ch_profiling), `PetscLogStage`, `PetscLogState`, `PetscLogStateClassGetInfo()`
2196873511fSToby Isaac S*/
2206873511fSToby Isaac typedef struct _PetscLogStageInfo {
2216873511fSToby Isaac   char *name; /* The stage name */
2226873511fSToby Isaac } PetscLogStageInfo;
2236873511fSToby Isaac 
2241c1ad86eSToby Isaac #endif
225