Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
14 Views

Static linking a multi-threaded mex file in Matlab - Getting dependency error

Hi All

I'm trying to build a mex file using the MKL, which allows for multi-threading and is statically linked. I use the following libraries:

'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', and 'libguide40' (The libguide40 can be omitted without linking error though).

But when I run a simple vdCos command, I get a "Invalid mex-file: The specified module could not be found." error. This states that a dll is not present, but I tried doing static linking.... so I'm confused :)

If I try a single-threaded link using the libraries 'mkl_intel_lp64', 'mkl_sequential', and 'mkl_core', Everything works fine ( I can calculate a cos-value anyway). Hence... it is the threading stuff that creates the linking error.

Is this working as intended, or am I doing something wrong?

Thank you

Henrik Andresen
0 Kudos
6 Replies
Highlighted
14 Views

Hello Henrik!

could you specify whichOS and MKL version do you use? Link line will be useful also.

Andrey
dr_pain
0 Kudos
Highlighted
Beginner
14 Views

Hi Andrey

Thank you for your response

OS: Windows 7 64-bit
Matlab: R2010b, 64-bit
Compiler: Microsoft Visual C++ Express 2008
MKL Version: 10.2.6.037

Since I'm linking through Matlab, the compiler gets called using the 'mex' command. The next parameter is the cpp file. Rest is:

-I = include path
-L = library path
-l = library to include (lower case L)


I am currently using this line:

mex mklLibrary.cpp -I"C:\Program Files\Intel\MKL\10.2.6.037\include" -L"C:\Program Files\Intel\MKL\10.2.6.037\em64t\lib" -lmkl_intel_lp64 -lmkl_sequential -lmkl_core

Which works to the point that I can call cblas_scopy(). Haven't tried anything else.

If I do this:
mex mklLibrary.cpp -I"C:\Program Files\Intel\MKL\10.2.6.037\include" -L"C:\Program Files\Intel\MKL\10.2.6.037\em64t\lib" -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -llibguide40

I get the dependency error: "??? Invalid MEX-file 'D:\Udvikling\Matlab\performance\mklMex\mklLibrary.mexw64': The specified module could not be found."

If I then copy the file 'libguide40.dll' to the same library as my .mexw64 file, it works fine again.


I hope this helps figuring out what is going on.

Cheers

Henrik
0 Kudos
Highlighted
Black Belt
14 Views

Did you have difficulty when using libiomp5mt rather than libguide40? When using a static OpenMP library, you must take care that it is the only OpenMP library linked, and that it is linked subsequent to all .obj which introduce dependencies. Given that you have VC Express, vcomp shouldn't be getting in the way. If you had any OpenMP references from VC, libiomp5 would take care of them, while libguide would not, but that is not the only reason for preferring the libiomp.
0 Kudos
Highlighted
14 Views

Henrik,

try to use libguide.lib or libiomp5mt.lib instead libguide40.lib.

Andrey
dr_pain
0 Kudos
Highlighted
Beginner
14 Views

Hi Andrey

Both the other libraries work fine. Only the libguide40.lib is creating this error.

So which library should I use? I will mostly be doing LU decomposition, and some transcendental functions calculation. From your reply, I guess you prefer the libiomp5mt. Will it make any difference to me?

Cheers

Henrik
0 Kudos
Highlighted
14 Views

Henrik,

it is no diferences for you which library to use libguide or libiomp5. These libraries contains OpenMP stuff and only difference between them is version of this stuff. I recommend to use libiomp5 library because it is newer than libguide.

Andrey
dr_pain
0 Kudos