forked from TUM-I5/SWE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SConstruct
394 lines (314 loc) · 12.9 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
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#! /usr/bin/python
# @file
# This file is part of SWE.
#
# @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer)
# @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
#
# @section LICENSE
#
# SWE is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SWE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SWE. If not, see <http://www.gnu.org/licenses/>.
#
#
# @section DESCRIPTION
#
# Builds the SWE code with several options.
#
# print the welcome message
print '****************************************'
print '** Welcome to the build script of SWE **'
print '****************************************'
print 'SWE Copyright (C) 2012-2013'
print ''
print ' Technische Universitaet Muenchen'
print ' Department of Informatics'
print ' Chair of Scientific Computing'
print ' http://www5.in.tum.de/SWE'
print ''
print 'SWE comes with ABSOLUTELY NO WARRANTY.'
print 'SWE is free software, and you are welcome to redistribute it'
print 'under certain conditions.'
print 'Details can be found in the file \'gpl.txt\'.'
print ''
import os
import sys
#
# set possible variables
#
vars = Variables()
# read parameters from a file if given
vars.AddVariables(
PathVariable( 'buildVariablesFile', 'location of the python file, which contains the build variables', None, PathVariable.PathIsFile )
)
env = Environment(variables=vars)
if 'buildVariablesFile' in env:
vars = Variables(env['buildVariablesFile'])
# SWE specific variables
vars.AddVariables(
PathVariable( 'buildDir', 'where to build the code', 'build', PathVariable.PathIsDirCreate ),
EnumVariable( 'compiler', 'used compiler', 'gnu',
allowed_values=('gnu', 'intel', 'cray')
),
EnumVariable( 'compileMode', 'mode of the compilation', 'release',
allowed_values=('debug', 'release')
),
EnumVariable( 'simdExtensions', 'SIMD extensions used for vectorization (for intrinsics code)', 'NONE',
allowed_values=('NONE', 'SSE4', 'AVX')
),
EnumVariable( 'parallelization', 'level of parallelization', 'none',
allowed_values=('none', 'cuda', 'mpi_with_cuda', 'mpi')
),
EnumVariable( 'computeCapability', 'optional architecture/compute capability of the CUDA card', 'sm_20',
allowed_values=('sm_10', 'sm_11', 'sm_12','sm_13',
'sm_20', 'sm_21', 'sm_22', 'sm_23',
'sm_30', 'sm_35' )
),
BoolVariable( 'openGL', 'compile with OpenGL visualization', False),
BoolVariable( 'openGL_instr', 'add instructions to openGL version (requires SDL_ttf)', False ),
BoolVariable( 'writeNetCDF', 'write output in the netCDF-format', False ),
BoolVariable( 'asagi', 'use ASAGI', False ),
PathVariable( 'asagiInputDir', 'location of netcdf input files', '', PathVariable.PathAccept ),
EnumVariable( 'solver', 'Riemann solver', 'augrie',
allowed_values=('rusanov', 'fwave', 'augrie', 'hybrid', 'fwavevec', 'augriefun', 'augrie_simd')
),
BoolVariable( 'vectorize', 'add pragmas to help vectorization (release only)', False ),
BoolVariable( 'openmp', 'compile with OpenMP parallelization enabled', False ),
BoolVariable( 'showVectorization', 'show loop vectorization (Intel compiler only)', False ),
EnumVariable( 'platform', 'compile for a specific platform (Intel compiler only)', 'default',
allowed_values=('default', 'mic' )
),
BoolVariable( 'xmlRuntime', 'use a xml-file for runtime parameters', False ),
BoolVariable( 'copyenv', 'copy the whole environment', False ),
BoolVariable( 'countflops', 'enable flop counting; defines the macro COUNTFLOPS', False )
)
# external variables
vars.AddVariables(
PathVariable( 'cudaToolkitDir', 'location of the CUDA toolkit', None ),
PathVariable( 'libSDLDir', 'location of libSDL', None),
PathVariable( 'netCDFDir', 'location of netCDF', None),
PathVariable( 'asagiDir', 'location of ASAGI', None),
PathVariable( 'libxmlDir', 'location of libxml2', None)
)
# set environment
env = Environment(ENV = {'PATH': os.environ['PATH']},
variables=vars)
# generate help text
Help(vars.GenerateHelpText(env))
# handle unknown, maybe misspelled variables
unknownVariables = vars.UnknownVariables()
# remove the buildVariablesFile from the list of unknown variables (used before)
if 'buildVariablesFile' in unknownVariables:
unknownVariables.pop('buildVariablesFile')
# exit in the case of unknown variables
if unknownVariables:
print >> sys.stderr, "*** The following build variables are unknown:", unknownVariables.keys()
Exit(1)
# valid solver for CUDA?
if env['parallelization'] in ['cuda', 'mpi_with_cuda'] and env['solver'] not in ['rusanov','fwave','augrie']:
print >> sys.stderr, '** The "'+env['solver']+'" solver is not supported in CUDA.'
Exit(3)
# CUDA parallelization for openGL
if env['parallelization'] != 'cuda' and env['openGL'] == True:
print >> sys.stderr, '** The parallelization "'+env['parallelization']+'" does not support OpenGL visualization (CUDA only).'
Exit(3)
# Copy whole environment?
if env['copyenv']:
env.AppendUnique(ENV=os.environ, delete_existing=1)
#
# precompiler, compiler and linker flags
#
# Select the compiler (MPI and/or Intel, GNU is default)
if env['parallelization'] in ['mpi', 'mpi_with_cuda']:
if env['compiler'] == 'cray':
env['CXX'] = 'CC'
else:
env['CXX'] = env['LINKERFORPROGRAMS'] = env.Detect(['mpiCC', 'mpicxx'])
if not env['CXX']:
print >> sys.stderr, '** MPI compiler not found, please update PATH environment variable'
Exit(1)
if env['compiler'] == 'intel':
# We need to the the mpiCC wrapper which compiler it should use
# Here are several environment variables that do the job for different MPI libraries
envVars = ['OMPI_CXX', 'MPICH_CXX']
for var in envVars:
env['ENV'][var] = 'icpc'
else:
if env['compiler'] == 'intel':
env['CXX'] = 'icpc'
elif env['compiler'] == 'cray':
env['CXX'] = env['LINKERFORPROGRAMS'] = 'CC'
# eclipse specific flag
if env['compiler'] != 'cray':
env.Append(CCFLAGS=['-fmessage-length=0'])
# xml parameters for the compiler TODO
# set (pre-)compiler flags for the compile modes
if env['compileMode'] == 'debug':
env.Append(CPPDEFINES=['DEBUG'])
if env['compiler'] == 'gnu':
env.Append(CCFLAGS=['-O0','-g3','-Wall'])
elif env['compiler'] == 'intel':
env.Append(CCFLAGS=['-O0','-g'])
elif env['compiler'] == 'cray':
env.Append(CCFLAGS=['-O0'])
elif env['compileMode'] == 'release':
env.Append(CPPDEFINES=['NDEBUG'])
if env['compiler'] == 'gnu':
env.Append(CCFLAGS=['-O3','-mtune=native'])
elif env['compiler'] == 'intel':
env.Append(CCFLAGS=['-O2'])
else: # especially for env['compiler'] == 'cray'
env.Append(CCFLAGS=['-O3'])
# Other compiler flags (for all compilers)
if env['compiler'] != 'cray':
env.Append(CCFLAGS=['-fstrict-aliasing', '-fargument-noalias'])
# env.Append(CCFLAGS=['-fno-strict-aliasing', '-fargument-noalias', '-g', '-g3', '-ggdb', '-Wall', '-Wextra', '-Wstrict-aliasing=2'])
# Vectorization via Intrinsics
if env['simdExtensions'] == 'SSE4':
env.Append(CCFLAGS=['-msse4'])
elif env['simdExtensions'] == 'AVX':
env.Append(CCFLAGS=['-mavx'])
if env['countflops']:
env.Append(CCFLAGS=['-DCOUNTFLOPS'])
# Vectorization?
if env['compileMode'] == 'release' and env['vectorize']:
env.Append(CPPDEFINES=['VECTORIZE'])
if env['compiler'] == 'intel' and env['platform'] != 'mic':
env.Append(CCFLAGS=['-xHost'])
if env['compiler'] == 'intel' and env['showVectorization']:
env.Append(CCFLAGS=['-vec-report2','-opt-report'])
# OpenMP parallelism
if env['openmp']:
if env['compiler'] == 'intel':
env.Append(CCFLAGS=['-openmp'])
env.Append(LINKFLAGS=['-openmp'])
if env['compiler'] == 'gnu':
env.Append(CCFLAGS=['-fopenmp'])
# cray: OpenMP turned on by default
# Platform
if env['compiler'] == 'intel' and env['platform'] == 'mic':
env.Append(CCFLAGS=['-mmic'])
env.Append(LINKFLAGS=['-mmic'])
# Compiler
if env['compiler'] == 'intel':
# Add Intel specific libraries
env.Append(LIBS=['svml', 'imf', 'intlc'])
# Add source directory to include path (important for subdirectories)
env.Append(CPPPATH=['.'])
env.Append(CPPPATH=['include'])
# set the precompiler variables for the solver
if env['solver'] == 'fwave':
env.Append(CPPDEFINES=['WAVE_PROPAGATION_SOLVER=1'])
elif env['solver'] == 'augrie' or env['solver'] == 'augriefun':
env.Append(CPPDEFINES=['WAVE_PROPAGATION_SOLVER=2'])
elif env['solver'] == 'hybrid':
env.Append(CPPDEFINES=['WAVE_PROPAGATION_SOLVER=0'])
elif env['solver'] == 'fwavevec':
env.Append(CPPDEFINES=['WAVE_PROPAGATION_SOLVER=4'])
elif env['solver'] == 'augrie_simd':
env.Append(CPPDEFINES=['WAVE_PROPAGATION_SOLVER=5'])
# set the precompiler flags for CUDA
if env['parallelization'] in ['cuda', 'mpi_with_cuda']:
env.Append(CPPDEFINES=['CUDA'])
# set the directories for the CudaTool
if 'cudaToolkitDir' in env:
env['CUDA_TOOLKIT_PATH'] = env['cudaToolkitDir']
env.Tool('CudaTool', toolpath = ['.'])
# set precompiler flag for nvcc
env.Append(NVCCFLAGS=['-DCUDA'])
if env['solver'] == 'augrie':
env.Append(NVCCFLAGS=['-DCUDA_AUGRIE'])
# set the compute capability of the cuda compiler (needs to be set after the CudaTool
env.Append(NVCCFLAGS=['--gpu-architecture='+env['computeCapability']])
# Append the source directory to the include path
env.Append(NVCCFLAGS=['-Isrc'])
# compile explicitly with 64-bit on Mac OS X
if env['PLATFORM'] == 'darwin':
env.Append(NVCCFLAGS=' -m64')
# set the nvcc precompiler flags for MPI (CUDA)
if env['parallelization'] == 'mpi_with_cuda':
env.Append(NVCCFLAGS=['-DUSEMPI'])
# set the precompiler flags for MPI (C++)
if env['parallelization'] in ['mpi_with_cuda', 'mpi']:
env.Append(CPPDEFINES=['USEMPI'])
if env['openGL'] == True:
env.Append(LIBS=['SDL', 'GL', 'GLU'])
if env['openGL_instr'] == True:
# We assume that SDL_ttf is in the same directory as SDL
env.Append(LIBS=['SDL_ttf'])
env.Append(CPPDEFINES=['USESDLTTF'])
# set the compiler flags for libSDL
if 'libSDLDir' in env:
env.Append(CPPPATH=[env['libSDLDir']+'/include'])
env.Append(LIBPATH=[env['libSDLDir']+'/lib'])
env.Append(RPATH=[env['libSDLDir']+'/lib'])
# set the precompiler flags and includes for netCDF
if env['writeNetCDF'] == True:
env.Append(CPPDEFINES=['WRITENETCDF'])
env.Append(LIBS=['netcdf'])
# set netCDF location
if 'netCDFDir' in env:
env.Append(CPPPATH=[env['netCDFDir']+'/include'])
env.Append(LIBPATH=[os.path.join(env['netCDFDir'], 'lib')])
env.Append(RPATH=[os.path.join(env['netCDFDir'], 'lib')])
# set the precompiler flags, includes and libraries for ASAGI
if env['asagi'] == True:
env.Append(CPPDEFINES=['ASAGI'])
if env['parallelization'] == 'none' or env['parallelization'] == 'cuda':
env.Append(CPPDEFINES=['ASAGI_NOMPI'])
env.Append(LIBS=['asagi_nompi'])
env.Append(LIBPATH=['lib'])
else:
env.Append(LIBS=['asagi'])
if 'asagiDir' in env:
env.Append(CPPPATH=[env['asagiDir']+'/include'])
env.Append(LIBPATH=[env['asagiDir']+'/lib'])
env.Append(RPATH=[os.path.join(env['asagiDir'], 'lib')])
if 'netCDFDir' in env:
env.Append(LIBPATH=[env['netCDFDir']+'/lib'])
env.Append(RPATH=[os.path.join(env['netCDFDir'], 'lib')])
if 'asagiInputDir' in env:
env.Append(CPPFLAGS=['\'-DASAGI_INPUT_DIR="'+env['asagiInputDir']+'"\''])
# xml runtime parameters
if env['xmlRuntime'] == True: #TODO
print 'xml runtime parameters are not implemented so far.'
Exit(1)
env.Append(CPPDEFINES=['READXML'])
#set xmllib2 location
if 'libxmlDir' in env:
env.Append(CPPPATH=[env['libxmlDir']+'/include/libxml2'])
env.Append(LIBPATH=[env['libxmlDir']+'/lib'])
#
# setup the program name and the build directory
#
program_name = 'SWE'
# compiler
program_name += '_'+env['compiler']
# compile mode
program_name += '_'+env['compileMode']
# parallelization
program_name += '_'+env['parallelization']
# solver
program_name += '_'+env['solver']
# vectorization
if env['vectorize'] == True:
program_name += '_vec'
# build directory
build_dir = env['buildDir']+'/build_'+program_name
# get the src-code files
env.src_files = []
Export('env')
SConscript('src/SConscript', variant_dir=build_dir, duplicate=0)
Import('env')
# build the program
env.Program('build/'+program_name, env.src_files)