I’m feeling really stupid right now. Not sure what I’m doing wrong. First, I’m a Fortran programmer, so I am not good at C. But, when I try and use OpenMP and Clang, I can’t seem to. Many things on line say I need to install libomp from brew but:
❯ brew install libomp
Warning: libomp 16.0.6 is already installed and up-to-date.
To reinstall 16.0.6, run:
brew reinstall libomp
So I have it install. But CMake never seems to see OpenMP. I kept whittling down my CMakeLists.txt until I got to:
cmake_minimum_required(VERSION 3.24)
project(test LANGUAGES C)
find_package(OpenMP)
with clang I get:
❯ cmake -B build . -DCMAKE_C_COMPILER=clang
-- The C compiler identification is AppleClang 14.0.3.14030022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND)
-- Configuring done (2.0s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/mathomp4/OpenMPTester/build
Is there something special I need to set in CMake to get this to work? Or is this just “Apple Clang be broken, sorry”?
If it matters, I’m on a M2 MacBook. Maybe this is an Arm thing?
@ben.boeckel Thanks for the pointer. For so long on my machines I’ve built (by hand) gcc. But in trying to make it easier for others I thought “Let’s just use clang for C”.
I’ll work with my admins and see if they can install that for testing. If we install it, does CMake have the magic inside to find and use it?
Ahh nice! Now the next fun I’ll be having is: why do I need to do this only on my M2 laptop but not my M1 Studio. They each have the same OS version, compilers, Xcode, CMake version…all identical. But on one, it’s needed, the other it’s not. So weird.
My dotfiles setup is identical all around as are the modulefiles (modulo compiler licenses). But, in the end, the OpenMP_ROOT fix might as well be applied to both for consistency!
Now I’m having fun with trying Intel on my M1/M2 under Rosetta2. It all works pretty well save…OpenMP! My guess is the libomp from brew is not for x86 so an ifort/clang/clang++ setup under Rosetta2 can’t handle that. And my tests of trying to build things with ifort/icc/icpc some libraries got VERY confused:
ld: warning: ignoring file ./.libs/libnco.a, building for macOS-x86_64 but attempting to link with file built for unknown-x86_64
But since Intel on Arm Mac is more of an experiment to “just try to get things good enough” so I can locally build/debug a library with Intel Fortran, and I don’t need C/C++ OpenMP…I’m okay with not caring too much. MPI works, OpenMP Fortran works…so I’m good.
Yeah, I’ve tried Intel oneAPI on Apple Silicon via Rosetta, and there are a lot of problems beyond just the one you are mentioning (not related to CMake).
For me the environment variable OpenMP_ROOT does not work. I need cmake -DOpenMP_CXX_FLAG="-Xclang -fopenmp" -DOpenMP_CXX_INCLUDE_DIR=/opt/homebrew/opt/libomp/include -DOpenMP_CXX_LIB_NAMES=libomp -DOpenMP_C_FLAG="-Xclang -fopenmp" -DOpenMP_C_INCLUDE_DIR=/opt/homebrew/opt/libomp/include -DOpenMP_C_LIB_NAMES=libomp -DOpenMP_libomp_LIBRARY=/opt/homebrew/opt/libomp/lib/libomp.dylib
This is for a freshly installed mac, where brew instals since Oct 2022 to /opt/homebrew/opt/libomp/. On my other (older system, also arm64), it is /opt/homebrew and I have no issues.