Inlining functions using *CONTAINS* statement

From: Arindam Chakraborty (arimail77_at_yahoo.com)
Date: 10/26/04


Date: 25 Oct 2004 21:40:30 -0700

Hi,
 I wish to inline a function in a loop, but I can't manually replace
the function call with its source code since the function is a HIGH
maintenance function and will be updated/modified frequently. The loop
is a high traffic loop and takes up 99% of the total run time of the
code. Right now I am using compiler directives to do the inlining, but
I will like to hardcode it into the program. By the way, the code is
written in F90.
 
[1]. Is there any way to inline a function (maybe using CPP
directives, or include statements) without replacing the function call
with its source code.

[2]. Does it matter in optimization and inlining (by compiler) if a
function is defined using the CONTAINS statement within the calling
program?

[3]. Any tips for optimizing big loop and functions calls will be very
useful.

Here is an example (test codes are listed below):

 Given a compiler (xlf90, pgf90, ifort) and a optimization level (say
O5) will program prog1 be better optimized than prog2 ?

Thanks in advance,
-Ari

PROGRAM prog1
implicit none
integer :: i,N
double precision :: x,y

! N is very large ~10**12

    do i=1,N
        y = bigfunc(x)
    end do

CONTAINS
FUNCTION bigfunc(x)
    : : :
    : : :
    : : :
END FUNCTION bigfunc

END PROGRAM prog1

PROGRAM prog2
implicit none
integer :: i,N
double precision :: x,y,bigfunc

! N is very large ~10**12

    do i=1,N
        y = bigfunc(x)
        : : :
        : : :
    end do

END PROGRAM prog2

FUNCTION bigfunc(x)
    : : :
    : : :
    : : :
END FUNCTION bigfunc



Relevant Pages

  • Re: Reducing build-times for large projects.
    ... If the line before it executed, then the very next inline code has ... if your architecture does speculative execution and fetch. ... > THE FUNCTION THAT IS ALREADY IN CACHE! ... Loop unrolling "works" because you get to do N iterations worth of the ...
    (comp.lang.cpp)
  • Re: I Hate Effects Loops
    ... HUGE difference in signal quality and noise between inline and looped; ... or in a loop. ...
    (alt.guitar.bass)
  • How to process a file (was: Report enhancements)
    ... >> you'd have to make if the inline PERFORM got too unwieldy. ... loop, not in the middle of it. ... wieldy program. ... the valid assertion that a valid record is available ...
    (comp.lang.cobol)
  • Re: Inlining functions using *CONTAINS* statement
    ... > I wish to inline a function in a loop, ... > the function call with its source code since the function is a HIGH ... > END FUNCTION bigfunc ... > END PROGRAM prog2 ...
    (comp.lang.fortran)
  • Re: [PATCH] tcp_cubic: faster cube root
    ... Therefore it is faster to unroll the loop. ... inline it won't cause code explosion. ...
    (Linux-Kernel)