I am required to set up an existing Fortran code to run with a time limit (i.e. 24 hour cycles). I'm trying to implement a simple run-time timing which measures the "real life" time (not CPU time) which the code was running and executes a proper save and terminate routine.
Since this check happens very often, I don't want to actually get the whole day-time and calculate the total hours/minutes from that. I would much prefer something on the lines of CPU_TIME()
and do a simple (Current-Start)/3600
(I really only need hours resolution).
I actually tried implementing the CPU_TIME()
in the simplest way and it seemed to work for short times, but apparently as the time increases, there is a "drift" and I end up running slightly more than the actual time limitation, which terminates my code without saving a "checkpoint".
Other then trying to set a lower limit on the hours to try to account for the "drift", is there a more precise, yet simple implementation that gets the correct run-time within a resolution of few minutes?
Edit:
I tried using system_clock
as well, but the actual time and the output time from this routine is completely off... What am I doing wrong?
INTEGER :: scount, & ! Starting "time"
ecount, & ! Ending "time"
rate ! number of clock ticks per second
call system_clock(scount,rate)
...
<CODE>
...
call system_clock(ecount)
timer_elapsed_time = real(ecount-scount,8)/real(rate,8)
write(*,*) "Calculated run time is ",timer_elapsed_time *3600," hours"
Solution: The clock rate can be real
and not integer
in some cases, such as my case.