Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Re: compiler efficency
  1997-01-27 20:37 Claus Denk
@ 1997-01-27 20:35 ` Brett McCormick
  1997-01-27 20:37 ` Lev D Gelb
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Brett McCormick @ 1997-01-27 20:35 UTC (permalink / raw)


Supposedly GCC has not yet been optimized for running on linux-alpha,
and that may have a lot to do with your problem.  When we had an alpha
I noticed that compilation wasn't especially speedy..

On Mon, 27 January 1997, at 21:37:16, Claus Denk wrote:

>  Hi all,
> 
> we just got a PC164 system and I did some benchmarks with our Fortran
> programs over here. One of the test-programs is a simple loop
> doing (output of f2c): 
> for (i = 2; i <= i__1; ++i) {
>         gam += 1. / (doublereal) i;
> }
> Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
> TWICE as fast as the gcc executable (I found this factor also in other
> programs). I have read that the gcc math libraries are not very fast,
> but I do not understand why this simple loop is that slow with gcc. So my
> questions:
>  1)  Any ideas why ? (This is Redhat 4.0). 
>  2)  Will this problem be eventually resolved some day (in the nearer future)?
>  3)  Has anyone successfully installed Digital Unix f77 on a Linux system ?
>  4)  What would be the license $ for f77/DU if 3) works ?
> 
> regards, Claus
> 
> --
> 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
> 

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* compiler efficency
@ 1997-01-27 20:37 Claus Denk
  1997-01-27 20:35 ` Brett McCormick
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Claus Denk @ 1997-01-27 20:37 UTC (permalink / raw)


Hi all,

we just got a PC164 system and I did some benchmarks with our Fortran
programs over here. One of the test-programs is a simple loop
doing (output of f2c): 
for (i = 2; i <= i__1; ++i) {
        gam += 1. / (doublereal) i;
}
Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
TWICE as fast as the gcc executable (I found this factor also in other
programs). I have read that the gcc math libraries are not very fast,
but I do not understand why this simple loop is that slow with gcc. So my
questions:
 1)  Any ideas why ? (This is Redhat 4.0). 
 2)  Will this problem be eventually resolved some day (in the nearer future)?
 3)  Has anyone successfully installed Digital Unix f77 on a Linux system ?
 4)  What would be the license $ for f77/DU if 3) works ?

regards, Claus

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
  1997-01-27 20:37 Claus Denk
  1997-01-27 20:35 ` Brett McCormick
@ 1997-01-27 20:37 ` Lev D Gelb
  1997-01-27 21:15 ` Jim Nance
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Lev D Gelb @ 1997-01-27 20:37 UTC (permalink / raw)


I have found similar problems between f2c+gcc and DEC f77, that
DEC f77 is 2x as fast as the converted code.
I believe that there is something terribly slow in the
libf77 that comes with f2c, because people in our group
have benchmarked gcc vs DEC cc on numerical C-codes, and found
only a 10-20% slowdown with gcc.

Eagerly awaiting g77 version 0.5.20, which should have Alpha
support...

Lev Gelb

On Mon, 27 Jan 1997, Claus Denk wrote:

>  Hi all,
> 
> we just got a PC164 system and I did some benchmarks with our Fortran
> programs over here. One of the test-programs is a simple loop
> doing (output of f2c): 
> for (i = 2; i <= i__1; ++i) {
>         gam += 1. / (doublereal) i;
> }
> Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
> TWICE as fast as the gcc executable (I found this factor also in other
> programs). I have read that the gcc math libraries are not very fast,
> but I do not understand why this simple loop is that slow with gcc. So my
> questions:
>  1)  Any ideas why ? (This is Redhat 4.0). 
>  2)  Will this problem be eventually resolved some day (in the nearer future)?
>  3)  Has anyone successfully installed Digital Unix f77 on a Linux system ?
>  4)  What would be the license $ for f77/DU if 3) works ?
> 
> regards, Claus
> 
> --
> 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
> 
> 

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-27 20:51 Robert Williams
  0 siblings, 0 replies; 15+ messages in thread
