views:

200

answers:

2

I'm working with Fortran code that has to work with various Fortran compilers (and is interacting with both C++ and Java code). Currently, we have it working with gfortran and g95, but I'm researching what it would take to get it working with ifort, and the first problem I'm having is figuring out how to determine in the source code whether it's using ifort or not.

For example, I currently have this piece of code:

#if defined(__GFORTRAN__)
// Macro to add name-mangling bits to fortran symbols. Currently for gfortran only
#define MODFUNCNAME(mod,fname) __ ## mod ## _MOD_ ## fname
#else
// Macro to add name-mangling bits to fortran symbols. Currently for g95 only
#define MODFUNCNAME(mod,fname) mod ## _MP_ ## fname
#endif // if __GFORTRAN__

What's the macro for ifort? I tried IFORT, but that wasn't right, and further guessing doesn't seem productive. I also tried reading the man page, using ifort -help, and Google.

+2  A: 

You're after __INTEL_COMPILER, as defined in http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/win/compiler_f/bldaps_for/common/bldaps_use_presym.htm

Donal Fellows
+1 for finding a link.
T.E.D.
Thanks! I also had to add that to my CMAKE_C_FLAGS and CMAKE_SWIG_FLAGS variables in my CMakeLists.txt file in order for the C++ code to create the correct bindings.
Ben Hocking
+1  A: 

According to their docs, they define __INTEL_COMPILER=910 . The 910 may be a version number, but you can probably just #ifdef on it.

I should note that ifort doesn't allow macros unless you explicity turn it on with the /fpp flag.

T.E.D.
Yes, it is a version ID. For ifort version 11.1, the value is 1110. You can also get macros / preprocessing by using filetype "F90" -- uppercase.
M. S. B.
By "filetype" do you mean the file's extension, or are you talking about a compiler flag?
T.E.D.