Actual source code: ptime.h
1: /* $Id: ptime.h,v 1.72 2001/01/15 21:44:04 bsmith Exp $ */
2: /*
3: Low cost access to system time. This, in general, should not
4: be included in user programs.
5: */
10: #include petsc.h
11: #if defined(PETSC_HAVE_SYS_TIME_H)
12: #include <sys/types.h>
13: #include <sys/time.h>
14: #endif
15: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
16: EXTERN_C_BEGIN
17: EXTERN int gettimeofday(struct timeval *,struct timezone *);
18: EXTERN_C_END
19: #endif
21: /*
22: PetscTime - Returns the current time of day in seconds.
24: Output Parameter:
25: . v - time counter
27: Synopsis:
28: PetscTime(PetscLogDouble v)
30: Usage:
31: PetscLogDouble v;
32: PetscTime(v);
33: .... perform some calculation ...
34: printf("Time for operation %gn",v);
36: Notes:
37: Since the PETSc libraries incorporate timing of phases and operations,
38: PetscTime() is intended only for timing of application codes.
39: The options database commands -log, -log_summary, and -log_all activate
40: PETSc library timing. See the users manual for further details.
42: .seealso: PetscTimeSubtract(), PetscTimeAdd()
44: .keywords: Petsc, time
45: */
47: /*
48: PetscTimeSubtract - Subtracts the current time of day (in seconds) from
49: the value v.
51: Input Parameter:
52: . v - time counter
54: Output Parameter:
55: . v - time counter (v = v - current time)
57: Synopsis:
58: PetscTimeSubtract(PetscLogDouble v)
60: Notes:
61: Since the PETSc libraries incorporate timing of phases and operations,
62: PetscTimeSubtract() is intended only for timing of application codes.
63: The options database commands -log, -log_summary, and -log_all activate
64: PETSc library timing. See the users manual for further details.
66: .seealso: PetscTime(), PetscTimeAdd()
68: .keywords: Petsc, time, subtract
69: */
71: /*
72: PetscTimeAdd - Adds the current time of day (in seconds) to the value v.
74: Input Parameter:
75: . v - time counter
77: Output Parameter:
78: . v - time counter (v = v + current time)
80: Synopsis:
81: PetscTimeAdd(PetscLogDouble v)
83: Notes:
84: Since the PETSc libraries incorporate timing of phases and operations,
85: PetscTimeAdd() is intended only for timing of application codes.
86: The options database commands -log, -log_summary, and -log_all activate
87: PETSc library timing. See the users manual for further details.
89: .seealso: PetscTime(), PetscTimeSubtract()
91: .keywords: Petsc, time, add
92: */
94: /* ------------------------------------------------------------------
95: Some machines have very fast MPI_Wtime()
96: */
97: #if (defined(PETSC_HAVE_FAST_MPI_WTIME) && !defined(_petsc_mpi_uni))
98: #define PetscTime(v) (v)=MPI_Wtime();
100: #define PetscTimeSubtract(v) (v)-=MPI_Wtime();
102: #define PetscTimeAdd(v) (v)+=MPI_Wtime();
104: /* ------------------------------------------------------------------
105: Power1,2,3,PC machines have a fast clock read_real_time()
106: */
107: #elif defined(PETSC_USE_READ_REAL_TIME)
108: EXTERN PetscLogDouble rs6000_time(void);
109: #define PetscTime(v) (v)=rs6000_time();
111: #define PetscTimeSubtract(v) (v)-=rs6000_time();
113: #define PetscTimeAdd(v) (v)+=rs6000_time();
115: /* ------------------------------------------------------------------
116: Dec Alpha has a very fast system clock accessible through getclock()
117: getclock() doesn't seem to have a prototype for C++
118: */
119: #elif defined(PETSC_USE_GETCLOCK)
120: EXTERN_C_BEGIN
121: EXTERN int getclock(int clock_type,struct timespec *tp);
122: EXTERN_C_END
125: #define PetscTime(v) {static struct timespec _tp;
126: getclock(TIMEOFDAY,&_tp);
127: (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);}
129: #define PetscTimeSubtract(v) {static struct timespec _tp;
130: getclock(TIMEOFDAY,&_tp);
131: (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);}
133: #define PetscTimeAdd(v) {static struct timespec _tp;
134: getclock(TIMEOFDAY,&_tp);
135: (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);}
137: /* ------------------------------------------------------------------
138: ASCI RED machine has a fast clock accessiable through dclock()
139: */
140: #elif defined (PETSC_USE_DCLOCK)
141: EXTERN_C_BEGIN
142: EXTERN PetscLogDouble dclock();
143: EXTERN_C_END
145: #define PetscTime(v) (v)=dclock();
147: #define PetscTimeSubtract(v) (v)-=dclock();
149: #define PetscTimeAdd(v) (v)+=dclock();
152: /* ------------------------------------------------------------------
153: NT uses a special time code
154: */
155: #elif defined (PETSC_USE_NT_TIME)
156: #include <time.h>
157: EXTERN PetscLogDouble nt_time(void);
158: #define PetscTime(v) (v)=nt_time();
160: #define PetscTimeSubtract(v) (v)-=nt_time();
162: #define PetscTimeAdd(v) (v)+=nt_time();
164: /* ------------------------------------------------------------------
165: The usual Unix time routines.
166: */
167: #else
168: #define PetscTime(v) {static struct timeval _tp;
169: gettimeofday(&_tp,(struct timezone *)0);
170: (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);}
172: #define PetscTimeSubtract(v) {static struct timeval _tp;
173: gettimeofday(&_tp,(struct timezone *)0);
174: (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);}
176: #define PetscTimeAdd(v) {static struct timeval _tp;
177: gettimeofday(&_tp,(struct timezone *)0);
178: (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);}
179: #endif
181: #endif