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

Run-time errors when running a MEX-compiled dll in Matlab using the MKL

henrikandr
Beginner
380 Views
Hi all

I have tried to create a small library which uses parts of the mkl for faster processing. The purpose is that this library is accessible from matlab, so I have made a MEX interface, which allow matlab to create a dll in windows (and something else in linux). I have no problem compiling the code, and get no linker errors. Also, when I use the same code in an example program in C++, it all works fine. But... when I run a part of the code in Matlab that does a call to the MKL library, I get segmentation violation errors.

Basically, I have tried both the vmlSetMode( VML_HA ), and a call to vsSqrt( 5, x, y ). I use MSVC++ 7.1, and does a normal mex call to compile in Matlab. I have tried to compile all the source files in my project and link to the MKL .lib files from matlab, and I have tried to make a static library as well, as well as to a DLL.

I use the MKL library in my project as static linked, which I guess might be causing me the problems. The reason why I want to do this is to reduce the number of files I need to move around for my toolbox to work. Am I doing something wrong when I use it in Matlab as it works fine from another C++ project made by msvc 7.1?

Or is it matlab that does some stupid and removes that part of the project.

Thanks

Henrik Andresen
0 Kudos
3 Replies
Andrey_G_Intel2
Employee
380 Views

I think what you are trying to use MKL statical library in your DLL. Am I right?

0 Kudos
henrikandr
Beginner
380 Views
Hi

Both yes and no.

I am trying 2 cases, where both ultimately leads to a dll being formed by Matlab. One case is to compile it directly by matlab, in which case you are correct. The other thing I try is to compile it to my own static linked library, and then use that to create a dll through matlab.

/Henrik
0 Kudos
Andrey_G_Intel2
Employee
380 Views
Ok. I think I understand now. It`s incorrect way of MKL usage - to use statical library in dynamical by any ways. If you plan to use your statical library in dinamical, you should link your library with dynamical version of MKL.
0 Kudos
Reply