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

Compiler-generated module files for PURE interfaces

ereisch
New Contributor II
854 Views

I have a large program with hundreds of source files.  I have been using the "-module" and "-gen-interfaces" features for several years now with great success to ensure all of our subroutine calls correctly match the target.  We are now starting to optimize our code base by putting in routine specifiers such as "PURE", in expectation that we will be parallelizing some things in the future.  However, I'm noticing that the Intel compiler does not appear to be utilizing the auto-generated interface file for ensuring a function (or subroutine) inside a PURE function (or subroutine) is also declared as PURE.

Example:  Subroutine FOO is declared PURE, and it is compiled with the above arguments to generate a "foo__genmod.mod" file and place it in the folder specified by the "-module" argument.  Subroutine BAR is declared PURE, and calls subroutine FOO.  The compiler include paths contain the path where the generated module for FOO is placed, yet when compiling bar.for, an error is issued:

error #7137: Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE.    [FOO]

Sure, I could probably turn on generation of the *__genmod.f90 file and explicitly INCLUDE that in the subroutine, but shouldn't prefix qualifiers for functions/subroutines already be in the auto-generated module file?  I know the explicit interface is already in there because it is what catches are argument mismatches.  I figure that would also be needed by the compiler for things like FORALL calls to properly optimize them at compile-time.

Using ifort 15.0.2.

0 Kudos
3 Replies
Steven_L_Intel1
Employee
854 Views

The generated interface checking did its job - it told you that an explicit interface is required, which it is. Generated interfaces are not a substitute for an explicit interface - they're to catch errors, and this one was caught. It knows that FOO is pure but the standard requires an explicit interface in this case and you don't have one.

A procedure other than a statement function shall have an explicit interface if it is referenced and
(1) a reference to the procedure appears
(a) with an argument keyword (12.5.2), or
(b) in a context that requires it to be pure,

0 Kudos
ereisch
New Contributor II
854 Views

Ah, I guess my assumption that compiler-generated interfaces were "explicit" was incorrect.  Is including the generated f90 interface file considered compliant, or should that not be counted on?  I understand that method is not {as} portable.

0 Kudos
Steven_L_Intel1
Employee
854 Views

The .f90 files can be useful in constructing explicit interfaces, but keep in mind that Fortran doesn't allow "interface to self", so if you collect all the interfaces into an include file or module and use that everywhere, you'll get errors if it pulls in an interface to the procedure being defined.

The better approach would be to put collections of procedures (not the interfaces) in modules. In general, if you write an explicit interface for a Fortran procedure, other than for use with submodules, you're doing it wrong. The approach you're currently taking is not "best practice", though it may be a convenient intermediate step.

0 Kudos
Reply