1 | from __future__ import division, print_function |
---|
2 | |
---|
3 | import os |
---|
4 | import sys |
---|
5 | import commands |
---|
6 | import shlex |
---|
7 | import string |
---|
8 | |
---|
9 | from os.path import join |
---|
10 | |
---|
11 | #================================================= |
---|
12 | # Code taken from pysph |
---|
13 | #================================================= |
---|
14 | |
---|
15 | def getoutput_mpicc(): |
---|
16 | """Returns the output of the command used to compile using |
---|
17 | mpicc.""" |
---|
18 | # LAM/OPENMPI/MPICH2 |
---|
19 | output = commands.getoutput('mpicc -show') + ' -fPIC' |
---|
20 | |
---|
21 | if output: |
---|
22 | return output |
---|
23 | |
---|
24 | # MPICH |
---|
25 | # works with MPICH version 1.2.1 (on Debian) |
---|
26 | output = commands.getoutput('mpicc -compile_info -link_info') |
---|
27 | if output: |
---|
28 | return output |
---|
29 | |
---|
30 | def parse_command(output): |
---|
31 | # Now get the include, library dirs and the libs to link. |
---|
32 | flags = shlex.split(output) |
---|
33 | #flags = uniq_arr(flags) # Remove repeated values. |
---|
34 | inc_dirs = [] |
---|
35 | lib_dirs = [] |
---|
36 | libs = [] |
---|
37 | def_macros = [] |
---|
38 | undef_macros = [] |
---|
39 | for f in flags: |
---|
40 | if f[:2] == '-I': |
---|
41 | inc_dirs.append(f[2:]) |
---|
42 | elif f[:2] == '-L': |
---|
43 | lib_dirs.append(f[2:]) |
---|
44 | elif f[:2] == '-l' and f[-1] != "'": # Patched by Michael McKerns July 2009 |
---|
45 | libs.append(f[2:]) |
---|
46 | elif f[:2] == '-U': |
---|
47 | undef_macros.append(f[2:]) |
---|
48 | elif f[:2] == '-D': |
---|
49 | tmp = string.split(f[2:], '=') |
---|
50 | if len(tmp) == 1: |
---|
51 | def_macros.append((tmp[0], None)) |
---|
52 | else: |
---|
53 | def_macros.append(tuple(tmp)) |
---|
54 | return {'inc_dirs': inc_dirs, 'lib_dirs': lib_dirs, 'libs':libs, |
---|
55 | 'def_macros': def_macros, 'undef_macros': undef_macros} |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | def configuration(parent_package='',top_path=None): |
---|
61 | |
---|
62 | from numpy.distutils.misc_util import Configuration |
---|
63 | from numpy.distutils.system_info import get_info |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | #print(mpi_flags) |
---|
68 | |
---|
69 | config = Configuration('parallel', parent_package, top_path) |
---|
70 | |
---|
71 | try: |
---|
72 | # Use this import to check if we are in a parallel environment |
---|
73 | import pypar |
---|
74 | |
---|
75 | #We are parallel! |
---|
76 | mpi_flags = parse_command(getoutput_mpicc()) |
---|
77 | |
---|
78 | config.add_data_dir('tests') |
---|
79 | config.add_data_dir('data') |
---|
80 | |
---|
81 | config.add_extension('mpiextras', |
---|
82 | sources=['mpiextras.c'], |
---|
83 | include_dirs=mpi_flags['inc_dirs'], |
---|
84 | library_dirs=mpi_flags['lib_dirs'], |
---|
85 | libraries=mpi_flags['libs'], |
---|
86 | define_macros=mpi_flags['def_macros'], |
---|
87 | undef_macros=mpi_flags['undef_macros']) |
---|
88 | except: |
---|
89 | #No parallel support, so just copy over the py files |
---|
90 | pass |
---|
91 | |
---|
92 | |
---|
93 | return config |
---|
94 | |
---|
95 | if __name__ == '__main__': |
---|
96 | from numpy.distutils.core import setup |
---|
97 | setup(configuration=configuration) |
---|
98 | |
---|
99 | |
---|
100 | |
---|