xref: /petsc/include/petsctime.h (revision fbf9dbe564678ed6eff1806adbc4c4f01b9743f4)
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
6 
7 #include <petscsys.h>
8 
9 /* SUBMANSEC = Sys */
10 
11 PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble *);
12 
13 /* Global counters */
14 PETSC_EXTERN PetscLogDouble petsc_BaseTime;
15 
16 /*MC
17    PetscTime - Returns the current time from some base time in the past in seconds.
18 
19    Synopsis:
20     #include <petsctime.h>
21     PetscErrorCode PetscTime(PetscLogDouble *v)
22 
23    Not Collective
24 
25    Output Parameter:
26 .  v - time counter
27 
28    Usage:
29 .vb
30      PetscLogDouble v;
31      PetscTime(&v);
32      .... perform some calculation ...
33      printf("Time for operation %g\n",v);
34 .ve
35 
36    Level: developer
37 
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.
43 
44 .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
45 M*/
46 
47 /*MC
48    PetscTimeSubtract - Subtracts the current time (in seconds) from the value `v`.
49 
50    Synopsis:
51     #include <petsctime.h>
52     PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
53 
54    Not Collective
55 
56    Input Parameter:
57 .  v - time counter
58 
59    Output Parameter:
60 .  v - time counter (`v` = `v` - current time)
61 
62    Level: developer
63 
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.
70 
71 .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
72 M*/
73 
74 /*MC
75    PetscTimeAdd - Adds the current time (in seconds) to the value `v`.
76 
77    Synopsis:
78     #include <petsctime.h>
79     PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
80 
81    Not Collective
82 
83    Input Parameter:
84 .  v - time counter
85 
86    Output Parameter:
87 .  v - time counter (`v` = `v` + current time)
88 
89    Level: developer
90 
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.
96 
97 .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
98 M*/
99 
100 static inline PetscErrorCode PetscTime(PetscLogDouble *v)
101 {
102   *v = MPI_Wtime();
103   return PETSC_SUCCESS;
104 }
105 
106 static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
107 {
108   *v -= MPI_Wtime();
109   return PETSC_SUCCESS;
110 }
111 
112 static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
113 {
114   *v += MPI_Wtime();
115   return PETSC_SUCCESS;
116 }
117 
118 #endif
119