1 /*
2 Low cost access to a system time. This, in general, should not be included in user programs.
3 */
4 #pragma once
5
6 #include <petscsys.h>
7
8 /* SUBMANSEC = Sys */
9
10 PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble *);
11
12 /* Global counters */
13 PETSC_EXTERN PetscLogDouble petsc_BaseTime;
14
15 /*@
16 PetscTime - Returns the current time from some base time in the past in seconds.
17
18 Not Collective
19
20 Output Parameter:
21 . v - time counter
22
23 Usage:
24 .vb
25 PetscLogDouble v;
26 PetscTime(&v);
27 .... perform some calculation ...
28 printf("Time for operation %g\n",v);
29 .ve
30
31 Level: developer
32
33 Note:
34 Since the PETSc libraries incorporate timing of phases and operations, we do not recommend ever using `PetscTime()`.
35 The options database command `-log_view` activates PETSc library timing.
36 See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
37 stages and events in application codes.
38
39 .seealso: `PetscTimeSubtract()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
40 @*/
PetscTime(PetscLogDouble * v)41 static inline PetscErrorCode PetscTime(PetscLogDouble *v)
42 {
43 *v = MPI_Wtime();
44 return PETSC_SUCCESS;
45 }
46
47 /*@
48 PetscTimeSubtract - Subtracts the current time (in seconds) from the value `v`.
49
50 Not Collective
51
52 Input Parameter:
53 . v - time counter
54
55 Output Parameter:
56 . v - time counter (`v` = `v` - current time)
57
58 Level: developer
59
60 Note:
61 Since the PETSc libraries incorporate timing of phases and operations, we do not always recommend using `PetscTimeSubtract()`.
62 The options database command `-log_view` activates PETSc library timing.
63 See `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()` for how to register
64 stages and events in application codes.
65
66 .seealso: `PetscTime()`, `PetscTimeAdd()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
67 @*/
PetscTimeSubtract(PetscLogDouble * v)68 static inline PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
69 {
70 *v -= MPI_Wtime();
71 return PETSC_SUCCESS;
72 }
73
74 /*@
75 PetscTimeAdd - Adds the current time (in seconds) to the value `v`.
76
77 Not Collective
78
79 Input Parameter:
80 . v - time counter
81
82 Output Parameter:
83 . v - time counter (`v` = `v` + current time)
84
85 Level: developer
86
87 Note:
88 Since the PETSc libraries incorporate timing of phases and operations, we do not ever recommend using `PetscTimeAdd()`.
89 The options database command `-log_view` activates PETSc library timing.
90
91 .seealso: `PetscTime()`, `PetscTimeSubtract()`, `PetscLogStageRegister()`, `PetscLogEventRegister()`, `PetscLogEventBegin()`, `PetscLogEventEnd()`
92 @*/
PetscTimeAdd(PetscLogDouble * v)93 static inline PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
94 {
95 *v += MPI_Wtime();
96 return PETSC_SUCCESS;
97 }
98