[gfortran] Implementation SYSTEM_CLOCK intrinsic subroutine

Paul Brook paul@codesourcery.com
Fri May 14 21:10:00 GMT 2004


> > A few issues:
> >
> > +try
> > +gfc_check_system_clock (gfc_expr * count, gfc_expr * count_rate,
> > +                        gfc_expr * count_max)
> > +{
> >
> > The standard specifies that all arguments must be of *default* integer
> > type.
>
> How do you deal with "gfortran -I8"?

Use gfc_default_integer_kind().

> > Also, the second parameter of *_check should be the argument number that
> > is being checked (ie. not always zero).
>
> I don't understand what you mean.  All arguments are optional and
> they can appear in any order.  My patch correctly compiles
>
>   program d
>   integer c, cr
>   call system_clock(count=c, count_rate=cr)
>   print *,  c, cr
>   call system_clock(count_rate=cr,count=c)
>   print *,  c, cr
>   end program d

The second argument of type_check et al. is used when generating error 
messages. Compiling the following code:

  real :: r
  call system_clock(count_rate = r)

With you patch reports:

Error: 'count' argument of 'system_clock' intrinsic at (1) must be INTEGER

The arguments have already been rearranged into the order specified in the 
standard by this stage.

> > Should be declared static.
> >
> >           t = ((double)tp.tv_sec + tp.tv_usec * 1.e-6) * TCK;
> >           if (t - t0 < (double)INT_MAX)
> >             *count = (int) (t - t0);
> >           else
> >             {
> >                *count = 0;
> >                t0 = t;
> >             }
> >
> > This is wrong. In the case where t - t0 > INT_MAX we should wrap,
> >  not truncate to 0.  This behaviour is specified by the standard.
>
> Can you send me the quote from the standard?  I only have a draft
> of the upcoming Fortran standard.  It states
>
>    COUNT   shall be scalar and of type integer.  It is an INTENT(OUT)
>            argument.  It is assigned a processor-dependent value based
>            on the current value of the processor clock, or -HUGE(COUNT)
>            if there is no clock.  The processor-dependent value is
>            incremented by one for each clock count until the value
>            COUNT_MAX is reached and is reset to zero at the next count.
>            It lies in the range 0 to COUNT_MAX if there is a clock.
>
> Two things to note.  COUNT is of type integer not *default* integer type.

That looks like a new change. My (draft) F95 standard says default integer.

> The value is reset to 0 not wrapped.

My interpretation is that the sentence describes how the hypothetical counter 
changes at each clock tick.
Say a call to system_clock returns count = 0. A second call to system_clock 
COUNT_MAX+n clock ticks later should return count = n. Your implementation 
will return 0 in this case. 

> >        t1 = TCK * (t - init_time);
> >        if (t1 < (time_t) INT_MAX)
> >          *count = (int) t1;
> >        else
> >          {
> >             *count = 0;
> >             init_time = t;
> >          }
> >
> > Likewise. Also t1 may be negative, and you're also assuming
> > sizeof(time_t) >= sizeof(INT_MAX). You shouldn't be multiplying by TCK.
>
> Yes, I need to multiply by TCK.  COUNT is the number of clock times.

Wouldn't it make more sense to return the time in seconds, and set count_rate 
= 1?

Paul



More information about the Fortran mailing list