From: overman@math.ohio-state.edu (Ed Overman)
Subject: Re: a**2 or a*a
Date: 1998/01/14 [thread overview]
Message-ID: <69j7mn$av5$1@mathserv.mps.ohio-state.edu> (raw)
In-Reply-To: 01bd2110$37868cc0$LocalHost@stupidwin95
In article <01bd2110$37868cc0$LocalHost@stupidwin95>,
Kevin G. Rhoads <T_Rhoads@NoSpam.CLASSIC.MSN.COM> wrote:
>Before optimizing compilers and coprocessor hardware, a*a was normally
>recommend over a**2. However, that isn't necessarily true now.
>
>The best way to answer this question, write it both ways in test program(s)
>and time it. With compiler optimizations turned off you can get an
>accurate idea of what the underlying hardware likes. With optimizations
>turned on, your code has to be structured to avoid getting optimized out of
>existence. Fill a large array with values, and loop over that.
>
>On x86 platforms w/ 87 coprocessors the answer to the above tends to be
>different than w/o a coprocessor -- similarly, the answer for integer
>multiplication in the x86 vs. integers loaded into the 87 are often
>different.
>
>On other platforms, there will be similar variations.
>--
>Kevin G. Rhoads, Ph.D.
>T_Rhoads@NO_SPAM.Classic.MSN.COM
Here are my timing results on a Sun ultrasparc 2/2200 in double precision.
routine Mflops
no opt optimized (-O)
x*x scalar 6.629541 64.191444
x*x vector 4.424184 22.368158
x**2 scala 7.637088 16.617260
x**2 vecto 5.365106 23.890512
x**2. scal 7.654577 16.549056
x**2. vect 5.342769 23.796837
x**2.01 sc 1.897283 2.610437
x**2.01 ve 0.567783 0.654413
x*x*x scal 5.668141 32.354875
x*x*x vect 3.702529 21.510906
x**3 scala 4.628581 13.199857
x**3 vecto 3.874324 21.533822
x**3. scal 1.659949 2.512280
x**3. vect 0.569286 0.670852
x**3.01 sc 1.884676 2.692186
x**3.01 ve 0.571896 0.647438
The entire code is rather long, but each pair of subroutines (scalar and
vector code) are similar to the following:
subroutine pwr21(aa,nloop,
$ times)
ccccc
ccccc a = a*a
ccccc
implicit double precision (a-h,o-z)
times = cputim()
do 10 i = 1,nloop
aa = aa*aa
10 continue
times = cputim() - times
return
end
subroutine pwr22(a,b,ncycle,maxnpt,
$ times)
ccccc
ccccc b(i) = a(i)*a(i)
ccccc
implicit double precision (a-h,o-z)
dimension a(*),b(*)
sum = 0.
times = cputim()
do 20 j = 1,ncycle
do 10 i = 1,maxnpt
b(i) = a(i)*a(i)
10 continue
sum = sum + b(maxnpt)
20 continue
times = cputim() - times
b(maxnpt) = b(maxnpt) + sum
return
end
(By the way, the reason for throwing in the variable sum is in case the
compiler is smart enough to drop the do 20 loop since this simply repeats
the do 10 loop ncycle times.)
Ed Overman
next prev parent reply other threads:[~1998-01-14 5:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-01-14 5:00 a**2 or a*a Yon Han CHONG
1998-01-14 5:00 ` Kevin G. Rhoads
1998-01-14 5:00 ` Ed Overman [this message]
1998-01-14 5:00 ` Arnaud Desitter
1998-01-15 5:00 ` Robert Corbett
1998-01-14 5:00 ` Phillip Helbig
1998-01-14 5:00 ` Peter Shenkin
1998-01-15 5:00 ` Nick Wagg
1998-01-15 5:00 ` Steve Lionel
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox