-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrilinos.py
311 lines (264 loc) · 14.9 KB
/
trilinos.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
##
# Copyright 2009-2021 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild 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 v2.
#
# EasyBuild 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 EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for Trilinos, implemented as an easyblock
@author: Kenneth Hoste (Ghent University)
"""
import os
import random
import re
from distutils.version import LooseVersion
import easybuild.tools.toolchain as toolchain
from easybuild.easyblocks.generic.cmakemake import CMakeMake
from easybuild.framework.easyconfig import CUSTOM
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_path
from easybuild.tools.filetools import mkdir, remove_dir, symlink
from easybuild.tools.modules import get_software_root
from easybuild.tools.py2vs3 import ascii_letters
from easybuild.tools.systemtools import get_shared_lib_ext
class EB_Trilinos(CMakeMake):
"""Support for building Trilinos."""
# see http://trilinos.sandia.gov/Trilinos10CMakeQuickstart.txt
@staticmethod
def extra_options():
"""Add extra config options specific to Trilinos."""
extra_vars = {
'shared_libs': [None, "Deprecated. Use build_shared_libs", CUSTOM],
'openmp': [True, "Enable OpenMP support", CUSTOM],
'all_exts': [True, "Enable all Trilinos packages", CUSTOM],
'skip_exts': [[], "List of Trilinos packages to skip", CUSTOM],
'verbose': [False, "Configure for verbose output", CUSTOM],
}
return CMakeMake.extra_options(extra_vars)
def __init__(self, *args, **kwargs):
"""Constructor of custom easyblock for Trilinos."""
super(EB_Trilinos, self).__init__(*args, **kwargs)
if self.cfg['shared_libs'] is not None:
self.log.deprecated("Use 'build_shared_libs' instead of 'shared_libs' easyconfig parameter", '5.0')
self.cfg['build_shared_libs'] = self.cfg['shared_libs']
def configure_step(self):
"""Set some extra environment variables before configuring."""
# enable verbose output if desired
if self.cfg['verbose']:
for x in ["CONFIGURE", "MAKEFILE"]:
self.cfg.update('configopts', "-DTrilinos_VERBOSE_%s:BOOL=ON" % x)
# compiler flags
cflags = [os.getenv('CFLAGS')]
cxxflags = [os.getenv('CXXFLAGS')]
fflags = [os.getenv('FFLAGS')]
ignore_cxx_seek_mpis = [toolchain.INTELMPI, toolchain.MPICH,
toolchain.MPICH2, toolchain.MVAPICH2] # @UndefinedVariable
ignore_cxx_seek_flag = "-DMPICH_IGNORE_CXX_SEEK"
if self.toolchain.mpi_family() in ignore_cxx_seek_mpis:
cflags.append(ignore_cxx_seek_flag)
cxxflags.append(ignore_cxx_seek_flag)
fflags.append(ignore_cxx_seek_flag)
self.cfg.update('configopts', '-DCMAKE_C_FLAGS="%s"' % ' '.join(cflags))
self.cfg.update('configopts', '-DCMAKE_CXX_FLAGS="%s"' % ' '.join(cxxflags))
self.cfg.update('configopts', '-DCMAKE_Fortran_FLAGS="%s"' % ' '.join(fflags))
# Make sure Tpetra/Kokkos Serial mode is enabled regardless of OpenMP
self.cfg.update('configopts', "-DKokkos_ENABLE_Serial:BOOL=ON")
self.cfg.update('configopts', "-DTpetra_INST_SERIAL:BOOL=ON")
# OpenMP
if self.cfg['openmp']:
self.cfg.update('configopts', "-DTrilinos_ENABLE_OpenMP:BOOL=ON")
self.cfg.update('configopts', "-DKokkos_ENABLE_OpenMP:BOOL=ON")
# MPI
if self.toolchain.options.get('usempi', None):
self.cfg.update('configopts', "-DTPL_ENABLE_MPI:BOOL=ON")
for root in self.toolchain.get_software_root(self.toolchain.MPI_MODULE_NAME or []):
self.cfg.update('configopts', "-DMPI_BASE_DIR:FILEPATH=%s" % root)
# enable full testing
self.cfg.update('configopts', "-DTrilinos_ENABLE_TESTS:BOOL=OFF")
self.cfg.update('configopts', "-DTrilinos_ENABLE_ALL_FORWARD_DEP_PACKAGES:BOOL=ON")
# Enable complex support
self.cfg.update('configopts', "-DTeuchos_ENABLE_COMPLEX=ON")
lib_re = re.compile("^lib(.*).a$")
# BLAS, LAPACK
for dep in ["BLAS", "LAPACK"]:
self.cfg.update('configopts', '-DTPL_ENABLE_%s:BOOL=ON' % dep)
libdirs = os.getenv('%s_LIB_DIR' % dep)
if self.toolchain.comp_family() == toolchain.GCC: # @UndefinedVariable
libdirs += ";%s/lib64" % get_software_root('GCC')
self.cfg.update('configopts', '-D%s_LIBRARY_DIRS="%s"' % (dep, libdirs))
if self.cfg['openmp']:
libs = os.getenv('%s_MT_STATIC_LIBS' % dep).split(',')
else:
libs = os.getenv('%s_STATIC_LIBS' % dep).split(',')
lib_names = ';'.join([lib_re.search(x).group(1) for x in libs])
if self.toolchain.comp_family() == toolchain.GCC: # @UndefinedVariable
# explicitely specify static lib!
lib_names += ";libgfortran.a"
self.cfg.update('configopts', '-D%s_LIBRARY_NAMES="%s"' % (dep, lib_names))
# MKL
if get_software_root('imkl') and LooseVersion(self.version) >= LooseVersion('12.12'):
self.cfg.update('configopts', "-DTPL_ENABLE_MKL:BOOL=ON")
self.cfg.update('configopts', '-DMKL_LIBRARY_DIRS:PATH="%s/lib/intel64"' % os.getenv('MKLROOT'))
self.cfg.update('configopts', '-DMKL_INCLUDE_DIRS:PATH="%s/include"' % os.getenv('MKLROOT'))
# UMFPACK is part of SuiteSparse
suitesparse = get_software_root('SuiteSparse')
if suitesparse:
self.cfg.update('configopts', "-DTPL_ENABLE_UMFPACK:BOOL=ON")
self.cfg.update('configopts', "-DTPL_ENABLE_Cholmod:BOOL=ON")
incdirs, libdirs, libnames = [], [], []
for lib in ["UMFPACK", "CHOLMOD", "COLAMD", "AMD", "CCOLAMD", "CAMD"]:
incdirs.append(os.path.join(suitesparse, lib, "Include"))
libdirs.append(os.path.join(suitesparse, lib, "Lib"))
libnames.append(lib.lower())
# add SuiteSparse config lib, it is in recent versions of suitesparse
libdirs.append(os.path.join(suitesparse, 'SuiteSparse_config'))
libnames.append('suitesparseconfig')
# because of "SuiteSparse_config.c:function SuiteSparse_tic: error: undefined reference to 'clock_gettime'"
libnames.append('rt')
# required to resolve METIS symbols in SuiteSparse's libcholmod.a
# doesn't need to be full location, probably because it can be found via $LIBRARY_PATH
# not easy to know whether it should come from METIS or ParMETIS...
# see https://answers.launchpad.net/dorsal/+question/223167
libnames.append('libmetis.a')
self.cfg.update('configopts', '-DUMFPACK_INCLUDE_DIRS:PATH="%s"' % ';'.join(incdirs))
self.cfg.update('configopts', '-DUMFPACK_LIBRARY_DIRS:PATH="%s"' % ';'.join(libdirs))
self.cfg.update('configopts', '-DUMFPACK_LIBRARY_NAMES:STRING="%s"' % ';'.join(libnames))
self.cfg.update('configopts', '-DCholmod_INCLUDE_DIRS:PATH="%s"' % ';'.join(incdirs))
self.cfg.update('configopts', '-DCholmod_LIBRARY_DIRS:PATH="%s"' % ';'.join(libdirs))
self.cfg.update('configopts', '-DCholmod_LIBRARY_NAMES:STRING="%s"' % ';'.join(libnames))
# BLACS
if get_software_root('BLACS'):
self.cfg.update('configopts', "-DTPL_ENABLE_BLACS:BOOL=ON")
self.cfg.update('configopts', '-DBLACS_INCLUDE_DIRS:PATH="%s"' % os.getenv('BLACS_INC_DIR'))
self.cfg.update('configopts', '-DBLACS_LIBRARY_DIRS:PATH="%s"' % os.getenv('BLACS_LIB_DIR'))
blacs_lib_names = os.getenv('BLACS_STATIC_LIBS').split(',')
blacs_lib_names = [lib_re.search(x).group(1) for x in blacs_lib_names]
self.cfg.update('configopts', '-DBLACS_LIBRARY_NAMES:STRING="%s"' % (';'.join(blacs_lib_names)))
# ScaLAPACK
if get_software_root('ScaLAPACK'):
self.cfg.update('configopts', "-DTPL_ENABLE_SCALAPACK:BOOL=ON")
self.cfg.update('configopts', '-DSCALAPACK_INCLUDE_DIRS:PATH="%s"' % os.getenv('SCALAPACK_INC_DIR'))
self.cfg.update('configopts', '-DSCALAPACK_LIBRARY_DIRS:PATH="%s;%s"' % (os.getenv('SCALAPACK_LIB_DIR'),
os.getenv('BLACS_LIB_DIR')))
# PETSc
petsc = get_software_root('PETSc')
if petsc:
self.cfg.update('configopts', "-DTPL_ENABLE_PETSC:BOOL=ON")
incdirs = [os.path.join(petsc, "include")]
self.cfg.update('configopts', '-DPETSC_INCLUDE_DIRS:PATH="%s"' % ';'.join(incdirs))
petsc_libdirs = [
os.path.join(petsc, "lib"),
os.path.join(suitesparse, "UMFPACK", "Lib"),
os.path.join(suitesparse, "CHOLMOD", "Lib"),
os.path.join(suitesparse, "COLAMD", "Lib"),
os.path.join(suitesparse, "AMD", "Lib"),
os.getenv('FFTW_LIB_DIR'),
os.path.join(get_software_root('ParMETIS'), "Lib")
]
self.cfg.update('configopts', '-DPETSC_LIBRARY_DIRS:PATH="%s"' % ';'.join(petsc_libdirs))
petsc_libnames = ["petsc", "umfpack", "cholmod", "colamd", "amd", "parmetis", "metis"]
petsc_libnames += [lib_re.search(x).group(1) for x in os.getenv('FFTW_STATIC_LIBS').split(',')]
self.cfg.update('configopts', '-DPETSC_LIBRARY_NAMES:STRING="%s"' % ';'.join(petsc_libnames))
# other Third-Party Libraries (TPLs)
deps = self.cfg.dependencies()
builddeps = [d['name'] for d in self.cfg.builddependencies()] + ["SuiteSparse"]
deps = [dep['name'] for dep in deps if not dep['name'] in builddeps]
for dep in deps:
deproot = get_software_root(dep)
if deproot:
depmap = {
'SCOTCH': 'Scotch',
'SuperLU_DIST': 'SuperLUDist',
'netCDF': 'Netcdf',
}
dep = depmap.get(dep, dep)
self.cfg.update('configopts', "-DTPL_ENABLE_%s:BOOL=ON" % dep)
incdir = os.path.join(deproot, "include")
self.cfg.update('configopts', '-D%s_INCLUDE_DIRS:PATH="%s"' % (dep, incdir))
libdir = os.path.join(deproot, "lib")
self.cfg.update('configopts', '-D%s_LIBRARY_DIRS:PATH="%s"' % (dep, libdir))
# extensions_step
if self.cfg['all_exts']:
self.cfg.update('configopts', "-DTrilinos_ENABLE_ALL_PACKAGES:BOOL=ON")
else:
for ext in self.cfg['exts_list']:
self.cfg.update('configopts', "-DTrilinos_ENABLE_%s=ON" % ext)
# packages to skip
skip_exts = self.cfg['skip_exts']
if skip_exts:
for ext in skip_exts:
self.cfg.update('configopts', "-DTrilinos_ENABLE_%s:BOOL=OFF" % ext)
# building in source dir not supported
# + if the build directory is a long path, problems like "Argument list too long" may occur
# cfr. https://github.com/trilinos/Trilinos/issues/2434
# so, try to create build directory with shorter path length to build in
salt = ''.join(random.choice(ascii_letters) for _ in range(5))
self.short_start_dir = os.path.join(build_path(), self.name + '-' + salt)
if os.path.exists(self.short_start_dir):
raise EasyBuildError("Short start directory %s for Trilinos already exists?!", self.short_start_dir)
self.log.info("Length of path to original start directory: %s", len(self.start_dir))
self.log.info("Short start directory: %s (length: %d)", self.short_start_dir, len(self.short_start_dir))
mkdir(self.short_start_dir)
short_src_dir = os.path.join(self.short_start_dir, 'src')
symlink(self.start_dir, short_src_dir)
short_build_dir = os.path.join(self.short_start_dir, 'obj')
obj_dir = os.path.join(self.builddir, 'obj')
mkdir(obj_dir)
symlink(obj_dir, short_build_dir)
# configure using cmake
super(EB_Trilinos, self).configure_step(srcdir=short_src_dir, builddir=short_build_dir)
def build_step(self):
"""Build with make (verbose logging enabled)."""
super(EB_Trilinos, self).build_step(verbose=True)
def sanity_check_step(self):
"""Custom sanity check for Trilinos."""
# selection of libraries
libs = ["Amesos", "Anasazi", "AztecOO", "Belos", "Epetra", "EpetraExt", "Galeri",
"Ifpack", "Intrepid", "Isorropia", "Kokkos",
"Komplex", "LOCA", "ML", "Moertel", "NOX",
"Pamgen", "PyTrilinos", "RTOp", "Rythmos", "Sacado", "Shards", "Stratimikos",
"Teko", "Teuchos", "Tpetra", "Triutils", "Zoltan"]
libs = [x for x in libs if x not in self.cfg['skip_exts']]
# Teuchos was refactored in 11.2
if LooseVersion(self.version) >= LooseVersion('11.2') and 'Teuchos' in libs:
libs.remove('Teuchos')
libs.extend(['teuchoscomm', 'teuchoscore', 'teuchosnumerics', 'teuchosparameterlist', 'teuchosremainder'])
# Kokkos was refactored in 12.x, check for libkokkoscore.a rather than libkokkos.a
if LooseVersion(self.version) >= LooseVersion('12') and 'Kokkos' in libs:
libs.remove('Kokkos')
libs.append('kokkoscore')
# libgaleri was split into libgaleri-epetra & libgaleri-xpetra
if LooseVersion(self.version) >= LooseVersion('12.6'):
libs.remove('Galeri')
libs.extend(['galeri-epetra', 'galeri-xpetra'])
# Get the library extension
if self.cfg['build_shared_libs']:
lib_ext = get_shared_lib_ext()
else:
lib_ext = 'a'
custom_paths = {
'files': [os.path.join('lib', 'lib%s.%s' % (x.lower(), lib_ext)) for x in libs],
'dirs': ['bin', 'include']
}
super(EB_Trilinos, self).sanity_check_step(custom_paths=custom_paths)
def cleanup_step(self):
"""Complete cleanup by also removing custom created short build directory."""
remove_dir(self.short_start_dir)