topic Quote:mecej4 wrote: in IntelĀ® oneAPI Math Kernel Library & IntelĀ® Math Kernel Library
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037731#M20505
<P></P><BLOCKQUOTE>mecej4 wrote:<BR /><P></P>
<P>One cause of crashes that you can take steps to avoid is that the MKL shared libraries called by Matlab are not the same as the ones used when the MEX file was built. Among others, there are two ways to proceed: (i) build the MEX using the MKL shared libraries that came with Matlab, and (ii) build the MEX using a different and independently obtained version of MKL. To do the latter, you may have to do the build from a shell window instead of using the <STRONG>mex</STRONG> script.</P>
<P>In either case, you have to make sure that the value of $LD_LIBRARY_PATH is such that the shared library used to build the MEX file is also the first one to be encountered by searching along the paths in LD_LIBRARY_PATH.</P>
<P></P></BLOCKQUOTE><P></P>
<P>Thanks. For solution (i), where do I find the the MKL shared libraries that came with Matlab ??</P>Tue, 02 Sep 2014 12:09:59 GMTCutter_S_2014-09-02T12:09:59ZIntel MKL's call from mex-files are crashing MATLAB
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037729#M20503
<P>Hello,</P>
<P>this is an issue already discussed but I have not been able to find a solution. I'm using Intel MKL 10.2 and MATLAB R2011b. My C function, which has many MKL BLAS and MKL Lapack calls, runs well when called from a C program.</P>
<P>When called from a mex file, MATLAB crashs. If I comment all the calls to mkl, it works (but output array are all zeros, as I don't perform calculations), so it is the call to Intel mkl that crashs matlab. I downlaoded yesterday the lastest version of Intel MKL but it did'nt solve the problem.</P>
<P>From what I can read here <A href="https://software.intel.com/en-us/articles/intel-math-kernel-library-intel-mkl-for-windows-using-intel-mkl-in-matlab-executable-mex-files">https://software.intel.com/en-us/articles/intel-math-kernel-library-intel-mkl-for-windows-using-intel-mkl-in-matlab-executable-mex-files</A></P>
<P>there are 2 possible causes:</P>
<P>1) The mex file is linked to the static threading library</P>
<P>or</P>
<P>2) The mex file is linked to the Intel MKL 10.3.x (or later) dynamic libraries. When the mex file is invoked, MATLAB crashes.. This occurs when the Intel MKL dynamic libraries used by the mex file are conflicting with those used by MATLAB. To resolve the problem, use static linking or link to a custom dynamic library and link to the dynamic threading library</P>
<P>I don't use the threading library, as I plan to use the matlabpool function later so I'm guessing the problem is 2). However, I use static linking:</P>
<P>mex mx_func_test.c -I/.../mkl/include -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lmkl_lapack -lrt -lm (I removed -lmkl_lapack when used MKL 11 because I doesn't exist anymore).</P>
<P>In MATLAB version -blas and -lapack return : Intel MKL 10.3.2.</P>
<P>So my questions are:</P>
<P>- is it possible to link my MKL call (in my C code) to the Intel MKL lib included in MATLAB (-> 10.3.2) ?</P>
<P>- or, is it possible to change the linking in MATLAB so it uses 10.2 or 11 ? It seems possible from what I read here but the procedure is not clear :<A href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/305856">http://www.mathworks.com/matlabcentral/newsreader/view_thread/305856</A></P>
<P>I hope I won't have to change my code to use ATLAS instead :(</P>
<P> </P>Tue, 02 Sep 2014 09:45:12 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037729#M20503Cutter_S_2014-09-02T09:45:12ZOne cause of crashes that you
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037730#M20504
<P>One cause of crashes that you can take steps to avoid is that the MKL shared libraries called by Matlab are not the same as the ones used when the MEX file was built. Among others, there are two ways to proceed: (i) build the MEX using the MKL shared libraries that came with Matlab, and (ii) build the MEX using a different and independently obtained version of MKL. To do the latter, you may have to do the build from a shell window instead of using the <STRONG>mex</STRONG> script.</P>
<P>In either case, you have to make sure that the value of $LD_LIBRARY_PATH is such that the shared library used to build the MEX file is also the first one to be encountered by searching along the paths in LD_LIBRARY_PATH.</P>Tue, 02 Sep 2014 11:38:50 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037730#M20504mecej42014-09-02T11:38:50ZQuote:mecej4 wrote:
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037731#M20505
<P></P><BLOCKQUOTE>mecej4 wrote:<BR /><P></P>
<P>One cause of crashes that you can take steps to avoid is that the MKL shared libraries called by Matlab are not the same as the ones used when the MEX file was built. Among others, there are two ways to proceed: (i) build the MEX using the MKL shared libraries that came with Matlab, and (ii) build the MEX using a different and independently obtained version of MKL. To do the latter, you may have to do the build from a shell window instead of using the <STRONG>mex</STRONG> script.</P>
<P>In either case, you have to make sure that the value of $LD_LIBRARY_PATH is such that the shared library used to build the MEX file is also the first one to be encountered by searching along the paths in LD_LIBRARY_PATH.</P>
<P></P></BLOCKQUOTE><P></P>
<P>Thanks. For solution (i), where do I find the the MKL shared libraries that came with Matlab ??</P>Tue, 02 Sep 2014 12:09:59 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037731#M20505Cutter_S_2014-09-02T12:09:59ZQuote:Thanks. For solution (i
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037732#M20506
<P></P><BLOCKQUOTE>Thanks. For solution (i), where do I find the the MKL shared libraries that came with Matlab</BLOCKQUOTE><P></P>
<P>They are in the main Matlab bin/<ARCH> directory. For example, on openSuse x64 and Matlab 2007b, I find .../ML2007b/bin/glnxa64/mklcompat.so and .../ML2007b/bin/glnxa64/mkl.so</ARCH></P>Tue, 02 Sep 2014 12:32:52 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037732#M20506mecej42014-09-02T12:32:52ZQuote:mecej4 wrote:
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037733#M20507
<P></P><BLOCKQUOTE>mecej4 wrote:<BR /><P></P>
<P><STRONG>Quote:</STRONG></P>
<BLOCKQUOTE>Thanks. For solution (i), where do I find the the MKL shared libraries that came with Matlab</BLOCKQUOTE>
<P>They are in the main Matlab bin/ directory. For example, on openSuse x64 and Matlab 2007b, I find .../ML2007b/bin/glnxa64/mklcompat.so and .../ML2007b/bin/glnxa64/mkl.so</P>
<P></P></BLOCKQUOTE><P></P>
<P>Alright, I have these two .so files. Can you give me an exemple of how your link mex to those files when compiling ?</P>
<P>Thanks</P>
<P>EDIT: I made a mistake on my post, as written in the compilation line, when compiling with mex I link with dynamic MKL libraries because I have not been able to link with static libraries. The mex script doesn't recognize the -Wl, --start-group .... command.</P>Tue, 02 Sep 2014 13:11:00 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037733#M20507Cutter_S_2014-09-02T13:11:00ZYou can see an example in
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037734#M20508
<P>You can see an example in this month-old post: https://software.intel.com/en-us/forums/topic/518312#comment-1794382. In short, the compiler options for x64 are:</P>
<P> -mkl -fp<SPAN style="color: rgb(0, 0, 0); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; line-height: 14.308799743652344px;">ic -shared -I <<EM>path to Matlab include subdirectory</EM>> <<EM>source files</EM>> -L <<EM>path to Matlab bin directory</EM>> lmex -lmx -o <<EM>mexname</EM>>.mexa64</SPAN></P>Tue, 02 Sep 2014 15:31:30 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037734#M20508mecej42014-09-02T15:31:30ZQuote:mecej4 wrote:
https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037735#M20509
<P></P><BLOCKQUOTE>mecej4 wrote:<BR /><P></P>
<P>You can see an example in this month-old post: <A href="https://software.intel.com/en-us/forums/topic/518312#comment-1794382">https://software.intel.com/en-us/forums/topic/518312#comment-1794382</A>. In short, the compiler options for x64 are:</P>
<P> -mkl -fpic -shared -I <<EM>path to Matlab include subdirectory</EM>> <<EM>source files</EM>> -L <<EM>path to Matlab bin directory</EM>> lmex -lmx -o <<EM>mexname</EM>>.mexa64</P>
<P></P></BLOCKQUOTE><P></P>
<P> </P>
<P>Thanks, I'll try this. In the meantime, I managed to make it work by compiling with static libraries and to avoid the -Wl, --start-group that is not recognized by mex, I set all the combinaisons of lib_mklcore.a, lib_intel_lp64.a and lib_mkl_sequential.a in the command line. It looks pretty ugly but it works!</P>Thu, 04 Sep 2014 06:56:08 GMThttps://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Intel-MKL-s-call-from-mex-files-are-crashing-MATLAB/m-p/1037735#M20509Cutter_S_2014-09-04T06:56:08Z