forked from mit-crpg/OpenMOC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
477 lines (367 loc) · 19.2 KB
/
config.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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
import sys, sysconfig
import copy
import numpy
from distutils.extension import Extension
from distutils.util import get_platform
from distutils.dist import Distribution
from distutils.command.install_lib import install_lib
def get_openmoc_object_name():
"""Returns the name of the main openmoc shared library object"""
ext_suffix = sysconfig.get_config_var('SOABI')
if ext_suffix is None:
filename = '_openmoc.so'
else:
filename = '_openmoc.{0}.so'.format(ext_suffix)
return filename
def get_shared_object_path():
"""Returns the name of the distutils build directory"""
install_lib_command = install_lib(Distribution())
install_lib_command.initialize_options()
install_lib_command.finalize_options()
directory = install_lib_command.build_dir
return directory
def get_openmoc():
"""Returns the path and name of the main shared library object"""
return get_shared_object_path() + '/' + get_openmoc_object_name()
class configuration:
"""User-defined build configuration options for OpenMOC
Configuration options may be set using compile time flags. To view a
list of these options, run 'python setup.py install --help' in the
console. The default configuration options are shown below and should
only be revised by developers familiar with the code and its configuration
management system.
"""
###########################################################################
# User Options
###########################################################################
# Default C++ compiler for the main openmoc module is GCC
cc = 'gcc'
# Default floating point for the main openmoc module is single precision
fp = 'single'
# The number of energy groups to compile for is by default not specified
num_groups = None
# Compile using ccache (for developers needing fast recompilation)
with_ccache = False
# Compile code with debug symbols (ie, -g)
debug_mode = False
# Compile code with address sanitizer
sanitizer_mode = False
# Compile code with profile symbols (ie, -g, -pg)
profile_mode = False
# Compile code with coverage symbols (ie, -fprofile-arcs -ftest-coverage)
coverage_mode = False
# Build the openmoc.cuda module
with_cuda = False
# The vector length used for the VectorizedSolver class. This will used
# as a hint for the Intel compiler to issue SIMD (ie, SSE, AVX, etc) vector
# instructions. This is accomplished by adding "dummy" energy groups such
# that the number of energy groups is be fit too a multiple of this
# vector_length, and restructuring the innermost loops in the solver to
# loop from 0 to the vector length
vector_length = 8
# The vector alignment used in the VectorizedSolver class when allocating
# aligned data structures using MM_MALLOC and MM_FREE
vector_alignment = 64
# List of C/C++/CUDA distutils.extension objects which are created based
# on which flags are specified at compile time.
extensions = list()
# List of the possible packages to install based on runtime options
packages = ['openmoc', 'openmoc.cuda']
###########################################################################
# Source Code
###########################################################################
# Dictionary of source code files to compile for each extension module
sources = dict()
sources['gcc'] = ['openmoc/swig/openmoc_wrap.cpp',
'src/Cell.cpp',
'src/Cmfd.cpp',
'src/CPUSolver.cpp',
'src/CPULSSolver.cpp',
'src/ExpEvaluator.cpp',
'src/Geometry.cpp',
'src/linalg.cpp',
'src/LocalCoords.cpp',
'src/log.cpp',
'src/Material.cpp',
'src/Matrix.cpp',
'src/Mesh.cpp',
'src/MOCKernel.cpp',
'src/Point.cpp',
'src/Progress.cpp',
'src/Quadrature.cpp',
'src/Region.cpp',
'src/RunTime.cpp',
'src/Solver.cpp',
'src/Surface.cpp',
'src/Timer.cpp',
'src/Track.cpp',
'src/Track3D.cpp',
'src/TrackGenerator.cpp',
'src/TrackGenerator3D.cpp',
'src/TrackTraversingAlgorithms.cpp',
'src/TraverseSegments.cpp',
'src/Universe.cpp',
'src/Vector.cpp']
sources['clang'] = sources['gcc']
sources['mpicc'] = sources['gcc']
sources['icpc'] = sources['gcc']
sources['bgxlc'] = sources['gcc']
sources['nvcc'] = ['openmoc/cuda/openmoc_cuda_wrap.cpp',
'src/accel/cuda/GPUQuery.cu',
'src/accel/cuda/clone.cu',
'src/accel/cuda/GPUSolver.cu']
###########################################################################
# Compiler Flags
###########################################################################
# A dictionary of the compiler flags to use for each compiler type
compiler_flags = dict()
compiler_flags['gcc'] = ['-c', '-O3', '-ffast-math', '-fopenmp',
'-std=c++11', '-fpic', '-march=native']
compiler_flags['mpicc'] = ['-c', '-O3', '-ffast-math', '-fopenmp',
'-std=c++11', '-fpic', '-march=native']
compiler_flags['clang'] = ['-c', '-O3', '-ffast-math', '-std=c++11',
'-Xpreprocessor -fopenmp', '-fvectorize', '-fpic',
'-Qunused-arguments',
'-Wno-deprecated-register',
'-Wno-parentheses-equality',
'-march=native']
compiler_flags['icpc'] =['-c', '-O3', '-fast','-qopenmp', '-xhost',
'-std=c++11','-fpic',]
compiler_flags['bgxlc'] = ['-c', '-O2', '-qarch=qp', '-qreport',
'-qsimd=auto', '-qtune=qp', '-qunroll=auto',
'-qsmp=omp', '-qpic']
compiler_flags['nvcc'] = ['--relocatable-device-code', 'true',
'-c', '-O3', '-std=c++11',
'--compiler-options', '-fpic', '--use_fast_math']
###########################################################################
# Linker Flags
###########################################################################
# A dictionary of the linker flags to use for each compiler type
linker_flags = dict()
if ('macosx' in get_platform()):
linker_flags['gcc'] = ['-fopenmp', '-dynamiclib',
'-Wl,-install_name,' + get_openmoc_object_name()]
linker_flags['mpicc'] = ['-fopenmp', '-dynamiclib',
'-Wl,-install_name,' + get_openmoc_object_name()]
linker_flags['clang'] = ['-Xpreprocessor', '-fopenmp', '-dynamiclib',
'-Wl,-install_name,' + get_openmoc_object_name()]
# Don't dynamically link python with conda which statically linked it
if ('conda' not in sys.version and 'Continuum' not in sys.version):
python_lib = sysconfig.get_config_vars('BLDLIBRARY')[0].split()[1]
linker_flags['gcc'].append(python_lib)
linker_flags['mpicc'].append(python_lib)
linker_flags['clang'].append(python_lib)
else:
linker_flags['gcc'].extend(('-undefined', 'dynamic_lookup'))
linker_flags['mpicc'].extend(('-undefined', 'dynamic_lookup'))
linker_flags['clang'].extend(('-undefined', 'dynamic_lookup'))
else:
linker_flags['gcc'] = ['-fopenmp', '-shared',
'-Wl,-soname,' + get_openmoc_object_name()]
linker_flags['mpicc'] = ['-fopenmp', '-shared',
'-Wl,-soname,' + get_openmoc_object_name()]
linker_flags['clang'] = ['-fopenmp', '-shared',
'-Wl,-soname,' + get_openmoc_object_name()]
linker_flags['icpc'] = [ '-qopenmp', '-shared',
'-Xlinker', '-soname=' + get_openmoc_object_name()]
linker_flags['bgxlc'] = ['-qmkshrobj', '-shared',
'-R/soft/compilers/ibmcmp-may2013/lib64/bg/bglib64',
'-Wl,-soname,' + get_openmoc_object_name()]
linker_flags['nvcc'] = ['-shared', get_openmoc()]
###########################################################################
# Shared Libraries
###########################################################################
# A dictionary of the shared libraries to use for each compiler type
shared_libraries = dict()
shared_libraries['gcc'] = ['stdc++', 'gomp', 'dl','pthread', 'm']
shared_libraries['mpicc'] = ['stdc++', 'gomp', 'dl','pthread', 'm']
shared_libraries['clang'] = ['stdc++', 'gomp', 'dl','pthread', 'm']
shared_libraries['icpc'] = ['stdc++', 'iomp5', 'pthread', 'irc',
'imf','rt', 'mkl_rt','m',]
shared_libraries['bgxlc'] = ['stdc++', 'pthread', 'm', 'xlsmp', 'rt']
shared_libraries['nvcc'] = ['cudadevrt', 'cudart']
###########################################################################
# Library Directories
###########################################################################
# A dictionary of the library directories to use for each compiler type
# if not set in the LD_LIBRARY_PATH environment variable
library_directories = dict()
usr_lib = sys.exec_prefix + '/lib'
library_directories['gcc'] = [usr_lib]
library_directories['mpicc'] = [usr_lib]
library_directories['clang'] = [usr_lib]
library_directories['icpc'] = [usr_lib]
library_directories['bgxlc'] = [usr_lib]
library_directories['nvcc'] = [usr_lib, '/usr/local/cuda/lib64']
###########################################################################
# Include Directories
###########################################################################
# A dictionary of the include directories to use for each compiler type
# for header files not found from paths set in the user's environment
include_directories = dict()
include_directories['gcc'] = list()
include_directories['mpicc'] = list()
include_directories['clang'] = list()
include_directories['icpc'] = list()
include_directories['bgxlc'] = list()
include_directories['nvcc'] = ['/usr/local/cuda/include']
###########################################################################
# SWIG Flags
###########################################################################
# A list of the flags for SWIG
swig_flags = ['-c++', '-python', '-keyword']
# Python 3 only
if sys.version_info[0] == 3:
swig_flags.append('-py3')
###########################################################################
# Macros
###########################################################################
# A dictionary of the macros to set at compile time for each compiler type
# and floating point precisin level
macros = dict()
macros['gcc'] = dict()
macros['mpicc'] = dict()
macros['clang'] = dict()
macros['icpc'] = dict()
macros['bgxlc'] = dict()
macros['nvcc'] = dict()
macros['gcc']['single']= [('FP_PRECISION', 'float'),
('GCC', None)]
macros['mpicc']['single']= [('FP_PRECISION', 'float'),
('MPICC', None)]
macros['clang']['single']= [('FP_PRECISION', 'float'),
('CLANG', None)]
macros['icpc']['single']= [('FP_PRECISION', 'float'),
('ICPC', None),
('MKL_ILP64', None)]
macros['bgxlc']['single'] = [('FP_PRECISION', 'float'),
('BGXLC', None),
('CCACHE_CC', 'bgxlc++_r')]
macros['nvcc']['single'] = [('FP_PRECISION', 'float'),
('NVCC', None),
('CCACHE_CC', 'nvcc')]
macros['gcc']['double'] = [('FP_PRECISION', 'double'),
('GCC', None)]
macros['mpicc']['double'] = [('FP_PRECISION', 'double'),
('MPICC', None)]
macros['clang']['double'] = [('FP_PRECISION', 'double'),
('CLANG', None)]
macros['icpc']['double'] = [('FP_PRECISION', 'double'),
('ICPC', None),
('MKL_ILP64', None)]
macros['bgxlc']['double'] = [('FP_PRECISION', 'double'),
('BGXLC', None),
('CCACHE_CC', 'bgxlc++_r')]
macros['nvcc']['double'] = [('FP_PRECISION', 'double'),
('CCACHE_CC', 'nvcc')]
# add flags for vector size and alignment for SIMD vectorization
for compiler in macros:
for precision in macros[compiler]:
macros[compiler][precision].append(('VEC_ALIGNMENT',
vector_alignment))
macros[compiler]['single'].append(('VEC_LENGTH', vector_length))
macros[compiler]['double'].append(('VEC_LENGTH', vector_length//2))
# set extra flag for determining precision
for compiler in macros:
for precision in macros[compiler]:
if precision == 'single':
macros[compiler][precision].append(('SINGLE', None))
# define OPENMP and SWIG (for log output)
for compiler in macros:
for precision in macros[compiler]:
macros[compiler][precision].append(('OPENMP', None))
macros[compiler][precision].append(('SWIG', None))
if compiler == 'mpicc':
macros[compiler][precision].append(('MPIx', None))
# set CMFD precision and linear algebra solver tolerance
for compiler in macros:
macros[compiler]['single'].append(('CMFD_PRECISION', 'float'))
macros[compiler]['single'].append(('LINALG_TOL', 1E-7))
macros[compiler]['double'].append(('CMFD_PRECISION', 'double'))
macros[compiler]['double'].append(('LINALG_TOL', 1E-15))
def setup_extension_modules(self):
"""Sets up the C/C++/CUDA extension modules for this distribution.
Create list of extensions for Python modules within the openmoc
Python package based on the user-defined flags defined at compile time.
"""
# If user wishes to specify number of groups at compile time
if self.num_groups:
for k in self.compiler_flags:
self.compiler_flags[k].append('-DNGROUPS=' +
str(self.num_groups))
# If the user wishes to compile using debug mode, append the debugging
# flag to all lists of compiler flags for all distribution types
if self.debug_mode:
for k in self.compiler_flags:
self.compiler_flags[k].append('-g')
# As of September 2019, nvcc does not support this flag:
if k != 'nvcc':
self.compiler_flags[k].append('-fno-omit-frame-pointer')
ind = [i for i, item in enumerate(self.compiler_flags[k]) \
if item.startswith('-O')]
self.compiler_flags[k][ind[0]] = '-O0'
# If the user wishes to compile using the address sanitizer, append
# flag to all lists of compiler flags for all distribution types
if self.sanitizer_mode:
for k in self.compiler_flags:
self.compiler_flags[k].append('-fsanitize=address')
# If the user wishes to compile using profile mode, append the profiling
# flag to all lists of compiler flags for all distribution types
if self.profile_mode:
for k in self.compiler_flags:
self.compiler_flags[k].append('-pg')
self.compiler_flags[k].append('-g')
# If the user wishes to compile using coverage mode, append the coverage
# flag to all lists of compiler flags for all distribution types
if self.coverage_mode:
for k in self.compiler_flags:
self.compiler_flags[k].append('-fprofile-arcs')
self.compiler_flags[k].append('-ftest-coverage')
self.linker_flags[k].append('-fprofile-arcs')
self.linker_flags[k].append('-ftest-coverage')
# Obtain the NumPy include directory
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
# Add the NumPy include directory to the include directories
# list for each type of compiler
for cc in self.include_directories.keys():
self.include_directories[cc].append(numpy_include)
# Add the mpi4py module directory
try:
import mpi4py
mpi4py_include = mpi4py.__file__.split("__")[0]+"include"
except:
mpi4py_include = ''
self.include_directories['mpicc'].append(mpi4py_include)
# The main openmoc extension (defaults are gcc and single precision)
self.swig_flags += ['-D' + self.fp.upper()]
if self.fp == 'double':
self.swig_flags += ['-DFP_PRECISION=double']
else:
self.swig_flags += ['-DFP_PRECISION=float']
if self.cc == 'mpicc':
self.swig_flags += ['-DMPIx']
self.extensions.append(
Extension(name = '_openmoc',
sources = copy.deepcopy(self.sources[self.cc]),
library_dirs = self.library_directories[self.cc],
libraries = self.shared_libraries[self.cc],
extra_link_args = self.linker_flags[self.cc],
include_dirs = self.include_directories[self.cc],
define_macros = self.macros[self.cc][self.fp],
swig_opts = self.swig_flags + ['-D' + self.cc.upper()]))
# The openmoc.cuda extension if requested by the user at compile
# time (--with-cuda)
if self.with_cuda:
self.extensions.append(
Extension(name = '_openmoc_cuda',
sources = copy.deepcopy(self.sources['nvcc']),
library_dirs = self.library_directories['nvcc'],
libraries = self.shared_libraries['nvcc'],
extra_link_args = self.linker_flags['nvcc'],
include_dirs = self.include_directories['nvcc'],
define_macros = self.macros['nvcc'][self.fp],
swig_opts = self.swig_flags + ['-DNVCC'],
export_symbols = ['init_openmoc']))