th3g3ntl3man
th3g3ntl3man

Reputation: 2106

OpenMP on macOS Mojave

I installed the gcc compiler via xcode-select --install but the version installed is 4.2.1 then it isn't possible to use the OpenMp flag -fopenmp for compile the source code.

I tried to install the compile via Homebrew and link this to the gcc exported but it doesn't work. I tried to install gcc building the latest GNU release but after building the operative system asked me if I would install gcc using xcode-select --install.

Moreover, I follow the answer to this question but I have this error:

Error: No available formula with the name "clang-omp"

Is there any solution or suggestion I can follow to execute the OpenMP code on my Mac and on any unix-like device without having to install particular dependencies because in this answer there is a solution but the user can install dependencies?

Upvotes: 1

Views: 3332

Answers (2)

Nil
Nil

Reputation: 2390

Thanks to Richard answer, I was able to compile a project that uses OpenMP on Mojave. I'm adding this answer because some of his flags are currently wrong or useless.

-DOpenMP_C_LIB_NAMES "libomp"
-DOpenMP_CXX_LIB_NAMES "libomp"
-DOpenMP_C_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/include"
-DOpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp -I/usr/local/include"
-DOpenMP_omp_LIBRARY "/usr/local/lib/libomp.dylib"
-DOpenMP_libomp_LIBRARY "/usr/local/lib/libomp.dylib"

libomp was installed with brew install libomp.

Upvotes: 1

Richard Barber
Richard Barber

Reputation: 6441

OpenMP code can be compiled with AppleClang on mojave. Xcode includes an openmp-aware preprocessor which must be invoked.

  • You must have an omp installed; libomp is the most common. I have also used libiomp5.

  • Adjust the flags in cmake to point to your openmp solution.:

cmake .. -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DOpenMP_C_FLAGS=-fopenmp=lomp -DOpenMP_CXX_FLAGS=-fopenmp=lomp -DOpenMP_C_LIB_NAMES="libomp" -DOpenMP_CXX_LIB_NAMES="libomp" -DOpenMP_libiomp5_LIBRARY="/opt/local/lib/libomp.dylib" -DOpenMP_CXX_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include" -DOpenMP_CXX_LIB_NAMES="libomp" -DOpenMP_omp_LIBRARY=/opt/local/lib/libomp.dylib -DOpenMP_C_FLAGS="-Xpreprocessor -fopenmp /opt/local/lib/libomp.dylib -I/opt/local/include" 

Similar flags for libiomp5: See this line.

Upvotes: 4

Related Questions