2016-05-12 12:22:25 +08:00
|
|
|
##############################################################################
|
|
|
|
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
|
|
|
|
# Produced at the Lawrence Livermore National Laboratory.
|
|
|
|
#
|
|
|
|
# This file is part of Spack.
|
|
|
|
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
|
|
|
# LLNL-CODE-647188
|
|
|
|
#
|
|
|
|
# For details, see https://github.com/llnl/spack
|
|
|
|
# Please also see the LICENSE file for our notice and the LGPL.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License (as
|
|
|
|
# published by the Free Software Foundation) version 2.1, February 1999.
|
|
|
|
#
|
|
|
|
# This program 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 terms and
|
|
|
|
# conditions of the GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
##############################################################################
|
2016-09-27 01:38:02 +08:00
|
|
|
|
2016-03-09 21:36:37 +08:00
|
|
|
import os
|
2016-09-27 01:38:02 +08:00
|
|
|
import sys
|
2015-05-28 08:39:17 +08:00
|
|
|
from spack import *
|
|
|
|
|
2016-03-09 21:36:37 +08:00
|
|
|
|
2015-05-28 08:39:17 +08:00
|
|
|
class Petsc(Package):
|
2016-08-24 23:32:29 +08:00
|
|
|
"""PETSc is a suite of data structures and routines for the scalable
|
2016-06-16 00:32:42 +08:00
|
|
|
(parallel) solution of scientific applications modeled by partial
|
2016-08-31 05:28:55 +08:00
|
|
|
differential equations.
|
|
|
|
"""
|
2015-05-28 08:39:17 +08:00
|
|
|
|
|
|
|
homepage = "http://www.mcs.anl.gov/petsc/index.html"
|
2016-03-09 21:36:37 +08:00
|
|
|
url = "http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-3.5.3.tar.gz"
|
2015-05-28 08:39:17 +08:00
|
|
|
|
2016-11-29 23:28:09 +08:00
|
|
|
version('develop', git='https://bitbucket.org/petsc/petsc.git', tag='master')
|
2016-12-11 08:22:36 +08:00
|
|
|
version('for-pflotran-0.1.0', git='https://bitbucket.org/petsc/petsc.git',
|
|
|
|
commit='7943f4e1472fff9cf1fc630a1100136616e4970f')
|
2016-12-13 17:32:42 +08:00
|
|
|
|
2017-01-15 18:34:48 +08:00
|
|
|
version('3.7.5', 'f00f6e6a3bac39052350dd47194b58a3')
|
2016-10-14 23:25:22 +08:00
|
|
|
version('3.7.4', 'aaf94fa54ef83022c14091f10866eedf')
|
2016-06-14 21:56:21 +08:00
|
|
|
version('3.7.2', '50da49867ce7a49e7a0c1b37f4ec7b34')
|
|
|
|
version('3.6.4', '7632da2375a3df35b8891c9526dbdde7')
|
2016-03-09 21:36:37 +08:00
|
|
|
version('3.6.3', '91dd3522de5a5ef039ff8f50800db606')
|
2015-05-28 08:39:17 +08:00
|
|
|
version('3.5.3', 'd4fd2734661e89f18ac6014b5dd1ef2f')
|
|
|
|
version('3.5.2', 'ad170802b3b058b5deb9cd1f968e7e13')
|
|
|
|
version('3.5.1', 'a557e029711ebf425544e117ffa44d8f')
|
2016-03-10 02:55:50 +08:00
|
|
|
version('3.4.4', '7edbc68aa6d8d6a3295dd5f6c2f6979d')
|
2015-05-28 08:39:17 +08:00
|
|
|
|
2016-08-10 16:50:00 +08:00
|
|
|
variant('shared', default=True,
|
|
|
|
description='Enables the build of shared libraries')
|
2016-03-28 20:35:01 +08:00
|
|
|
variant('mpi', default=True, description='Activates MPI support')
|
2016-08-10 16:50:00 +08:00
|
|
|
variant('double', default=True,
|
|
|
|
description='Switches between single and double precision')
|
2016-03-28 20:35:01 +08:00
|
|
|
variant('complex', default=False, description='Build with complex numbers')
|
|
|
|
variant('debug', default=False, description='Compile in debug mode')
|
|
|
|
|
2016-08-10 16:50:00 +08:00
|
|
|
variant('metis', default=True,
|
|
|
|
description='Activates support for metis and parmetis')
|
|
|
|
variant('hdf5', default=True,
|
|
|
|
description='Activates support for HDF5 (only parallel)')
|
2016-03-28 20:35:01 +08:00
|
|
|
variant('boost', default=True, description='Activates support for Boost')
|
2016-08-10 16:50:00 +08:00
|
|
|
variant('hypre', default=True,
|
|
|
|
description='Activates support for Hypre (only parallel)')
|
|
|
|
variant('mumps', default=True,
|
|
|
|
description='Activates support for MUMPS (only parallel)')
|
|
|
|
variant('superlu-dist', default=True,
|
|
|
|
description='Activates support for SuperluDist (only parallel)')
|
2016-03-09 21:36:37 +08:00
|
|
|
|
|
|
|
# Virtual dependencies
|
2016-11-29 23:28:09 +08:00
|
|
|
# Git repository needs sowing to build Fortran interface
|
|
|
|
depends_on('sowing', when='@develop')
|
2016-12-10 00:43:38 +08:00
|
|
|
|
2016-03-09 21:36:37 +08:00
|
|
|
depends_on('blas')
|
|
|
|
depends_on('lapack')
|
|
|
|
depends_on('mpi', when='+mpi')
|
2016-01-09 11:24:42 +08:00
|
|
|
|
2016-03-10 02:55:50 +08:00
|
|
|
# Build dependencies
|
2016-12-13 17:32:42 +08:00
|
|
|
depends_on('python @2.6:2.7', type='build')
|
2016-03-10 02:55:50 +08:00
|
|
|
|
2016-03-09 21:36:37 +08:00
|
|
|
# Other dependencies
|
2016-10-18 23:09:18 +08:00
|
|
|
depends_on('boost', when='@:3.5+boost')
|
2016-04-06 10:00:28 +08:00
|
|
|
depends_on('metis@5:', when='+metis')
|
2016-03-09 21:36:37 +08:00
|
|
|
|
2016-03-10 02:55:50 +08:00
|
|
|
depends_on('hdf5+mpi', when='+hdf5+mpi')
|
2016-03-09 21:36:37 +08:00
|
|
|
depends_on('parmetis', when='+metis+mpi')
|
2016-03-28 23:49:20 +08:00
|
|
|
# Hypre does not support complex numbers.
|
2016-06-16 00:32:42 +08:00
|
|
|
# Also PETSc prefer to build it without internal superlu, likely due to
|
|
|
|
# conflict in headers see
|
2016-08-11 05:05:59 +08:00
|
|
|
# https://bitbucket.org/petsc/petsc/src/90564b43f6b05485163c147b464b5d6d28cde3ef/config/BuildSystem/config/packages/hypre.py
|
2016-03-28 23:49:20 +08:00
|
|
|
depends_on('hypre~internal-superlu', when='+hypre+mpi~complex')
|
2016-12-11 08:22:36 +08:00
|
|
|
depends_on('superlu-dist@:4.3', when='@3.4.4:3.6.4+superlu-dist+mpi')
|
2016-06-14 21:56:21 +08:00
|
|
|
depends_on('superlu-dist@5.0.0:', when='@3.7:+superlu-dist+mpi')
|
2016-12-13 17:32:42 +08:00
|
|
|
depends_on('superlu-dist@5.0.0:', when='@for-pflotran-0.1.0+superlu-dist+mpi')
|
2016-03-28 20:35:01 +08:00
|
|
|
depends_on('mumps+mpi', when='+mumps+mpi')
|
|
|
|
depends_on('scalapack', when='+mumps+mpi')
|
2016-03-09 21:36:37 +08:00
|
|
|
|
|
|
|
def mpi_dependent_options(self):
|
|
|
|
if '~mpi' in self.spec:
|
|
|
|
compiler_opts = [
|
|
|
|
'--with-cc=%s' % os.environ['CC'],
|
2016-08-11 05:05:59 +08:00
|
|
|
'--with-cxx=%s' % (os.environ['CXX']
|
|
|
|
if self.compiler.cxx is not None else '0'),
|
|
|
|
'--with-fc=%s' % (os.environ['FC']
|
|
|
|
if self.compiler.fc is not None else '0'),
|
2016-03-09 21:36:37 +08:00
|
|
|
'--with-mpi=0'
|
|
|
|
]
|
2016-08-11 05:05:59 +08:00
|
|
|
error_message_fmt = \
|
|
|
|
'\t{library} support requires "+mpi" to be activated'
|
2016-03-10 03:26:37 +08:00
|
|
|
|
2016-06-16 00:32:42 +08:00
|
|
|
# If mpi is disabled (~mpi), it's an error to have any of these
|
|
|
|
# enabled. This generates a list of any such errors.
|
2016-08-11 05:05:59 +08:00
|
|
|
errors = [
|
|
|
|
error_message_fmt.format(library=x)
|
|
|
|
for x in ('hdf5', 'hypre', 'parmetis', 'mumps', 'superlu-dist')
|
|
|
|
if ('+' + x) in self.spec]
|
2016-03-09 21:36:37 +08:00
|
|
|
if errors:
|
|
|
|
errors = ['incompatible variants given'] + errors
|
|
|
|
raise RuntimeError('\n'.join(errors))
|
|
|
|
else:
|
2016-03-31 01:26:03 +08:00
|
|
|
compiler_opts = [
|
|
|
|
'--with-mpi=1',
|
|
|
|
'--with-mpi-dir=%s' % self.spec['mpi'].prefix,
|
|
|
|
]
|
2016-09-27 01:38:02 +08:00
|
|
|
if sys.platform != "darwin":
|
|
|
|
compiler_opts.extend([
|
|
|
|
'--with-cpp=cpp',
|
|
|
|
'--with-cxxcpp=cpp',
|
|
|
|
])
|
2016-03-09 21:36:37 +08:00
|
|
|
return compiler_opts
|
2015-05-28 08:39:17 +08:00
|
|
|
|
|
|
|
def install(self, spec, prefix):
|
2016-10-18 23:09:18 +08:00
|
|
|
options = ['--with-ssl=0',
|
2016-12-10 00:43:38 +08:00
|
|
|
'--with-x=0',
|
2016-10-18 23:09:18 +08:00
|
|
|
'--download-c2html=0',
|
2016-12-10 00:43:38 +08:00
|
|
|
'--download-sowing=0',
|
2016-10-18 23:09:18 +08:00
|
|
|
'--download-hwloc=0']
|
2016-03-09 21:36:37 +08:00
|
|
|
options.extend(self.mpi_dependent_options())
|
|
|
|
options.extend([
|
2016-08-11 05:05:59 +08:00
|
|
|
'--with-precision=%s' % (
|
|
|
|
'double' if '+double' in spec else 'single'),
|
|
|
|
'--with-scalar-type=%s' % (
|
|
|
|
'complex' if '+complex' in spec else 'real'),
|
2016-03-09 21:36:37 +08:00
|
|
|
'--with-shared-libraries=%s' % ('1' if '+shared' in spec else '0'),
|
2016-09-27 01:37:23 +08:00
|
|
|
'--with-debugging=%s' % ('1' if '+debug' in spec else '0')
|
2016-03-09 21:36:37 +08:00
|
|
|
])
|
2016-09-27 01:37:23 +08:00
|
|
|
# Make sure we use exactly the same Blas/Lapack libraries
|
|
|
|
# across the DAG. To that end list them explicitly
|
|
|
|
lapack_blas = spec['lapack'].lapack_libs + spec['blas'].blas_libs
|
|
|
|
options.extend([
|
|
|
|
'--with-blas-lapack-lib=%s' % lapack_blas.joined()
|
|
|
|
])
|
|
|
|
|
2016-03-09 21:36:37 +08:00
|
|
|
# Activates library support if needed
|
2016-06-16 00:32:42 +08:00
|
|
|
for library in ('metis', 'boost', 'hdf5', 'hypre', 'parmetis',
|
|
|
|
'mumps', 'scalapack'):
|
2016-03-09 21:36:37 +08:00
|
|
|
options.append(
|
2016-08-11 05:05:59 +08:00
|
|
|
'--with-{library}={value}'.format(
|
|
|
|
library=library, value=('1' if library in spec else '0'))
|
2016-03-09 21:36:37 +08:00
|
|
|
)
|
|
|
|
if library in spec:
|
|
|
|
options.append(
|
2016-08-11 05:05:59 +08:00
|
|
|
'--with-{library}-dir={path}'.format(
|
|
|
|
library=library, path=spec[library].prefix)
|
2016-03-09 21:36:37 +08:00
|
|
|
)
|
2016-06-16 00:32:42 +08:00
|
|
|
# PETSc does not pick up SuperluDist from the dir as they look for
|
|
|
|
# superlu_dist_4.1.a
|
2016-03-28 23:49:20 +08:00
|
|
|
if 'superlu-dist' in spec:
|
|
|
|
options.extend([
|
2016-06-16 00:32:42 +08:00
|
|
|
'--with-superlu_dist-include=%s' %
|
|
|
|
spec['superlu-dist'].prefix.include,
|
|
|
|
'--with-superlu_dist-lib=%s' %
|
|
|
|
join_path(spec['superlu-dist'].prefix.lib,
|
|
|
|
'libsuperlu_dist.a'),
|
2016-03-28 23:49:20 +08:00
|
|
|
'--with-superlu_dist=1'
|
|
|
|
])
|
|
|
|
else:
|
|
|
|
options.append(
|
|
|
|
'--with-superlu_dist=0'
|
|
|
|
)
|
2016-03-09 21:36:37 +08:00
|
|
|
|
|
|
|
configure('--prefix=%s' % prefix, *options)
|
2016-03-10 02:55:50 +08:00
|
|
|
|
2015-06-07 08:41:15 +08:00
|
|
|
# PETSc has its own way of doing parallel make.
|
|
|
|
make('MAKE_NP=%s' % make_jobs, parallel=False)
|
2015-05-28 08:39:17 +08:00
|
|
|
make("install")
|
2016-03-22 18:44:38 +08:00
|
|
|
|
2016-06-30 06:19:50 +08:00
|
|
|
# solve Poisson equation in 2D to make sure nothing is broken:
|
2016-07-07 04:45:43 +08:00
|
|
|
if ('mpi' in spec) and self.run_tests:
|
|
|
|
with working_dir('src/ksp/ksp/examples/tutorials'):
|
|
|
|
env['PETSC_DIR'] = self.prefix
|
|
|
|
cc = Executable(spec['mpi'].mpicc)
|
|
|
|
cc('ex50.c', '-I%s' % prefix.include, '-L%s' % prefix.lib,
|
2016-07-09 14:12:34 +08:00
|
|
|
'-lpetsc', '-lm', '-o', 'ex50')
|
2016-07-07 04:45:43 +08:00
|
|
|
run = Executable(join_path(spec['mpi'].prefix.bin, 'mpirun'))
|
|
|
|
run('ex50', '-da_grid_x', '4', '-da_grid_y', '4')
|
|
|
|
if 'superlu-dist' in spec:
|
2016-08-11 05:05:59 +08:00
|
|
|
run('ex50',
|
|
|
|
'-da_grid_x', '4',
|
|
|
|
'-da_grid_y', '4',
|
|
|
|
'-pc_type', 'lu',
|
|
|
|
'-pc_factor_mat_solver_package', 'superlu_dist')
|
2016-07-07 04:45:43 +08:00
|
|
|
|
|
|
|
if 'mumps' in spec:
|
2016-08-11 05:05:59 +08:00
|
|
|
run('ex50',
|
|
|
|
'-da_grid_x', '4',
|
|
|
|
'-da_grid_y', '4',
|
|
|
|
'-pc_type', 'lu',
|
|
|
|
'-pc_factor_mat_solver_package', 'mumps')
|
2016-07-07 04:45:43 +08:00
|
|
|
|
|
|
|
if 'hypre' in spec:
|
2016-08-11 05:05:59 +08:00
|
|
|
run('ex50',
|
|
|
|
'-da_grid_x', '4',
|
|
|
|
'-da_grid_y', '4',
|
|
|
|
'-pc_type', 'hypre',
|
|
|
|
'-pc_hypre_type', 'boomeramg')
|
2016-06-30 06:19:50 +08:00
|
|
|
|
2017-01-08 09:38:53 +08:00
|
|
|
def setup_environment(self, spack_env, run_env):
|
|
|
|
# configure fails if these env vars are set outside of Spack
|
|
|
|
spack_env.unset('PETSC_DIR')
|
|
|
|
spack_env.unset('PETSC_ARCH')
|
|
|
|
|
|
|
|
# Set PETSC_DIR in the module file
|
|
|
|
run_env.set('PETSC_DIR', self.prefix)
|
|
|
|
run_env.unset('PETSC_ARCH')
|
|
|
|
|
2016-03-22 18:44:38 +08:00
|
|
|
def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
|
2017-01-08 09:38:53 +08:00
|
|
|
# Set up PETSC_DIR for everyone using PETSc package
|
2016-03-22 18:44:38 +08:00
|
|
|
spack_env.set('PETSC_DIR', self.prefix)
|
2017-01-08 09:38:53 +08:00
|
|
|
spack_env.unset('PETSC_ARCH')
|