How to Build an Intel® MKL Application with Intel® Visual Fortran Compiler

This document describes the steps to build an Intel® MKL application with Intel® Visual Fortran Compiler XE for Windows* OS integrated with Microsoft Visual Studio* 2013

Software Requirement:

1. Intel® Visual Fortran Compiler XE for Windows* OS 15.0 or a later version
    The compiler must be installed and integrated correctly with Microsoft Visual Studio* 2013.

2. Intel® MKL 2017 or a later version
    Intel® MKL is included in the Intel® Parallel Studio XE suite, or standalone version.

3. Microsoft* Visual Studio 2013 

Step 1:  Select whether you are building  IA-32 or Intel® 64 application
Based on the target machine your application will run on, select:

IA32: 32-bit application for IA-32 architecture
Intel 64: 64-bit application for Intel® 64 architecture

For more information about IA-32 and Intel® 64 architectures, see this article.

When building 32bit or 64bit application within Microsoft VS* environment, check the Build→Configuration manager→ Active solution platform setting. It should be either “X86"  (which corresponds to 32bit application). or "X64" (which corresponds to 64bit application).

Step 2: Create one Intel MKL Visual Studio project 

The Intel MKL package includes much of code examples ( c and fortran file), located in the examples subdirectory of the install directory. i.e C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\mkl\examples.

User can build one Intel Fortran Project based on one of sample Fortran files. See the way of build project in the article: https://software.intel.com/en-us/get-started-with-fortran-compiler-17.0-for-windows-parallel-studio-xe-2017

The attached zip file at the end of the article contains a MSVS* 2013 project (Intel® Visual Fortran Compiler XE for Windows* OS IA-32/X64 application) for your reference.

Step 3: Link to Intel® MKL in your project automatically - quick option /Qmkl:[parallel|sequential|cluster]

Note: Step 3 and the Step 4 (optional) are equivalent in most cases. Be sure to use only one of these options, don’t mix them. 

The latest Intel® MKL versions have a single 'Build' menu in MSVS* environment. Refer to the MSVS* screenshot below. Open Project → Property Pages →Fortran → Libraries →Use Intel Math Kernel Library. Select the desired option, such as /Qmkl:parallel or /Qmkl:sequential. Once selected all of environment settings and required libraries are ready for your project. Proceed to build and run the application.

Then click OK and build the project. In most of case, the setting should be enough for building a Fortran application based on Intel® MKL. But if you have some customized requirement  to link Intel MKL, then please refer to below manual step.

Step 4: How to link to Intel® MKL in your project manually (Optional)

Step 4.1: Select the wanted libraries to link from Intel® MKL 
Use the on-line Intel® Math Kernel Library Link Line Advisor to determine which libraries your application needs to link to, based on your platform settings.

Intel® Math Kernel Library Link Line Advisor will list the libraries you need to link to from Intel® MKL

Example:
IA32 Windows* application:
"mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib" are common libraries

Intel® 64 Windows* application: "mkl_intel_lp64.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib"

Step 4.2: link to Intel® MKL manually in your project
Follow these steps to add the include path, library path and Intel® MKL libraries listed by the Intel® Math Kernel Library Link Line Advisor.  

1. To add the include path manually refer to the MSVS* screenshot below. Open Project → Property Pages →Fortran →General. Type/Paste the library directory in the 'Additional Include Directories' field.



2. To add the library path manually refer to the MSVS* screenshot below. Open Project → Property Pages → Linker →General. Type/Paste the library directory in the 'Additional Library Directories' field.

Make sure to check the library path and enter the correct directory:

<MKL install dir>\ia32,  for IA-32 application
<MKL install dir>\intel64, for x64 application                                                                                                                                              

3. To add  the required libraries manually refer to the MSVS* screenshot below. Open Project → Property Pages → Linker → Additional Dependencies. Paste the libraries from the Intel® Math Kernel Library Link Line Advisor.

Code Sample:

The attached zip file contains a MSVS* 2013 project (Intel® Visual Fortran Compiler XE for Windows* OS IA-32 manually /X64 /Qmkl application) for your reference. DFT_VF_sample.zip does Real 1d DFT.

Notes:

Some interface libraries (i.e. mkl_lapack95.lib mkl_blas95.lib fftw3xc_ms) may not Intel® MKL standard libraries, as such "Step 2 - quick option" does not support them.  You can add those libraries manually if you need to use them.

Troubleshooting:


You may encounter the following errors when building the project:

1. "fatal error LNK1104: cannot open file 'mkl_xxx.lib'"
    Make sure the library is included in the library path and the path you enter in step 3 or step 4 is correct.

2. "error #7002: Error opening the compiled module file.  Check INCLUDE paths. [MKL_DFTI]."                                                        Add the header file mkl_dfti.f90 in your code, for example:

! Include to build module MKL_DFTI
INCLUDE 'mkl_dfti.f90'

before the code line
USE MKL_DFTI

Alternatively, copy the mkl_dfti.f90 file to your project's source directory and include it in your project. 

3. Can't run exe as lack of some *.dll run-time library 

If you link with dynamic library, the execute file will ask the *.dll at run time.  So you have to make sure the all of DLL exist in your running environment.

In most of cases, the installer will add the path of Intel software tools to system environment.  But if no, please add it manually,

for example, in Windows* 7

open Computer Property page(right click Computer)=> Advanced system settings=> Advanced Tab=>Environment Variables

In Path variables, to add run-time library path,  like C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\redist\ia32_win\mkl and C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\redist\ia32_win\compiler etc.

For more complete information about compiler optimizations, see our Optimization Notice.