forked from bempp/bempp-legacy
/
bempp_setup.py
333 lines (281 loc) · 13.3 KB
/
bempp_setup.py
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
#Copyright (C) 2011 by the BEM++ Authors
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
# BEM++ setup script
import os, sys, traceback
sys.path.append("installer")
from py_modules.tools import writeOptions, setDefaultConfigOption, pythonInfo, checkCreateDir, testBlas, testLapack, cleanUp, checkDeleteFile, checkInstallUpdates, installUpdates, normalizePath, to_bool
from ConfigParser import ConfigParser
from optparse import OptionParser
import py_modules.ahmed as ahmed
import py_modules.armadillo as armadillo
import py_modules.bempp as bempp
import py_modules.boost as boost
import py_modules.dune as dune
import py_modules.cmake as cmake
import py_modules.mkl as mkl
import py_modules.swig as swig
import py_modules.tbb as tbb
import py_modules.tools as tools
import py_modules.trilinos as trilinos
libraries = {'ahmed':ahmed,
'armadillo':armadillo,
'boost':boost,
'dune':dune,
'mkl':mkl,
'swig':swig,
'tbb':tbb,
'trilinos':trilinos,
}
library_names = sorted(libraries.keys())
library_names = sorted(library_names, key=lambda n: -1 if n == 'mkl' or n == 'swig' else 1)
###########################
# The following functions determine the directory in which the file resides.
# Trick taken from http://stackoverflow.com/questions/2632199/how-do-i-get-the-path-of-the-current-executed-file-in-python
def we_are_frozen():
# All of the modules are built-in to the interpreter, e.g., by py2exe
return hasattr(sys, "frozen")
def module_path():
if we_are_frozen():
return os.path.split(os.path.abspath(sys.executable))[0]
return os.path.split(os.path.abspath(__file__))[0]
def downloadDependencies(root,config):
print "Downloading dependencies"
for dep in library_names:
libraries[dep].download(root,config)
def bootstrap(root,config):
cleanUp(root,config)
dep_build_dir=config.get('Main','dependency_build_dir')
checkCreateDir(dep_build_dir)
dep_download_dir=config.get('Main','dependency_download_dir')
checkCreateDir(dep_download_dir)
bempp_build_dir=config.get('Bempp','build_dir')
checkCreateDir(bempp_build_dir)
checkCreateDir(prefix+"/bempp")
checkCreateDir(prefix+"/bempp/lib")
checkCreateDir(prefix+"/bempp/include")
cmake.download(root,config)
downloadDependencies(root,config)
cmake.prepare(root,config)
cmake.configure(root,config)
cmake.build(root,config)
cmake.install(root,config)
def prepareDependencies(root,config):
for dep in library_names:
libraries[dep].prepare(root,config)
def installDependencies(root,config):
for dep in library_names:
libraries[dep].configure(root,config)
libraries[dep].build(root,config)
libraries[dep].install(root,config)
def prepare(root,config):
# Test whether the main options are present
if not config.has_option('Main','prefix'): raise Exception('prefix not defined')
setDefaultConfigOption(config,'Main','cc','gcc')
setDefaultConfigOption(config,'Main','cxx','g++')
setDefaultConfigOption(config,'Main','architecture','intel64')
setDefaultConfigOption(config,'Main','flags',"")
setDefaultConfigOption(config,'Main','libs',"")
setDefaultConfigOption(config,'Main','cflags',"")
setDefaultConfigOption(config,'Main','cxxflags',"")
setDefaultConfigOption(config,'Main','root_dir',root)
setDefaultConfigOption(config,'Main','build_jobs',"1")
# Retrieve path to configuration file
optfile = config.get('Main','optfile')
# Retrieve build directory
setDefaultConfigOption(config,'Main','build_dir',root+'/build')
build_dir = normalizePath(config, config.get('Main','build_dir'))
# Set build directories for BEM++ and its dependencies
config.set('Main','build_dir',build_dir)
config.set('Bempp','build_dir',build_dir+'/bempp')
config.set('Main','dependency_build_dir',build_dir+'/contrib')
# Set
config.set('Main','dependency_download_dir',root+'/installer/files')
# Set default MKL/libs option
setDefaultConfigOption(config,'MKL','lib',"-lmkl_rt")
# Set default MPI options
setDefaultConfigOption(config,'MPI','enable_mpi','false')
setDefaultConfigOption(config,'MPI','mpi_cxx_libs','')
setDefaultConfigOption(config,'MPI','mpi_include_dir','')
enable_mpi = to_bool(config.get('MPI','enable_mpi'))
if enable_mpi:
mpi_include_dir = config.get('MPI','mpi_include_dir')
cflags = config.get('Main','cflags')
cxxflags = config.get('Main','cxxflags')
config.set('Main','with_mpi','ON')
if len(mpi_include_dir)>0:
config.set('Main','cflags',cflags+" -I"+mpi_include_dir)
config.set('Main','cxxflags',cxxflags+" -I"+mpi_include_dir)
else:
config.set('MPI','with_mpi','OFF')
# Set empty BLAS/Lapack options if none exist
setDefaultConfigOption(config,'BLAS','lib',"")
setDefaultConfigOption(config,'LAPACK','lib',"")
# Add the correct architecture parameters
cflags = config.get('Main','cflags')
cxxflags = config.get('Main','cxxflags')
arch = config.get('Main','architecture')
if not arch in ['ia32','ia64','intel64']:
raise Exception("Architecture '"+arch+"' is not supported. "
"Supported architectures: ia32, ia64, intel64.")
if sys.platform.startswith('darwin'):
if arch=='intel64':
param = '-arch x86_64'
else:
param = '-arch i386'
config.set('Main','cflags',cflags+" "+param)
config.set('Main','cxxflags',cxxflags+" "+param)
setDefaultConfigOption(config,'Main','optflags','-O3 -march=core2')
elif sys.platform.startswith('linux'):
if arch=='intel64' or arch=='ia64':
param = '-m64'
else:
param = '-m32'
config.set('Main','cflags',cflags+" "+param)
config.set('Main','cxxflags',cxxflags+" "+param)
setDefaultConfigOption(config,'Main','optflags','-O3 -march=native')
else:
raise Exception("Platform '"+sys.platform+"' is not supported")
# Add the correct Python options
import numpy
(py_exe,py_lib,py_include) = pythonInfo(config)
setDefaultConfigOption(config,'Python','exe',py_exe)
setDefaultConfigOption(config,'Python','lib',py_lib)
setDefaultConfigOption(config,'Python','include_dir',py_include)
setDefaultConfigOption(config,'Python','numpy_include_dir',numpy.get_include())
# Add the CMake configuration
prefix = config.get('Main','prefix')
setDefaultConfigOption(config,"CMake","exe",prefix+"/bempp/bin/cmake",overwrite=True)
###########################
if __name__ == "__main__":
usage = "usage: %prog [options] configuration_file"
parser = OptionParser()
parser.add_option("-b","--bootstrap", action="store_true",
help="Download dependencies and prepare directories")
parser.add_option("-c", "--configure", action="store_true",
help="Configure the setup program")
parser.add_option("-u","--update", action="store_true",help="Automatically update BEM++")
parser.add_option("","--resume-update", action="store_true",help="Resume update process after changing the source tree")
parser.add_option("-i", "--install", type="string", metavar="WHAT",
help="Build and install WHAT. Possible values for WHAT: "
"all (BEM++ and its dependencies), bempp (BEM++ only), " +
", ".join(library_names) + " (particular BEM++ dependencies)")
(options,args) = parser.parse_args()
root=module_path()
config=ConfigParser()
if len(args) != 1:
parser.error("Configuration file not specified")
optfile = args[0]
optfile_generated = root+"/"+os.path.basename(optfile)+".generated"
try:
optfileobj = open(optfile)
config.readfp(optfileobj)
optfileobj.close()
optfile_full = os.path.abspath(os.path.expanduser(optfile))
tools.setDefaultConfigOption(config,'Main','optfile',
optfile_full,overwrite=True)
prefix = normalizePath(config, config.get('Main','prefix'))
tools.setDefaultConfigOption(config,'Main','prefix',prefix,
overwrite=True)
except Exception, e:
print ("Parsing of configuration file '" + optfile +
"' failed with error message:\n" + str(e))
sys.exit(1)
try:
prepare(root,config)
if options.resume_update:
# Must be the first "if": the intention is that if this option
# is present, the update procedure is resumed and all other work
# modes are ignored.
config = ConfigParser()
if not os.path.exists(optfile_generated):
print ("You must first successfully run bempp_setup.py "
"with the --configure (-c) option.")
sys.exit(1)
config.read(optfile_generated)
installUpdates(root,config)
sys.exit(0) # don't do anything else
if options.update:
config = ConfigParser()
if not os.path.exists(optfile_generated):
print ("You must first successfully run bempp_setup.py "
"with the --configure (-c) option.")
sys.exit(1)
config.read(optfile_generated)
checkInstallUpdates(root,config)
if options.bootstrap:
bootstrap(root,config)
if options.configure:
checkDeleteFile(optfile_generated)
prepareDependencies(root,config)
bempp.prepare(root,config)
testBlas(root,config)
testLapack(root,config)
opt_fp = open(optfile_generated,'w')
config.write(opt_fp)
opt_fp.close()
print "Updated configuration written to '"+optfile_generated+"'"
enable_mkl = tools.to_bool(config.get('MKL','enable_mkl'))
if not enable_mkl:
print ("----------------------------------------------------------\n"
"You configured BEM++ to use another BLAS and LAPACK\n"
"libraries than Intel MKL. For optimum performance, ensure\n"
"that your BLAS and LAPACK libraries are configured to work\n"
"in single-threaded mode, as otherwise threads spawned by\n"
"BLAS and LAPACK will compete for resources with those\n"
"spawned by BEM++. For instance, if you are using\n"
"GotoBLAS, set the environmental variable GOTO_NUM_THREADS\n"
"to '1' before running any programs using BEM++.\n")
if options.install:
config = ConfigParser()
if not os.path.exists(optfile_generated):
print ("You must first successfully run bempp_setup.py "
"with the --configure (-c) option.")
sys.exit(1)
config.read(optfile_generated)
writeOptions(root,config)
if options.install in library_names:
libraries[options.install].configure(root,config)
libraries[options.install].build(root,config)
libraries[options.install].install(root,config)
elif options.install == "all":
installDependencies(root,config)
bempp.configure(root,config)
bempp.build(root,config)
bempp.install(root,config)
elif options.install == "bempp":
bempp.configure(root,config)
bempp.build(root,config)
bempp.install(root,config)
else:
raise Exception("Library name not recognized.")
except Exception, e:
print "=" * 78, "\nBEM++ INSTALLATION FAILED WITH ERROR MESSAGE: \n"+ str(e)
try:
error_log = open(root+"/bempp_setup.err", "w")
error_log.write(traceback.format_exc())
error_log.close()
print ("-" * 78 + "\n"
"Note: A stack trace of the BEM++ installer, providing detailed "
"information\non where the problem occured, has been written "
"to the file 'bempp_setup.err'.\nPlease include this "
"file if you report the problem to BEM++ developers.")
except:
pass
sys.exit(1)