HARM
harm and utilities
 All Data Structures Files Functions Variables Typedefs Macros Pages
mytime.h
Go to the documentation of this file.
1 
7 #ifndef _MYTIME_H
8 #define _MYTIME_H
9 
10 // whether to force gettimeofday(tp,tzp) to have NULL pionter for tzp as required on some systems, e.g. queenbee/loni
11 #define GETTIMEOFDAYPROBLEM 0
12 
13 #include <signal.h>
14 #include <time.h>
15 
16 #ifndef WIN32 // if not windows
17 #include <sys/time.h>
18 #include <sys/resource.h>
19 #include <unistd.h>
20 #include <sys/times.h>
21 
22 
23 #if(GETTIMEOFDAYPROBLEM==0)
24 #define GETTIMEZONETYPE static struct timezone
25 #else
26 #define GETTIMEZONETYPE static void *
27 #endif
28 
29 
30 
31 #else // else if windows
32 
33 #include <Winsock2.h>
34 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
35 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
36 #else
37 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
38 #endif
39 
40 
41 
42 
43 #if(GETTIMEOFDAYPROBLEM==0) // no gettimeofday() problem
44 struct timezone
45 {
46  int tz_minuteswest; /* minutes W of Greenwich */
47  int tz_dsttime; /* type of dst correction */
48 };
49 extern int gettimeofday(struct timeval *tv, struct timezone *tz);
50 
51 #else // gettimeofday() problem
52 
53 static void *tz;
54 tz=NULL;
55 extern int gettimeofday(struct timeval *tv, void *tz);
56 
57 #endif // end if gettimeofday() problem
58 
59 
60 
61 #endif // end if windows
62 
63 
64 
65 
66 void mycpuclock(clock_t *time);
67 void myustimes(clock_t *time);
68 void myustimes2(clock_t *usertime,clock_t *systime);
69 
70 
71 #ifndef WIN32
72 // 0: old second accurate method for walltime
73 // 1: new microsecond accurate method for walltime
74 // 2: cpu(user+system) time, accurate to 1/CLOCKS_PER_SECOND seconds, not wall time
75 // 3: reports user/system and child user/system times (good for understanding if system is eating lot of your time (i.e. HD or net or whatever hardware device run by kernel))
76 #if(PERFTEST==1)
77 #define TIMEMETHOD 2 // SUPERMARK
78 #else
79 #define TIMEMETHOD 1 // used for measurements in wall time
80 #endif
81 
82 #else
83 // can choose TIMEMETHOD == 0,1,2
84 #define TIMEMETHOD 1
85 #endif
86 
87 
88 
89 // average time to completion is: T= ((zc/s)^{-1}) * (#zones) * (dt/tf) . dt~dx/v -> T~dx^3 for 2D dx^4 for 3D
90 
91 
92 
93 #define SEC2HOUR (2.77777777777777E-4)
94 
95 #if(GETTIMEOFDAYPROBLEM==0)
96 #define microtime(time) gettimeofday(time,&tz)
97 #else
98 #define microtime(time) gettimeofday(time,tz) // tz is NULL pointer
99 #endif
100 
101 #define diffmicrotime(timestop,timestart) ((SFTYPE)(timestop.tv_sec-timestart.tv_sec)+(SFTYPE)(timestop.tv_usec-timestart.tv_usec)*1E-6)
102 // can use clock() if time is < 71.5827882667 minutes for 32-bit systems.
103 // *time is used since sending pointer in general
104 #define TOTALTICKS (4294967296) // 32-bit system
105 //#define TOTALTICKS (18446744073709551616) // 64-bit system (compiler complains even though shouldn't?!)
106 //#endif
107 
108 #define cpuclock(time) mycpuclock(time)
109 #if(NCSA==0)
110 #define diffcpuclock(timestop,timestart) ((timestop>timestart) ? (SFTYPE)(timestop-timestart)/(SFTYPE)(CLOCKS_PER_SEC) : (SFTYPE)(timestop-(timestart-TOTALTICKS))/(SFTYPE)(CLOCKS_PER_SEC) )
111 #else
112 #define diffcpuclock(timestop,timestart) ((SFTYPE)(timestop-timestart)/(SFTYPE)(CLOCKS_PER_SEC)) // can't trust above since not taking 64bit totaltick value
113 #endif
114 #define diffmyustimes(timestop,timestart) ((SFTYPE)(timestop-timestart)/1000000.0)
115 
116 // can use nanosleep() or clock_nanosleep() to pause for
117 
118 #if(TIMEMETHOD==0)
119 #define GETTIME time
120 #define DELTATIME difftime
121 #elif(TIMEMETHOD==1)
122 #define GETTIME microtime
123 #define DELTATIME diffmicrotime
124 #elif(TIMEMETHOD==2)
125 #define GETTIME cpuclock
126 #define DELTATIME diffcpuclock
127 #elif(TIMEMETHOD==3)
128 #define GETTIME myustimes
129 #define DELTATIME diffmyustimes
130 #endif
131 
132 
133 
134 
135 #endif // end ifndef _MYTIME_H
136 
137