Using Intel® MKL with MATLAB*

1. Overview

This guide is intended to help Intel Math Kernel Library (Intel® MKL) customers use the latest version of Intel® MKL for Windows* with The MathWorks* MATLAB
MATLAB* is an interactive software program that performs mathematical computations and visualization. For more information about MATLAB visit www.mathworks.com/products/matlab.

2. Dependencies

Software:
This note applies to MATLAB R2017b and Intel MKL 2018

Hardware:  
The note should work for all hardware configurations that meet the system requirements for both MATLAB R2017b and Intel MKL 2018. This note has been tested on Intel® Core® i7-6820HQ CPU.

Operating System:
This note should work for Windows* users of MATLAB. Process on Linux is similar.


3. Obtaining the Latest Version of Intel MKL

The latest release of the Intel Math Kernel Library is available at www.intel.com/software/products/mkl.  You can download the latest Intel MKL if you have a valid license.  You can also obtain the latest version by renewing your current license or registering for a free 30-day evaluation or get the community license for free.


4. Building a Custom DLL

By default, MATLAB R2017b uses the Intel MKL 11.3.1 Basic Linear Algebra Subroutines (BLAS) libraries to perform computations.

Version of Matlab R2017b and MKL

To upgrade to the Intel MKL 2018 release, you need to create a DLL using the Intel MKL 2018 or later custom DLL builder located in ${MKL}\tools\builder:

  • Scroll to the bottom of this page and download the attached file matlab_custom_dll.zip.
  • Extract and copy the files from matlab_custom_dll.zip and copy them to ${MKL}\tools\builder. It may be preferable to save the old ones by renaming them or moving them to a temporary folder.
  • Customize the makefile by editing the CB_EXPORT=functions_list. It’s in line 101.
  • The custom DLL is built from the command line via a makefile with command nmake. Set the command environment as appropriate for your compiler.
    To Start the Microsoft® Compiler, from the Start Menu select Programs>>Microsoft Visual Studio 20xx>> Visual Studio Tools>> Visual Studio 20xx Command Prompt.​ For Microsoft Visual Studio 2017, please use x64 Native Tools Command Prompt for VS 2017 for 64bit compilation, and x86 Native Tools Command Prompt for VS 2017 for 32bit compilation
  • Build the custom DLL with the following command nmake libintel64 for a 64-static library. For additional options such as customizing the name of the DLL, please refer to the Intel MKL User Guide.
    After this you will find the resulting file at ${MKL}\tools\builder\mkl_custom.dll.

5. MATLAB Configuration and Running

Modify the system environment so that MATLAB uses the Intel MKL BLAS functions from the custom DLL. Set the BLAS_VERSION environment variable by following the steps on Windows 10:

  • Right click Start, select System.
  • Click the Advanced System Settings.
  • Click the Environment Variables button to open the Environment Variables dialog box.
  • Under the User variables section, click the New button to open the New User Variable dialog box.
  • Set the name of the variable to BLAS_VERSION and set the value of the variable to mkl_custom.dll. I.e. BLAS_VERSION=mkl_custom.dll

Start MATLAB as you normally would and the Intel MKL BLAS library will be called.

Alternatively, Users can use the attached script file matlab_mkl.bat/matlab_mkl.sh to start Matlab with all necessary configurations. Please be sure to modify the script file to edit values according to your own environment, like MKL path, custom MKL dll path and name, etc.

6. Verifying Correctness

From MATLAB, run the command version -blas and check that the output should be “Version information not found” (Since mkl_custom.dll does not include version information).

Alternatively, run the command version -modules and check the output list to verify that the custom DLL is loaded.

7. Troubleshooting

The error "The specified module could not be found." occurs for two cases:

  1. One or more of the required interfaces is missing from the custom DLL
    Solution: Follow the steps in section 4 and rebuild the custom DLL.
  2. The custom DLL is not found.
    Solution: Verify that the path to and the name of the custom DLL is correct (see section 5).
    Alternatively, use Matlab command getenv() and setenv() to add the custom DLL path into environment variable PATH.

    --------------------------code-------------------------------------------------------------------------------

    >>setenv('PATH',[getenv('PATH') ';C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_xxxx.x.xxx\windows\mkl\tools\builder']);

    -------------------------------------------------------------------------------------------------------------


Appendix A - References

For more complete information about compiler optimizations, see our Optimization Notice.
AttachmentSize
Package icon matlab_custom_dll.zip1.11 KB
Package icon matlab_mkl.zip724 bytes

4 comments

Top
Davide T.'s picture

 matlab_custom_dll.rar where is supposed to be? lul

Noah C.'s picture

I do not see any download link for a .dll, .rar, or a .zip at the bottom of the page, contrary to what the article suggests.

anonymous's picture

Can you, please, expand this article by adding instructions for models the canal.
Thank you.

eliosh's picture

Can you, please, expand this article by adding instructions for Linux.
Thank you.

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.