From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,f8f184f3bc3517df X-Google-Attributes: gidfc89c,public X-Google-Thread: f678f,f8f184f3bc3517df X-Google-Attributes: gidf678f,public X-Google-Thread: 1094ba,f8f184f3bc3517df X-Google-Attributes: gid1094ba,public From: overman@math.ohio-state.edu (Ed Overman) Subject: Re: a**2 or a*a Date: 1998/01/14 Message-ID: <69j7mn$av5$1@mathserv.mps.ohio-state.edu>#1/1 X-Deja-AN: 315950729 References: <34BCC4A4.F27A00D1@cranfield.ac.uk> <01bd2110$37868cc0$LocalHost@stupidwin95> Organization: Department of Mathematics, The Ohio State University Newsgroups: comp.lang.fortran,comp.unix.osf.misc,comp.unix.programmer In article <01bd2110$37868cc0$LocalHost@stupidwin95>, Kevin G. Rhoads 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