Repository navigation
Expand file tree
/
Copy pathsetup_parallel.py
More file actions
85 lines (71 loc) · 2.37 KB
/
Copy pathsetup_parallel.py
File metadata and controls
85 lines (71 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# usually the name should only be setup.py
# on the terminal run
# python setup_parallel.py install
import os
import sys
import glob
from setuptools import Extension, setup
try:
from Cython.Build import cythonize
use_cython = True
except ImportError:
use_cython = False
# top-level information
NAME = 'pairwise3'
VERSION = '0.0.1'
USE_OPENMP = True
def set_gcc(use_openmp):
"""
try to find and use GCC on OSX for OpenMP support.
Reference
---------
https://github.com/maciejkula/glove-python/blob/master/setup.py
"""
# For macports and homebrew
patterns = ['/opt/local/bin/gcc-mp-[0-9].[0-9]',
'/opt/local/bin/gcc-mp-[0-9]',
'/usr/local/bin/gcc-[0-9].[0-9]',
'/usr/local/bin/gcc-[0-9]']
if 'darwin' in sys.platform.lower():
gcc_binaries = []
for pattern in patterns:
gcc_binaries += glob.glob(pattern)
gcc_binaries.sort()
if gcc_binaries:
_, gcc = os.path.split(gcc_binaries[-1])
os.environ['CC'] = gcc
else:
use_openmp = False
logging.warning('No GCC available. Install gcc from Homebrew '
'using brew install gcc.')
return use_openmp
def define_extensions(use_cython, use_openmp):
if sys.platform.startswith('win'):
# compile args from
# https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx
link_args = []
compile_args = ['/O2', '/openmp']
else:
link_args = []
compile_args = ['-Wno-unused-function', '-Wno-maybe-uninitialized','-O3', '-ffast-math']
if use_openmp:
compile_args.append('-fopenmp')
link_args.append('-fopenmp')
if 'anaconda' not in sys.version.lower():
compile_args.append('-march=native')
src_ext = '.pyx' if use_cython else '.c'
modules = [ Extension( 'pairwise3',
[ os.path.join('pairwise3' + src_ext) ],
extra_compile_args = compile_args,
extra_link_args = link_args ) ]
if use_cython:
return cythonize(modules)
else:
return modules
USE_OPENMP = set_gcc(USE_OPENMP)
setup(
name = NAME,
version = VERSION,
description = 'pairwise distance quickstart',
ext_modules = define_extensions(use_cython, USE_OPENMP)
)