preprocessor include path differences

preprocessor include path differences

I'm trying to compile code I have written, using both ifort and gfortran. The problem I am having is relating to my use of the preprocessor and directory structure.

In my fortran source I have something like:

#include "includes/myinclude1.inc"

In  "includes/myinclude1.inc" I want to include another file, say "includes/sub/myinclude2.inc".

In ifort the preprocessor uses the directory relative to the source directory, so in "includes/myinclude1.inc" I may just do:

#include "includes/sub/myinclude2.inc"

However, in gfortran it is relative to the location of the current include file, so I instead must do:

#include "sub/myinclude2.inc"

Is there a compiler option (either in ifort or gfortran) that will allow me to get the same behavior across compilers?

Thanks.

22 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Are you calling fpp directly or are you calling it implicitly by using input files with F suffixes (e.g. .F. F90, etc)?  

One fix is to supply a -I flag to ifort, e.g. -Iincludes , which will allow all relative include paths from that directory to be found.  The man page for fpp does say that the current directory of the include file is in the search path for "" includes, but in a quick test I did, and in your case, that does not appear to be the case.  

A second alternative is to use the GNU preprocessor "cpp" to preprocess your source and then compile the resulting fortran files with ifort.  

gfortran pre-processing is available separately from full compilation by

gfortran -E file.F > file.f

or

gcc -E -traditional -x c file.F > file.f

As Casey hinted, many people do this to get consistent pre-processing.

For Windows compatibility, the files need to be written in a separate directory from the original.

The problem where the Intel Fortran preprocessor did not do source-relative #includes is fixed in the compiler version being released in early September.  For reference, the issue ID is DPD200151471.

Steve - Intel Developer Support

Quote:

Steve Lionel (Intel) wrote:

The problem where the Intel Fortran preprocessor did not do source-relative #includes is fixed in the compiler version being released in early September.  For reference, the issue ID is DPD200151471.

Thanks Steve. With the update, will there be a compiler flag that allows one to use the current preprocessing mode (i.e. fortran- rather than include-source relative paths)? 

There already is such a flag: -assume nosource_include. The compiler honors this today for Fortran INCLUDE, but the preprocessor does not. With the fix, the preprocessor will honor -assume source_include, which is the default.

I assume that by "fortran-relative" you mean "current directory-relative".

Steve - Intel Developer Support

Hello Steve,
Is this issue meant to be fixed in ifort 14.0, or am I misunderstanding something? The directory structure is:


main.f90

includes

    |----level1.inc

    |----level2.inc

file main.f90:


program main

implicit none

integer, parameter :: this = 42

# include "includes/level1.inc"

end program main

file includes/level1.inc


# include "level2.inc"

file includes/level2.inc


print *, this

This does not compile either with nosource_include or source_include assumed (it doesn't find level2.inc, unless it is included as "includes/level2.inc", which then doesn't work with other preprocessors)

Thanks.

Cant say if its a bug or intented, but it looks like there is a difference in how fpp and cpp treat "nested" #include directives.  It looks like the fpp search path is the cwd of the .F90 file whereas cpp uses the cwd of the included file.  I'll defer to others on if that is the intent.

For workarounds, use

ifort -Iincludes -fpp -o main main.f90

or, rename main.f90 to main.F90 and do

cpp -P main.F90 > main.f90
ifort -o main main.f90

You can also invoke the c pre-processor as "gcc -E -P" or "icc -E -P" with the same results. 

The difference Casey notes is the bug that was fixed in the 14.0 compiler. Henry, are you using the 14.0 compiler and seeing unexpected results? The default for fpp should now be that #include starts relative to the file that has the #include.

Steve - Intel Developer Support

Steve,

I am using ifort 14.0 and am still experiencing the same problem

Thanks.

Steve,

   I'll also add that the behavior I noted was observed in version 14.0 of ifort. (14.0.0 20130728)

Versions:

casey@convect ~/code/iforttest/inctest $ ifort --version
ifort (IFORT) 14.0.0 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
casey@convect ~/code/iforttest/inctest $ icc --version
icc (ICC) 14.0.0 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
casey@convect ~/code/iforttest/inctest $ gcc --version
gcc (Gentoo 4.7.3 p1.0, pie-0.5.5) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
casey@convect ~/code/iforttest/inctest $ fpp -V
Intel(R) Fortran Preprocessor for applications running on Intel(R) 64, Version 14.0.0.080 Build 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
# 1 "stdin"
^C

The files:

casey@convect ~/code/iforttest/inctest $ cat main.F90 
program main
implicit none
integer, parameter :: this = 42
#include "includes/level1.inc"
end program main
casey@convect ~/code/iforttest/inctest $ cat includes/level1.inc 
#include "level2.inc"
casey@convect ~/code/iforttest/inctest $ cat includes/level2.inc 
print *, this

The tests

ifort:

:
casey@convect ~/code/iforttest/inctest $ ifort -E -P main.F90
program main
implicit none
integer, parameter :: this = 42
level1.inc(1): #error: can't find include file: level2.inc
end program main

