Actual source code: petsctime.h
1: /*
2: Low cost access to system time. This, in general, should not
3: be included in user programs.
4: */
9: #include petsc.h
10: #if defined(PETSC_HAVE_SYS_TIME_H)
11: #include <sys/types.h>
12: #include <sys/time.h>
13: #endif
14: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
16: EXTERN int gettimeofday(struct timeval *,struct timezone *);
18: #endif
20: /*
21: PetscTime - Returns the current time of day in seconds.
23: Output Parameter:
24: . v - time counter
26: Synopsis:
27: PetscTime(PetscLogDouble v)
29: Usage:
30: PetscLogDouble v;
31: PetscTime(v);
32: .... perform some calculation ...
33: printf("Time for operation %g\n",v);
35: Notes:
36: Since the PETSc libraries incorporate timing of phases and operations,
37: PetscTime() is intended only for timing of application codes.
38: The options database commands -log, -log_summary, and -log_all activate
39: PETSc library timing. See the users manual for further details.
41: .seealso: PetscTimeSubtract(), PetscTimeAdd()
43: .keywords: Petsc, time
44: */
46: /*
47: PetscTimeSubtract - Subtracts the current time of day (in seconds) from
48: the value v.
50: Input Parameter:
51: . v - time counter
53: Output Parameter:
54: . v - time counter (v = v - current time)
56: Synopsis:
57: PetscTimeSubtract(PetscLogDouble v)
59: Notes:
60: Since the PETSc libraries incorporate timing of phases and operations,
61: PetscTimeSubtract() is intended only for timing of application codes.
62: The options database commands -log, -log_summary, and -log_all activate
63: PETSc library timing. See the users manual for further details.
65: .seealso: PetscTime(), PetscTimeAdd()
67: .keywords: Petsc, time, subtract
68: */
70: /*
71: PetscTimeAdd - Adds the current time of day (in seconds) to the value v.
73: Input Parameter:
74: . v - time counter
76: Output Parameter:
77: . v - time counter (v = v + current time)
79: Synopsis:
80: PetscTimeAdd(PetscLogDouble v)
82: Notes:
83: Since the PETSc libraries incorporate timing of phases and operations,
84: PetscTimeAdd() is intended only for timing of application codes.
85: The options database commands -log, -log_summary, and -log_all activate
86: PETSc library timing. See the users manual for further details.
88: .seealso: PetscTime(), PetscTimeSubtract()
90: .keywords: Petsc, time, add
91: */
93: /* ------------------------------------------------------------------
94: Some machines have very fast MPI_Wtime()
95: */
96: #if (defined(PETSC_HAVE_FAST_MPI_WTIME) && !defined(_petsc_mpi_uni))
97: #define PetscTime(v) (v)=MPI_Wtime();
99: #define PetscTimeSubtract(v) (v)-=MPI_Wtime();
101: #define PetscTimeAdd(v) (v)+=MPI_Wtime();
103: /* ------------------------------------------------------------------
104: Power1,2,3,PC machines have a fast clock read_real_time()
105: */
106: #elif defined(PETSC_USE_READ_REAL_TIME)
107: EXTERN PetscLogDouble rs6000_time(void);
108: #define PetscTime(v) (v)=rs6000_time();
110: #define PetscTimeSubtract(v) (v)-=rs6000_time();
112: #define PetscTimeAdd(v) (v)+=rs6000_time();
114: /* ------------------------------------------------------------------
115: Dec Alpha has a very fast system clock accessible through getclock()
116: getclock() doesn't seem to have a prototype for C++
117: */
118: #elif defined(PETSC_USE_GETCLOCK)
120: EXTERN int getclock(int clock_type,struct timespec *tp);
124: #define PetscTime(v) {static struct timespec _tp; \
125: getclock(TIMEOFDAY,&_tp); \
126: (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);}
128: #define PetscTimeSubtract(v) {static struct timespec _tp; \
129: getclock(TIMEOFDAY,&_tp); \
130: (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);}
132: #define PetscTimeAdd(v) {static struct timespec _tp; \
133: getclock(TIMEOFDAY,&_tp); \
134: (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);}
136: /* ------------------------------------------------------------------
137: ASCI RED machine has a fast clock accessiable through dclock()
138: */
139: #elif defined (PETSC_USE_DCLOCK)
141: EXTERN PetscLogDouble dclock();
144: #define PetscTime(v) (v)=dclock();
146: #define PetscTimeSubtract(v) (v)-=dclock();
148: #define PetscTimeAdd(v) (v)+=dclock();
151: /* ------------------------------------------------------------------
152: Windows uses a special time code
153: */
154: #elif defined (PETSC_USE_NT_TIME)
155: #include <time.h>
156: EXTERN PetscLogDouble nt_time(void);
157: #define PetscTime(v) (v)=nt_time();
159: #define PetscTimeSubtract(v) (v)-=nt_time();
161: #define PetscTimeAdd(v) (v)+=nt_time();
163: /* ------------------------------------------------------------------
164: The usual Unix time routines.
165: */
166: #else
167: #define PetscTime(v) {static struct timeval _tp; \
168: gettimeofday(&_tp,(struct timezone *)0);\
169: (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);}
171: #define PetscTimeSubtract(v) {static struct timeval _tp; \
172: gettimeofday(&_tp,(struct timezone *)0);\
173: (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);}
175: #define PetscTimeAdd(v) {static struct timeval _tp; \
176: gettimeofday(&_tp,(struct timezone *)0);\
177: (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);}
178: #endif
180: #endif