| Last Modified On : | May 27, 2009 4:31 PM PDT |
Rate |
|
Introduction
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 the BLAS, LAPACK, DFTI (the FFT interface), the PARDISO direct sparse solver, and the vector math library (VML).
Building the Examples
Follow these steps to build the example programs:
nmake ia32 MKLROOT="c:\program files\intel\mkl\10.1.1.015"This will create an executable for each of the example programs.
Example files: Intel_MKL_C#_Examples.zip
Take our C++/C# interface survey for Intel® Math Kernel Library
| April 9, 2009 10:09 PM PDT
Vladimir Koldakov (Intel)
|
Thank you, Oleg! Of course, MKL root directory should be in command line. -Vladimir |
| July 16, 2009 7:32 AM PDT
michasspamgmx.de
|
Hi, the example does not work on my system. As you can see in the errorcode below I am working with MKL 10.0.1.015. I am using Visual Studio 2005 Framework 2.0. Are there any known solutions to this? Best regards Micha |
| July 16, 2009 7:33 AM PDT
michasspamgmx.de
|
Sorry, here comes the error code: D:CsharpTestUmgebungMKL_Einbinden>nmake ia32 MKLROOT="C:ProgrammeIntelMKL10.0.1.015" Microsoft (R) Program Maintenance Utility, Version 8.00.50727.42 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. Add path of the MKL libraries to the lib environment variable set lib=%MKLROOT%ia32lib;%lib% MKL entries for custom dll Workaround for pardiso Microsoft (R) 32-Bit C/C++-Optimierungscompiler Version 14.00.50727.42 für 80x86 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. _fseeki64.c Build MKL custom dll nmake mkl.dll MACHINE=IX86 MKL_LIB="mkl_intel_c_dll.lib mkl_intel_thread_dll.lib mkl_core_dll.lib" MSL Microsoft (R) Program Maintenance Utility, Version 8.00.50727.42 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. link /DLL /MACHINE:IX86 /def:user.def _fseeki64.obj mkl_intel_c_dll.lib mkl_intel_thread_dll.lib mkl_cor Microsoft (R) Incremental Linker Version 8.00.50727.42 Copyright (C) Microsoft Corporation. All rights reserved. Bibliothek "mkl.lib" und Objekt "mkl.exp" werden erstellt. mkl_intel_c_dll.lib(_pardiso.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_mkl_solver_pa mkl.dll : fatal error LNK1120: 1 nicht aufgelöste externe Verweise. NMAKE : fatal error U1077: ""C:ProgrammeMicrosoft Visual Studio 8VCBINlink.EXE"": Rückgabe-Code "0x460" Stop. NMAKE : fatal error U1077: ""C:ProgrammeMicrosoft Visual Studio 8VCBINnmake.EXE"": Rückgabe-Code "0x2" Stop. |
| July 17, 2009 6:00 AM PDT
Vladimir Koldakov (Intel)
|
Hello, Micha, Thank you for the interest to these examples. For MKL 10.0 you need add one more library: 44c44 < MKL_LIB="mkl_intel_c_dll.lib mkl_intel_thread_dll.lib mkl_core_dll.lib" --- > MKL_LIB="mkl_intel_c_dll.lib mkl_intel_thread_dll.lib mkl_core_dll.lib mkl_solver.lib" And replace OMP library: 99c99 < libiomp5md.lib $(MSLIB) /out:mkl.dll --- > libguide40.lib $(MSLIB) /out:mkl.dll It’s better also to run examples on the drive C: The security permission problem can be appeared otherwise: Run dgemm example <…skipped…> Unhandled Exception: System.Security.SecurityException: System.Security.Permissions.SecurityPermission at mkl.CBLAS.dgemm(Int32 Order, Int32 TransA, Int32 TransB, Int32 M, Int32 N, Int32 K, Double alpha, Double[] A, Int32 lda, Double[] B, Int32 ldb, Double beta, Double[] C, Int32 ldc) at test_dgemm.Main(String[] args) Best regards, -Vladimir |
| September 24, 2009 10:04 AM PDT
Tommy |
Hi, Is there going to be an official wrapper release for C#? Thanks, Tommy |
| September 30, 2009 4:24 AM PDT
Jo Cotterell |
Hi MKL gurus, We have successfully linked a C# program to MKL thanks to your examples, but a problem remain: It seems that MKL can't span multiple threads when being called from our managed environment. When calling cblas_dgemm from a freshly built DLL, the linkage is successfully done (pinning, ...) and the Matrix-Matrix multiplication is processed, but on an Intel Xeon 5130, we attained only 25% of CPU Usage, even after setting some environment variables (MKL_DYNAMIC=FALSE, MKL_NUM_THREADS=x) which seemed to have no impact on this issue... Of course we were expecting some overhead coming from the C#->C transition, but such a behavior seems strange. Is it expected or have we gone wrong on something? Does C# constrain the use of unmanaged code to only one thread? Best Regards. |
| November 2, 2009 3:18 AM PST
Vladimir Koldakov (Intel)
|
Hi, Jo. I've checked on an 8 core Xeon - it is ok with MKL_NUM_THREADS=2 or 4 or (default) 8. I used the makefile attached to the examples to build custom dll and run example with N=9000, K=8000, M=6000. Could you please provide more details how do you build dll? And a small test if it is possible. Thanks, Vladimir |

English | 中文 | Русский | Français
Vladimir Koldakov (Intel)
| ||
Todd Rosenquist (Intel)
|
Oleg Golubovsky
value of MKLROOT environment variable should be reduced to "C:\Program Files\Intel\MKL\RR.r.y.xxx", where RR.r is the version number, y is the release-update number, and xxx is the package number, for
example, "C:\Program Files\Intel\MKL\10.1.0.004", otherwise you will get compilation and linkage errors.