Questions about system_clock()

What is the time unit of system_clock(), and I found out during the test that it’s not milliseconds

Hi yaoshunyu,

It’s system dependent. Though you can use the optional “count_rate” argument in combination with “count” to obtain the time in seconds. See: https://www.pgroup.com/resources/docs/19.10/x86/pgi-user-guide/index.htm#opt-exe-timing-inst-cnt

I wrote up the following small example to illustrate it’s use:

% cat clock.f90
function spin(n)
   integer(8) :: i,n
   real(8) :: x,y, spin
   y = 1.023
   do i=1,n
     x = real(i) * 0.123
     y = cos(x)*sin(y)
   end do
   spin = y

end function spin

PROGRAM test_system_clock
  INTEGER :: cnt0, cnt1, hz
  real    :: time
  real(8) :: spin, y
  CALL SYSTEM_CLOCK(count_rate=hz)
  WRITE(*,*) "Clock Count Rate: ", hz
  CALL SYSTEM_CLOCK(count=cnt0)
  y = spin(10000000_8)
  CALL SYSTEM_CLOCK(count=cnt1)
  time = real(cnt1-cnt0) / real(hz)
  WRITE(*,*) "Time of spin1 ", time
  CALL SYSTEM_CLOCK(count=cnt0)
  y = spin(888899088_8)
  CALL SYSTEM_CLOCK(count=cnt1)
  time = real(cnt1-cnt0) / real(hz)
  WRITE(*,*) "Time of spin2 ", time
END PROGRAM
% pgfortran clock.f90 -o clock.out ; ./clock.out
 Clock Count Rate:       1000000
 Time of spin1    0.2665410
 Time of spin2     19.62897

Hope this helps,
Mat

thanks for your help