Enable OpenMP support in clang in Mac OS X (sierra & Mojave)

clang: error: unsupported option '-fopenmp' mac
clang openmp mac mojave
install openmp on mac
openmp mac catalina
clang: error: unsupported option '-fopenmp' catalina
xcode openmp
r clang: error: unsupported option '-fopenmp'
cmake openmp mac

I am using Mac OS X Sierra, and I found that clang (LLVM version 8.1.0 (clang-802.0.38)) does not support OpenMP: when I run clang -fopenmp program_name.c, I got the following error:

clang: error: unsupported option '-fopenmp'

It seems that clang does not support -fopenmp flag.

I could not find any openmp library in homebrew. According to LLVM website, LLVM already supports OpenMP. But I could not find a way to enable it during compiling.

Does this mean that the default clang in Mac does not support OpenMP? Could you provide any suggestions?

(When I switch to GCC to compile the same program (gcc is installed using brew install gcc --without-multilib), and the compilation is successful.)

Try using Homebrew's llvm:

brew install llvm

You then have all the llvm binaries in /usr/local/opt/llvm/bin. To compile the OpenMP Hello World program, for example, type

/usr/local/opt/llvm/bin/clang -fopenmp -L/usr/local/opt/llvm/lib omp_hello.c -o hello

You might also have to set the CPPFLAGS with -I/usr/local/opt/llvm/include.

A makefile should look like this:

CPP = /usr/local/opt/llvm/bin/clang
CPPFLAGS = -I/usr/local/opt/llvm/include -fopenmp
LDFLAGS = -L/usr/local/opt/llvm/lib

omp_hello: omp_hello.c
    $(CPP) $(CPPFLAGS) $^ -o $@ $(LDFLAGS)

Update: In macOS 10.14 (Mojave) you might get an error like

/usr/local/Cellar/llvm/7.0.1/lib/clang/7.0.1/include/omp.h:118:13: fatal error: 'stdlib.h' file not found

If this happens, the macOS SDK headers are missing from /usr/include. They moved into the SDK itself with Xcode 10. Install the headers into /usr/include with

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

OpenMP on High Sierra, Building OpenMP code is actually possible using Apple Clang that comes This will install the necessary files into $(brew --prefix libomp) (usually An example of a CMakeLists.txt that would support OpenMP on macOS:. To build with OpenMP support, you need to make sure you're not invoking Apple's clang from Xcode. Even if you install llvm or gcc via brew, you should try gcc -v and clang -v in your terminal session. Both likely invoke Apple's version. You can use GNU gcc or LLVM; both are available via brew.

Other people have given one solution (using Homebrew llvm). You can also use OpenMP with Apple Clang and Homebrew libomp (brew install libomp). Just replace a command like clang -fopenmp test.c with clang -Xpreprocessor -fopenmp test.c -lomp.

Setting up gcc / OpenMP on OSX (Homebrew edition) – MathCancer , Of course, you can use other compilers and more sophisticated integrated desktop Note 1: OSX / Xcode appears to have gcc out of the box (you can type “gcc” in a Terminal window), On my 2012 Macbook Air, this step took 16 hours. you probably used Apple's build of clang, which does not include OpenMP support. Although it is possible to get openmp compilation working on a Mac Sierra by updating clang (not sure if newer versions of MacOS have fixed this by updating clang) as in Enable OpenMP support in clang in Mac OS X (sierra) it is also possible to get Apple's default clang to work.

MacOS Mojave with CMake

  1. Install LLVM with openmp and libomp with brew

     brew update
     brew install llvm libomp
  2. add include directories and link directories in CMakeList.txt

     include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
     link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
  3. run CMake with the new compilers

     cmake -DCMAKE_C_COMPILER="/usr/local/opt/llvm/bin/clang" -DCMAKE_CXX_COMPILER="/usr/local/opt/llvm/bin/clang++" ..

The clang version is 7.0.1 at time of writing

Clang + OpenMP Setup in macOS | by Александр Светлый, about how to use llvm with OpenMP in macOS in terminal and Xcode. 2015 OpenMP support has been included in clang/llvm compiler,� OS X currently uses Apple builds of clang with no OpenMP support. On a more positive note though, official OpenMP with clang should be arriving sometime in June after WWDC as the Intel funded clang-omp feature has been merged into the main clang branch. Thus, there is hope that in XCode 9 OS X users may once again join the flock of OpenMP

OpenMP on macOS with Xcode tools, For those impatient, skip to how to enable OpenMP in packages. OpenMP support in Xcode. Apple has explicitly disabled OpenMP support in compilers that they ship In fact, the clang compiler in Xcode can generate all the necessary They are signed and support macOS 10.13 (High Sierra) and higher. The NAG Fortran Compiler is available on Linux, Microsoft Windows and Mac OS X. The latest release (6.2) has extensive support for both modern and legacy Fortran features, and also supports parallel programming with OpenMP.

OpenMP�/Clang, Development activity of OpenMP support in clang/llvm compiler has moved to get OpenMP-enabled clang (OpenMP 3.1 is fully supported in clang/llvm 3.7) and On Mac OS X, replace LD_LIBRARY_PATH with DYLD_LIBRARY_PATH. CppCompilerVersion=5andabove o OpenMP=NO CC=g++ On MacOS machines, to leverage OpenMP multicore execution, you must install a gcc (g++) version different from the one provided within the compiler front end “Clang” which until now has not built-in support for OpenMP.

CMake can't find OpenMP with Apple Clang � Issue #591 � oneapi , Summary I'm trying to build DNNL on macOS with Apple Clang, but it won't pick up the See https://iscinumpy.gitlab.io/post/omp-on-high-sierra/. I've successfully used this to build scikit-learn with OpenMP support. it is now, it would be necessary to use a custom-built Clang on macOS to enable OpenMP. I've been trying to get timing comparisons of various file IO functions today and managed to get everything working except the OpenMP implementation of fwrite(). When I run fwrite() in my bench

  • Indeed, Apple-provided clang does not support OpenMP.
  • brew install llvm should install the latest LLVM version, i.e. 4.0.0. Does this fix the problem?
  • Apple-provided clang does not support OpenMP by default. It is possible to enable the feature in Apple-provided clang and also possible to install a more recent version of clang that does support OpenMP by default.
  • @IncreasinglyIdiotic How do we enable it? do we just need to compile and install the openmp runtime?
  • @MarcusJ you should just need to brew install llvm libomp and then make sure to use the new clang to compile with the -fopenmp flag
  • You may also need brew install libomp
  • Indeed, with llvm@8, I had to install libomp
  • I tried that, but it wouldn't find omp.h for inclusion.
  • If you are sure you have install libomp under Homebrew, you can ask on the Homebrew forum discourse.brew.sh. In my case, omp.h is installed under /usr/local/Cellar/libomp/10.0.0/include, symlinked to /usr/local/include.
  • Is it known why Apple clang requires the -Xpreprocessor flag?
  • After trying to build Blender on macOS (which has libomp as a dependency) for 3 days, this is the solution that worked for me, though my symptoms were a bit different. For me the compilation completed, but there were linker errors about missing x86_64 symbols from the libomp library. This worked for Homebrew's GCC 9.1.0 as of this comment.
  • Where is the CMakelists.txt ? I have at least 6 files named this way.
  • Thank you so much! It works for me in Clion and Mac OS 10.14.6
  • An improvement on this answer would be to use brew --prefix llvm rather than assuming /usr/local/opt/llvm. Something like execute_process(COMMAND brew --prefix llvm OUTPUT_VARIABLE LLVM_PREFIX)