Paul,
I have again come across problems using SYSTEM_CLOCK, where the clock counter still counts backwards for faster processors. My 2ghz notebook works ok but my 3.17ghz desktop does not. I would expect that all processors faster than 2ghz show the problem.
I am including a simple program which tests system_clock for 10,000 different results and stores the differences and reports the elapsed time, calculated via date_and_time. This clearly shows the difference on the faster processor. There must be an integer*4 overflow there somewhere.
!
integer*4, parameter :: m_rate = 10000
integer*8 count_start, rate_start, max_start, &
count_next, rate_next, max_next, &
counts(0:m_rate)
integer*4 n_call, n_diff, i, calls(0:m_rate), values_in(8), values_out(8)
CHARACTER DATE*8, TIME*10, ZONE*5
real*8 dt, start, finish
!
call DATE_AND_TIME (DATE, TIME, ZONE, VALUES_in)
START= CPU_CLOCK@()
!
call system_clock (count_start, rate_start, max_start)
counts(0) = count_start
calls(0) = 0
!
n_call = 0
n_diff = 0
do
n_call = n_call + 1
call system_clock (count_next, rate_next, max_next)
if (rate_next /= rate_start) write (*,*) 'Unexpected change of rate',rate_start, rate_next
if (max_next /= max_start) write (*,*) 'Unexpected change of max ',max_start, max_next
if (count_next == count_start) cycle
count_start = count_next
n_diff = n_diff + 1
counts(n_diff) = count_next
calls(n_diff) = n_call
if (n_diff >= m_rate) exit
end do
!
call DATE_AND_TIME (DATE, TIME, ZONE, VALUES_out)
FINISH = CPU_CLOCK@()
!
dt = (( (values_out(5)-values_in(5)) ) *24 + & ! hours
(values_out(6)-values_in(6)) ) *60 + & ! minutes
(values_out(7)-values_in(7)) ! seconds
dt = dt + dble (values_out(8)-values_in(8)) * .001d0
!
do i = 1,10
write (*,*) i, calls(i), counts(i), (calls(i)-calls(i-1)), (counts(i)-counts(i-1))
end do
write (*,*) counts(0),' incremented by one for each clock count '
write (*,*) rate_start,' number of processor clock counts per second'
write (*,*) max_start,' maximum value that COUNT can have'
write (*,*) n_diff,' different calls'
write (*,*) n_call,' total calls'
write (*,*) dt,' elapsed seconds for',n_diff,' ticks'
write (*,*) (finish-start),' ticks of cpu_clock@'
write (*,*) (finish-start)/dt/1.d9,' ticks per nano-second'
end