OpenMP is enabled by default in our cmake configuration and should be picked up with the line find_package(OpenMP). What do you see when you run cmake?
This is macOS Catalina (10.15.7) on a Mac Pro with 8 cores / 16 threads, using HomeBrew.
The relevant output lines from cmake are:
â Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
â Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
â Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
There are two basic problems here:
âbrew install libompâ does not install OpenMP-config.cmake. It does install omp.h, libomp.a, and libomp.dyllib into /usr/local. So the code is there, but cmake cannot find it.
Appleâs clang does not support OpenMP, and does not recognize â-fopenmpâ
I got it to work by:
brew install llvm
edit CMakeLists.txt to replace the find_package: #TJR find_package(OpenMP)
set(OPENMP_FOUND TRUE)
set(OpenMP_CXX_FLAGS â-fopenmpâ) #TJR end edits
use this command in the empty build directory: CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS=-L/usr/local/lib cmake -DCMAKE_INSTALL_PREFIX=$HOME/openmc ..
Note the brew-installed g++-11 did not work (some missing libraries). But the brew-installed clang++ (in package âllvmâ) does work.
This is clearly very Mac and HomeBrew specific, and required a level of software expertise not often found in physicists. I do not know why neither Apple nor HomeBrew got it right.
@tjrob Glad you were able to figure out a workaround. Out of curiousity what version of CMake are you using? Iâm wondering if perhaps they have fixed the OpenMP module to work out of the box in recent releases â ideally the find_package(OpenMP) call should just work!
Thatâs quite old â apparently I installed it manually some time ago. So I removed it and did âbrew install cmakeâ and got cmake version 3.23.1.
I removed my edits to CMakeLists.txt, removed and recreated the build directory, and now cmake finds OpenMP. The Apple clang++ compiler still cannot use it, but HomeBrewâs clang++ can; not editing CMakeLists.txt is a big improvement.
For the record, after âbrew upgrade; brew install llvm libompâ, with source in $HOME/openmc, the commands are:
cd $HOME/openmc; rm -fr build; mkdir build; cd build; CC=/usr/local/opt/llvm/bin/clang CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS=-L/usr/local/lib cmake -DCMAKE_INSTALL_PREFIX=$HOME/openmc ..; make install