Mex-files + Visual studio 2013 + openMP cause Matlab crashes
3 次查看(过去 30 天)
显示 更早的评论
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
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
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 Center 和 File Exchange 中查找有关 Execution Speed 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!