From: Robert Williams @ 1997-01-27 20:51 UTC (permalink / raw)


Lev D Gelb wrote:
> 
> I have found similar problems between f2c+gcc and DEC f77, that
> DEC f77 is 2x as fast as the converted code.

Benchmarks of LAPACK routines made with f2c+gcc
versus g77 show that g77 can be twice as fast as
f2c+gcc.
http://www.fysik.dtu.dk/~schiotz/linux/lapack-linux.html

--
from Bob Williams, mailto:bob@bob.usuf2.usuhs.mil

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
  1997-01-27 20:37 Claus Denk
  1997-01-27 20:35 ` Brett McCormick
  1997-01-27 20:37 ` Lev D Gelb
@ 1997-01-27 21:15 ` Jim Nance
  1997-01-27 22:13 ` Scott Locklin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 15+ messages in thread
From: Jim Nance @ 1997-01-27 21:15 UTC (permalink / raw)


Hi Claus,

> for (i = 2; i <= i__1; ++i) {
>         gam += 1. / (doublereal) i;
> }

> Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
> TWICE as fast as the gcc executable (I found this factor also in other
> programs). I have read that the gcc math libraries are not very fast,
> but I do not understand why this simple loop is that slow with gcc. So my
> questions:
>  1)  Any ideas why ? (This is Redhat 4.0). 

I am not supprised that it is faster, but the factor of 2 does supprise me.
I would find it interesting if you could compile the output of f2c with the
Digital cc compiler to see if the difference is related to the f2c translation
or a problem with gcc.  I think the g77 people are working on making their
stuff run on 64 bit platforms.  You might see if you can get hold of some
of that code and see if it runs better.

>  2)  Will this problem be eventually resolved some day (in the nearer future)?

People are aware that both the Linux libraries and the gcc optimizer need
to be improved.  As far as I know, no one has taken this project on.

>  3)  Has anyone successfully installed Digital Unix f77 on a Linux system ?
>  4)  What would be the license $ for f77/DU if 3) works ?

It is probably possible to get Digitals f77 to run under linux but its going
to be a lot of work.  You would probably be happier setting up your machine
to dualboot Linux and Digital Unix.

Sorry I don't have better news,

Jim

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-27 21:48 Toon Moene
  0 siblings, 0 replies; 15+ messages in thread
From: Toon Moene @ 1997-01-27 21:48 UTC (permalink / raw)


Lev D Gelb <gelb@cheme.cornell.edu> wrote:

>  I have found similar problems between f2c+gcc and DEC
>  f77, that DEC f77 is 2x as fast as the converted code.
>  I believe that there is something terribly slow in the
>  libf77 that comes with f2c, because people in our group
>  have benchmarked gcc vs DEC cc on numerical C-codes, and
>  found only a 10-20% slowdown with gcc.
>
>  Eagerly awaiting g77 version 0.5.20, which should have
>  Alpha support...

Hmm, haven't seen anything by Craig yet, so lets jump in:

The top entries of the plan file (finger -l fortran@gnu.ai.mit.edu):

Currently planned for 0.5.20, intended to be a "development"  
version for some new features/workarounds:

  -  Support DEC Alpha (AXP) chip (running Linux, primarily).
     (Done.)

  -  Fix bugs in gcc back end (AXP support; loop unrolling crash).
     Package in g77 as patches to gcc-2.7.2 and 2.7.2.1.  Submit for
     inclusion in gcc-2.8.0.  (Done.)

Besides, to say more about Claus's code example, we need a fully  
compilable program module; just a few lines out of context won't  
prove anything.  Note, for instance, that the Digital compiler might  
throw the loop away, because (apparently) nothing is done with the  
result (gam) calculated inside ....  If this is not the reason (:-)  
the speed difference might be caused by the fact that at the default  
optimisation level the Digital Fortran compiler unrolls loops,  
whereas g77/gcc won't do that (because this is a CPU architecture  
dependent optimisation).

