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: #ifndef PETSCTIME_H
5: #define PETSCTIME_H
7: #include <petscsys.h>
9: /* SUBMANSEC = Sys */
11: PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble *);
13: /* Global counters */
14: PETSC_EXTERN PetscLogDouble petsc_BaseTime;
16: /*MC
17: PetscTime - Returns the current time from some base time in the past in seconds.
19: Synopsis:
20: #include <petsctime.h>
21: PetscErrorCode PetscTime(PetscLogDouble *v)
23: Not Collective
25: Output Parameter:
26: . v - time counter
28: Usage:
29: .vb
30: PetscLogDouble v;
31: PetscTime(&v);
32: .... perform some calculation ...
33: printf("Time for operation %g\n",v);
34: .ve
36: Level: developer
38: Notes:
39: Since the PETSc libraries incorporate timing of phases and operations,
40: we do not recommend ever using PetscTime()
41: The options database command `-log_view` activates
42: PETSc library timing.
44: .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
45: M*/
47: /*MC
48: PetscTimeSubtract - Subtracts the current time (in seconds) from the value `v`.
50: Synopsis:
51: #include <petsctime.h>
52: PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
54: Not Collective
56: Input Parameter:
57: . v - time counter
59: Output Parameter:
60: . v - time counter (`v` = `v` - current time)
62: Level: developer
64: Notes:
65: Since the PETSc libraries incorporate timing of phases and operations,
66: we do not always recommend using `PetscTimeSubtract()`.
67: The options database command `-log_view` activates
68: PETSc library timing. See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
69: stages and events in application codes.
71: .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
72: M*/
74: /*MC
75: PetscTimeAdd - Adds the current time (in seconds) to the value `v`.
77: Synopsis:
78: #include <petsctime.h>
79: PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
81: Not Collective
83: Input Parameter:
84: . v - time counter
86: Output Parameter:
87: . v - time counter (`v` = `v` + current time)
89: Level: developer
91: Notes:
92: Since the PETSc libraries incorporate timing of phases and operations,
93: we do not ever recommend using `PetscTimeAdd()`.
94: The options database command `-log_view` activates
95: PETSc library timing.
97: .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
98: M*/
100: static inline PetscErrorCode PetscTime(PetscLogDouble *v)
101: {
102: *v = MPI_Wtime();
103: return PETSC_SUCCESS;
104: }
106: static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
107: {
108: *v -= MPI_Wtime();
109: return PETSC_SUCCESS;
110: }
112: static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
113: {
114: *v += MPI_Wtime();
115: return PETSC_SUCCESS;
116: }
118: #endif