1 /* 2 Low cost access to system time. This, in general, should not 3 be included in user programs. 4 */ 5 6 #if !defined(__PETSCTIME_H) 7 #define __PETSCTIME_H 8 9 #include <petscsys.h> 10 #if defined(PETSC_HAVE_SYS_TIME_H) 11 #include <sys/time.h> 12 #endif 13 #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO) 14 EXTERN_C_BEGIN 15 extern int gettimeofday(struct timeval *,struct timezone *); 16 EXTERN_C_END 17 #endif 18 19 /* Global counters */ 20 PETSC_EXTERN PetscLogDouble petsc_BaseTime; 21 22 /* 23 PetscTime - Returns the current time of day in seconds. 24 25 Synopsis: 26 #include "petsctime.h" 27 PetscTime(PetscLogDouble v) 28 29 Not Collective 30 31 Output Parameter: 32 . v - time counter 33 34 35 Usage: 36 PetscLogDouble v; 37 PetscTime(v); 38 .... perform some calculation ... 39 printf("Time for operation %g\n",v); 40 41 Notes: 42 Since the PETSc libraries incorporate timing of phases and operations, 43 PetscTime() is intended only for timing of application codes. 44 The options database commands -log, -log_summary, and -log_all activate 45 PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details. 46 47 .seealso: PetscTimeSubtract(), PetscTimeAdd() 48 49 .keywords: Petsc, time 50 */ 51 52 /* 53 PetscTimeSubtract - Subtracts the current time of day (in seconds) from 54 the value v. 55 56 Synopsis: 57 #include "petsctime.h" 58 PetscTimeSubtract(PetscLogDouble v) 59 60 Not Collective 61 62 Input Parameter: 63 . v - time counter 64 65 Output Parameter: 66 . v - time counter (v = v - current time) 67 68 69 Notes: 70 Since the PETSc libraries incorporate timing of phases and operations, 71 PetscTimeSubtract() is intended only for timing of application codes. 72 The options database commands -log, -log_summary, and -log_all activate 73 PETSc library timing. See the <A href="../../docs/manual.pdf">Users Manual</A> for more details. 74 75 .seealso: PetscTime(), PetscTimeAdd() 76 77 .keywords: Petsc, time, subtract 78 */ 79 80 /* 81 PetscTimeAdd - Adds the current time of day (in seconds) to the value v. 82 83 Synopsis: 84 #include "petsctime.h" 85 PetscTimeAdd(PetscLogDouble v) 86 87 Not Collective 88 89 Input Parameter: 90 . v - time counter 91 92 Output Parameter: 93 . v - time counter (v = v + current time) 94 95 Notes: 96 Since the PETSc libraries incorporate timing of phases and operations, 97 PetscTimeAdd() is intended only for timing of application codes. 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. 100 101 .seealso: PetscTime(), PetscTimeSubtract() 102 103 .keywords: Petsc, time, add 104 */ 105 106 /* ------------------------------------------------------------------ 107 Some machines have very fast MPI_Wtime() 108 */ 109 #if (defined(PETSC_HAVE_FAST_MPI_WTIME) && !defined(__MPIUNI_H)) 110 #define PetscTime(v) (v)=MPI_Wtime(); 111 112 #define PetscTimeSubtract(v) (v)-=MPI_Wtime(); 113 114 #define PetscTimeAdd(v) (v)+=MPI_Wtime(); 115 116 /* ------------------------------------------------------------------ 117 IBM Power and PowerPC machines have a fast clock read_real_time() 118 */ 119 #elif defined(PETSC_USE_READ_REAL_TIME) 120 PETSC_EXTERN PetscLogDouble PetscReadRealTime(void); 121 #define PetscTime(v) (v)=PetscReadRealTime(); 122 123 #define PetscTimeSubtract(v) (v)-=PetscReadRealTime(); 124 125 #define PetscTimeAdd(v) (v)+=PetscReadRealTime(); 126 127 /* ------------------------------------------------------------------ 128 Microsoft Windows has its own time routines 129 */ 130 #elif defined (PETSC_USE_MICROSOFT_TIME) 131 #include <time.h> 132 EXTERN_C_BEGIN 133 PETSC_EXTERN PetscLogDouble PetscMicrosoftTime(void); 134 EXTERN_C_END 135 #define PetscTime(v) (v)=PetscMicrosoftTime(); 136 137 #define PetscTimeSubtract(v) (v)-=PetscMicrosoftTime(); 138 139 #define PetscTimeAdd(v) (v)+=PetscMicrosoftTime(); 140 141 /* ------------------------------------------------------------------ 142 The usual Unix time routines. 143 */ 144 #else 145 #define PetscTime(v) do { \ 146 static struct timeval _tp; \ 147 gettimeofday(&_tp,(struct timezone *)0); \ 148 (v)=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec); \ 149 } while (0) 150 151 #define PetscTimeSubtract(v) do { \ 152 static struct timeval _tp; \ 153 gettimeofday(&_tp,(struct timezone *)0); \ 154 (v)-=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec); \ 155 } while (0) 156 157 #define PetscTimeAdd(v) do { \ 158 static struct timeval _tp; \ 159 gettimeofday(&_tp,(struct timezone *)0); \ 160 (v)+=((PetscLogDouble)_tp.tv_sec)+(1.0e-6)*(_tp.tv_usec); \ 161 } while (0) 162 #endif 163 164 #endif 165 166 167 168 169 170