Hope this helps,

--
Toon Moene (mailto:toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
g77 Support: mailto:fortran@gnu.ai.mit.edu; NWP:  
http://www.knmi.nl/hirlam

PS: Perhaps I should add that the g77 development group has the
    utmost confidence that Steve Lionel's team can counter all our
    attacks at being the "best" Fortran compiler for the Alpha plat-
    form.  To us, frequent readers (and posters) to comp.lang.fortran
    he is *the* example to follow in precision and reasonableness
    when it comes to offering support via this unpaid-for medium  
...

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
  1997-01-27 20:37 Claus Denk
                   ` (2 preceding siblings ...)
  1997-01-27 21:15 ` Jim Nance
@ 1997-01-27 22:13 ` Scott Locklin
  1997-01-27 22:41 ` Michal Jaegermann
  1997-01-27 23:35 ` Richard Henderson
  5 siblings, 0 replies; 15+ messages in thread
From: Scott Locklin @ 1997-01-27 22:13 UTC (permalink / raw)


> 
>  Hi all,
> 
> we just got a PC164 system and I did some benchmarks with our Fortran
> programs over here. One of the test-programs is a simple loop
> doing (output of f2c): 
> for (i = 2; i <= i__1; ++i) {
>         gam += 1. / (doublereal) i;
> }
> Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
> TWICE as fast as the gcc executable (I found this factor also in other
> programs). I have read that the gcc math libraries are not very fast,
> but I do not understand why this simple loop is that slow with gcc. So my
> questions:
>  1)  Any ideas why ? (This is Redhat 4.0). 

Well, I don't have your original source code, and I don't have a 21164 to 
check it on, but I would guess instruction scheduling is the culprit.
21164 is theoretically capable of 4 instructions per cycle, but they have 
to be scheduled properly or no go. Doubtless DEC has put more effort into 
this than GNU, and understands the issues and trickies rather more than 
GNU folks.
gprof looks neato. You could also use DMT's cycle checker bit o code to 
see where the cycles are taken up. (There are timer registers on the 
Alpha for this purpose).

-SL

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-27 22:15 Przemek Klosowski
  0 siblings, 0 replies; 15+ messages in thread
From: Przemek Klosowski @ 1997-01-27 22:15 UTC (permalink / raw)


Claus wrote:

   for (i = 2; i <= i__1; ++i) {
	   gam += 1. / (doublereal) i;
   }

   Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
   TWICE as fast as the gcc executable (I found this factor also in other

I took a look at machine code from gcc and DEC cc. I had a good laugh
when GCC optimized away the loop entirely with -O2 (initially I didn't
use the computed value of gam).  Here is a test case:

typedef double doublereal;
double
x () {
   int i, i__1 = 9999;
   double gam = 0;
   for (i = 2; i <= i__1; ++i) {
      gam += 1. / (doublereal) i;
   }
   return gam;
}

and here is DEC cc -O2 code                            and GCC -O2 code

 #    5    double gam = 0;		               cpys $f31,$f31,$f0     
        cpys    $f31, $f31, $f1		               bis $31,2,$2           
        .loc    2 6			               ldt $f10,0($1)         
 #    6    for (i = 2; i <= i__1; ++i) {               .align 5               
        ldil    $16, 2			       $43:                           
        ldit    $f0, 1.			               stq $2,0($30)          
        .align  3			               ldt $f11,0($30)        
$32:					               cvtqt $f11,$f1         
        .loc    2 6			               divt $f10,$f1,$f1      
					               addl $2,1,$2           
        .loc    2 7			               cmple $2,$3,$1         
 #    7       gam += 1. / (doublereal) i;              addt $f0,$f1,$f0       
        stq     $16, 0($sp)		               bne $1,$43             
        ldt     $f10, 0($sp)		               addq $30,16,$30        
        cvtqt   $f10, $f11		               ret $31,($26),1        
        divt    $f0, $f11, $f12		               .end x                 
        addt    $f1, $f12, $f1
        addl    $16, 1, $16
        cmplt   $0, $16, $1
        beq     $1, $32
 #    8    }
        cpys    $f1, $f1, $f0
        lda     $sp, 16($sp)
        ret     $31, ($26), 1
        .end    x

As you can see, not much difference, except that DEC cc probably does
better scheduling so that 21164 can multiple-issue, but still, a 2x
difference is more than I expected.

I would guess that most of the difference comes from naive translation
by f2c, in which case g77 should do better. Also, are you sure you
compiled with optimizations turned on?

			przemek klosowski <przemek@nist.gov>  (301) 975-6249
			Reactor Division (bldg. 235), E111 
			National Institute of Standards and Technology
			Gaithersburg, MD 20899,      USA

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-27 22:41 Craig Burley
  0 siblings, 0 replies; 15+ messages in thread
From: Craig Burley @ 1997-01-27 22:41 UTC (permalink / raw)


>Eagerly awaiting g77 version 0.5.20, which should have Alpha
>support...

Make that "will".

However, it's not clear that g77 0.5.20 will be noticably better
at generating optimal code than f2c|gcc in any particular case.
There _are_ some performance improvements in 0.5.20 that will
make it better for some kinds of code, but I don't think any of
them will improve things like division and square root on the
Alpha.

So, while g77 is going to support Linux/Alpha soon, it won't be
giving _everyone_ a reason not to use Digital UNIX and f77.

However, I am pretty sure g77 _will_ also get better at producing
decent Alpha code in the future.  0.5.20 will just be the first
release of note to Alpha users.  For example, if it's true that
gcc 2.8 or some new version of gcc offers improved code generation
for Alpha, then that almost certainly means a subsequent version of
g77 will be made available that supports that new version of gcc.

        tq vm, (burley)

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
  1997-01-27 20:37 Claus Denk
                   ` (3 preceding siblings ...)
  1997-01-27 22:13 ` Scott Locklin
@ 1997-01-27 22:41 ` Michal Jaegermann
  1997-01-27 23:35 ` Richard Henderson
  5 siblings, 0 replies; 15+ messages in thread
From: Michal Jaegermann @ 1997-01-27 22:41 UTC (permalink / raw)


> 
> we just got a PC164 system and I did some benchmarks with our Fortran
> programs over here. One of the test-programs is a simple loop
> doing (output of f2c): 
> for (i = 2; i <= i__1; ++i) {
>         gam += 1. / (doublereal) i;
> }
> Now, the Fortran-program compiled with the Digital Unix (f77) compiler executes
> TWICE as fast as the gcc executable

Just a word of caution.  Benchmarking a quite complicated system on a loop
like that (or something like the famous "sieve") has a value on par with
the BogoMips indicator.  It tells you only that this loop runs faster or
slower in some circumstances.  It might (note: MIGHT) indicate that
an instruction scheduler and branch prediction in DEC compiler is better
than in gcc (it is highly likely that this is the case :-) but without
a detailed analysis even that cannot be concluded.  You even skipped an
information what optimizer flags, if any, were used in both compilations.
gcc without optimizations is **designed** to output a very simple-minded
code.  DEC Fortran compiler is likely, for example, to unroll loops by
default; you will not get that in gcc unless explicitely requested.

> (I found this factor also in other programs).

This is a bit more significant, although in an absence of what these
programs were and how they were compiled is still of a limited value.

It is known that gcc support for alpha, libraries and g77 (the next
release apparently should be "alpha ready" - RSN) needs work.  But
**they** - meaning developers - likely can use some help.  In any
case boundaries between developers and users in FSF projects are not
so well defined as in other circumstances. :-)

There is also something which is a "porting bug" in f2c - IMHO.
If you will look closer you will notice that basic Fortran types
of REAL*4 and INTEGER*4 are really 8 bytes wide on Alpha.
This may have some effect on speed and creates porting headaches -
especially if a "legacy code" is a mixture of Fortran and C.
The issue can be dealt with but is likely beyond a grasp of many
Fortran programmers. :-)

All in all, I would not mind seeing at last g77 running correctly on
alpha. :-)

  Michal

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
  1997-01-27 20:37 Claus Denk
                   ` (4 preceding siblings ...)
  1997-01-27 22:41 ` Michal Jaegermann
@ 1997-01-27 23:35 ` Richard Henderson
  5 siblings, 0 replies; 15+ messages in thread
From: Richard Henderson @ 1997-01-27 23:35 UTC (permalink / raw)


> (output of f2c): 
> for (i = 2; i <= i__1; ++i) {
>         gam += 1. / (doublereal) i;
> }

The cast is likely the problem.  If you rewrite the loop like so:

	long i, i__1;
	double i__d, gam;
	for (i__d = i = 2; i <= i__1; ++i, ++i__d) {
		gam += 1. / i__d;
	}

things go much faster.  This is because in order to cast from 
integer to double, we must save the register to memory, load into
an fp register, then do a cvtqt instruction.  You can save all
that by keeping a parallel loop counter as a double.

Testing this hypothesis on an ev45/275, I get a 1.4 times speedup.

Now, because of the nature of FP, it is not legal for GCC to 
to automatically do this conversion unless it can bound i__1
below 2**56 or something.  But I bet it doesn't do anything
under any circumstances, nor is it likely to in the future.

I don't know what context this appeared in in the original
Fortran source, but your best bet is to fix f2c to shadow the
loop variable itself.

r~

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-28 11:22 Claus Denk
  0 siblings, 0 replies; 15+ messages in thread
From: Claus Denk @ 1997-01-28 11:22 UTC (permalink / raw)


Toon Moene <toon@moene.indiv.nluug.nl> wrote:

>  -  Support DEC Alpha (AXP) chip (running Linux, primarily).
>     (Done.)

This sounds fine. When 0.5.20 will be released I'll give it a try.

> Besides, to say more about Claus's code example, we need a fully  
> compilable program module; just a few lines out of context won't  
> prove anything.

Here you go: ( I was just posting the loop, as this is where almost all
the time is spent)

        PROGRAM EULER
        DOUBLE PRECISION GAM
        GAM = 1.0d0
        NMAX=100000000
        DO I=2,NMAX
          GAM=GAM+1.0d0/dble(I)
        ENDDO
        GAM = GAM - DLOG(dble(NMAX))
        WRITE(*,*) GAM
        WRITE(*,*) 'Exact: 0,57721566490153286060'
        END

  
> the speed difference might be caused by the fact that at the default  
> optimisation level the Digital Fortran compiler unrolls loops,  
> whereas g77/gcc won't do that (because this is a CPU architecture  
> dependent optimisation).

