On Mon, 18 Sep 2000, Aleksandar Donev wrote:
> 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'
--------------------------------------------------
Alberto Fasso'
Stanford Linear Accelerator Center
Radiation Physics Dept. ms 48
2575 Sand Hill Road
Menlo Park, CA 94025
Tel. +1 650 926 4062 Fax: +1 650 926 3569
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|