Actual source code: petsctime.h

  1: /*
  2:        Low cost access to a system time. This, in general, should not be included in user programs.
  3: */
  4: #pragma once

  6: #include <petscsys.h>

  8: /* SUBMANSEC = Sys */

 10: PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble *);

 12: /* Global counters */
 13: PETSC_EXTERN PetscLogDouble petsc_BaseTime;

 15: /*@
 16:   PetscTime - Returns the current time from some base time in the past in seconds.

 18:   Not Collective

 20:   Output Parameter:
 21: . v - time counter

 23:   Usage:
 24: .vb
 25:      PetscLogDouble v;
 26:      PetscTime(&v);
 27:      .... perform some calculation ...
 28:      printf("Time for operation %g\n",v);
 29: .ve

 31:   Level: developer

 33:   Note:
 34:   Since the PETSc libraries incorporate timing of phases and operations, we do not recommend ever using `PetscTime()`.
 35:   The options database command  `-log_view` activates PETSc library timing.
 36:   See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
 37:   stages and events in application codes.

 39: .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
 40: @*/
 41: static inline PetscErrorCode PetscTime(PetscLogDouble *v)
 42: {
 43:   *v = MPI_Wtime();
 44:   return PETSC_SUCCESS;
 45: }

 47: /*@
 48:   PetscTimeSubtract - Subtracts the current time (in seconds) from the value `v`.

 50:   Not Collective

 52:   Input Parameter:
 53: . v - time counter

 55:   Output Parameter:
 56: . v - time counter (`v` = `v` - current time)

 58:   Level: developer

 60:   Note:
 61:   Since the PETSc libraries incorporate timing of phases and operations, we do not always recommend using `PetscTimeSubtract()`.
 62:   The options database command  `-log_view` activates PETSc library timing.
 63:   See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
 64:   stages and events in application codes.

 66: .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
 67: @*/
 68: static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
 69: {
 70:   *v -= MPI_Wtime();
 71:   return PETSC_SUCCESS;
 72: }

 74: /*@
 75:   PetscTimeAdd - Adds the current time (in seconds) to the value `v`.

 77:   Not Collective

 79:   Input Parameter:
 80: . v - time counter

 82:   Output Parameter:
 83: . v - time counter (`v` = `v` + current time)

 85:   Level: developer

 87:   Note:
 88:   Since the PETSc libraries incorporate timing of phases and operations,  we do not ever recommend using `PetscTimeAdd()`.
 89:   The options database command `-log_view` activates PETSc library timing.

 91: .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
 92: @*/
 93: static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
 94: {
 95:   *v += MPI_Wtime();
 96:   return PETSC_SUCCESS;
 97: }