Tests were done with -O3 on both gcc and f77. I got on a 433 Mhz 21164/Linux

gcc: 12.09 sec.
f77:  6.80 sec.

On a Pentium 133/Linux I get:

f2c+gcc: 40.58
g77    : 39.09

If anyone tries the program, please send me your results (Compiler/Options
Machine/OS), so I can add it to my list.  

regards, Claus

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-28 20:02 Toon Moene
  0 siblings, 0 replies; 15+ messages in thread
From: Toon Moene @ 1997-01-28 20:02 UTC (permalink / raw)


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

This is indeed a transformation that's not done by g77 or gcc (nor  
by f2c in the translation from Fortran to C).  I seem to remember  
that SGI's Fortran compiler has an explicit option to _prohibit_  
such an optimisation.  I belief, though, that in most ordinary  
Fortran code few conversions from INTEGER to REAL occur.

>  Tests were done with -O3 on both gcc and f77. I got on
>  a 433 Mhz 21164/Linux

This is actually not fair with respect to f77; its highest  
optimisation level is -O5; on the other hand, gcc -O3 -funroll-loops  
might result in a better figure for the gcc timing.

>  If anyone tries the program, please send me your results
>  (Compiler/Options Machine/OS), so I can add it to my
>  list.

Hmmm, can't resist (this is on a 25 Mhz Motorola 68040 based  
NeXTStation - but my other computer is a 47 CPU Fujitsu :-)

