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 <petscsys.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 /* Global counters */ 21 PETSC_EXTERN PetscLogDouble petsc_BaseTime; 22 23 /* 24 PetscTime - Returns the current time of day in seconds. 25 26 Synopsis: 27 #include "petsctime.h" 28 PetscTime(PetscLogDouble v) 29 30 Not Collective 31 32 Output Parameter: 33 . v - time counter 34 35 36 Usage: 37 PetscLogDouble v; 38 PetscTime(v); 39 .... perform some calculation ... 40 printf("Time for operation %g\n",v); 41 42 Notes: 43 Since the PETSc libraries incorporate timing of phases and operations, 44 PetscTime() is intended only for timing of application codes. 45 The options database commands -log, -log_summary, and -log_all activate 46 PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details. 47 48 .seealso: PetscTimeSubtract(), PetscTimeAdd() 49 50 .keywords: Petsc, time 51 */ 52 53 /* 54 PetscTimeSubtract - Subtracts the current time of day (in seconds) from 55 the value v. 56 57 Synopsis: 58 #include "petsctime.h" 59 PetscTimeSubtract(PetscLogDouble v) 60 61 Not Collective 62 63 Input Parameter: 64 . v - time counter 65 66 Output Parameter: 67 . v - time counter (v = v - current time) 68 69 70 Notes: 71 Since the PETSc libraries incorporate timing of phases and operations, 72 PetscTimeSubtract() is intended only for timing of application codes. 73 The options database commands -log, -log_summary, and -log_all activate 74 PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details. 75 76 .seealso: PetscTime(), PetscTimeAdd() 77 78 .keywords: Petsc, time, subtract 79 */ 80 81 /* 82 PetscTimeAdd - Adds the current time of day (in seconds) to the value v. 83 84 Synopsis: 85 #include "petsctime.h" 86 PetscTimeAdd(PetscLogDouble v) 87 88 Not Collective 89 90 Input Parameter: 91 . v - time counter 92 93 Output Parameter: 94 . v - time counter (v = v + current time) 95 96 Notes: 97 Since the PETSc libraries incorporate timing of phases and operations, 98 PetscTimeAdd() is intended only for timing of application codes. 99 The options database commands -log, -log_summary, and -log_all activate 100 PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details. 101 102 .seealso: PetscTime(), PetscTimeSubtract() 103 104 .keywords: Petsc, time, add 105 */ 106 107 /* ------------------------------------------------------------------ 108 Some machines have very fast MPI_Wtime() 109 */ 110 #if (defined(PETSC_HAVE_FAST_MPI_WTIME) && !defined(__MPIUNI_H)) 111 #define PetscTime(v) (v)=MPI_Wtime(); 112 113 #define PetscTimeSubtract(v) (v)-=MPI_Wtime(); 114 115 #define PetscTimeAdd(v) (v)+=MPI_Wtime(); 116 117 /* ------------------------------------------------------------------ 118 Power1,2,3,PC machines have a fast clock read_real_time() 119 */ 120 #elif defined(PETSC_USE_READ_REAL_TIME) 121 PETSC_EXTERN PetscLogDouble rs6000_time(void); 122 #define PetscTime(v) (v)=rs6000_time(); 123 124 #define PetscTimeSubtract(v) (v)-=rs6000_time(); 125 126 #define PetscTimeAdd(v) (v)+=rs6000_time(); 127 128 /* ------------------------------------------------------------------ 129 Dec Alpha has a very fast system clock accessible through getclock() 130 getclock() doesn't seem to have a prototype for C++ 131 */ 132 #elif defined(PETSC_USE_GETCLOCK) 133 EXTERN_C_BEGIN 134 extern int getclock(int clock_type,struct timespec *tp); 135 EXTERN_C_END 136 137 138 #define PetscTime(v) {static struct timespec _tp; \ 139 getclock(TIMEOFDAY,&_tp); \ 140 (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);} 141 142 #define PetscTimeSubtract(v) {static struct timespec _tp; \ 143 getclock(TIMEOFDAY,&_tp); \ 144 (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);} 145 146 #define PetscTimeAdd(v) {static struct timespec _tp; \ 147 getclock(TIMEOFDAY,&_tp); \ 148 (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-9)*(_tp.tv_nsec);} 149 150 /* ------------------------------------------------------------------ 151 ASCI RED machine has a fast clock accessiable through dclock() 152 */ 153 #elif defined (PETSC_USE_DCLOCK) 154 EXTERN_C_BEGIN 155 PETSC_EXTERN PetscLogDouble dclock(); 156 EXTERN_C_END 157 158 #define PetscTime(v) (v)=dclock(); 159 160 #define PetscTimeSubtract(v) (v)-=dclock(); 161 162 #define PetscTimeAdd(v) (v)+=dclock(); 163 164 165 /* ------------------------------------------------------------------ 166 Windows uses a special time code 167 */ 168 #elif defined (PETSC_USE_NT_TIME) 169 #include <time.h> 170 EXTERN_C_BEGIN 171 PETSC_EXTERN PetscLogDouble nt_time(void); 172 EXTERN_C_END 173 #define PetscTime(v) (v)=nt_time(); 174 175 #define PetscTimeSubtract(v) (v)-=nt_time(); 176 177 #define PetscTimeAdd(v) (v)+=nt_time(); 178 179 /* ------------------------------------------------------------------ 180 The usual Unix time routines. 181 */ 182 #else 183 #define PetscTime(v) do { \ 184 static struct timeval _tp; \ 185 gettimeofday(&_tp,(struct timezone *)0); \ 186 (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec); \ 187 } while (0) 188 189 #define PetscTimeSubtract(v) do { \ 190 static struct timeval _tp; \ 191 gettimeofday(&_tp,(struct timezone *)0); \ 192 (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec); \ 193 } while (0) 194 195 #define PetscTimeAdd(v) do { \ 196 static struct timeval _tp; \ 197 gettimeofday(&_tp,(struct timezone *)0); \ 198 (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec); \ 199 } while (0) 200 #endif 201 202 #endif 203 204 205 206 207 208