public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Fwd: Severe performance degradation when calling functions
@ 2003-11-27 19:39 Paul Brook
  0 siblings, 0 replies; only message in thread
From: Paul Brook @ 2003-11-27 19:39 UTC (permalink / raw)
  To: gcc; +Cc: Alejandro Mota

fortran@gcc.gnu.org is mainly concerned with development of the new fortran 
frontend, rather than g77. I'm forwarding your message to the main gcc 
list.

I tested your code on a 1.1GHz Athlon with g77 3.3.2 (Debian) and ifc 7.1, 
and got more or less identical timings (~160s) from both. Maybe it's P4 
specific wierdness.

It looks like ifc/fort are clever enough to inline the call to my_max. 
Moving the definition my_max before the main program allows this to happen 
in g77.

I also tested with gfortran, and got abysmal results. I'm working on a patch 
to bring this in line with g77 and ifc.

Paul

----------  Forwarded Message  ----------

Subject: Severe performance degradation when calling functions
Date: Thursday 27 November 2003 11:10 am
From: Alejandro Mota <mota@caltech.edu>
To: fortran@gcc.gnu.org

There seems to be severe performance degradation when calling a function
that involves comparisons of floating point numbers. The following code
shows it:

      program comp
      implicit none

      real*8 x, y, z, my_max
      integer*4 i, j, n

      n = 100000
      x = 0.0d0
      y = 1.0d9

      do i = 1,n
        do j = 1,n
            z = my_max( x, y )
            x = x + 1.0d0
            y = y - 1.0d0
        end do
      end do

      stop
      end

      real*8 function my_max( x, y )
      implicit none

      real*8 x, y

      my_max = dmax1( x, y )

      return
      end


I compiled this code as shown here, and also by changing the call in the
main loop to be dmax1 instead of my_max. I tried both g77 and Intel's
Fortran compiler on a Pentium 4 machine running Fedora Core 1, and g77
and Compaq's Fortran compiler on an Alpha machine running Red Hat Linux
7.0. These are the execution times in seconds:

          P4         P4     Alpha EV67   Alpha EV67
        g77 -O3   ifc -O3    g77 -03      fort -O5

dmax1:    5.6       12.7       32.6         70.3
my_max:  91.9       12.7      451.7         70.4

As far as I can tell with this limited testing, this problem only
appears when comparisons are made within the function. Arithmetic
operations do not seem to be affected (I tested with several matrix
multiplication routines). Translating this code to C also solves the
problem, so it seems to be specific to g77.

I used gcc 3.3.2 on the P4 and gcc 3.1 on the Alpha. I also downloaded
the latest gcc-3.4 snapshot (2003/11/26) and compiled it on the P4, but
the situation is the same.

I realized about this while profiling the finite element code we use for
numerical simulations, so I wonder if someone else has also noticed
this. I appreciate comments and suggestions.

Alejandro
--
Alejandro Mota                   www.solids.caltech.edu/~mota/
Staff Scientist, Graduate Aeronautical Laboratories
California Institute of Technology
1200 E. California Blvd., Mail Stop 205-45, Pasadena CA 91125, USA

-------------------------------------------------------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-11-27 15:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-27 19:39 Fwd: Severe performance degradation when calling functions Paul Brook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).