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