public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31067]  New: MINLOC should sometimes be inlined (gas_dyn is sooooo sloooow)
@ 2007-03-07 10:20 fxcoudert at gcc dot gnu dot org
  2007-03-07 11:28 ` [Bug fortran/31067] " tkoenig at gcc dot gnu dot org
                   ` (40 more replies)
  0 siblings, 41 replies; 46+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-07 10:20 UTC (permalink / raw)
  To: gcc-bugs

[see http://www.polyhedron.co.uk/pb05/linux/f90bench_AMD.html for the original
polyhedron benchmark results, an explanation of what the benchmark is and the
source code]

Typical timings for the gas_dyn.f90 benchmark on my AMD64/linux system are:

* ifort -O3 -xW -ipo -static -V gas_dyn.f90 -o gas_dyn.intel
=> ./gas_dyn.intel  10.53s user 0.43s system 99% cpu 10.976 total

* gfortran -static -ftree-vectorize -march=opteron -ffast-math -funroll-loops
-O3 gas_dyn.f90 -o gas_dyn.gfortran
./gas_dyn.gfortran  15.92s user 0.05s system 99% cpu 15.969 total

Experimenting a bit with Intel options to understand why it is so fast, I found
that:
  * disabling inlining doesn't change the execution time
  * disabling vectorization drops it to the same execution time as gfortran
(roughly speaking)

Following an analysis by Tobias Burnus, and noting that 22.16% of the total
time is spent in the MINLOC library routine, I modified the source by replacing
a call to MINLOC by inline code:
--- gas_dyn.f90 2007-03-07 09:36:23.000000000 +0100
+++ gas_dyn.modified.f90        2007-03-07 10:44:14.000000000 +0100
@@ -234,12 +234,23 @@ end module ints
 !-----------------------------------------------
 !   L o c a l   V a r i a b l e s
 !-----------------------------------------------
-      INTEGER :: ISET(1)
-      REAL :: VSET, SSET
+      INTEGER :: ISET(1), I
+      REAL :: VSET, SSET, T
       REAL, DIMENSION (NODES) :: DTEMP
 !-----------------------------------------------
       DTEMP = DX/(ABS(VEL) + SOUND)
-      ISET = MINLOC (DTEMP)
+! FXC replace this:
+!      ISET = MINLOC (DTEMP)
+! by this:
+      ISET(1) = 0
+      T = HUGE(T)
+      DO I = 1, NODES
+        IF (DTEMP(I) < T) THEN
+          T = DTEMP(I)
+          ISET(1) = I
+        END IF
+      END DO
+! end of modification
       DT = DTEMP(ISET(1))
       VSET = VEL(ISET(1))
       SSET = SOUND(ISET(1))

this makes the code faster by 14%:
./gas_dyn.modified.gfortran  13.56s user 0.05s system 99% cpu 13.614 total

Maybe we should have MINLOC inlined when there's no mask, stride 1 and
one-dimensional?


PS: Other hot spots are:
  %   cumulative   self              self     total
 time   seconds   seconds    calls  Ts/call  Ts/call  name
 29.13      4.18     4.18                             eos_ (gas_dyn.f90:410 @
413386)
 14.22      6.22     2.04                             chozdt_ (gas_dyn.f90:241
@ 4152b3)

Both lines are whole-array operations, corresponding to:
    CS(:NODES) = SQRT(CGAMMA*PRES(:NODES)/DENS(:NODES))
and
    DTEMP = DX/(ABS(VEL) + SOUND)

I filed PR31066, which is I think a small reproducer for the two lines above.


-- 
           Summary: MINLOC should sometimes be inlined (gas_dyn is sooooo
                    sloooow)
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fxcoudert at gcc dot gnu dot org
 BugsThisDependsOn: 31066


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31067


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

end of thread, other threads:[~2011-07-29  7:13 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-31067-4@http.gcc.gnu.org/bugzilla/>
2011-07-25 15:44 ` [Bug fortran/31067] MINLOC should sometimes be inlined (gas_dyn is sooooo sloooow) rguenth at gcc dot gnu.org
2011-07-28 13:52 ` jakub at gcc dot gnu.org
2011-07-28 16:03 ` jakub at gcc dot gnu.org
2011-07-28 20:58 ` jakub at gcc dot gnu.org
2011-07-29  7:13 ` burnus at gcc dot gnu.org
2007-03-07 10:20 [Bug fortran/31067] New: " fxcoudert at gcc dot gnu dot org
2007-03-07 11:28 ` [Bug fortran/31067] " tkoenig at gcc dot gnu dot org
2007-03-07 12:18 ` fxcoudert at gcc dot gnu dot org
2007-03-07 21:00 ` tkoenig at gcc dot gnu dot org
2007-03-07 21:09 ` fxcoudert at gmail dot com
2007-03-07 21:10 ` tkoenig at gcc dot gnu dot org
2007-03-07 21:29 ` tkoenig at gcc dot gnu dot org
2007-03-08  5:50 ` fxcoudert at gcc dot gnu dot org
2007-03-10 12:34 ` tkoenig at gcc dot gnu dot org
2007-03-11 19:43 ` tkoenig at gcc dot gnu dot org
2007-03-12 19:04 ` pault at gcc dot gnu dot org
2007-03-13 20:12 ` tkoenig at gcc dot gnu dot org
2007-03-26 10:38 ` pault at gcc dot gnu dot org
2007-03-26 11:44 ` pault at gcc dot gnu dot org
2007-04-02 16:44 ` tkoenig at gcc dot gnu dot org
2007-04-02 20:01 ` tkoenig at gcc dot gnu dot org
2007-05-18 20:16 ` jb at gcc dot gnu dot org
2007-05-18 20:20 ` jb at gcc dot gnu dot org
2007-06-15 20:35 ` tkoenig at gcc dot gnu dot org
2007-06-27 14:49 ` jb at gcc dot gnu dot org
2008-01-02 21:03 ` pault at gcc dot gnu dot org
2008-01-02 21:07 ` dominiq at lps dot ens dot fr
2009-07-03 10:00 ` rguenth at gcc dot gnu dot org
2009-07-03 12:19 ` rguenth at gcc dot gnu dot org
2009-07-03 12:41 ` burnus at gcc dot gnu dot org
2009-07-03 12:57 ` rguenth at gcc dot gnu dot org
2009-07-03 13:07 ` burnus at gcc dot gnu dot org
2009-07-05  6:48 ` irar at il dot ibm dot com
2009-07-20 12:04 ` irar at il dot ibm dot com
2009-07-24  7:57 ` jakub at gcc dot gnu dot org
2009-07-24  8:20 ` burnus at gcc dot gnu dot org
2009-07-24  8:30 ` jakub at gcc dot gnu dot org
2009-07-26  7:48 ` irar at il dot ibm dot com
2009-07-26  9:50 ` burnus at gcc dot gnu dot org
2009-07-27  8:36 ` irar at il dot ibm dot com
2009-07-27  9:18 ` burnus at gcc dot gnu dot org
2009-07-27 11:03 ` jakub at gcc dot gnu dot org
2009-07-27 11:10 ` jakub at gcc dot gnu dot org
2009-07-27 12:44 ` irar at il dot ibm dot com
2009-07-27 13:15 ` burnus at gcc dot gnu dot org
2009-07-27 14:51 ` jakub at gcc dot gnu dot org
2009-07-28  8:12 ` irar at il dot ibm dot com

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