This article is intended to help users get started with intel® MKL quickly. Please click the topic you are interested in from the below table.
#1: Set build environment variable
#2: Write your first intel® MKL program
#3: Use intel® MKL Source Code Examples
• Set run time environment variable and executing
• Multi-threading (Multi-Core) Support
• Building a Custom Dynamic (Shared) Library
Before getting started, it may be helpful to take a look at the following links available online for the latest information regarding the Intel® MKL library:
Please register your product using your preferred email address. This helps Intel recognize you as a valued customer in the support forum and insures that you will be notified of product updates. You can read Intel's Online Privacy Notice Summary if you have any questions regarding the use of your email address for software product registration.
A script (batch file on Windows, shell script on other platforms) located in the <mkl install directory>>\ compilers_and_libraries_2017\windows\mkl\bin\ directory (by default, it is C:\Program Files (x86)\IntelSWTools\ compilers_and_libraries_2017\windows\mkl\bin\) can be used to set the MKLROOT, LIB, INCLUDE and any required system-specific environment variables to point to the appropriate MKL library directories. Use of this script is an optional, but convenient, means by which to configure your development system for compiling and linking with intel® MKL.
You run the script with a single input that specifies the primary processor architecture of interest. For example, mklvars_.bat ia32 configures the environment variables for compiling and linking a 32-bit Intel MKL application. Likewise, mklvars.bat intel64 configures your development environment to build 64-bit intel® MKL applications.
Note: in the text that follows, <arch> refers to the primary processor architecture, such as ia32 or intel64 and <MKLROOT> refers to the Intel MKL installation directory. Additionally, '\' and '/' are used interchangeably as directory separators.
An alternate architecture-specific script file is located in the <MKLROOT>\bin\<arch> directory that can be run without any input parameters. It calls the mklvars script mentioned above with the appropriate architecture as an input parameter.
Once defined, you can reference the MKLROOT variable within your makefiles and/or project files to locate the header and library files necessary to compile and link applications using Intel MKL.
Before running the build scripts provided with the Intel MKL example programs you must first be sure to set the MKLROOT environment variable to point to the MKL installation directory on your system. MKLROOT must point to that directory which contains the Intel MKL bin, lib, include and tools directories. The sample build scripts will reference the MKLROOT environment variable in order to locate Intel MKL and any additional tools required.
On a Windows system the following batch files are available to configure the environment for building Intel MKL applications:
On a Linux* system the following shell scripts are available to configure the environment for building Intel MKL applications:
Step1: Include Files
Intel MKL functions and structures are defined within several header files for C and interface files and modules for Fortran. These can be found in the <MKLROOT>\include directory and for Fortran several nested directories depending on architecture and interface. The "mkl.h" and "mkl.fi" files include all of these. The environment variable scripts can be used to point to the appropriate directories.
Step 2: Calling Intel MKL Functions
Calling Intel MKL function is as simple as calling any C function or FORTRAN function in your program. MKL provides both FORTRAN and C interface for most routines. Please see the MKL manual to find the function list you hope to use.
For example. compute C=A*B, A is mxn matrix, B is nxk matrix.
sgemm(transa, transb, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc)
Step 3: Linking Intel® MKL library with your program
The dynamic library dispatcher and static library mechanisms in Intel MKL are designed to make the process of calling Intel MKL functions as simple as calling any library. Multiple SIMD-optimized versions of each function are concealed behind a single entry point. But you don't need to worry about the optimized code for get started, just make sure link the right libraries for your application.
Please click the intel® MKL link line advisor to find the needed libraries, example
The command line is like below,
> \mkl\bin\mklvars.bat" ia32
> cl.exe mkl_lab_solution.c mkl_intel_c.lib mkl_core.lib mkl_intel_thread.lib libiomp5md.lib
If with Intel Composer XE, as intel mkl is intergrated to it. The command line is simpler,
> icl.exe mkl_lab_solution.c /Qmkl
If with Microsoft* Visual Studio, please refer to Compile and Link MKL with Microsoft* Visual C/C++* or Automatically Linking Your Intel® Visual Fortran Project with Intel® MKL
1) if with gcc
$source /opt/intel/mkl/bin/mklvars.sh ia32
$gcc -m32 mkl_lab_solution.c -lmkl_intel -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm
2) If with Intel Parallel Studio XE, the command line is easy
$ source /opt/intel/bin/iccvars.sh ia32 ( or intel64 )
$ icc mkl_lab_solution.c -mkl
$ icc mkl_lab_solution.c -mkl
1. Intel® MKL provide source code samples, almost for each function, like blas, lapack, FFT etc, both C and Fortran source code. You may find them under the <mkl install directory>\ compilers_and_libraries\windows\mkl\examples.
2. Intel® MKL knowledge base also provide many source code sample, please explore sample there, for example,
You can set run-time environment as above description. If you have done with script, you can run the executable program directly.
$ source /opt/intel/mkl/bin/mklvars.sh ia32
Enter matrix size N=1024
Dgemm_multiply(). Elapsed time = 0.49 seconds
or set LD_LIBRARY_PATH under linux and PATH under windows.
$ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/ia32:$LD_LIBRARY_PATH
Intel MKL 2017 uses OpenMP/TBB threading internally to support parallelism and leverage the performance benefits of multicore architectures.
Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.
Notice revision #20110804