Several users have asked how to call and link the Intel® Math Kernel Library (Intel® MKL) functions from their C# programs. While the standard way of interfacing with third party software libraries from C# is well documented, some of the steps in interfacing with Intel MKL specifically may still be confusing. The attached source code package is intended to show how to navigate the whole process for Intel MKL users. These examples show how to create a DLL from Intel MKL libraries, call those functions from their C# source, and interface with that DLL.
Examples are provided for calling mkl from 5 MKL domains
1. dgemm.cs - BLAS (CBLAS)
2. dgeev.cs - LAPACK
3. pardiso.cs - PARDISO direct sparse solver
4. dfti_d1.cs - DFTI (the FFT interface)
5. vddiv.cs - VML vector math library
Building the Examples
Follow these steps to build the example programs:
- unzip the contents of the attached zip file
- Open a Microsoft Visual Studio command prompt or add the Microsoft.NET Framework to the PATH environment variable in another command prompt
- Run the build script (makefile) using nmake
nmake ia32 MKLROOT="c:\program files\intel\mkl\10.1.1.015"
- The makefile provides further explanation of the parameters in comments
This will create an executable for each of the example programs.
Example files: Intel_MKL_C#_Examples.zip
Building the Examples with Intel® MKL 10.3
Dynamic interface libraries have been added in Intel MKL 10.3 for improved linkage from C#. It is not required to build a custom DLL. The Intel MKL library named mkl_rt.dll can be called directly from C# code. Below is an updated version of the examples. Follow the same steps and run the nmake command.
Example: nmake ia32 MKLREDIST="c:\Program Files\Intel\ComposerXE-2011\redist"
Example files: Intel_MKL_C#_Examples_02.zip
Take our C++/C# interface survey for Intel® Math Kernel Library