Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

INCLUDE-ing a file that contains fpp directives

OP1
New Contributor III
1,770 Views
Is there a way to INCLUDE a file that contains fpp directives, such as __LINE__ ?

For instance, assume I have a module MY_MOD for which FPP preprocessing is allowed. This MY_MOD module has a CONTAIN section in which a INCLUDE 'MY_SUB.f90' statement appears. The subroutine MY_SUB contains, somewhere, a __LINE__ preprocessing directive.

When doing so the compiler complains about __LINE__ not being recognized.

Now, if, instead of using the Fortran INCLUDE statement, I try to use the FPP #INCLUDE preprocessing directive directly (shot in the dark...), my code compiles well but then when I execute it I get a program exception/access violation.

All this is with IVF 11.1 - and yes I know that with IVF 12 I could avoid all these headaches by using submodules ;) .

Any thoughts?

Thanks,
Olivier
0 Kudos
13 Replies
Steven_L_Intel1
Employee
1,770 Views
Well, no, you could not use submodules in version 12. We have not yet implemented those.

The problem is that fpp doesn't see INCLUDE. #include should work. If you're getting a run-time error, thast's a different problem which you'll need to debug.
0 Kudos
OP1
New Contributor III
1,770 Views

I think I have a better diagnostic of what happens with the #INCLUDE directives.

Assume that:

1. My module contains (in the CONTAIN section) such #INCLUDE preprocessor directives.
2. I Build>Clean my solution.
3. I manually delete all content in the DEBUG and RELEASE folders for my solution.
4. I rebuild the entire solution.

If, after step 4, I launch the code, it starts working properly and then crashes with a Program Exception/Access Violation error somewhere.

Now, assume that:

5. I manually request a new compilation of the module just after step 4.

Then the code works properly. It seems that multiple compiling passes are required.

Strange - and a bit unsettling as far as having confidence in what the code actually does.

Olivier

0 Kudos
Steven_L_Intel1
Employee
1,770 Views
As an experiment, try turning off Fortran > Diagnostics > Check Routine Interfaces. (I think that's where it was in 11.1).
0 Kudos
OP1
New Contributor III
1,770 Views
ok - so I turned off the "Check Routine Interfaces" option. Then I cleaned up the solution, and deleted all file from the DEBUG and RELEASE directories.
The first compilation pass to rebuild thewhole thingled to many ERROR #7002 errors (I guess because the .mod files had not been created yet). A second compilation pass was successful and the code was built.
However, when launching it, again I bumped into this Program Exception - access violation error.

This time, no matter how many times I tried to recompile manuallymy module, I couldn't get rid of this error.

Odd. I will use the double-compile strategy as a workaround (with the Check Routine Interfaces on), but I think something fishy is going on here.

Olivier
0 Kudos
Steven_L_Intel1
Employee
1,770 Views
Close Visual Studio. Delete the .suo and .u2d files in the project directory (these are "hidden" files so you may need to change the folder viewing options to see them). Then reopen the project and do Build > Rebuild.
0 Kudos
OP1
New Contributor III
1,770 Views
Steve,

Deleting the .suo and .u2d files helped build the code (with Check Routine Interfaces on)in one pass (no more #7002 errors), but I still got the access violation error. Again, compiling once more the incriminated module helped solve the problem.

Olivier
0 Kudos
Steven_L_Intel1
Employee
1,770 Views
I'm going to guess that you are accessing memory outside the bounds somewhere and the order in which modules get linked changes the behavior. I can't think of anything else that would change simply by recompiling - if you have /warn:interface disabled. There have been bugs where that option changed code inappropriately.
0 Kudos
OP1
New Contributor III
1,770 Views
Steve,

The culprit was a subroutine that was INCLUDEd (through fpp #INCLUDE directive)in the CONTAINS portion of the module, and which needed an explicit interface (due to having a deferred-shape argument). The option of having interfaces generated automatically was turned on however(and the corresponding warning message was issued by the compiler); but I suppose a glitch still happened somewhere.

The problem was solved by using an explicit interface for this subroutine. The code builds nicely in one pass now - without causing runtime errors.

I tried to create a small reproducer for this - to no avail.Butifyou are still interested I can try a little harder.

Thanks,
Olivier
0 Kudos
Steven_L_Intel1
Employee
1,770 Views
I'm a bit confused here - any procedure in the CONTAINS section of a module automatically has an explicit interface, both within the module and for any caller that USEs the module.
0 Kudos
OP1
New Contributor III
1,770 Views
Steve,

You are correct - I didn't describe the situation properly. It is actually the INCLUDEd subroutine that calls another subroutine which in turn requires an explicit interface. I will try to see if I can reproduce this behavior on a small scale test code.

Thanks,
Olivier
0 Kudos
Steven_L_Intel1
Employee
1,770 Views
Ah, now that makes sense, and may not be easy to reproduce. Did not /warn:interface detect this? (It might not depending on order of compilation.)
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,770 Views
Steve,

Does Visual Studio dependency walker, with IVF add-ons, make dependency checks on fpp #include files?
If not, then module source files with #include would not get rebuilt when required.
0 Kudos
Steven_L_Intel1
Employee
1,770 Views
Yes, the build dependency analyzer does take #include files into account.
0 Kudos
Reply