Segmentation Faults when Running MEX files in Parallel

조회 수: 2 (최근 30일)
Berk Ustun
Berk Ustun 2012년 4월 17일
편집: jian shulei 2016년 1월 8일
I am currently running repetitions of an experiment that uses MEX files in MATLAB 2012a and occasionally running into segmentation faults that I cannot understand.
Some information about the faults
- They occur randomly
- They only occur when I run multiple repetitions of my experiment in parallel on a Linux machine using a parfor loop.
- They do not occur when I run the repeitions of my experiment in parallel on my Mac using a parfor loop.
- They do not occur when I run or do they occur whenThey do not occur when I run the repetitions sequentially.
- They appear to occur far less frequently when I run 2 experiments in parallel - as opposed to 12 experiments in parallel.
- They occur in MATLAB 2011b and 2012a...
Some information about my MEX file:
- It is written in C
- It uses the IBM CPLEX 12.4 API (this is thread-safe)
- It was compiled using GCC 4.6.3
My thoughts are that there may be some kind of file access issue. Can anyone shed any light on what might be going on? I'd be happy to provide more information as necessary.
  댓글 수: 6
Berk Ustun
Berk Ustun 2012년 4월 20일
After sending in the Stack Trace to MATLAB. It turns out that segmentation faults do originate from the thread safety, but that the function belongs to another API package that I was using in the MEX file.
Thanks for the help everyone!
jian shulei
jian shulei 2016년 1월 8일
편집: jian shulei 2016년 1월 8일
I meet the same question,can you tell me how to do?

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

답변 (2개)

James Tursa
James Tursa 2012년 4월 17일
Do you use any MATLAB API functions that allocate or change memory, such as mxCreateDoubleMatrix, mxMalloc, etc.? These are not thread-safe in general ... I don't know specifically about how parfor deals with this. What kind of file access are you doing?

Berk Ustun
Berk Ustun 2012년 4월 17일
I'm actually using malloc and free instead of the MATLAB API functions so I think I should be fine on that regard.
The only file that is being accessed is the MEX file - could there be something going wrong there?
  댓글 수: 8
James Tursa
James Tursa 2012년 4월 18일
Another thought: Let's assume for the purposes of discussion that the mex API creation functions are not thread-safe. What you could do is create the "output" variables at the m-file level before calling the mex routine. Then pass these in as arguments and modify them in-place in the mex routine. That completely bypasses the thread-safeness issues of the mex API functions.
Berk Ustun
Berk Ustun 2012년 4월 23일
That's a great idea! Will try that out as well.

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

카테고리

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