cpu_time problem

cpu_time problem

I can't seem to get the intrinsic function cpu_time to work correctly under v6.5 on a Win98 machine. The function seems to give me the "wall clock" time instead of cpu processing time. Following is a short test program:

program time
implicit none
integer i
real :: t1,t2
call cpu_time(t1)
print *, 'Input integer: '
read(*,*) i
print *, i
call cpu_time(t2)
write(*,*) "Time = ",t2-t1
end program time

The cpu time reported depends on how long I take to enter the requested integer. Is this a bug or am I doing something wrong? Thanks.

Wei Loh

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Sorry, I didn't realize that the mailer wrapped my test program. Here it is again:

program time

implicit none

integer i

real :: t1,t2

call cpu_time(t1)

print *, 'Input integer: '

read(*,*) i

print *, i

call cpu_time(t2)

write(*,*) "Time = ",t2-t1

end program time

It's really a question of the OS doing something strange. On NT (at least Alpha NT) the time spent waiting to get input from the user isn't counted. Just what kinds of events should contribute towards CPU_time can be a difficult call to make and not everyone would agree with the answers you come up with. For example, should OS events contribute to CPU_time? If you say yes, people are going to complain that interrupts external to your program count against your programs speed, while if you say no your program won't measure the time for swapping (I have seen results with CVF on Alpha NT where a program actually measures a smaller CPU_time when it swaps!) or DTB fills. Even when you get it right (as here) the particular OS you are working with can undermine your efforts as you have seen with Win98. Another aspect of the problem could be seen if you consider that default input could be via redirection rather than user input. I suggest that you time around the read: find the time taken up to the read and the time after the read and add the results.

Windows 9x returns zero in the field for CPU time in the call to GetProcessTimes, so CPU_TIME uses the wall-clock time instead. As far as I know, W9x doesn't track CPU time separately.

Steve

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today