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

preprocessor directives for gfortran and Intel

Robinson__Donald
Beginner
1,941 Views

I help to develop a Fortran/C/C++ open-source project (open-fvs) that builds on Unix, MinGW and VisualStudio/Intel Fortran tool chains, based on cmake tools. I've been stumped by a recent Fortran preprocessor issue that seems like it should be simple. Equivalent issues in C work across the 3 tool chains. In the Visual Studio-Intel Fortran 12 environment  I need to call getpid(), which requires using "USE IFPORT". I would like the same code to be able to work across all environments, and preprocessors would seem to be the way to go. Assuming __GFORTRAN__ is defined in the gfortran situation and not in VS/Intel, something like this klunky example is what I have in mind:

!DEC$ IF DEFINED (__GFORTRAN__)
!DEC$ ELSE      
      use ifport
!DEC$ ENDIF

The !DEC$ lines are ignored by gfortran, but USE IFPORT obviously isn't. I'd appreciate advice on how to create preprocessor directives that will work across the tool chains.

0 Kudos
4 Replies
TimP
Honored Contributor III
1,941 Views

It doesn't seem imaginative, but I use the /fpp directives which are understood by both gfortran and ifort. 

I've had customers who set up to use a separate gcc pre-processing step regardless of which fortran is involved.

gcc -E -traditional -x c  (or gfortran -E) to translate .F to .f.   On Windows, the preprocessed files must go in a new folder or be named .for.

0 Kudos
JVanB
Valued Contributor II
1,941 Views

Just create a file:

!DEC$ IF(.FALSE.)
module ifport
end module ifport
!DEC$ ENDIF

When you compile it with ifort, you get nothing; compile with others and you get an ifport module you may safely USE.

 

0 Kudos
FortranFan
Honored Contributor III
1,941 Views

You could write your own interface for _getpid, thereby avoid IFPORT in Intel Fortran, and simply ignore the warning you'd get about shadowing an intrinsic in gfortran.

0 Kudos
Steven_L_Intel1
Employee
1,941 Views

Don't use the !DEC$ directives - as Tim hints, use #ifdef and add /fpp when compiling with Intel Fortran.

0 Kudos
Reply