00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "config.h"
00024 #if HAVE_STDLIB_H
00025 # include <stdlib.h>
00026 #endif
00027 #if HAVE_UNISTD_H
00028 # include <unistd.h>
00029 #endif
00030 #include <sys/types.h>
00031 #if HAVE_SYS_TIMES_H
00032 # include <sys/times.h>
00033 #endif
00034 #if HAVE_SYS_PARAM_H
00035 # include <sys/param.h>
00036 #endif
00037 #if HAVE_GETRUSAGE
00038 # include <sys/time.h>
00039 # include <sys/resource.h>
00040 #endif
00041 #if defined (_WIN32)
00042 # include <windows.h>
00043 # undef min
00044 # undef max
00045 #endif
00046 #include <errno.h>
00047 #include "f2c.h"
00048
00049 #ifdef KEY
00050
00051 #include "cray/mtlock.h"
00052
00053 #include "pathf90_libU_intrin.h"
00054
00055
00056 float
00057 pathf90_dtime (float tarray[2])
00058 {
00059 float utime, stime;
00060 static float old_utime = 0.0, old_stime = 0.0;
00061 static plock_t mut = PTHREAD_MUTEX_INITIALIZER;
00062 struct rusage rbuff;
00063
00064 MEM_LOCK(&mut);
00065 if (getrusage (RUSAGE_SELF, &rbuff) != 0)
00066 abort ();
00067 utime = (float) (rbuff.ru_utime).tv_sec +
00068 (float) (rbuff.ru_utime).tv_usec / 1000000.0;
00069 tarray[0] = utime - (float) old_utime;
00070 stime = (float) (rbuff.ru_stime).tv_sec +
00071 (float) (rbuff.ru_stime).tv_usec / 1000000.0;
00072 tarray[1] = stime - old_stime;
00073 old_utime = utime;
00074 old_stime = stime;
00075 MEM_UNLOCK(&mut);
00076
00077 return (tarray[0] + tarray[1]);
00078 }
00079
00080
00081 void
00082 pathf90_subr_dtime (float tarray[2], float *result)
00083 {
00084 *result = pathf90_dtime(tarray);
00085 }
00086
00087 #else
00088
00089 double
00090 dtime_ (real tarray[2])
00091 {
00092 #if defined (_WIN32)
00093 static int win32_platform = -1;
00094
00095 if (win32_platform == -1)
00096 {
00097 OSVERSIONINFO osv;
00098 osv.dwOSVersionInfoSize = sizeof (osv);
00099 GetVersionEx (&osv);
00100 win32_platform = osv.dwPlatformId;
00101 }
00102
00103
00104
00105 if (win32_platform != VER_PLATFORM_WIN32_NT)
00106 {
00107 static unsigned long long clock_freq;
00108 static unsigned long long old_count;
00109 unsigned long long count;
00110 double delta;
00111 LARGE_INTEGER counter_val;
00112
00113 if (clock_freq == 0)
00114 {
00115 LARGE_INTEGER freq;
00116 if (!QueryPerformanceFrequency (&freq))
00117 {
00118 errno = ENOSYS;
00119 return 0.0;
00120 }
00121 else
00122 {
00123 clock_freq = ((unsigned long long) freq.HighPart << 32)
00124 + ((unsigned) freq.LowPart);
00125 }
00126 }
00127
00128 if (!QueryPerformanceCounter (&counter_val))
00129 return -1.0;
00130
00131 count = ((unsigned long long) counter_val.HighPart << 32)
00132 + (unsigned) counter_val.LowPart;
00133 delta = ((double) (count - old_count)) / clock_freq;
00134 tarray[0] = (float) delta;
00135 tarray[1] = 0.0;
00136 old_count = count;
00137 }
00138 else
00139 {
00140 static unsigned long long old_utime, old_stime;
00141 unsigned long long utime, stime;
00142 FILETIME creation_time, exit_time, kernel_time, user_time;
00143
00144 GetProcessTimes (GetCurrentProcess (), &creation_time, &exit_time,
00145 &kernel_time, &user_time);
00146 utime = ((unsigned long long) user_time.dwHighDateTime << 32)
00147 + (unsigned) user_time.dwLowDateTime;
00148 stime = ((unsigned long long) kernel_time.dwHighDateTime << 32)
00149 + (unsigned) kernel_time.dwLowDateTime;
00150
00151 tarray[0] = (utime - old_utime) / 1.0e7;
00152 tarray[1] = (stime - old_stime) / 1.0e7;
00153 old_utime = utime;
00154 old_stime = stime;
00155 }
00156 return tarray[0] + tarray[1];
00157
00158 #elif defined (HAVE_GETRUSAGE) || defined (HAVE_TIMES)
00159
00160 #ifdef HAVE_GETRUSAGE
00161 float utime, stime;
00162 static float old_utime = 0.0, old_stime = 0.0;
00163 struct rusage rbuff;
00164
00165 if (getrusage (RUSAGE_SELF, &rbuff) != 0)
00166 abort ();
00167 utime = (float) (rbuff.ru_utime).tv_sec +
00168 (float) (rbuff.ru_utime).tv_usec / 1000000.0;
00169 tarray[0] = utime - (float) old_utime;
00170 stime = (float) (rbuff.ru_stime).tv_sec +
00171 (float) (rbuff.ru_stime).tv_usec / 1000000.0;
00172 tarray[1] = stime - old_stime;
00173 #else
00174
00175
00176
00177
00178
00179 static long clk_tck = 0;
00180 time_t utime, stime;
00181 static time_t old_utime = 0, old_stime = 0;
00182 struct tms buffer;
00183
00184
00185
00186 # if defined _SC_CLK_TCK && defined _POSIX_VERSION
00187 if (!clk_tck)
00188 clk_tck = sysconf (_SC_CLK_TCK);
00189 # elif defined CLOCKS_PER_SECOND
00190 if (!clk_tck)
00191 clk_tck = CLOCKS_PER_SECOND;
00192 # elif defined CLK_TCK
00193 if (!clk_tck)
00194 clk_tck = CLK_TCK;
00195 # elif defined HZ
00196 if (!clk_tck)
00197 clk_tck = HZ;
00198 # elif defined HAVE_GETRUSAGE
00199 # else
00200 #error Dont know clock tick length
00201 # endif
00202 if (times (&buffer) == (clock_t) - 1)
00203 return -1.0;
00204 utime = buffer.tms_utime;
00205 stime = buffer.tms_stime;
00206 tarray[0] = ((float) (utime - old_utime)) / (float) clk_tck;
00207 tarray[1] = ((float) (stime - old_stime)) / (float) clk_tck;
00208 #endif
00209 old_utime = utime;
00210 old_stime = stime;
00211 return (tarray[0] + tarray[1]);
00212 #else
00213 errno = ENOSYS;
00214 return 0.0;
00215 #endif
00216 }
00217 #endif