Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7074 Discussions

MKL wrappers in C# fails when LAPACK is called

Goicochea__Javier
997 Views

Dear All, 

I am trying to create MKL wrapper for accessing LAPACK functions in C# (mainly those related to QR factorization). However, when I call the corresponding LAPACK function, the program just exits without any error message or sometimes gives BadImageFormatException exception.

I have tried to use the example (intel-mkl-c#-examples_02.zip (11.54 KB)) provided in: 

https://software.intel.com/en-us/articles/using-intel-mkl-in-your-c-program/

... and the same problem happens when the function below is called:

LAPACKNative.dgeev(ref c_jobvl, ref c_jobvr, ref n, a, ref lda, wr, wi, vl, ref ldvl, vr, ref ldvr,

 work1, ref lwork, ref info);

 

Currently, I am using a Win7 64 bits computer and I have tried to use both versions (32 and 64 bits) of the mkl_rt.dll (MKL ver 11.2). Attached you will find the solution that gives me the error. This uses the source code provided in the cited example. I have also tried with a sample solution provided by Gianluca G. and fails similarly. 

Kindly advise. Thank you in advance, Javier

 

 

 

0 Kudos
2 Replies
Ying_H_Intel
Employee
997 Views

Hi Goicox, 

I try the Test_lapack.exe in the debug folder. It seem work no problem.  i run it in command line as below, MKL 11.2.4 intel64. 

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\yhu5>"C:\Program Files (x86)\Intel\Composer XE 2015\mkl\bin\mklvars.bat
"

Syntax:
   mklvars.bat <arch> [MKL_interface] [mod]

   <arch> must be one of the following
       ia32         : Setup for IA-32 architecture
       intel64      : Setup for Intel(R) 64 architecture

   mod (optional) - set path to MKL F95 modules

   MKL_interface (optional) - MKL programming interface for intel64
                              Not applicable without mod
       lp64         : 4 bytes integer (default)
       ilp64        : 8 bytes integer

C:\Users\yhu5>"C:\Program Files (x86)\Intel\Composer XE 2015\mkl\bin\mklvars.bat
" intel64

C:\Users\yhu5>cd C:\Users\yhu5\Downloads\Test_LAPACK\Test_LAPACK\bin\Debug

C:\Users\yhu5\Downloads\Test_LAPACK\Test_LAPACK\bin\Debug>Test_LAPACK.exe
MKL LAPACK dgeev example

Matrix A:
        -2      -5      1       -1      -3
        5       0       -4      -1      9
        8       -1      1       6       0
        2       0       3       1       -2
        -4      -3      4       -4      -2
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.  

As you see, the mkl_rt.dll will depend on the other MKL dynamic library.  So we recommend put all of them together ( or keep same folder).   So i remove the mkl_rt.dll in your debug folder.  just use the all libraries in MKL folder.  it run as below. 

( one more comment,  maybe you can use the custom dll builder tool, which can build custom dll based on mkl static library, thus you don't need redistribute mkl dynamic library with your application. ) 

C:\Users\yhu5\Downloads\Test_LAPACK\Test_LAPACK\bin\Debug>Test_LAPACK.exe
MKL LAPACK dgeev example

Matrix A:
        -2      -5      1       -1      -3
        5       0       -4      -1      9
        8       -1      1       6       0
        2       0       3       1       -2
        -4      -3      4       -4      -2
Matrix A on exit:
        -3.74979687498421       3.30457083287809        0       0       0.272727
272727273
        -10.4969456995383       -3.74979687498421       0       0       0
        6.28146648851724        6.68544105675216        -2.34478199802706
0       0
        0.961154157305769       -2.58938020040906       -2.97051040398257
2.05286581472406        0
        3.08511288713447        -0.862950290140918      -1.09233902416012
6.28154038161816        5.79150993327142
Wr on exit:
        -3.74979687498421       -3.74979687498421       -2.34478199802706
2.05286581472406        5.79150993327142
Wi on exit:
        5.88964350304832        -5.88964350304832       0       0       0
info on exit: 0
TEST PASSED


C:\Users\yhu5\Downloads\Test_LAPACK\Test_LAPACK\bin\Debug>echo %MKLROOT%
C:\Program Files (x86)\Intel\Composer XE 2015\mkl

C:\Users\yhu5\Downloads\Test_LAPACK\Test_LAPACK\bin\Debug>

Best Regards,

Ying 

0 Kudos
Goicochea__Javier
997 Views

Dear Ying, 

Thank you very much for your help. I followed your instructions and new the test case is now working. :-) I did not know that the mkl_rt.dll depended on other  dlls

Regards, Javier

 

0 Kudos
Reply