Mex-files + Visual studio 2013 + openMP cause Matlab crashes

조회 수: 1 (최근 30일)
Pierre Guilbert
Pierre Guilbert 2016년 7월 21일
댓글: Walter Roberson 2019년 1월 23일
Dear all,
I'm trying to use openMP inside a mexFunction. After a lot of tests I noticed that the simple "#pragma omp parallel" instruction causes a crash of matlab.
Here is my code :
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
#pragma omp parallel
{
}
plhs[0] = mxCreateDoubleScalar(0.0f);
}
It works perfectly in debug mode. But when I run it in release mode matlab crashes brutally.
But if I add a "PAUSE" instruction, everything work fine :
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
#pragma omp parallel
{
}
mexCallMATLAB(0, NULL, 0, NULL, "pause");//pause;
plhs[0] = mxCreateDoubleScalar(0.0f);
}
According to this post : https://fr.mathworks.com/matlabcentral/answers/237411-can-i-make-use-of-openmp-in-my-matlab-mex-files it may have a conflict between 2 versions of openMP and I should use the intel implementation. But I don't want to buy the intel C++ compiler.
if you have any ideas or solutions about this problem, I would be very grateful
Regards, Pierre.G

답변 (1개)

sjhstone
sjhstone 2019년 1월 23일
Under Windows, it is not that difficult to use Intel's OpenMP library with Microsoft Visual C++ Compiler.
Try use the following line of command and see what will happen.
mex -v c_with_openmp.c COMPFLAGS="$COMPFLAGS /openmp" LINKFLAGS="$LINKFLAGS /nodefaultlib:vcomp libiomp5md.lib"
There are several functions that may cause crash if they are called within #pragma omp parallel block, like mexPrintf.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 23일
Note though that the old SDK 7.1 and one of the old VS Express compilers did not support OpenMP. Sufficiently old VS predates OpenMP as well. So you have to be a bit careful about which VC++ you are using. My memory is a bit fuzzy as to whether the VS2013 Express had OpenMP support; I believe all of the VS2015 and later versions do have OpenMP support.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by