フィルターのクリア

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 件のコメント
Royi Avital
Royi Avital 2017 年 8 月 8 日
Did you find any solution?

サインインしてコメントする。

回答 (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 Center および File ExchangeExecution Speed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by