Compiling and Linking Intel® Math Kernel Library with Microsoft* Visual C++*

The following provides hints for linking your program with Intel® MKL from the Microsoft* Visual Studio Environment: 

Microsoft* Visual Studio 2015/2013/2012/2010 -- Automatically

Microsoft* Visual Studio 2015/2013/2012/2010 -- Manually


Intel® MKL with Microsoft* Visual Studio 2015/2013/2012/2010

Intel® Math Kernel Library could be installed as sub-component of Intel® Parallel Studio XE integrated into the Microsoft* Visual Studio* (MSVS). While user fully install the Intel® Parallel Studio or select Intel MKL manually to install, the math kernel library will be integrated into MSVS automatically. User could use Intel MKL wit your projects in MSVS Integrated Development Environment (IDE) by one step. In this section, using Intel MKL with MSVS 2015 will be discussed as an example, for Microsoft* Visual Studio 2010 and MSVS 2012, please follow the same guide.

Use Intel® MKL in Microsoft* Visual Studio 2015/2012/2010 - Automatically

Step 1: Right click solution, select Properties » Configuration properties » Intel Performance Libraries » Use Intel® MKL; Figure 1 shows the screenshot of this step.

use mkl in msvs

Figure 1. Using Intel MKL in MSVS 2015

Step 2: Change the Use MKL property setting by selecting Parallel, Sequential, or Cluster as appropriate, and apply this change to your project. The detailed information of each option is shown below:

-No: Disable use of Intel MKL libraries;
-Parallel: To link with a certain Intel MKL threading layer depending on the threading option of OpenMP or Intel® TBB;
-Sequential: To link with sequential version of Intel MKL;
-Cluster: To link with Intel MKL cluster components (sequential) that use Intel® MPI.

* Learn more about using OpenMP and Intel® TBB for parallel operation, please refer document of Using Intel® MKL with Threaded Applications; For using Intel MPI with MKL, please view Using Intel® MKL MPI wrapper with the Intel® MKL cluster functions.

Step 3 (Optional): For linking with static/ dynamic library, please right click your solution and select Properties » Configuration properties » C/C++ » Code Generation, set the runtime library value from following list:

-Multi-threaded (/MT): linking with static Intel MKL libraries
-Multi-threaded DLL (/MD): linking with dynamic Intel MKL libraries

* If user link with dynamic library, the execute file of your project should be required with dll files that you have to make sure the MKL has been installed in your running environment. Learn more information about linking MKL library, please see following documents:
Linking with Compiler Run-time Libraries
Libraries (libm.lib, libmmt.lib, libmmd.lib, libiomp5mt.lib, libiomp5md.lib, libirc.lib, libircmt.lib, svml_disp.lib, svml_dispmd.lib ...) provided by Intel® C++ Compiler for Windows and Intel Parallel Composer

Now, you could start your work with Intel MKL and test examples under the MKL root path. Or you could visit Intel® Math Kernel Library (Intel® MKL) Support to find more online sample codes of BLAS, FFT and LAPACK.


 

Use Intel® MKL in Microsoft* Visual Studio 2015/2012/2010 - Manually

This section is the guide for setting to use Intel MKL in MSVS* manually. Normally, the Intel MKL path and DLL files could be added automatically, there is unnecessary to complete this section. User could use the "Step 1" to have a check. If the MKL path has not been inserted into include & library directories by default, please follow instructions below to make sure the MKL could be used in MSVS successfully. 

Step 1: Check and set the path of Include & Library Directories

  1.  In Project Property pages, select Configuration Properties » VC++ Directories; View Include Directories by editing this option. Make sure following path has been added into Include Directories:
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\mkl\include
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\mkl\include
    \<arch>
    Also notice the Include path of Intel C++ Compiler should be added as well like following:
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\compiler\include
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.****\windows\compiler\include\<arch>
    *The <arch> must be specified as "ia32" or "intel64"
  2. View Library Directories by editing this option. Make sure following path has been added into Library Directories:
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\mkl\lib
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\mkl\lib\<arch>_win

    Also notice the library path of Intel C++ complier should be added as well like following:
    C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\compiler\lib\<arch>_win
    *The <arch> must be specified as "ia32" or "intel64", the screenshot of Include Directories and Library Directories are shown in following Figure 2 and Figure 3:

add mkl inculde path to application

Figure 2. Add MKL include path with application

add mkl library path to application

Figure 3. Add MKL library path with application

Step 2: Link required MKL library into your project

Select the Linker » Input » Additional Dependencies, add the required MKL libraries (e.g. common link: mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib). The screenshot of adding additional dependencies of MKL library displayed in Figure 4.

* Generally, to link with Intel MKL, you may need to choose one library from the Interface layer and one library from the Threading layer and add the only library from the Computational layer and run-time libraries (RTL). See MKL Link Line Advisor

Link MKL library files as additional dependencies

Figure 4. Link MKL library files as additional dependencies 

Step 3: Run script to set environment variables for Intel MKL (optional for DLL)

You can add Intel® MKL dll path either in your system environment setting by system Start Menu>> Right Click Computer >>Properties>> Advanced System setting >>Open System Properties Page >> Advanced >> Edit the system environment variables >>Add mkl dll path <parent product directory>\redist\<arch>\mkl\ to Path

Or do following instructions:

  1. Start with command prompt, run mklvars.bat <arch> [MKL_interface] [mod] from directory <mkl root path>\bin\ in one command window, (by default mkl root path should be like:C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017.*.***\windows\mkl
  2. Then start < Microsoft Visual Studio>/IDE/devenv.exe in the same command windows. The detailed instructions can be found in following Figure 5.

​* Please view Setting Environment Variables to learn how to write command lines to run script. For more information about MKL directories structure, see High-level Directory Structure.

Add MKL library to environment variables

Figure 5. Run script to set environment variables

* For more settings of MKL using command lines, please visit Using the Custom Dynamic-link Library Builder in the Command-line Mode

Now, you could start your work with Intel MKL and test examples under the MKL root path. Or you could visit Intel® Math Kernel Library (Intel® MKL) Support to find more online sample codes of BLAS, FFT and LAPACK.



Note 1: for link MKL in Intel Fortran Or C++ Compiler for windows*, please refer to Using MKL in Intel® Compiler - mkl, Qmkl options

Note 2: Since from MKL 10.3 release, MKL is part of Intel Parallel Studio XE.  This provides an easy way to compile and link MKL in Parallel Studio XE environments. But the directory and integration has changed a bit compared to the previous releases (MKL 10.2 and earlier versions). Please see A new directory hierarchy in Intel MKL package .

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