- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have Visual Fortran Prof. edition 6.6A on a Windows XP machine. I am having problems using the cpu_time function. The returned value only seems to update at a rate of 1.5625e-2 second, and it's not giving me the microsecond resolution that I need. I found a two year old post related to cpu_time, with a response to the effect of "it's the fault of the OS". I wrote a test program and got the same problem, shown below.
program test_cpu_time
real gettime0,gettime1
call cpu_time(gettime0)
do i=1,100,1
print *, i
end do
call cpu_time(gettime1)
deltatime=gettime1-gettime0
print *, gettime0,gettime1,deltatime
end
The output is as follows:
95
96
97
98
99
100
1.5625000E-02 1.5625000E-02 0.0000000E+00
Press any key to continue
Thanks for any help.
Kent
program test_cpu_time
real gettime0,gettime1
call cpu_time(gettime0)
do i=1,100,1
print *, i
end do
call cpu_time(gettime1)
deltatime=gettime1-gettime0
print *, gettime0,gettime1,deltatime
end
The output is as follows:
95
96
97
98
99
100
1.5625000E-02 1.5625000E-02 0.0000000E+00
Press any key to continue
Thanks for any help.
Kent
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Same response. The system time that CPU_TIME looks at is updated by the OS at about a 10ms interval. Microsecond timing may not be available without specialized hardware, but look at the Win32 Platform SDK documentation topics on "multimedia timers".
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are also QueryPerformanceCounter/QueryPerformanceFrequency APIs, but I forgot what their resolution was. (Oh, got it:
The Win32 API QueryPerformanceCounter() returns the resolution of a high- resolution performance counter if the hardware supports one. For x86, the resolution is about 0.8 microseconds (0.0008 ms). You need to call QueryPerformanceFrequency() to get the frequency of the
high-resolution performance counter.
)
You'll need some integer(8) arithmetic to get that right.
Jugoslav
The Win32 API QueryPerformanceCounter() returns the resolution of a high- resolution performance counter if the hardware supports one. For x86, the resolution is about 0.8 microseconds (0.0008 ms). You need to call QueryPerformanceFrequency() to get the frequency of the
high-resolution performance counter.
)
You'll need some integer(8) arithmetic to get that right.
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In order to get microsecond resolution, you give up the ability to collect process time, and basically count CPU cycles. If you have an up to date Microsoft C compiler, there should be direct support for the rdtsc intrinsic. Up to now, we link in a function which goes through a number of #ifdef's to select the appropriate asm code. This gives better resolution than the QueryPerformance API's, but you also have the problem of finding independently the CPU clock rate. It varies if you have thermal or power saver throttling.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page