I have created a small case that demonstrates that MKL crashes when used from MATLAB.
The MATLAB mex file should be created using MATLAB r2013a on linux64x86. The key is if the mex file, which is a shared object, is linked with libiomp5 then MKL crashes. If the mex file is linked without it works fine. You can reproduce the crash as follows
Try it again but remove -liomp5 in buildomp.sh.
Why does it crash when libiomp5 is linked into the mex file?
The system does not allow me to attached the needed files on this post but will try in the reply.
It looks the files are not upload yet. Since Matlab itself is also using Intel MKL internally, to avoid conflicts with some other version MKL, it is suggested to build one customer DLL , then link the MKL to that customer DLL. Could you check these two articles for the steps:
It takes windows at the example, it also has similar tools is also at mkl/tools/builder
Also have a check if you have other versions of openmp libraries from the matlab?
I am trying to find the matlab to reproduce this problem. Also I have a few questions when I review your test code here:
1)The code is actually linking with libmkl_sequential.a, the sequential MKL libraries, so it actually does not need to add the –liomp5. Is the OpenMP runtime library added only for testing?
2)In the previous post, the list the code is crash bellow when adding OpenMP:
Is this still the code where it crash now? This code is actually not related to the OpenMP.
3)It looks you want to test whether OpenMP library is link it or not. Matlab is internally also using OpenMP, and include OpenMP libraries, so the system may have two copies of OpenMP libraries. Have you check if the OpenMP library you are linking with (the OpenMP with the MKL) is the same one when the cod is running?
I do understand that OpenMP is used for nothing in the code. This is a small illustrative example based on some real world code which is way more complicated. The code is very small and should be very easy to check whether we call mkl_disable_fast_mm(). As far as I remeber we do not.
Can you reproduce the crash? I think it would nice to understand why it crash even if we do something wrong because then we understand the assumptions behind OpenMP and MKL better.
I am not sure if MATLAB uses the same version on OpenMP. You can see my my blog post about why your reply about whether MATLAB and my application uses the same OpenMP library is one I hate. If that is an issue then we cannot OpenMP in the library we sell to our customers.
As far I understand we should be able to link with another version of MKL than MATLAB when we link with the static sequential version. Am I wrong on this assumption?
>>As far I understand we should be able to link with another version of MKL than MATLAB when we link with the static sequential versionYes, this is true.
As to reproduce this problem, I am working with MKL code owner to have some further code review, and locate some more info. Now we are still working on to setup the matlab machine.