Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Fortran Preprocessor Check For MKL

ScottBoyce
Beginner
397 Views

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:

[fortran]

#if MKL availible

call MKL_SUB(a)

#else

call SUB(a)

#endif

[/fortran]

or

[fortran]

#if MKL availible

#def "call SUB(a)" "call MKL_SUB(a)"

#endif

call SUB(a)

#undef "call SUB(a)"

[/fortran]

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

0 Kudos
6 Replies
TimP
Honored Contributor III
397 Views

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.

0 Kudos
ScottBoyce
Beginner
397 Views

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.

0 Kudos
ScottBoyce
Beginner
397 Views

What are !dec$ directives?

0 Kudos
TimP
Honored Contributor III
397 Views

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.

0 Kudos
ScottBoyce
Beginner
397 Views

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

[fortran]

#ifdef __INTEL_COMPILER=1200

#define   BESSEL(x)   call MKLBESSEL(x)

#endif

[/fortran]

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.

0 Kudos
TimP
Honored Contributor III
397 Views

The limited Intel documentation on fpp is here:

http://software.intel.com/sites/products/documentation/doclib/stdxe/2013/composerxe/compiler/fortran-lin/GUID-4A598AC5-1C5F-48F2-BA42-DA8F38D46CB3.htm

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

#ifdef __INTEL_COMPILER

or

#if __INTEL_COMPILER > 1000

or

#if defined __INTEL_COMPILER && __INTEL_COMPILER > 1000

(in view of MKL being included in ifort versions since 10.0)

0 Kudos
Reply