Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

OPTIONS /RECURSIVE

fortranrific
Beginner
1,296 Views
I have some code I am porting from VMS to use the Intel Fortran Compiler on Linux. The code makes extensive use of OPTIONS /RECURSIVE in the code to turn on recursiveness for certain functions (the code was written for Fortran 77 but has been somewhat ported to Fortran 90). So we have a mix of functions that need static variables and some that need automatic variables. The ones that need automatic variables are marked with OPTIONS /RECURSIVE and this works perfectly fine on VMS.

It seems that OPTIONS /RECURSIVE is supported by the Intel compiler because it appears in its documentation. However, no further detail is given other than its existance. I can't figure out if OPTIONS /RECURSIVE does the same thing as it does on VMS, due to this complete lack of documentation. Also, I'm having a hard time figuring out what compiler option is equivalent to the VMS compiler option /NORECURSIVE (which is the default on VMS). Is it "-save"?
0 Kudos
5 Replies
mecej4
Honored Contributor III
1,296 Views
The /RECURSIVE option is described in the Intel Fortran User Guide . Compiler options, directives and program declarations have definite orders of precedence, and it can be troublesome to keep those rules in mind. Overuse of directives and compiler switches makes your code error-prone.

I think that you will find your code easier to understand and manage if you use the recursion facilities and rules of Fortran 95/2003, rather than trying to match VMS-Fortran compiler options and the Intel compiler options.

If a routine is designated "recursive", whether by Fortran attribute, compiler directive or compiler switch, it follows that any of its local variables whose values depend on the input variables and affect the output variables cannot be given the SAVE attribute.

At the machine-code level, given that X86/X64 CPUs have few registers, allowing recursion has the consequence that passing subroutine arguments in registers will have to be given up.
0 Kudos
fortranrific
Beginner
1,296 Views
The link you provided from the manual just says:

This option tells the compiler that all routines should be compiled for possible recursive execution. It sets the automatic option.


Whereas on VMS, the description actually has useful details:

Controls whether HP Fortran generates code and allocates data
so that a subroutine or function can be called recursively.

The default is /NORECURSIVE.

Specifying /RECURSIVE does the following:

o Changes the default allocation class for all local variables
from STATIC to AUTOMATIC, except for variables that are
data-initialized, named in a SAVE statement, or declared as
STATIC.

o Permits reference to a routine name from inside the routine.


Subprograms declared with the RECURSIVE keyword are always
recursive (whether you specify or omit the /RECURSIVE qualifier).

Data objects declared as AUTOMATIC always use stack-based storage
(whether you specify or omit the /RECURSIVE or /AUTOMATIC
qualifiers).

Specifying /RECURSIVE sets /AUTOMATIC.

You can also specify this qualifier using the OPTIONS statement.

So I guess I am just hoping these are the same between the two platforms. Since some of the authors of the HP compiler now work on the Linux one, I have a pretty good feeling that the behavior will indeed match.

We don't have "old" HP Fortran manuals to "dig up"; we are actually using a version of the compiler that was released two years ago and this code is actively maintained and changed on a daily basis. I consider the VMS manuals superior to the Intel Linux ones anyway, as my example above illustrates.

I'm surprised you are suggesting that I go through and change 63,000 lines of Fortan to work using automatic variables, rather than just supply a compiler flag on Linux for code that already works fine on VMS. It is always good to try to keep code updated for the latest standard, but in this case I think the risks outweigh the benefits.

0 Kudos
TimP
Honored Contributor III
1,296 Views
Nothing has changed in standards, except that RECURSIVE was supported for the first time in f90 standard. Thus, code for which you might have had a reason to use non-standard facilities 20 years ago has been covered by the standard (with no changes) since then.
As far as we can see from what you have said, the /recursive switch of current compilers should work, among the options available to you. Likewise, RECURSIVE keyword should work, and relieve you from depending on command line options, as both compilers support it in accordance with the standard.
0 Kudos
Steven_L_Intel1
Employee
1,296 Views
The Intel compiler treats OPTIONS RECURSIVE the same way the VMS compiler did. It is the same as adding /recursive or adding the RECURSIVE prefix (F90 feature).
0 Kudos
fortranrific
Beginner
1,296 Views
Thanks for the confirmation!
0 Kudos
Reply