Actual source code: loglegacy.c

  1: #include <petsc/private/loghandlerimpl.h>

  3: typedef struct _n_PetscLogHandler_Legacy *PetscLogHandler_Legacy;
  4: struct _n_PetscLogHandler_Legacy {
  5:   PetscErrorCode (*PetscLogPLB)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject);
  6:   PetscErrorCode (*PetscLogPLE)(PetscLogEvent, int, PetscObject, PetscObject, PetscObject, PetscObject);
  7:   PetscErrorCode (*PetscLogPHC)(PetscObject);
  8:   PetscErrorCode (*PetscLogPHD)(PetscObject);
  9: };

 11: static PetscErrorCode PetscLogHandlerEventBegin_Legacy(PetscLogHandler handler, PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
 12: {
 13:   PetscLogHandler_Legacy legacy = (PetscLogHandler_Legacy)handler->data;

 15:   return (*legacy->PetscLogPLB)(e, 0, o1, o2, o3, o4);
 16: }

 18: static PetscErrorCode PetscLogHandlerEventEnd_Legacy(PetscLogHandler handler, PetscLogEvent e, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4)
 19: {
 20:   PetscLogHandler_Legacy legacy = (PetscLogHandler_Legacy)handler->data;

 22:   return (*legacy->PetscLogPLE)(e, 0, o1, o2, o3, o4);
 23: }

 25: static PetscErrorCode PetscLogHandlerObjectCreate_Legacy(PetscLogHandler handler, PetscObject o)
 26: {
 27:   PetscLogHandler_Legacy legacy = (PetscLogHandler_Legacy)handler->data;

 29:   return (*legacy->PetscLogPHC)(o);
 30: }

 32: static PetscErrorCode PetscLogHandlerObjectDestroy_Legacy(PetscLogHandler handler, PetscObject o)
 33: {
 34:   PetscLogHandler_Legacy legacy = (PetscLogHandler_Legacy)handler->data;

 36:   return (*legacy->PetscLogPHD)(o);
 37: }

 39: static PetscErrorCode PetcLogHandlerDestroy_Legacy(PetscLogHandler handler)
 40: {
 41:   PetscFunctionBegin;
 42:   PetscCall(PetscFree(handler->data));
 43:   PetscFunctionReturn(PETSC_SUCCESS);
 44: }

 46: /*MC
 47:   PETSCLOGHANDLERLEGACY - PETSCLOGHANDLERLEGACY = "legacy" -  A
 48:   `PetscLogHandler` that can be constructed from the callbacks used in
 49:   `PetscLogSet()`.  A log handler of this type is created and started by
 50:   `PetscLogLegacyCallbacksBegin()`.

 52:   Level: developer

 54: .seealso: [](ch_profiling), `PetscLogHandler`, `PetscLogHandlerCreateLegacy()`
 55: M*/

 57: PETSC_INTERN PetscErrorCode PetscLogHandlerCreate_Legacy(PetscLogHandler handler)
 58: {
 59:   PetscLogHandler_Legacy legacy;

 61:   PetscFunctionBegin;
 62:   PetscCall(PetscNew(&legacy));
 63:   handler->data         = (void *)legacy;
 64:   handler->ops->destroy = PetcLogHandlerDestroy_Legacy;
 65:   PetscFunctionReturn(PETSC_SUCCESS);
 66: }

 68: /*@C
 69:   PetscLogHandlerCreateLegacy - Create a `PetscLogHandler` from callbacks matching PETSc's legacy log handler callbacks

 71:   Collective

 73:   Input Parameters:
 74: + comm        - an MPI communicator
 75: . PetscLogPLB - a function to call during `PetscLogHandlerEventBegin()` (or `NULL`)
 76: . PetscLogPLE - a function to call during `PetscLogHandlerEventEnd()` (or `NULL`)
 77: . PetscLogPHC - a function to call during `PetscLogHandlerObjectCreate()` (or `NULL`)
 78: - PetscLogPHD - a function to call during `PetscLogHandlerObjectDestroy()` (or `NULL`)

 80:   Output Parameter:
 81: . handler - a `PetscLogHandler`

 83:   Calling sequence of `PetscLogPLB`:
 84: + e  - a `PetscLogEvent` that is beginning
 85: . _i - deprecated, unused
 86: . o1 - a `PetscObject` associated with `e` (or `NULL`)
 87: . o2 - a `PetscObject` associated with `e` (or `NULL`)
 88: . o3 - a `PetscObject` associated with `e` (or `NULL`)
 89: - o4 - a `PetscObject` associated with `e` (or `NULL`)

 91:   Calling sequence of `PetscLogPLE`:
 92: + e  - a `PetscLogEvent` that is beginning
 93: . _i - deprecated, unused
 94: . o1 - a `PetscObject` associated with `e` (or `NULL`)
 95: . o2 - a `PetscObject` associated with `e` (or `NULL`)
 96: . o3 - a `PetscObject` associated with `e` (or `NULL`)
 97: - o4 - a `PetscObject` associated with `e` (or `NULL`)

 99:   Calling sequence of `PetscLogPHC`:
100: . o - a `PetscObject` that has just been created

102:   Calling sequence of `PetscLogPHD`:
103: . o - a `PetscObject` that is about to be destroyed

105:   Level: developer

107:   Notes:
108:   This is for transitioning from the deprecated function `PetscLogSet()` and should not be used in new code.

110:   `PetscLogLegacyCallbacksBegin()`, which calls this function, creates and starts (`PetscLogHandlerStart()`) a log handler,
111:   should be used in almost all cases.

113: .seealso: [](ch_profiling)
114: @*/
115: PetscErrorCode PetscLogHandlerCreateLegacy(MPI_Comm comm, PetscErrorCode (*PetscLogPLB)(PetscLogEvent e, int _i, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4), PetscErrorCode (*PetscLogPLE)(PetscLogEvent e, int _i, PetscObject o1, PetscObject o2, PetscObject o3, PetscObject o4), PetscErrorCode (*PetscLogPHC)(PetscObject o), PetscErrorCode (*PetscLogPHD)(PetscObject o), PetscLogHandler *handler)
116: {
117:   PetscLogHandler_Legacy legacy;
118:   PetscLogHandler        h;

120:   PetscFunctionBegin;
121:   PetscCall(PetscLogHandlerCreate(comm, handler));
122:   h = *handler;
123:   PetscCall(PetscLogHandlerSetType(h, PETSCLOGHANDLERLEGACY));
124:   legacy = (PetscLogHandler_Legacy)h->data;

126:   legacy->PetscLogPLB = PetscLogPLB;
127:   legacy->PetscLogPLE = PetscLogPLE;
128:   legacy->PetscLogPHC = PetscLogPHC;
129:   legacy->PetscLogPHD = PetscLogPHD;

131:   h->ops->eventbegin    = PetscLogPLB ? PetscLogHandlerEventBegin_Legacy : NULL;
132:   h->ops->eventend      = PetscLogPLE ? PetscLogHandlerEventEnd_Legacy : NULL;
133:   h->ops->objectcreate  = PetscLogPHC ? PetscLogHandlerObjectCreate_Legacy : NULL;
134:   h->ops->objectdestroy = PetscLogPHD ? PetscLogHandlerObjectDestroy_Legacy : NULL;
135:   PetscFunctionReturn(PETSC_SUCCESS);
136: }