This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

inline question


I'm having troubles understanding how to get gfortran to inline a
subroutine. This is a simplified example but if I can't inline a function that
does a=a+b then I don't have hope for any other functions. What am
I doing wrong? (This example rewritten for gcc DOES inline the function call.)


There are two loops in the example program. The top loop calls a subroutine
'simple_add' to do the work and the bottom loop I inlined by hand to do the
exact same work.

                                   time in seconds (lower is better)
                                               top_loop        bottom_loop
gfortran -O0                            18.3                10.7
ifort -O0                                  17.3                10.4

gfortran -O4                            11.5                3.3
ifort -O4                                    3.8                3.3

ifort -O4 -fno-inline-functions 11.43 3.3


I'm using gfortran version:


/usr/apps/gnu/4.3.2/bin/gfortran -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.3.2/configure --prefix=/usr/local/apps/gnu/4.3.2 --with-mpfr-include=/usr/local/apps/gnu/4.3.2/include --with-mpfr-lib=/usr/local/apps/gnu/4.3.2/lib --disable-multilib --with-gmp=/usr/local/apps/gnu/4.3.2/lib --with-gmp-include=/usr/local/apps/gnu/4.3.2/include --enable-languages=c,c++,fortran,java,objc
Thread model: posix
gcc version 4.3.2 (GCC)


----

!The example program
subroutine simple_add (dda, ddb)
implicit none
real*8  dda,ddb

dda = dda + ddb
return
end subroutine

program sum_test
implicit none
real*8 ar,br, cr, cr1
integer k

call system ('date +%s.%N')
ar=1.d0
br=1.d0
cr1=1.d0
do k = 1, 2000000000
call simple_add(cr1,br)
enddo

call system ('date  +%s.%N')
ar=1.d0
br=1.d0
cr=1.d0
do k = 1, 2000000000
cr=cr+br
enddo
call system ('date +%s.%N')

write(*,*) cr1, cr
end



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]