From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <40ffdccf8758a12e2e23c40f2d24e75d.axp-list@archive.invalid> X-Archive-Original-Message-ID: <2.2.32.19970128232350.013cba90@lucifer.its.latrobe.edu.au> Date: Wed, 29 Jan 1997 10:23:50 +1100 From: Huw Davies Subject: Re: compiler efficency At 09:02 PM 1/28/97 +0100, Toon Moene wrote: >Claus Denk wrote: > >> Here you go: ( I was just posting the loop, as this is >> where almost all the time is spent) > >[ ... Deleted ... ] > >To implement Richard Henderson's suggestion (which sounds >reasonable to me), change the program as follows: > > PROGRAM EULER > DOUBLE PRECISION GAM, FAC > GAM = 1.0d0 > FAC = 1.0d0 > NMAX=100000000 > DO I=2,NMAX > FAC=FAC+1.0d0 > GAM=GAM+1.0d0/FAC > ENDDO > GAM = GAM - DLOG(dble(NMAX)) > WRITE(*,*) GAM > WRITE(*,*) 'Exact: 0,57721566490153286060' > END To improve numerical precision, you should start with the smallest fractions first. I had to post this as it's the first time I can show off all those years spent playing Numerical Analyst... A simple change gives: PROGRAM EULER DOUBLE PRECISION GAM, FAC GAM = 1.0d0 NMAX=100000000 FAC = dble(NMAX) DO I=2,NMAX GAM=GAM+1.0d0/FAC FAC=FAC-1.0d0 ENDDO GAM = GAM - DLOG(dble(NMAX)) WRITE(*,*) GAM WRITE(*,*) 'Exact: 0,57721566490153286060' END And run times (where linux.f is the original program and linux2.f is the modified version) for a alphastation 200 4/166 with Digital Unix are: lux-1> time ./linux 0.577215669900188 Exact: 0,57721566490153286060 real 40.3 user 38.1 sys 0.1 lux-2> time ./linux2 0.577215669898866 Exact: 0,57721566490153286060 real 38.4 user 37.1 sys 0.1 Huw Davies | e-mail: Huw.Davies@latrobe.edu.au Information Technology Services | Phone: +61 3 9479 1550 Fax: +61 3 9479 1999 La Trobe University | "My Alfas keep me poor in a monetary Melbourne Australia 3083 | sense, but rich in so many other ways" -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com