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

Can not run Matlab mex. Built using MKL for FFT and VML on Mac OSX dual core duo 32-bit XCode

jman19_926
Beginner
1,118 Views
In C++ wrote mex file to calculate 1-D FFT. Crashes Matlab upon execution. Have tried many link line variations.
Currently have:
-undefined suppress -flat_namespace -lstdc++ -lmx -lmkl_intel -lmkl_intel_thread -lmkl_core -openmp -lpthread

have tried:
per this link
-undefined suppress -flat_namespace -lstdc++ -lmx -lmkl_intel -lmkl_intel_thread -lmkl_core -lguide -lpthread
also have tried adding -lm as suggested per the manual

Have also used link line generated by tool in forum sticky.

Mex executes successfully from Matlab when commenting out FFT calls. If all FFT calls except for DftiCreateDescriptor() are commented out mex will crash.

Have copied 32-bit dynamic libraries (libiomp5.dylib, libmkl_core.dylib, libmkl_intel.dylib, libmkl_intel_thread.dylib) to directory of mex file.

Is it possible for this to work?

MKL 10.1
ICC 11.0 (059)
Matlab_R2009a (32-bit)
XCode 3.1.1
Mac OS X 10.5.6
2.2 GHz Intel Core 2 Duo
0 Kudos
3 Replies
Tyler_T_Intel
Employee
1,118 Views
Have you tried the instructions provided here? Using Intel MKL in MATLAB Executable (MEX) Files
0 Kudos
jman19_926
Beginner
1,118 Views
Yes. I noted the following.

"It is important to always dynamically link to the Intel MKL threading library, libguide40.lib, to the mex file. Linking to the other threading libraries, libiomp5md.lib, libguide.lib, and libiomp5mt.lib can result in an application crash."

On the Mac I am assuming this translates to not using -liomp5 (libiomp5.dylib), -lguide (libguide.dylib). But what is the Mac equivalent of libguide40.lib? I read on...

"MATLAB crashes when running my mex file built with Intel MKL.
There can be two reasons for this:
1) The mex file is linked to the static threading library, libiomp5mt.lib or libguide.lib. When the mex file is invoked, MATLAB crashes with one of the following error message printed in a command-line window:
  • OMP: Error #15: Initializing libiomp5mt.lib, but found libguide40.dll already intialized
  • OMP: Error #15: Initializing libguide.lib, but found libguide40.dll already intialized
  • OMP: Error #15: Initializing libiomp5md.dll, but found libguide40.dll already intialized"

I understood this to mean don't statically link to libguide.a

"2)The mex file is linked to the Intel MKL 10.0 (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. For more information see the document Intel MKL Version Compatibility."

The second reason says to statically link. Does this mean I can expect to run into "reason one" problems should I statically link?

I ended up statically linking the libs for the layers (libmkl_intel.a, libmkl_intel_thread.a, libmkl_core.a, libguide.a). The link line included options -lpthread and -lm. This works! However Chapter 5 of the userguide states:

"You are strongly encouraged to dynamically link in Intel Legacy OpenMP* run-time
library libguide and Intel Compatibility OpenMP* run-time library libiomp. Linking to
static OpenMP run-time library is not recommended, as it is very easy with layered
software to link in more than one copy of the library.
"

A little frustrated and weary of future issues with this solution...

0 Kudos
jman19_926
Beginner
1,118 Views
So the phrase "custom dynamic library linking", does this mean create your own dynamic library that statically links libguide.a then link your dynamic library to your mex code?
0 Kudos
Reply