g77 -O2:	278.5 s
g77 -O2:	251.7 s	(with 'FAC')
f2c + gcc -O2:	278.4 s
f2c + gcc -O2:	260.1 s	(with 'FAC')

Cheers,
Toon.

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
@ 1997-01-28 23:23 Huw Davies
  0 siblings, 0 replies; 15+ messages in thread
From: Huw Davies @ 1997-01-28 23:23 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: compiler efficency
       [not found] <9701282002.AA15294@moene.indiv.nluug.nl>
@ 1997-01-29  0:10 ` Michal Jaegermann
  0 siblings, 0 replies; 15+ messages in thread
From: Michal Jaegermann @ 1997-01-29  0:10 UTC (permalink / raw)


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

I tried this loop on the following machine (275 MHz Cabriolet):

cpu model               : EV4
cpu variation           : 0
cpu revision            : 0
cpu serial number       : Linux_is_Great!
system type             : Cabriolet
system variation        : 0
system revision         : 0
system serial number    : MILO-0000
cycle frequency [Hz]    : 274951883
timer frequency [Hz]    : 1024.00
page size [bytes]       : 8192
phys. address bits      : 34
max. addr. space #      : 63
BogoMIPS                : 271.58
kernel unaligned acc    : 0 (pc=0,va=0)
user unaligned acc      : 0 (pc=0,va=0)
cpu                     : Alpha

A compiler is gcc version 2.7.2, as distributed with RH 4.0, and
programs were compiled with 'fort77 -O6' (but a peek into a generated
assembler code does not reveal any differences with -O3).

Times were like this:

For an original version

20.94user 0.00system 0:20.95elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (84major+25minor)pagefaults 0swaps

For rewrite by Toon Moene

18.00user 0.00system 0:18.00elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (84major+25minor)pagefaults 0swaps

And this one

15.78user 0.00system 0:15.80elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (84major+25minor)pagefaults 0swaps

for the following variant:

      PROGRAM EULER
      DOUBLE PRECISION GAM, I, NMAX
      GAM = 1.0d0
      NMAX=100000000.
      DO I=NMAX,2.,-1
         GAM=GAM+1.0d0/I
      ENDDO
      GAM = GAM - DLOG(dble(NMAX))
      WRITE(*,*) GAM
      WRITE(*,*) 'Exact: 0,57721566490153286060'
      END

Yes, I realize that using a floating point loop control is, in general,
a Very Bad Idea (TM).  But in this particular case we can get away
with it. :-)

Unfortunately I cannot compare with results of Fortran compiler from DU. :-(

  Michal

--
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

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~1997-01-29  0:10 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-01-27 22:41 compiler efficency Craig Burley
     [not found] <9701282002.AA15294@moene.indiv.nluug.nl>
1997-01-29  0:10 ` Michal Jaegermann
  -- strict thread matches above, loose matches on Subject: below --
1997-01-28 23:23 Huw Davies
1997-01-28 20:02 Toon Moene
1997-01-28 11:22 Claus Denk
1997-01-27 22:15 Przemek Klosowski
1997-01-27 21:48 Toon Moene
1997-01-27 20:51 Robert Williams
1997-01-27 20:37 Claus Denk
1997-01-27 20:35 ` Brett McCormick
1997-01-27 20:37 ` Lev D Gelb
1997-01-27 21:15 ` Jim Nance
1997-01-27 22:13 ` Scott Locklin
1997-01-27 22:41 ` Michal Jaegermann
1997-01-27 23:35 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox