Actual source code: petsctime.h
petsc-3.4.3 2013-10-15
1: /*
2: Low cost access to system time. This, in general, should not
3: be included in user programs.
4: */
8: #include <petscsys.h>
10: PETSC_EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*);
12: /* Global counters */
13: PETSC_EXTERN PetscLogDouble petsc_BaseTime;
15: /*MC
16: PetscTime - Returns the current time of day in seconds.
18: Synopsis:
19: #include "petsctime.h"
20: PetscTime(PetscLogDouble *v)
22: Not Collective
24: Output Parameter:
25: . v - time counter
28: Usage:
29: PetscLogDouble v;
30: PetscTime(&v);
31: .... perform some calculation ...
32: printf("Time for operation %g\n",v);
34: Level: developer
36: Notes:
37: Since the PETSc libraries incorporate timing of phases and operations,
38: we do not recomment every using PetscTime()
39: The options database command -log_summary activate
40: PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details.
42: .seealso: PetscTimeSubtract(), PetscTimeAdd(), PetscLogStageRegister(), PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd()
44: .keywords: Petsc, time
45: M*/
47: /*MC
48: PetscTimeSubtract - Subtracts the current time of day (in seconds) from
49: the value v.
51: Synopsis:
52: #include "petsctime.h"
53: PetscTimeSubtract(&PetscLogDouble *v)
55: Not Collective
57: Input Parameter:
58: . v - time counter
60: Output Parameter:
61: . v - time counter (v = v - current time)
63: Level: developer
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_summary activates
69: PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details, also
70: see PetscLogStageRegister(), PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd() for how to register
71: stages and events in application codes.
73: .seealso: PetscTime(), PetscTimeAdd(), PetscLogStageRegister(), PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd()
75: .keywords: Petsc, time, subtract
76: M*/
78: /*MC
79: PetscTimeAdd - Adds the current time of day (in seconds) to the value v.
81: Synopsis:
82: #include "petsctime.h"
83: PetscTimeAdd(PetscLogDouble *v)
85: Not Collective
87: Input Parameter:
88: . v - time counter
90: Output Parameter:
91: . v - time counter (v = v + current time)
93: Level: developer
95: Notes:
96: Since the PETSc libraries incorporate timing of phases and operations,
97: we do not ever recommend using PetscTimeAdd().
98: The options database command -log_summary activate
99: PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details.
101: .seealso: PetscTime(), PetscTimeSubtract(), PetscLogStageRegister(), PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd()
103: .keywords: Petsc, time, add
104: M*/
106: /* ------------------------------------------------------------------
107: Some machines have very fast MPI_Wtime()
108: */
109: #if (defined(PETSC_HAVE_FAST_MPI_WTIME) && !defined(__MPIUNI_H))
110: PETSC_STATIC_INLINE PetscErrorCode PetscTime(PetscLogDouble *v)
111: {
112: *v = MPI_Wtime();
113: return 0;
114: }
116: PETSC_STATIC_INLINE PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
117: {
118: *v -= MPI_Wtime();
119: return 0;
120: }
122: PETSC_STATIC_INLINE PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
123: {
124: *v += MPI_Wtime();
125: return 0;
126: }
128: /* ------------------------------------------------------------------
129: IBM Power and PowerPC machines have a fast clock read_real_time()
130: */
131: #elif defined(PETSC_USE_READ_REAL_TIME)
132: PETSC_EXTERN PetscLogDouble PetscReadRealTime(void);
134: PETSC_STATIC_INLINE PetscErrorCode PetscTime(PetscLogDouble *v)
135: {
136: *v = PetscReadRealTime();
137: return 0;
138: }
140: PETSC_STATIC_INLINE PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
141: {
142: *v -= PetscReadRealTime();
143: return 0;
144: }
146: PETSC_STATIC_INLINE PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
147: {
148: *v += PetscReadRealTime();
149: return 0;
150: }
152: /* ------------------------------------------------------------------
153: Microsoft Windows has its own time routines
154: */
155: #elif defined (PETSC_USE_MICROSOFT_TIME)
156: #include <time.h>
157: PETSC_EXTERN PetscLogDouble PetscMicrosoftTime(void);
159: PETSC_STATIC_INLINE PetscErrorCode PetscTime(PetscLogDouble *v)
160: {
161: *v = PetscMicrosoftTime();
162: return 0;
163: }
165: PETSC_STATIC_INLINE PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
166: {
167: *v -= PetscMicrosoftTime();
168: return 0;
169: }
171: PETSC_STATIC_INLINE PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
172: {
173: *v += PetscMicrosoftTime();
174: return 0;
175: }
177: /* ------------------------------------------------------------------
178: The usual Unix time routines.
179: */
180: #else
182: #if defined(PETSC_HAVE_SYS_TIME_H)
183: #include <sys/time.h>
184: #endif
186: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
187: PETSC_EXTERN int gettimeofday(struct timeval *,struct timezone *);
188: #endif
190: PETSC_STATIC_INLINE PetscErrorCode PetscTime(PetscLogDouble *v)
191: {
192: static struct timeval _tp;
193: gettimeofday(&_tp,(struct timezone *)0);
194: *v = ((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);
195: return 0;
196: }
198: PETSC_STATIC_INLINE PetscErrorCode PetscTimeSubtract(PetscLogDouble *v)
199: {
200: static struct timeval _tp;
201: gettimeofday(&_tp,(struct timezone *)0);
202: *v -= ((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);
203: return 0;
204: }
206: PETSC_STATIC_INLINE PetscErrorCode PetscTimeAdd(PetscLogDouble *v)
207: {
208: static struct timeval _tp;
209: gettimeofday(&_tp,(struct timezone *)0);
210: *v += ((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);
211: return 0;
212: }
214: #endif
216: #endif