MATLAB Answers

Problem using Intel MKL with MEX

21 views (last 30 days)
AP
AP on 18 Feb 2013
Dear All,
Is it possible to use Intel MKL 10.3 in MEX? I am having problem in using MKL 10.3 along with MEX. I have no problem in compiling and linking the source code. But MATLAB crashes with no helpful message when I run the executable. The same code works perfectly in Visual Studio C++. Is there any conflict for using MKL in MALTAB?
Thanks

  3 Comments

James Tursa
James Tursa on 18 Feb 2013
Can you post a small sample of code that crashes? There may be a mismatch with expected types in the arguments (e.g., integer lengths). What MATLAB version and operating system are you using?
AP
AP on 18 Feb 2013
Thanks @James. I am using MATLAB Version: 8.0.0.783 (R2012b) in Windows 7 64bit. This code works perfectly in Microsoft Visual C++ 2008 as a standalone code. Crash happens at the end of the code, where I am cleaning up to prevent memory leak. The following is the part of the code, that causes the crash:
if (stat!=0) goto FAILURE;
MKL_FreeBuffers();
free( dpar );
free( f );
FAILURE: printf("\nFAILED to compute ");
MKL_FreeBuffers();
free( dpar );
free( f );
For some reasons, FAILURE runs when the code is successful. I chekced the value of 'stat' and it is always zero which means successful. Why free() should be called twice to cause the crash? When I comment out functions:
free( dpar );
free( f );
right before the label FAILURE, MATLAB does not crash. May I have your thoughts on this?
IntelMKL
IntelMKL on 19 Feb 2013
Afala, In your snippet it seems like the free() calls would naturally be called twice since stat==0 as you say. So it seems you should expect what you get. Besides this, it seems that MKL is not the problem since the problem goes away when you comment the free() calls (and presumeably not the MKL_Free_Buffers() calls).
If you still think this is a problem with using Intel MKL, another option is to post this question (a larger test case would also be helpful) on the Intel MKL user's forum: http://software.intel.com/en-us/forums/intel-math-kernel-library
I don't recall any known problems with useing MKL 10.3 with this version of Matlab.

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 19 Feb 2013
Your posted code looks erroneous because in the success case it will naturally drop through the FAILURE label and do the free stuff again. Maybe you want something like this instead:
if (stat!=0) {
printf("\nFAILED to compute \n");
}
MKL_FreeBuffers();
free( dpar );
free( f );

  1 Comment

AP
AP on 19 Feb 2013
Thanks @James and @IntelMKL. I put a return before FAILURE and it worked perfectly. Very good catch.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags


Translated by