xref: /petsc/include/petsctime.h (revision a69119a591a03a9d906b29c0a4e9802e4d7c9795)
1 /*
2        Low cost access to system time. This, in general, should not
3      be included in user programs.
4 */
5 #if !defined(PETSCTIME_H)
6 #define PETSCTIME_H
7 
8 #include <petscsys.h>
9 
10 /* SUBMANSEC = Sys */
11 
12 PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble *);
13 
14 /* Global counters */
15 PETSC_EXTERN PetscLogDouble petsc_BaseTime;
16 
17 /*MC
18    PetscTime - Returns the current time of day in seconds.
19 
20    Synopsis:
21     #include <petsctime.h>
22     PetscErrorCode PetscTime(PetscLogDouble *v)
23 
24    Not Collective
25 
26    Output Parameter:
27 .  v - time counter
28 
29    Usage:
30      PetscLogDouble v;
31      PetscTime(&v);
32      .... perform some calculation ...
33      printf("Time for operation %g\n",v);
34 
35    Level: developer
36 
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 activate
41    PETSc library timing. See Users-Manual: ch_profiling for more details.
42 
43 .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
44 
45 M*/
46 
47 /*MC
48    PetscTimeSubtract - Subtracts the current time of day (in seconds) from
49    the value v.
50 
51    Synopsis:
52     #include <petsctime.h>
53     PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
54 
55    Not Collective
56 
57    Input Parameter:
58 .  v - time counter
59 
60    Output Parameter:
61 .  v - time counter (v = v - current time)
62 
63    Level: developer
64 
65    Notes:
66    Since the PETSc libraries incorporate timing of phases and operations,
67    we do not every recommend using PetscTimeSubtract()
68    The options database command  -log_view activates
69    PETSc library timing.  See Users-Manual: ch_profiling for more details, also
70    see PetscLogStageRegister(), PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd() for how to register
71    stages and events in application codes.
72 
73 .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
74 
75 M*/
76 
77 /*MC
78    PetscTimeAdd - Adds the current time of day (in seconds) to the value v.
79 
80    Synopsis:
81     #include <petsctime.h>
82     PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
83 
84    Not Collective
85 
86    Input Parameter:
87 .  v - time counter
88 
89    Output Parameter:
90 .  v - time counter (v = v + current time)
91 
92    Level: developer
93 
94    Notes:
95    Since the PETSc libraries incorporate timing of phases and operations,
96    we do not ever recommend using PetscTimeAdd().
97    The options database command -log_view activate
98    PETSc library timing. See Users-Manual: ch_profiling for more details.
99 
100 .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
101 
102 M*/
103 
104 static inline PetscErrorCode PetscTime(PetscLogDouble *v) {
105   *v = MPI_Wtime();
106   return 0;
107 }
108 
109 static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v) {
110   *v -= MPI_Wtime();
111   return 0;
112 }
113 
114 static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v) {
115   *v += MPI_Wtime();
116   return 0;
117 }
118 
119 #endif
120