-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
285 lines (223 loc) · 8.62 KB
/
SConstruct
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
###############################################################################
# Copyright (C) 2007 Peter Krusche, The University of Warwick
# peter@dcs.warwick.ac.uk
###############################################################################
import os
import os.path
import glob
import string
import re
import sys
import platform;
from SCons.Defaults import *
###############################################################################
# Modular helpers
###############################################################################
import SConsHelpers.mpi
import SConsHelpers.blas
import SConsHelpers.tbb
import SConsHelpers.boost
import SConsHelpers.autoconfig
###############################################################################
# read options and configure directories
###############################################################################
optfilename = 'opts.py'
# Try to find options file based on hostname
optfilename_local = 'opts_'+platform.uname()[1]+'_'+platform.uname()[0]+'_'+platform.uname()[4]+'.py'
if len(glob.glob(optfilename_local)) > 0:
optfilename = optfilename_local
else:
print 'To use specific options for this system, use options file "'+optfilename_local+'"'
print 'Using options from ' + optfilename
subarch = platform.uname()[4]
opts = Variables(optfilename)
# these are the options that can be specified through the command line
opts.AddVariables(
EnumVariable('mode', 'Build mode: set to debug or release', 'debug',
allowed_values = ('debug', 'release'),
ignorecase = 1),
BoolVariable('profile', 'Enable profiling. Also enables debug information.', 0),
BoolVariable('runtests', 'Run tests.', 0),
BoolVariable('debuginfo', 'Include debug information also in release version.', 1),
BoolVariable('threadsafe', 'Make bspwww library thread safe.', 1),
('toolset', 'Specify compiler and linker tools: msvc|gnu|intel', 'gnu'),
('additional_lflags', 'Additional linker flags', ''),
('additional_cflags', 'Additional compiler flags', ''),
('mpiexec', 'MPI exec command for testing', 'mpiexec'),
('mpiexec_params', 'MPI exec parameters for testing', '-n 3')
)
SCons.Defaults.DefaultEnvironment(tools = [])
# read options before creating root environment
readopts = Environment(tools = [], options = opts)
###############################################################################
# Set up the root environment
###############################################################################
toolset = readopts['toolset']
if toolset == 'msvc':
ttools = ['msvc', 'mslib', 'mslink']
elif toolset == 'gnu':
ttools = ['gnulink', 'gcc', 'g++', 'ar']
elif toolset == 'intel':
ttools = ['icc', 'ilink', 'intelc' ,'ar']
elif toolset == 'intel_windows':
ttools = ['ilink', 'icl', 'mslib']
else:
print "[W] Unknown toolset " + toolset + ", using default tools"
ttools = ['default']
## add included options
SConsHelpers.mpi.MakeOptions(opts)
SConsHelpers.boost.MakeOptions(opts)
SConsHelpers.tbb.MakeOptions(opts)
SConsHelpers.blas.MakeOptions(opts)
root = Environment(
tools = ttools,
options = opts,
)
# load toolset specific implementation of PrepareEnv
SConscript ('SConsHelpers/toolsets/'+toolset+'.py')
Help(opts.GenerateHelpText(root))
###############################################################################
# Setup compiling parameters
###############################################################################
root.Append(
ENV = os.environ,
BINDIR = "#bin",
LIBDIR = "#lib",
SRCDIR = "#src",
)
# dependency optimization
root.SetOption('max_drift', 4)
root.SetOption('implicit_cache', 1)
root.SetOption('diskcheck', None)
root.Ignore('', '')
platform_name = platform.uname()[0]
platform = ARGUMENTS.get('OS', root['PLATFORM'])
mode = root['mode']
profile = root['profile']
sequential = root['sequential']
threadsafe = root['threadsafe']
debuginfo = root['debuginfo']
runtests = root['runtests']
root.Append(
CCFLAGS = ' $CFLAGS',
CPPPATH = ['#include', '#src'],
LIBPATH = ['#lib'],
)
###############################################################################
# Setup debug / release mode flags
###############################################################################
Import ('PrepareEnv')
PrepareEnv(root)
###############################################################################
# Setup Boost, TBB and MPI library linking
###############################################################################
SConsHelpers.tbb.MakeEnv(root)
SConsHelpers.mpi.MakeEnv(root)
SConsHelpers.boost.MakeEnv(root)
SConsHelpers.blas.MakeEnv(root)
## additional flags not covered by any of the above
root.Append (
LINKFLAGS = root['additional_lflags'],
CCFLAGS = root['additional_cflags']
)
###############################################################################
# Automatic configuration code
###############################################################################
def ConfRunner(conf, autohdr):
if root['sequential']:
autohdr.write("""
#define _BSP_INIT BSP_INIT_SEQ
#define _BSP_EXIT BSP_EXIT_SEQ
#define _BSP_ABORT BSP_ABORT_SEQ
#define _BSP_COMM0 BSP_SEQ_ALLTOALL_COMM
#define _BSP_COMM1 BSP_SEQ_ALLTOALLV_COMM
#define _NO_MPI 1
""")
else:
autohdr.write("""
#define _BSP_INIT BSP_INIT_MPI
#define _BSP_EXIT BSP_EXIT_MPI
#define _BSP_ABORT BSP_ABORT_MPI
#define _BSP_COMM0 BSP_MPI_ALLTOALL_COMM
#define _BSP_COMM1 BSP_MPI_ALLTOALLV_COMM
#define _HAVE_MPI 1
""")
if threadsafe:
autohdr.write("""
#define BSP_THREADSAFE 1
""")
if not root['sequential']:
if not conf.CheckMPI(2):
print "You have enabled MPI, but I could not find an installation. Have a look at SConsHelpers/mpi.py"
if not conf.CheckBoost('1.40'):
print "I could not find Boost >= 1.40. Have a look at SConsHelpers/boost.py"
if not conf.CheckTBB(3):
print "I could not find Intel TBB version >= 3.0. Have a look at SConsHelpers/tbb.py"
if not conf.CheckBLAS():
print "No version of BLAS was found"
else:
print "BLAS Support enabled"
autohdr.write("""
#define _HAVE_CBLAS
""")
SConsHelpers.autoconfig.AutoConfig ( root, ConfRunner, {
'CheckBoost' : SConsHelpers.boost.Check,
'CheckMPI' : SConsHelpers.mpi.Check,
'CheckTBB' : SConsHelpers.tbb.Check,
'CheckBLAS' : SConsHelpers.blas.Check,
} )
###############################################################################
# Set up thread safe version of BSP
###############################################################################
if threadsafe:
root.Append (CPPDEFINES = ["BSP_THREADSAFE"])
###############################################################################
# Set up unit testing
###############################################################################
def builder_unit_test(target, source, env):
app = str(source[0].abspath)
if os.spawnl(os.P_WAIT, app, app) == 0:
open(str(target[0]),'w').write("PASSED\n")
else:
return 1
def builder_unit_test_mpi(target, source, env):
# for MPI tests, we run with these processor counts
mpiexec = env["mpiexec"]
mpiexec_params = env["mpiexec_params"]
app = str(source[0].abspath)
runme = mpiexec + " " + mpiexec_params + ' "' + app + '" > ' + str(target[0])
print "Test: running " + runme
if os.system(runme) == 0:
open(str(target[0]),'a').write("PASSED\n")
else:
return 1
# Create a builder for tests
if sequential:
bld = Builder(action = builder_unit_test)
root.Append(BUILDERS = {'Test' : bld})
else:
bld = Builder(action = builder_unit_test_mpi)
root.Append(BUILDERS = {'Test' : bld})
###############################################################################
# Export our build environments for the SConscripts
###############################################################################
libsuffix = ''
if sequential:
libsuffix += 'nompi'
if mode == 'debug':
libsuffix += '_debug'
if threadsafe:
libsuffix += '_mt'
bsp = root.Clone()
bsp.Prepend(LIBS = ['bsponmpi'+libsuffix ,])
Export(['root', 'bsp', 'sequential' , 'libsuffix', 'runtests'])
###############################################################################
# get SConscripts
###############################################################################
SConscript('src/SConscript')
SConscript('tests/SConscript')
SConscript('examples/SConscript')
SConscript('examples/bspedupack/SConscript')
SConscript('examples/mpiedupack/SConscript')
SConscript('examples/bspedupack++/SConscript')
SConscript('examples/benchmark/SConscript')