Clear Filters
Clear Filters

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

7 views (last 30 days)
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,

Answers (1)

Siddharth Bhutiya
Siddharth Bhutiya on 13 Nov 2018
There are some limitations for mex files using OpenMP. Please take a look at the MATLAB Answers post below for details


Find more on Execution Speed in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!