Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenMP on Mac OS #172

Open
yipihey opened this issue Nov 2, 2018 · 4 comments
Open

OpenMP on Mac OS #172

yipihey opened this issue Nov 2, 2018 · 4 comments
Milestone

Comments

@yipihey
Copy link

yipihey commented Nov 2, 2018

Significant warnings are issued suggesting that Mac OS openMP does not work with the system
installed clang toc comile Corrfunc.

Following,
https://iscinumpy.gitlab.io/post/omp-on-high-sierra/
explains how to use the existing clang on Mac OS and still use openMP.
I tested this on Mojave 10.4.1 and it works well.

I used home-brew:
brew install libomp

And added in common.mk

Add any compiler specific flags you want

CFLAGS ?= -Xpreprocessor -fopenmp

Add any compiler specific link flags you want

CLINK ?= -lomp

If a kernel crashes it can happen when two openMP libs are installed.
To avoid this you can add this in your python script:
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'

Or set the variable in your shell environment.

Speed up on MacBook pro is as expected.

Perhaps common.mk could be adjusted to suggest this possibility given how many
astronomers use Macs?

Best,
Tom

@lgarrison
Copy link
Collaborator

Thanks for the report! common.mk should currently print out the following advice:

../common.mk:302: Compiler is Apple clang and does not support OpenMP
If you want OpenMP support, please install clang with OpenMP support
For homebrew, use "brew update && (brew outdated xctool || brew upgrade xctool) && brew tap homebrew/versions && brew install clang-omp"
For Macports, use "sudo port install clang-3.8 +assertions +debug + openmp"

But possibly we'd prefer to just install libomp instead of clang-omp? If the latter happens to fix the duplicate OpenMP library issue, then that would be a strong argument in its favor (seems unlikely though). I've also found that -Wl\,--as-needed in the linker args can help avoid a lot of mischief in loading duplicate OpenMP libs.

I don't have a Mac, but if you or @manodeep could test that linker arg, it could help us decide on a path for stable OpenMP for clang.

@manodeep
Copy link
Owner

manodeep commented Nov 2, 2018

Thanks Tom!

One of the goals of Corrfunc is to ensure that the code compiles on all systems. Supporting OpenMP automatically in a Mac is a complex task, and that's why we only try to do the minimum and leave the responsibility on the user. For reference, I use Corrfunc with OpenMP regularly on my MAC laptop, but I have installed the necessary clang with the OpenMP support.

That being said, the section of the common.mk dealing with clang-omp, and the OpenMP checking + info messages can certainly be improved. And better yet, we could add in documentation on how to install libomp (or libgomp?) on OSX, and then enable OMP support at compile time.

@lgarrison The linker on OSX does not support the --as,needed flag :(

@manodeep manodeep added this to the v2.4.0 milestone May 31, 2019
@manodeep
Copy link
Owner

I can compile and run with multiple threads even with Apple clang with the following steps:

$ conda install llvm-openmp

Then adding the following to the `common.mk` file
CC :=/usr/bin/clang

#### Add any compiler specific flags you want                                                                                                                          
CFLAGS ?=-Xpreprocessor -fopenmp -I$(CONDA_PREFIX)/include

#### Add any compiler specific link flags you want                                                                                                                     
CLINK ?=-L$(CONDA_PREFIX)/lib -lomp -Xlinker -rpath -Xlinker $(CONDA_PREFIX)/lib

Of course, we will need to detect apple-clang, and then conda (and possibly brew if conda is unavailable), install the llvm-openmp package, and add those options to CFLAGS and CLINK.

Noting the solution here for incorporating into the v2.4

@manodeep
Copy link
Owner

If we were thinking of supporting cases where conda is not available, then this page might be useful

@manodeep manodeep modified the milestones: v2.4.0, v2.5.0 Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants