| Issue |
176505
|
| Summary |
[flang] system_clock inflates time differences on macOS
|
| Labels |
flang
|
| Assignees |
|
| Reporter |
rouson
|
I wrote the program below to demonstrate that Flang's `system_clock` implementation appears to inflate time differences by approximately a factor of 1000. The other tested compilers listed in the `#else` line all yield the same, expected result in terms of the order of magnitude of time differences. Clause 16.9.202, lines 31-33 of the [Fortran 2023 Interpretation Document] states that `COUNT_RATE` "is assigned a processor-dependent approximation to the number of processor clock counts per second, or zero if there is no clock for the invoking image," which suggests that, although the approximation is processor-dependent, one would expect the order of magnitude to be the same for a reasonably good approximation with each compiler.
A different set of test programs described [here] indicate that the problem does *not* appear in tests on Linux.
```
program timer
use iso_fortran_env, only : int64, real64
implicit none
integer(int64) start_time, end_time, clock_rate, i
integer, parameter :: N = 12
real(real64) A(N,N), B(N,N), C(N,N)
call system_clock(start_time, clock_rate)
#if defined(__LFORTRAN__)
call random_init(.true., .true.)
#else
call random_init(repeatable=.true., image_distinct=.true.)
#endif
call random_number(A)
call random_number(B)
call random_number(C)
#if defined(__LFORTRAN__)
do i = 1, 2400000
#else
do i = 1, 24000000
#endif
A = matmul(B,C)
end do
print *, "maxval(A) = ", maxval(A)
call system_clock(end_time, clock_rate)
#if defined(__flang__)
print '(*(a,:,f0.3))', "Elapsed system time (flang): ", (end_time - start_time)/(1000*real(clock_rate, real64)), " sec."
#elif defined(__INTEL_COMPILER) || defined(__LFORTRAN__) || defined(__GFORTRAN__) || defined(_CRAYFTN) || defined(NAGFOR)
print '(*(a,:,f0.3))', "Elapsed system time: ", (end_time - start_time)/(real(clock_rate, real64)), " sec."
#else
print '(*(a,:,f0.3))', "Elapsed system time (unknown compiler): ", (end_time - start_time)/real(clock_rate, real64), " sec."
#endif
end program
```
[here]: https://github.com/BerkeleyLab/julienne/issues/155#issuecomment-3651903947
[Fortran 2023 Interpretation Document]: https://go.lbl.gov/fortran-2023
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs