Amber-MD / pytraj

Python interface of cpptraj
https://amber-md.github.io/pytraj
170 stars 38 forks source link

setup.py should be more informative on OS X #1151

Closed drroe closed 8 years ago

drroe commented 8 years ago

I've recently been trying to compile cpptraj/pytraj on OS X and ran into an issue that took me some time to track down. After getting Macports/cython etc all set up, I built libcpptraj and then tried to make pytraj. I first got hit with this error:

libcpptraj was NOT detected to be installed with openmp. You can recompile it with -openmp flag or
disable openpm install in pytraj by adding --disable-openmp

Fair enough - so I went back and re-configured libcpptraj with OpenMP. After that build finished I once again tried to install pytraj. Ended up with a new error:

...
8 warnings generated.
clang++ -bundle -undefined dynamic_lookup -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/lib/db48 build/temp.macosx-10.11-x86_64-2.7/pytraj/c_dict.o -L/Users/test/GitHub/cpptraj/lib/ -lcpptraj -o build/lib.macosx-10.11-x86_64-2.7/pytraj/c_dict.so -O0 -ggdb -fopenmp
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang++' failed with exit status 1

What I found strange was that instead of gcc (my active port) pytraj setup was defaulting to clang. This persisted even when I tried to explicitly set the CC/CXX environment variables. After some digging, I found it was due to this part of setup.py:

if sys.platform == 'darwin':
    # copied from ParmEd
    # You *need* to use clang and clang++ for extensions on a Mac;
    # Anaconda does annoying stuff that breaks this, since their distutils
    # automatically tries to use "gcc", which would conflict with the MacPorts
    # gcc... sigh.
    os.environ['CXX'] = 'clang++'
    os.environ['CC'] = 'clang'

So clang is a silent requirement to build on OS X. The problem is that the default clang does not support OpenMP (@swails I think maybe the macports one does?), but requiring OpenMP is the default for pytraj. I think that pytraj's setup.py should be a bit more informative and state that clang is required on OSX, and disable the OpenMP requirement on OS X (with a warning) if the active clang does not support it. @hainm What do you think?

hainm commented 8 years ago

I am ok with anything you and Jason do for osx :)).

I initially added openmp as default since you told me this (gchat) :D

I mean, I don't know of any compilers that don't support openmp.

@swails do you want to have a quick fix for that since I don't have osx for testing.

May be make openmp as default for linux and turn it off for osx. Just try to make the setup less complicated.

hainm commented 8 years ago

@drroe while waiting for @swails feedback, I added suggestion to disable openmp in osx

https://github.com/Amber-MD/pytraj/pull/1154/files

swails commented 8 years ago

clang does not support OpenMP yet to my knowledge. If they do now, it's very recent.

hainm commented 8 years ago

thanks. so openmp will be disabled in osx.

drroe commented 8 years ago

The very latest one from macports does (3.9 i think?). I enabled openmp for cpptraj with clang (configure bow tests that openmp works).

On Thursday, February 25, 2016, Jason Swails notifications@github.com wrote:

clang does not support OpenMP yet to my knowledge. If they do now, it's very recent.

— Reply to this email directly or view it on GitHub https://github.com/Amber-MD/pytraj/issues/1151#issuecomment-188924257.


Daniel R. Roe, PhD Department of Medicinal Chemistry University of Utah 30 South 2000 East, Room 307 Salt Lake City, UT 84112-5820 http://home.chpc.utah.edu/~cheatham/ (801) 587-9652 (801) 585-6208 (Fax)

hainm commented 8 years ago

since I do not have osx to test and we don't have much time, I just added more info to README file

So clang is a silent requirement to build on OS X.

https://github.com/Amber-MD/pytraj/blob/master/README.md#install

# osx: pytraj will use clang to compile cython extension.
# if you want to change compiler, please check setup.py file
python setup.py install --disable-openmp

pytraj's setup.py should be a bit more informative and state that clang is required on OSX

I updated README file and the setup message too: https://github.com/Amber-MD/pytraj/blob/master/scripts/base_setup.py#L80-L81

Also, if libcpptraj was installed with openmp, pytraj will raise error https://github.com/Amber-MD/pytraj/pull/1157/files

thanks

hainm commented 8 years ago

close after a bunch of osx fixing.