source: trunk/anuga_core/source/pypar-numeric/setup.py.bak @ 7766

Last change on this file since 7766 was 5779, checked in by steve, 16 years ago

Added the old version of pypar which works with Numeric. Necessary for parallel code until we move anuga to numpy (and then we can use pypar as distribute via sourceforge).

File size: 4.8 KB
Line 
1#!/usr/bin/env python
2
3# Examples of setup
4#
5# python setup.py install
6# python setup.py install --prefix=/opt/python-2.3
7# python setup.py install --home=~
8#
9# Some times you'll have to add a file called pypar.pth
10# containing the word pypar to site-packages
11
12
13
14from distutils.core import setup, Extension
15import distutils.sysconfig
16import distutils.debug
17import os, sys
18import popen2
19import string
20import tempfile
21
22def setup_compiler():
23    distutils.sysconfig.get_config_vars()
24    config_vars = distutils.sysconfig._config_vars
25
26    if sys.platform == 'sunos5':
27        config_vars['LDSHARED'] = "gcc -G"
28        config_vars['CCSHARED'] = ""
29
30
31def uniq_arr(arr):
32    """Remove repeated values from an array and return new array."""
33    ret = []
34    for i in arr:
35        if i not in ret:
36            ret.append(i)
37    return ret
38
39
40def _run_command(cmd):
41    out_file, in_file, err_file = popen2.popen3(cmd)
42    output = out_file.read() + err_file.read()
43    out_file.close()
44    in_file.close()
45    err_file.close()
46    # need this hack to get the exit status
47    out_file = os.popen(cmd)
48    if out_file.close():
49        # close returns exit status of command.
50        return ""
51    else:
52        # no errors, out_file.close() returns None.
53        return output
54
55
56def _get_mpi_cmd():
57    """Returns the output of the command used to compile using
58    mpicc."""
59    # LAM
60    output = _run_command("mpicc -showme")
61    if output:
62        return output
63
64    # MPICH
65    # works with MPICH version 1.2.1 (on Debian)
66    output = _run_command("mpicc -compile_info -link_info")
67    if output:
68        return output
69
70    # old version of MPICH needs this hack.
71    tmp_base = tempfile.mktemp()
72    tmp_c = tmp_base + ".c"
73    tmp_o = tmp_base + ".o"
74    tmp_file = open(tmp_c, "w")
75    tmp_file.write('#include "mpi.h"\nint main(){return 0;}\n')
76    tmp_file.close()
77    output = _run_command("mpicc -show;"\
78                          "mpicc -echo -c %s -o %s"%(tmp_c, tmp_o))
79    os.remove(tmp_c)
80    if os.path.exists(tmp_o):
81        os.remove(tmp_o)
82    if output:
83        return output
84    else:
85        return ""
86
87
88def get_mpi_flags():
89    output = _get_mpi_cmd()
90    print output
91    if not output:
92        if sys.platform=='win32': #From Simon Frost
93            #output = "gcc -L$MPICH_DIR\SDK.gcc\lib -lmpich -I$MPICH_DIR\SDK.gcc\include"
94            output = "gcc -L$C:\MPICH2\lib -lmpi -IC:\MPICH2\include"
95
96        else:
97            output = "cc -L/usr/opt/mpi -lmpi -lelan"
98
99
100    # now get the include, library dirs and the libs to link with.
101    flags = string.split(output)
102    flags = uniq_arr(flags) # remove repeated values.
103    inc_dirs = []
104    lib_dirs = []
105    libs = []
106    def_macros = []
107    undef_macros = []
108    for f in flags:
109        if f[:2] == '-I':
110            inc_dirs.append(f[2:])
111        elif f[:2] == '-L':
112            lib_dirs.append(f[2:])
113        elif f[:2] == '-l':
114            libs.append(f[2:])
115        elif f[:2] == '-U':
116            undef_macros.append(f[2:])
117        elif f[:2] == '-D':
118            tmp = string.split(f[2:], '=')
119            if len(tmp) == 1:
120                def_macros.append((tmp[0], None))
121            else:
122                def_macros.append(tuple(tmp))
123    return {'inc_dirs': inc_dirs, 'lib_dirs': lib_dirs, 'libs':libs,
124            'def_macros': def_macros, 'undef_macros': undef_macros}
125
126
127if __name__ == "__main__":
128    setup_compiler()
129
130    mpi_flags = get_mpi_flags()
131
132
133    # FIXME: It would be good to set specific compiler flags, e.g.
134    # for our AMD opteron cluster which is using the portland group
135    # compiler pgcc, but I can't get this to work let alone get distutils
136    # to give some diagnostics on what flags it is actually using.
137    if os.name == 'posix' and os.uname()[4] == 'x86_64':
138        #Extra flags for 64 bit architectures
139        #extra_compile_args = ' -fPIC -m64' #Valid for gcc       
140        extra_compile_args = ' -fPIC -tp amd64' #Valid for pgcc
141    else:
142        extra_compile_args = None
143
144
145   
146
147    setup(name="Pypar",
148          version="1.9.2",
149          description="Pypar - Parallel Python",
150          long_description="Pypar - Parallel Python, no-frills MPI interface",
151          author="Ole Nielsen",
152          author_email="Ole.Nielsen@anu.edu.au",
153          url="http://datamining.anu.edu.au/pypar",
154          package_dir = {'': 'lib'},
155          packages  = ['pypar'],
156          ext_modules = [Extension('pypar.mpiext',
157                                   ['mpiext.c'],
158                                   include_dirs=mpi_flags['inc_dirs'],
159                                   library_dirs=mpi_flags['lib_dirs'],
160                                   libraries=mpi_flags['libs'],
161                                   define_macros=mpi_flags['def_macros'],
162                                   undef_macros=mpi_flags['undef_macros'],
163                                   extra_compile_args=extra_compile_args)]
164          )
Note: See TracBrowser for help on using the repository browser.