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:
project(test LANGUAGES C)
with clang I get:
❯ cmake -B build . -DCMAKE_C_COMPILER=clang
-- The C compiler identification is AppleClang 22.214.171.12430022
-- 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?
I think it’s an Xcode thing. See this page.
@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?
I have no idea. I don’t remember why that is in my browser history, but I don’t remember the results (if any) of testing its results.
Need to set OpenMP_ROOT on macOS to point to libomp. Details: OpenMP with CMake · GitHub
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.
Maybe one has an environment variable like CMAKE_PREFIX_PATH or OpenMP_ROOT set already?
Or Homebrew is loaded by default on the M1 machine? I’d diff
env output on each just to make sure.
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).