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