Fortran intrinsic timing routines, which is better? cpu_time or system_clock

前端 未结 4 546
再見小時候
再見小時候 2020-12-03 09:54

When timing a FORTRAN program i usually just use the command call cpu_time(t).
Then i stumbled across call system_clock([count,count_rate,count_max])<

相关标签:
4条回答
  • 2020-12-03 10:24

    I find itime (see gfortran manual) to be a good alternative to system_clock for timing fortran programs. It is very easy to use:

    integer, dimension(3) :: time
    call itime(time)
    print *, 'Hour:  ', time(1)
    print *, 'Minute:', time(2)
    print *, 'Second:', time(3)
    
    0 讨论(0)
  • 2020-12-03 10:29

    cpu_time() usually has a resolution of about 0.01 second on Intel compatible CPUs. This means that a smaller time interval may count as zero time. Most current compilers for linux make the resolution of system_clock() depend on the data types of the arguments, so integer(int64) will give better than 1 microsecond resolution, as well as permitting counting over a significant time interval. gfortran for Windows was changed recently (during 2015) so as to make system_clock() equivalent to query_performance calls. ifort Windows, however, still shows about 0.01 resolution for system_clock, even after omp_get_wtime was changed to use query_performance. I would discount previous comments about measuring cpu_time or system_clock resolution in clock ticks, particularly if that may be thought to relate to CPU or data buss ticks, such as rdtsc instruction could report.

    0 讨论(0)
  • 2020-12-03 10:31

    I find secnds() to be the easiest way to get wall time. Its usage is almost identical to cpu_time().

    real(8)::t1,delta
    t1=secnds(0.0)
    !Do stuff
    delta=seconds(t1)
    
    0 讨论(0)
  • 2020-12-03 10:37

    These two intrinsics report different types of time. system_clock reports "wall time" or elapsed time. cpu_time reports time used by the CPU. On a multi-tasking machine these could be very different, e.g., if your process shared the CPU equally with three other processes and therefore received 25% of the CPU and used 10 cpu seconds, it would take about 40 seconds of actual elapsed or wall clock time.

    0 讨论(0)
提交回复
热议问题