Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline keyword gfortran

Is there any Fortran keyword equivalent to the C "inline" keyword?

If some compiler-specific keyword exist, is there any for gfortran?

like image 843
TheRealNeo Avatar asked Jul 20 '11 14:07

TheRealNeo


People also ask

What are the conditions of inlining a function?

1) Function call overhead doesn't occur. 2) It also saves the overhead of push/pop variables on the stack when function is called. 3) It also saves overhead of a return call from a function. 4) When you inline a function, you may enable compiler to perform context specific optimization on the body of function.

How do you define a function in Fortran?

They are started with a line that includes the type of value the function will return, the function name, and the list of arguments the function takes as inputs. Any variables the function uses, including the arguments, must be declared in the function right after the first line.

What is the maximum length allowed in defining a variable in Fortran?

Variable names in Fortran consist of 1-6 characters chosen from the letters a-z and the digits 0-9.


2 Answers

In general, the Fortran specifications grant the compiler writers enormous scope in how to implement things, so a language-level construct that forced (or even hinted) specific optimizations would be very un-Fortran-y.

What you typically do in modern Fortran is not specify optimizations, but tell the compiler things it can use to decide what optimizations to implement. So an example is labelling a side-effect-free function or subroutine PURE, so that certain optimizations are enabled (and actually, this may make for easier inlining).

Otherwise, as @Vladimir F points out, you can use compiler options which are presecriptive in this way.

In a similar vein, it seems that CONTAINed subprogram are more aggressively inlined by gfortran, but that may or may not help.

like image 135
Jonathan Dursi Avatar answered Sep 19 '22 07:09

Jonathan Dursi


There is no source code statement I know of. Sometimes you can use statement functions, which are obviously inlined. Otherwise use compiler comand line options as gfortran's "-finline-functions".

like image 44
Vladimir F Героям слава Avatar answered Sep 18 '22 07:09

Vladimir F Героям слава