Discussion:
system_clock
(too old to reply)
Neil
2024-11-04 22:43:11 UTC
Permalink
Hello,

I have a question about the behaviour of system_clock.

Consider the following little program:

wayland-2022:~> cat t.f90
PROGRAM t
IMPLICIT NONE
INTEGER icount,icount_rate,icount_max
CALL system_CLOCK(icount,icount_rate,icount_max)
WRITE(*,*)'count, count_rate, count_max = ',icount,icount_rate,icount_max
END PROGRAM t

When I compile and (repeatedly) run this with nvfortran, it always
gives count=0:

wayland-2022:~> nvfortran --version

nvfortran 23.9-0 64-bit target on x86-64 Linux -tp cascadelake
NVIDIA Compilers and Tools
Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
wayland-2022:~> nvfortran t.f90
wayland-2022:~> ./a.out
count, count_rate, count_max = 0 1000000 2147483647
wayland-2022:~> ./a.out
count, count_rate, count_max = 0 1000000 2147483647
wayland-2022:~> ./a.out
count, count_rate, count_max = 0 1000000 2147483647

This is surely incorrect behaviour? It happens even if I insert some
delaying code before the call to system_clock.


By contrast the behaviour is as expected with gfortran, with a
plausible time interval of a second or so between my re-runs:

wayland-2022:~> gfortran --version
GNU Fortran (GCC) 8.5.0 20210514 (Red Hat 8.5.0-22)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

wayland-2022:~> gfortran t.f90
wayland-2022:~> ./a.out
count, count_rate, count_max = 627874925 1000 2147483647
wayland-2022:~> ./a.out
count, count_rate, count_max = 627876335 1000 2147483647
wayland-2022:~> ./a.out
count, count_rate, count_max = 627878101 1000 2147483647

(The zero of time seems to be when the machine was powered on in this
case.)


Likewise ifort gives the sort of behaviour I would expect, with the
interval between re-runs being a second or so:

wayland-2022:~> ifort --version
ifort (IFORT) 2021.4.0 20210910
Copyright (C) 1985-2021 Intel Corporation. All rights reserved.

wayland-2022:~> ifort t.f90
wayland-2022:~> ./a.out
count, count_rate, count_max = 1045988618 10000 2147483647
wayland-2022:~> ./a.out
count, count_rate, count_max = 1046003030 10000 2147483647
wayland-2022:~> ./a.out
count, count_rate, count_max = 1046017558 10000 2147483647


Why is nvfortran so different? Is this a compiler bug or is it
something permitted by the standard?


Thanks very much,

Neil.
Lawrence D'Oliveiro
2024-11-04 23:09:12 UTC
Permalink
Post by Neil
I have a question about the behaviour of system_clock.
The Fortran 2018 spec just says it returns a “processor-dependent value”
which is “incremented by one for each clock count until the value
COUNT_MAX is reached and is reset to zero at the next count”.
Post by Neil
Why is nvfortran so different?
This code is running on the GPU, right? That very likely does not maintain
its own system clock.

Loading...