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: Note:
38: Since the PETSc libraries incorporate timing of phases and operations, we do not recommend ever using `PetscTime()`.
39: The options database command `-log_view` activates PETSc library timing.
40: See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
41: stages and events in application codes.
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: Note:
64: Since the PETSc libraries incorporate timing of phases and operations, we do not always recommend using `PetscTimeSubtract()`.
65: The options database command `-log_view` activates PETSc library timing.
66: See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
67: stages and events in application codes.
69: .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
70: M*/
72: /*MC
73: PetscTimeAdd - Adds the current time (in seconds) to the value `v`.
75: Synopsis:
76: #include <petsctime.h>
77: PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
79: Not Collective
81: Input Parameter:
82: . v - time counter
84: Output Parameter:
85: . v - time counter (`v` = `v` + current time)
87: Level: developer
89: Note:
90: Since the PETSc libraries incorporate timing of phases and operations, we do not ever recommend using `PetscTimeAdd()`.
91: The options database command `-log_view` activates PETSc library timing.
93: .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
94: M*/
96: static inline PetscErrorCode PetscTime(PetscLogDouble *v)
97: {
98: *v = MPI_Wtime();
99: return PETSC_SUCCESS;
100: }
102: static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
103: {
104: *v -= MPI_Wtime();
105: return PETSC_SUCCESS;
106: }
108: static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
109: {
110: *v += MPI_Wtime();
111: return PETSC_SUCCESS;
112: }