ifort with -I:

casey@convect ~/code/iforttest/inctest $ ifort -Iincludes -E -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main

fpp:

casey@convect ~/code/iforttest/inctest $ fpp -P main.F90
program main
implicit none
integer, parameter :: this = 42
level1.inc(1): #error: can't find include file: level2.inc
end program main

fpp with -I:

casey@convect ~/code/iforttest/inctest $ fpp -Iincludes -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main

GNU cpp:

casey@convect ~/code/iforttest/inctest $ cpp -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main

preprocessor invoked by icc:

casey@convect ~/code/iforttest/inctest $ icc -E -P main.F90 
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main

preprocessor invoked by gcc:

casey@convect ~/code/iforttest/inctest $ gcc -E -P main.F90 
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main

Sigh...  We fixed only part of the problem. -assume source_include is supposed to be the default. It is for the compiler but not for fpp. The part we fixed was that even if you explicitly specified -assume source_include, it wasn't being applied to fpp. We'll fix this. For now, add -assume source_include to the compile options and it should work the way you want. Issue ID is DPD200247863.

Steve - Intel Developer Support

Steve,
I can not get this working even by specifying -assume source_include: My output:


henry@xc:~/iforttest$ ifort --version

ifort (IFORT) 14.0.0 20130728

Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.
henry@xc:~/iforttest$ cat main.f90

program main

implicit none

integer, parameter :: this = 42

# include "includes/level1.inc"

end program main
henry@xc:~/iforttest$ cat includes/level1.inc

# include "level2.inc"
henry@xc:~/iforttest$ cat includes/level2.inc

print *, this
henry@xc:~/iforttest$ ifort -fpp -assume source_include main.f90

level1.inc(1): #error: can't find include file: level2.inc

Thanks

Hmm - it works when I try it. Would you also add -watch to the ifort command and show me the output?

Steve - Intel Developer Support

~/iforttest$ ifort -fpp -watch -assume source_include main.f90 
echo main.f90
main.f90
/opt/intel/composer_xe_2013_sp1.0.080/bin/intel64/fpp 
 -D__INTEL_COMPILER=1400 
 -D__INTEL_COMPILER_UPDATE=0 
 -D__unix__ 
 -D__unix 
 -D__linux__ 
 -D__linux 
 -D__gnu_linux__ 
 -Dunix 
 -Dlinux 
 -D__ELF__ 
 -D__x86_64 
 -D__x86_64__ 
 -D_MT 
 -D__INTEL_COMPILER_BUILD_DATE=20130728 
 -D__INTEL_OFFLOAD 
 -D__i686 
 -D__i686__ 
 -D__pentiumpro 
 -D__pentiumpro__ 
 -D__pentium4 
 -D__pentium4__ 
 -D__tune_pentium4__ 
 -D__SSE2__ 
 -D__SSE__ 
 -D__MMX__ 
 -I. 
 -I/opt/intel/composer_xe_2013_sp1.0.080/mkl/include 
 -I/opt/intel/composer_xe_2013_sp1.0.080/compiler/include/intel64 
 -I/opt/intel/composer_xe_2013_sp1.0.080/compiler/include 
 -I/usr/local/include 
 -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include 
 -I/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed 
 -I/usr/include 
 -I/usr/include/x86_64-linux-gnu 
 -free 
 -4Ycpp 
 -4Ncvf 
 -f_com=yes 
 main.f90 
 /tmp/ifortkNe6fW.i90
level1.inc(1): #error: can't find include file: level2.inc
rm /tmp/ifortlibgccfbGIFr
rm /tmp/ifortgnudirsmo2lj4
rm /tmp/ifort6CnOBj.o
rm /tmp/ifortkNe6fW.i90
rm /tmp/ifortdummyD5fpUy.c
rm /tmp/ifortdashvTBEJyb
rm /tmp/ifortargDm09eO
rm /tmp/ifort6CnOBj.o

Are you still using a beta version? Please upgrade to the released version.

Steve - Intel Developer Support

Steve,

I have never used the beta for version 14. I only download this after it was announced and the build date above 20130728 is exactly the same as I see on the (non-commerical) download page.

Thanks.

My mistake - you have the released version. I'm not used to the Linux and Windows build numbers being so far apart. Let me look into this further.

Steve - Intel Developer Support

Hello Steve, were you able to reproduce this issue?

Thanks,

Yes, I can. Sorry for the delay getting back to you.  It's not quite the same scenario we were working with earlier. Let me talk to the developers about it.

Steve - Intel Developer Support

Quote:

Steve Lionel (Intel) wrote:

Yes, I can. Sorry for the delay getting back to you.  It's not quite the same scenario we were working with earlier. Let me talk to the developers about it.

 

Hello Steve,

Is there any progress on this issue? What was the response of the developers?

Thanks

It's not yet fixed, but is being worked on. explicitly specifying -source-include is a workaround.

Steve - Intel Developer Support

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen