Segmentation Faults when Running MEX files in Parallel

2 vues (au cours des 30 derniers jours)
Berk Ustun
Berk Ustun le 17 Avr 2012
Modifié(e) : jian shulei le 8 Jan 2016
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 commentaires
Berk Ustun
Berk Ustun le 20 Avr 2012
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 le 8 Jan 2016
Modifié(e) : jian shulei le 8 Jan 2016
I meet the same question,can you tell me how to do?

Connectez-vous pour commenter.

Réponses (2)

James Tursa
James Tursa le 17 Avr 2012
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 le 17 Avr 2012
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 commentaires
James Tursa
James Tursa le 18 Avr 2012
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 le 23 Avr 2012
That's a great idea! Will try that out as well.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by