David Adams wrote:
> 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.
Well, if the thing to do is to trick the compiler, how about doing the
following (this avoids using arrays. On today's computers one would need to
call Erf many-many times, so let's save memory):
MODULE DummyErf
USE Erf
CONTAINS
FUNCTION CallErf(x,k) RESULT(erf_x) ! The cost of argument passing and Erf
REAL, INTENT(IN) :: x
INTEGER, INTENT(IN) :: k
REAL :: erf_x
erf_x=Erf(x)
END FUNCTION CallErf
FUNCTION JustCall(x,k) RESULT(erf_x) ! Just the cost of argument passing
REAL, INTENT(IN) :: x
INTEGER, INTENT(IN) :: k
REAL :: erf_x
erf_x=1.0 ! Same cost up to the call to Erf(x)
END FUNCTION CallErf
END MODULE DummyErf
PROGRAM TimeErf
USE DummyErf
....
CALL SYSTEM_CLOCK(CLOCK=c1)
DO k=1,1000
y=JustCall(x,k)
END DO
CALL SYSTEM_CLOCK(CLOCK=c2)
DO k=1,1000
y=CallErf(x,k)
END DO
CALL SYSTEM_CLOCK(CLOCK=c3)
counts=(c3-c2) - (c2-c1)
END DO
But before I accept this solution, I gotta ask again. When people do timing
tests for such functions, do they try to trick the compiler this way, or is
there a nicer way.
Thanks,
Aleksandar
--
_____________________________________________
Aleksandar Donev
[log in to unmask]
http://www.pa.msu.edu/~donev/
Department of Physics and Astronomy
Michigan State University
East Lansing, MI 48825
(517) 432-6770
_____________________________________________
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|