MATLAB Answers

0

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
Hello,
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 http://llvm.org/svn/llvm-project/openmp/trunk. 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: https://bpaste.net/show/0c6f919e8662 and the crash dump: https://bpaste.net/show/97854a69a87c
The sample extension https://bpaste.net/show/0c6f919e8662 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,
Ingmar

  0 Comments

Sign in to comment.

Products


Release

R2018b

0 Answers