This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Relaxing argument requiremens on SYSTEM_CLOCK
- From: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- To: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- Cc: FX <fxcoudert at gmail dot com>, gfortran <fortran at gcc dot gnu dot org>
- Date: Sun, 8 Jun 2014 08:21:55 +0300
- Subject: Re: Relaxing argument requiremens on SYSTEM_CLOCK
- Authentication-results: sourceware.org; auth=none
- References: <8B5AB16A-FA89-4AFD-BB04-8B1B0D6B9991 at gmail dot com> <20140607142427 dot GA27096 at troutmask dot apl dot washington dot edu> <D985C7D6-C86D-477D-A5D9-A025CA8833CD at gmail dot com> <20140607153817 dot GA27372 at troutmask dot apl dot washington dot edu>
On Sat, Jun 7, 2014 at 6:38 PM, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> On Sat, Jun 07, 2014 at 04:36:47PM +0200, FX wrote:
>> > The standard says that "it is is assigned a processor-dependent
>> > approximation to the number of processor clock counts per second, or
>> > zero if there is no clock." Given modern hardware where cpu throttling
>> > is common, it would seem to me that the clock rate can varying.
I think it means "processor" as per the Fortran standard definition of
the term rather than the vernacular definition. Certainly the
intention cannot be that the clock rate would vary with the cpu clock
rate, as the intention clearly is that system_clock provides a clock
suitable for wall-time measurements (as opposed to cpu_clock).
>> I agree that CLOCK_RATE can vary in principle, *if something happens
>> to the processor clock*.
>>
>> Right now, in gfortran, suppose you call SYSTEM_CLOCK twice, once
>> with a 32-bit integer, once with a 64-bit integer. The two values
>> of clock rate will differ by 3 orders of magnitude, but there is
>> supposed to be one clock (that?s how the standard reads), which
>> has not varied in the meantime.
I think originally the two versions were due to supporting
-fdefault-integer-8 in Fortran 95. Then when F2003 allowed arbitrary
integer kinds and reals we got the integer(8) version for free (and
now with your patch the rest as well, woo!). Anyway, by my reading of
the standard the current implementation is allowed, "a
processor-dependent value based on the value of the processor clock"
could mean that the "processor-dependent value" depends on the
types/kinds of the arguments, no? Same goes for COUNT_MAX; if it
wasn't allowed to provide a different COUNT_MAX for different kinds,
supporting INTEGER(1) would mean that COUNT_MAX would be 127 for all
the other kinds, which is clearly unusable.
> Oh my. I just scanned libgfortran/intrinsics/system_clock.c.
> It contains hardcoded values. It seems that we should be able
> to use clock_getres() (on at least linux/*bsd systems).
Well, struct timespec tv_nsec is in units of nanoseconds, no matter
what clock_getres says. So at worst we might be giving the user a
false sense of more accuracy than is really available, but AFAICS the
calculation should be correct. Secondly, what are we going to do with
the data provided by clock_getres? Unless the resolution happens to be
evenly divisible by all potential tv_nsec values, we'd potentially
lose information by dividing the tv_nsec value with the resolution.
FWIW, on Linux/glibc, AFAIK clock_getres always returns a resolution
of 1 nanosecond, so clock_getres is a bit pointless there.
--
Janne Blomqvist