Skip to content

Commit f01d1c4

Browse files
committed
petsc : added variants and logic to build various flavors
1 parent 31cebb9 commit f01d1c4

File tree

1 file changed

+69
-23
lines changed

1 file changed

+69
-23
lines changed
Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,86 @@
1+
import os
12
from spack import *
23

4+
35
class Petsc(Package):
4-
"""PETSc is a suite of data structures and routines for the
5-
scalable (parallel) solution of scientific applications modeled by
6-
partial differential equations."""
6+
"""
7+
PETSc is a suite of data structures and routines for the scalable (parallel) solution of scientific applications
8+
modeled by partial differential equations.
9+
"""
710

811
homepage = "http://www.mcs.anl.gov/petsc/index.html"
9-
url = "http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.5.3.tar.gz"
12+
url = "http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.5.3.tar.gz"
1013

14+
version('3.6.3', '91dd3522de5a5ef039ff8f50800db606')
1115
version('3.5.3', 'd4fd2734661e89f18ac6014b5dd1ef2f')
1216
version('3.5.2', 'ad170802b3b058b5deb9cd1f968e7e13')
1317
version('3.5.1', 'a557e029711ebf425544e117ffa44d8f')
1418

15-
depends_on("python @2.6:2.9") # requires Python for building
19+
variant('shared', default=True, description='Enables the build of shared libraries')
20+
variant('mpi', default=True, description='Activates MPI support')
21+
variant('double', default=True, description='Switches between single and double precision')
22+
23+
variant('metis', default=True, description='Activates support for metis and parmetis')
24+
variant('hdf5', default=True, description='Activates support for HDF5 (only parallel)')
25+
variant('boost', default=True, description='Activates support for Boost')
26+
variant('hypre', default=True, description='Activates support for Hypre')
27+
28+
# Build dependencies
29+
depends_on('python @2.6:2.9') # requires Python for building
30+
31+
# Virtual dependencies
32+
depends_on('blas')
33+
depends_on('lapack')
34+
depends_on('mpi', when='+mpi')
1635

17-
depends_on("boost")
18-
depends_on("blas")
19-
depends_on("lapack")
20-
depends_on("hypre")
21-
depends_on("parmetis")
22-
depends_on("metis")
23-
depends_on("hdf5+mpi")
24-
depends_on("mpi")
36+
# Other dependencies
37+
depends_on('boost', when='+boost')
38+
depends_on('metis', when='+metis')
39+
40+
depends_on('hdf5~cxx~unsupported+mpi', when='+hdf5+mpi')
41+
depends_on('parmetis', when='+metis+mpi')
42+
depends_on('hypre', when='+hypre+mpi')
43+
44+
def mpi_dependent_options(self):
45+
if '~mpi' in self.spec:
46+
compiler_opts = [
47+
'--with-cc=%s' % os.environ['CC'],
48+
'--with-cxx=%s' % (os.environ['CXX'] if self.compiler.cxx is not None else '0'),
49+
'--with-fc=%s' % (os.environ['FC'] if self.compiler.fc is not None else '0'),
50+
'--with-mpi=0'
51+
]
52+
error_message_fmt = '\t{library} support requires "+mpi" to be activated'
53+
errors = [error_message_fmt.format(library=x) for x in ('hdf5', 'hypre') if ('+'+x) in self.spec]
54+
if errors:
55+
errors = ['incompatible variants given'] + errors
56+
raise RuntimeError('\n'.join(errors))
57+
else:
58+
compiler_opts = [
59+
'--with-mpi=1',
60+
'--with-mpi-dir=%s' % self.spec['mpi'].prefix,
61+
]
62+
return compiler_opts
2563

2664
def install(self, spec, prefix):
27-
configure("--prefix=%s" % prefix,
28-
"--with-blas-lib=%s/libblas.a" % spec['blas'].prefix.lib,
29-
"--with-lapack-lib=%s/liblapack.a" % spec['lapack'].prefix.lib,
30-
"--with-boost-dir=%s" % spec['boost'].prefix,
31-
"--with-hypre-dir=%s" % spec['hypre'].prefix,
32-
"--with-parmetis-dir=%s" % spec['parmetis'].prefix,
33-
"--with-metis-dir=%s" % spec['metis'].prefix,
34-
"--with-hdf5-dir=%s" % spec['hdf5'].prefix,
35-
"--with-mpi-dir=%s" % spec['mpi'].prefix,
36-
"--with-shared-libraries=0")
65+
options = []
66+
options.extend(self.mpi_dependent_options())
67+
options.extend([
68+
'--with-precision=%s' % ('double' if '+double' in spec else 'single'),
69+
'--with-shared-libraries=%s' % ('1' if '+shared' in spec else '0'),
70+
'--with-blas-lapack-dir=%s' % spec['lapack'].prefix
71+
])
72+
# Activates library support if needed
73+
for library in ('metis', 'boost', 'hfd5', 'hypre', 'parmetis'):
74+
options.append(
75+
'--with-{library}={value}'.format(library=library, value=('1' if library in spec else '0'))
76+
)
77+
if library in spec:
78+
options.append(
79+
'--with-{library}-dir={path}'.format(library=library, path=spec[library].prefix)
80+
)
81+
3782

83+
configure('--prefix=%s' % prefix, *options)
3884
# PETSc has its own way of doing parallel make.
3985
make('MAKE_NP=%s' % make_jobs, parallel=False)
4086
make("install")

0 commit comments

Comments
 (0)