lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
230 stars 285 forks source link

It *is* possible to compile with clang + openmp #405

Open defjaf opened 3 years ago

defjaf commented 3 years ago

Contrary to what is stated in the docs, it is actually not difficult to compile with clang and OpenMP: clang (even the Apple-supplied version) has actually supported working with OpenMP for several versions, but you have to have the libomp libraries. You can get these (for example) with homebrew, so all you have to do is:

So in the Makefile, you need lines like the following:

CC       = clang
...
OMPFLAG   = -Xclang -fopenmp
...
LDFLAG += -lomp
lesgourg commented 3 years ago

This is an awesome tipp, thank you Andrew!

defjaf commented 3 years ago

And for what it's worth, my anecdotal evidence is that clang on macOS is a little bit faster than gcc.

lesgourg commented 3 years ago

Great. In the next minor revision 3.0.2, will plan to document this in the Makefile and in the wiki section devoted to installation.

echaussidon commented 3 years ago

Thank you for the tip ! (it works perfectly for mac os x 11.4 with Apple clang version 12.0.0)

I just want to add an additional comment for classy. I don't know if it obvious, but it can maybe help some one else.

I got the following error: from classy import Class ImportError: dlopen(/usr/local/anaconda3/lib/python3.7/site-packages/classy.cpython-37m-darwin.so, 2): Symbol not found: ___kmpc_barrier

The problem comes from the path of openMP lib which is not correctly set in python/setup.py. To solve it, I modify extra_link_args=['-lgomp'] to extra_link_args=['-lomp'] (which is the lib that it is used here during the compilation). Then make clean, make and classy works.