> > I am wondering what the safe way to time a routine in Fortran 90 is, if
> > it takes a very short time. With the usual approach:
> >
> > CALL SYSTEM_CLOCK(CLOCK=c1)
> > DO k=1,1000...
> > erf=Erf(x)
> > END DO
> > CALL SYSTEM_CLOCK(CLOCK=c2)
> > counts=c2-c1
> >
> > and the Fortran 90 compiler fully informed that the function Erf is a
> > harmless PURE procedure, I am afraid a smart compiler would optimize
> > "too" well the above code and make the timings invalid.
>
> My solution:
> declare an array y of dimension 1000, fill all its elements
> with the same value x, and write:
>
> CALL SYSTEM_CLOCK(CLOCK=c1)
> DO k=1,1000...
> erf=Erf(y(k))
> END DO
> CALL SYSTEM_CLOCK(CLOCK=c2)
> counts=c2-c1
>
> Do you think that the compiler would be smart enough to see
> that all elements are identical?
>
> Alberto Fasso'
How about:
CALL SYSTEM_CLOCK(CLOCK=c1)
DO k=1,1000
y(k)=x(1001 - k)
END DO
CALL SYSTEM_CLOCK(CLOCK=c2)
DO k=1,1000
y(k)=Erf(x(1001 - k))
END DO
CALL SYSTEM_CLOCK(CLOCK=c3)
counts=(c3-c2) - (c2-c1)
The (1001 - k) index is intended to prevent optimisation
of the first DO loop which cannot be done in the second.
--
David J Adams
<[log in to unmask]>
Computing Services
University of Southampton
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|