Hopefully this has a simple answer, but I have a software where the source code is distributed with the final exectuable. The final exectuable is made with Intel Fortran and I would like to start making use of the MKL subrouines, but the code has to be written in a manner that it can be compiled with other compilers.
I thought it would work to have some sort of preprossor definitions that would check if intel compiler and MKL is availible. Something like:
#if MKL availible
#if MKL availible
#def "call SUB(a)" "call MKL_SUB(a)"
#undef "call SUB(a)"
Any thoughts or suggestions would be greatly appreciated. I am new to using preprossors. Are there any special compile flags and.or do I have to rename the files to .fpp
For Ifort on Windows, adding /fpp option will invoke #ifdef style pre-processing. There are also !dec$ directives.
On linux or Mac, the source file can either be named with .F or .F90, or -fpp option added, to invoke fpp style pre-processing.
If you look up the topic of pre-defined compiler macros in the compiler docs, you will see the symbol __INTEL_COMPILER; unfortunately it guarantees only that MKL was available to install, as it's optional in the install script. On linux, the MKL supports most compilers you are likely to use, provided that it is installed, which it is less likely to be without presence of icc or ifort.
In the BLAS and lapack area, the library calls are the same regardless of whether you use MKL, open source, or other vendor provided libraries, so you wouldn't likely use conditional compilation this way.
I want to use several of the Bessil function calls. Right now the code has a home written version and I like to use MKL's version when MKL is present.Right now the code usess two include files for intel specific features and tells the end sure to modify that when compiling with something else, but I rather have the end user not worry and just use the preprossor.
I probably shouldn't have mentioned !dec$ as it would be more obscure how to use them for the purpose of differentiating between ifort and other Fortran compilers, but they are written up in ifort documentation.
That is fine, I like that because it would be read as a comment if its not understood. Where would I find information on that. I tried trying to find the intel documentation, but everything is an html link and a searh for !dec$ yielded nothing.
For the predefined macros would I do something like
#define BESSEL(x) call MKLBESSEL(x)
that work? Is the definition only applied to the subroutine that it resides in or the entire file?
Sorry for being a bit obtuse with this, there seems to be little documentation/examples with macros. I really like to start incorporating more of them with the government models that I develop.
The limited Intel documentation on fpp is here:
The versions at http://www.netlib.org/fortran/ are probably the closest to a de facto portable version, but probably not much used nowadays given that most compilers have their own version. As there is no standard (other than the way gnu Fortran pre-processing works, which is more comprehensive), I don't think you will find any authoritative advice. What you want should fall well within what will work with fpp supplied with any compiler (at least any compiler with OpenMP).
You probably mean
#if __INTEL_COMPILER > 1000
#if defined __INTEL_COMPILER && __INTEL_COMPILER > 1000
(in view of MKL being included in ifort versions since 10.0)