oslocyclotronlab / ompy_Archive_Sept2019

Archived version om ompy as of 27. Sept 2019 -- Please use this instead:
https://github.com/oslocyclotronlab/ompy/
GNU General Public License v3.0
0 stars 1 forks source link

Cython build fails with "clang: error: unsupported option '-fopenmp'" #30

Closed fzeiser closed 5 years ago

fzeiser commented 5 years ago

Issue by magneg Thursday Aug 29, 2019 at 11:14 GMT Originally opened as https://github.com/oslocyclotronlab/ompy/issues/30


I get following error during the installation:

magneg@fysmac-kef12.uio.no:ompy>python setup.py build_ext --inplace
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    from Cython.Build import cythonize
ImportError: No module named Cython.Build
magneg@fysmac-kef12.uio.no:ompy>python3 setup.py build_ext --inplace
Compiling ompy/decomposition.pyx because it changed.
Compiling ompy/gauss_smoothing.pyx because it depends on /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Cython/Includes/numpy/__init__.pxd.
Compiling ompy/rhosig.pyx because it changed.
[1/3] Cythonizing ompy/decomposition.pyx
[2/3] Cythonizing ompy/rhosig.pyx
[3/3] Cythonizing ompy/gauss_smoothing.pyx
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'zip_safe'
  warnings.warn(msg)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'install_requires'
  warnings.warn(msg)
running build_ext
building 'decomposition' extension
creating build
creating build/temp.macosx-10.9-x86_64-3.7
creating build/temp.macosx-10.9-x86_64-3.7/ompy
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c ompy/decomposition.c -o build/temp.macosx-10.9-x86_64-3.7/ompy/decomposition.o -O3 -ffast-math -march=native -fopenmp
clang: error: unsupported option '-fopenmp'
error: command 'gcc' failed with exit status 1
magneg@fysmac-kef12.uio.no:ompy>
fzeiser commented 5 years ago

Comment by magneg Thursday Aug 29, 2019 at 11:29 GMT


Fabio: Seems like -fopenmp was missing.

Can be installed with brew install libomp, but gcc seems to need to get an extra flag for MAC, -Xpreprocessor -fopenmp.

For a possible fix in the setup.py, see https://github.com/GalacticDynamics-Oxford/Agama/blob/master/setup.py

fzeiser commented 5 years ago

Comment by magneg Thursday Aug 29, 2019 at 11:30 GMT


I also checked that it compiles if I manually add the -Xpreprocessor flag and it works.

fzeiser commented 5 years ago

Comment by magneg Thursday Aug 29, 2019 at 11:37 GMT


Hotfix:

        Extension("decomposition",
                  ["ompy/decomposition.pyx"],
                  extra_compile_args=["-O3", "-ffast-math", "-march=native",
                                      "-Xpreprocessor", "-fopenmp"],
                  extra_link_args=["-Xpreprocessor", "-fopenmp"],
                  include_dirs=[numpy.get_include()]
                  ),

But the next error after installing is:

magneg@fysmac-kef12.uio.no:ompy>python3
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ompy as om
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/ompy/ompy/__init__.py", line 4, in <module>
    from .rebin import *
ModuleNotFoundError: No module named 'ompy.rebin'
fzeiser commented 5 years ago

Comment by fzeiser Thursday Aug 29, 2019 at 17:23 GMT


It might be nice to be able to run it on mac directly, but I'll anyhow create a docker image

fzeiser commented 5 years ago

Comment by fzeiser Thursday Aug 29, 2019 at 17:42 GMT


Potentially the above fixed the fpenmp isse and the rest is just something that is borken at the current commit of rhosig, see #31: "Build" broken in current rhosig branch

fzeiser commented 5 years ago

Comment by fzeiser Friday Aug 30, 2019 at 09:21 GMT


Also installed gcc via conda and fixed setup.py

fzeiser commented 5 years ago

Comment by magneg Friday Aug 30, 2019 at 11:09 GMT


Installing with conda gcc gives:

(ompy) magneg@fysmac-kef12.uio.no:ompy>python setup.py build_ext --inplace
running build_ext
building 'ompy.decomposition' extension
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/magneg/miniconda3/envs/ompy/include -arch x86_64 -I/Users/magneg/miniconda3/envs/ompy/include -arch x86_64 -I/Users/magneg/miniconda3/envs/ompy/lib/python3.7/site-packages/numpy/core/include -I/Users/magneg/miniconda3/envs/ompy/include/python3.7m -c ompy/decomposition.c -o build/temp.macosx-10.9-x86_64-3.7/ompy/decomposition.o -O3 -ffast-math -march=native -Xpreprocessor -fopenmp
In file included from /Users/magneg/miniconda3/envs/ompy/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/syslimits.h:7:0,
                 from /Users/magneg/miniconda3/envs/ompy/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/limits.h:34,
                 from /Users/magneg/miniconda3/envs/ompy/include/python3.7m/Python.h:11,
                 from ompy/decomposition.c:32:
/Users/magneg/miniconda3/envs/ompy/lib/gcc/x86_64-apple-darwin11.4.2/4.8.5/include-fixed/limits.h:168:61: fatal error: limits.h: No such file or directory
 #include_next <limits.h>  /* recurse down to the real one */
                                                             ^
compilation terminated.
error: command 'gcc' failed with exit status 1

and installing with macs inbuild gcc works, but the import gives:

[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ompy
^[[B^[[AMatplotlib is building the font cache using fc-list. This may take a moment.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/ompy/ompy/__init__.py", line 6, in <module>
    from .fit_rho_T import *
  File "/Applications/ompy/ompy/fit_rho_T.py", line 35, in <module>
    from . import rhosig as rsg
  File "ompy/rhosig.pyx", line 32, in init rhosig
  File "/Applications/ompy/ompy/matrix.py", line 47, in <module>
    from .decomposition import index
ImportError: dlopen(/Applications/ompy/ompy/decomposition.cpython-37m-darwin.so, 2): Symbol not found: ___kmpc_barrier
  Referenced from: /Applications/ompy/ompy/decomposition.cpython-37m-darwin.so
  Expected in: flat namespace
 in /Applications/ompy/ompy/decomposition.cpython-37m-darwin.so
fzeiser commented 5 years ago

Comment by fzeiser Friday Aug 30, 2019 at 13:04 GMT


It might be easiest to set a precompiler info. If it's a mac, we take ra nge instead of prange. Alternatively one could grep a environment variable determining whether or not to use with multithread