For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2005 > When do compilers inline?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author When do compilers inline?
Niels L Ellegaard

2005-12-05, 8:08 am

Dear great masters

Here are some questions on (c++-style) inlining.

I understand that the average fortran compiler will automatically
inline small functions, but what is the largest function that an
average compiler will automatically inline?
Will it inline a simple function with 1 do loop?
How about 2 do loops or 3 do loops?
Is there a simple rule of thumb?

Should I be careful not to place small functions in separate modules,
or
is it easy for compilers to inline small functions across modules?
Is it ever useful to place a small function in a header file and use
"include" to import it (as a local function) into the modules where it
is needed?

I pressume that the following three code snippets will nornally result
in the same machine code:
x(1:3) = x(1:3) + 2

do i=1,3
x(i) = x(i) + 2
en do

x(1) = x(1) + 2
x(2) = x(2) + 2
x(3) = x(3) + 2

But how about x(1:30) = x(1:30) + 2?
Can I use a simple rule of thumb to determine if a given do-loop will
be treated in compile time?

Thanks in advance

Niels

Greg Lindahl

2005-12-05, 7:04 pm

In article <1133790311.910340.72750@f14g2000cwb.googlegroups.com>,
Niels L Ellegaard <niels.ellegaard@gmail.com> wrote:

>I understand that the average fortran compiler will automatically
>inline small functions, but what is the largest function that an
>average compiler will automatically inline?


There is no limit; functions which are only called once in a program
can be inlined without bloat.

>Is there a simple rule of thumb?


No.

>Should I be careful not to place small functions in separate modules,
>or
>is it easy for compilers to inline small functions across modules?


Compilers that inline between source files are fairly rare.

>I pressume that the following three code snippets will nornally result
>in the same machine code:
>x(1:3) = x(1:3) + 2
>
>do i=1,3
> x(i) = x(i) + 2
>en do
>
>x(1) = x(1) + 2
>x(2) = x(2) + 2
>x(3) = x(3) + 2


The style of the 3rd snippet does inhibit optimization in some compilers,
but probably won't hurt you at N=3. At N=30, I wouldn't recommend the
3rd style.

-- greg
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com