Openmp support on apple silicon

Hello,

On a M2 Mac Mini, running this command gives me a long list of compiler directives:

 g++ -E -dM -Ofast -DNDEBUG -Ofast -DHAVE_CXX0X -march=native -fpic -ftree-vectorize - < /dev/null

the full list is here. But as soon as I add the -openmp flag, all the output disappears:

 g++ -E -dM -Ofast -DNDEBUG -Ofast -DHAVE_CXX0X -march=native -fpic -ftree-vectorize -openmp - < /dev/null

Why? And using -fopenmp gives me this error:

clang: error: unsupported option ‘-fopenmp’

can anyone explain this to me? I have:

└─[$] g++ --version                                                                                                       [14:52:49]
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

M.

“-openmp” is parsed as “-o penmp”, i.e. write the output to the file named “penmp”.

Not sure why -fopenmp isn’t working for you. Some Googling seems to indicate support for the flag is disabled in Apple clang.

Yes it is. I’m unsure if you can work around that or if you need to build your own clang on apple, e.g., homebrew. @shiltian ?

As @alexey-bataev @jdoerfert suggests, OpenMP support is removed by Apple’s clang driver. (“Thankfully” just driver not front end) If you use the system clang (or “gcc”), then you will have to pass OpenMP flag explicitly to front end, and add the corresponding linker flag.
On the other hand, you can always build your own clang or use the one from HomeBrew, then -fopenmp and all the other stuff will work as expected.