1 /* 2 Low cost access to system time. This, in general, should not 3 be included in user programs. 4 */ 5 6 #if !defined(__PTIME_H) 7 #define __PTIME_H 8 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) 15 EXTERN_C_BEGIN 16 EXTERN int gettimeofday(struct timeval *,struct timezone *); 17 EXTERN_C_END 18 #endif 19 20 /* 21 PetscTime - Returns the current time of day in seconds. 22 23 Output Parameter: 24 . v - time counter 25 26 Synopsis: 27 PetscTime(PetscLogDouble v) 28 29 Usage: 30 PetscLogDouble v; 31 PetscTime(v); 32 .... perform some calculation ... 33 printf("Time for operation %g\n",v); 34 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. 40 41 .seealso: PetscTimeSubtract(), PetscTimeAdd() 42 43 .keywords: Petsc, time 44 */ 45 46 /* 47 PetscTimeSubtract - Subtracts the current time of day (in seconds) from 48 the value v. 49 50 Input Parameter: 51 . v - time counter 52 53 Output Parameter: 54 . v - time counter (v = v - current time) 55 56 Synopsis: 57 PetscTimeSubtract(PetscLogDouble v) 58 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. 64 65 .seealso: PetscTime(), PetscTimeAdd() 66 67 .keywords: Petsc, time, subtract 68 */ 69 70 /* 71 PetscTimeAdd - Adds the current time of day (in seconds) to the value v. 72 73 Input Parameter: 74 . v - time counter 75 76 Output Parameter: 77 . v - time counter (v = v + current time) 78 79 Synopsis: 80 PetscTimeAdd(PetscLogDouble v) 81 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. 87 88 .seealso: PetscTime(), PetscTimeSubtract() 89 90 .keywords: Petsc, time, add 91 */ 92 93 /* ------------------------------------------------------------------ 94 Some machines have very fast MPI_Wtime() 95 */ 96 #if (defined(PETSC_HAVE_FAST_MPI_WTIME) && !defined(__MPIUNI_H)) 97 #define PetscTime(v) (v)=MPI_Wtime(); 98 99 #define PetscTimeSubtract(v) (v)-=MPI_Wtime(); 100 101 #define PetscTimeAdd(v) (v)+=MPI_Wtime(); 102 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(); 109 110 #define PetscTimeSubtract(v) (v)-=rs6000_time(); 111 112 #define PetscTimeAdd(v) (v)+=rs6000_time(); 113 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) 119 EXTERN_C_BEGIN 120 EXTERN int getclock(int clock_type,struct timespec *tp); 121 EXTERN_C_END 122 123 124 #define PetscTime(v) {static struct timespec _tp; \ 125 getclock(TIMEOFDAY,&_tp); \ 126 (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);} 127 128 #define PetscTimeSubtract(v) {static struct timespec _tp; \ 129 getclock(TIMEOFDAY,&_tp); \ 130 (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);} 131 132 #define PetscTimeAdd(v) {static struct timespec _tp; \ 133 getclock(TIMEOFDAY,&_tp); \ 134 (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);} 135 136 /* ------------------------------------------------------------------ 137 ASCI RED machine has a fast clock accessiable through dclock() 138 */ 139 #elif defined (PETSC_USE_DCLOCK) 140 EXTERN_C_BEGIN 141 EXTERN PetscLogDouble dclock(); 142 EXTERN_C_END 143 144 #define PetscTime(v) (v)=dclock(); 145 146 #define PetscTimeSubtract(v) (v)-=dclock(); 147 148 #define PetscTimeAdd(v) (v)+=dclock(); 149 150 151 /* ------------------------------------------------------------------ 152 Windows uses a special time code 153 */ 154 #elif defined (PETSC_USE_NT_TIME) 155 #include <time.h> 156 EXTERN_C_BEGIN 157 EXTERN PetscLogDouble nt_time(void); 158 EXTERN_C_END 159 #define PetscTime(v) (v)=nt_time(); 160 161 #define PetscTimeSubtract(v) (v)-=nt_time(); 162 163 #define PetscTimeAdd(v) (v)+=nt_time(); 164 165 /* ------------------------------------------------------------------ 166 The usual Unix time routines. 167 */ 168 #else 169 #define PetscTime(v) {static struct timeval _tp; \ 170 gettimeofday(&_tp,(struct timezone *)0);\ 171 (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);} 172 173 #define PetscTimeSubtract(v) {static struct timeval _tp; \ 174 gettimeofday(&_tp,(struct timezone *)0);\ 175 (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);} 176 177 #define PetscTimeAdd(v) {static struct timeval _tp; \ 178 gettimeofday(&_tp,(struct timezone *)0);\ 179 (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec);} 180 #endif 181 182 #endif 183 184 185 186 187 188