MATLAB Answers


How to compile&link mex extension with OpenMP on macOS? / MATLAB crash on call

Asked by Ingmar Rieger on 10 Nov 2018 at 21:28
Latest activity Edited by Walter Roberson
on 10 Nov 2018 at 21:30
I'm working on a MATLAB extension using some C++ code that is working with OpenMP for parallelisation for data processing. The mex file works well on Windows and Linux using OpenMP, while on macOS it works single threaded only. As llvm/clang on macOS/Xcode comes without OpenMP support, I compiled libomp myself as a static library with the code from the llvm project Building an executable from some OpenMP test code with a command like
c++ -Xpreprocessor -fopenmp -I/path/to/omp/include -lpthread -o testcode omptest.cpp /path/to/omp/libomp.a
results in a well working executable.
In MATLAB I'm able to compile a mex extension with OpenMP with some additional parameters. However, when executed, it results in a MATLAB crash when it tries to fork the process. Here is some sample code I build to demonstrate the problem: and the crash dump:
The sample extension works on Linux but not on macOS. The C++ code contains the mex compiler call I used on both systems and a sample how I called the mex function in the comments. Can anyone help how to get OpenMP running in a mex extension?
Kind regards,


Sign in to comment.




0 Answers