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: /*MC
16: PetscTime - Returns the current time from some base time in the past in seconds.
18: Synopsis:
19: #include <petsctime.h>
20: PetscErrorCode PetscTime(PetscLogDouble *v)
22: Not Collective
24: Output Parameter:
25: . v - time counter
27: Usage:
28: .vb
29: PetscLogDouble v;
30: PetscTime(&v);
31: .... perform some calculation ...
32: printf("Time for operation %g\n",v);
33: .ve
35: Level: developer
37: Notes:
38: Since the PETSc libraries incorporate timing of phases and operations,
39: we do not recommend ever using PetscTime()
40: The options database command `-log_view` activates
41: PETSc library timing.
43: .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
44: M*/
46: /*MC
47: PetscTimeSubtract - Subtracts the current time (in seconds) from the value `v`.
49: Synopsis:
50: #include <petsctime.h>
51: PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
53: Not Collective
55: Input Parameter:
56: . v - time counter
58: Output Parameter:
59: . v - time counter (`v` = `v` - current time)
61: Level: developer
63: Notes:
64: Since the PETSc libraries incorporate timing of phases and operations,
65: we do not always recommend using `PetscTimeSubtract()`.
66: The options database command `-log_view` activates
67: PETSc library timing. See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
68: stages and events in application codes.
70: .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
71: M*/
73: /*MC
74: PetscTimeAdd - Adds the current time (in seconds) to the value `v`.
76: Synopsis:
77: #include <petsctime.h>
78: PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
80: Not Collective
82: Input Parameter:
83: . v - time counter
85: Output Parameter:
86: . v - time counter (`v` = `v` + current time)
88: Level: developer
90: Notes:
91: Since the PETSc libraries incorporate timing of phases and operations,
92: we do not ever recommend using `PetscTimeAdd()`.
93: The options database command `-log_view` activates
94: PETSc library timing.
96: .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
97: M*/
99: static inline PetscErrorCode PetscTime(PetscLogDouble *v)
100: {
101: *v = MPI_Wtime();
102: return PETSC_SUCCESS;
103: }
105: static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
106: {
107: *v -= MPI_Wtime();
108: return PETSC_SUCCESS;
109: }
111: static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
112: {
113: *v += MPI_Wtime();
114: return PETSC_SUCCESS;
115: }