summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/petsc/package.py
blob: 079e0b7af4ec85e9b867cb1ef86c308e3abe4d2b (plain) (blame)
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
##############################################################################
# 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
##############################################################################
import os
from spack import *


class Petsc(Package):
    """
    PETSc is a suite of data structures and routines for the scalable
    (parallel) solution of scientific applications modeled by partial
    differential equations.
    """

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

    version('3.7.2', '50da49867ce7a49e7a0c1b37f4ec7b34')
    version('3.6.4', '7632da2375a3df35b8891c9526dbdde7')
    version('3.6.3', '91dd3522de5a5ef039ff8f50800db606')
    version('3.5.3', 'd4fd2734661e89f18ac6014b5dd1ef2f')
    version('3.5.2', 'ad170802b3b058b5deb9cd1f968e7e13')
    version('3.5.1', 'a557e029711ebf425544e117ffa44d8f')
    version('3.4.4', '7edbc68aa6d8d6a3295dd5f6c2f6979d')

    variant('shared',  default=True,
            description='Enables the build of shared libraries')
    variant('mpi',     default=True,  description='Activates MPI support')
    variant('double',  default=True,
            description='Switches between single and double precision')
    variant('complex', default=False, description='Build with complex numbers')
    variant('debug',   default=False, description='Compile in debug mode')

    variant('metis',   default=True,
            description='Activates support for metis and parmetis')
    variant('hdf5',    default=True,
            description='Activates support for HDF5 (only parallel)')
    variant('boost',   default=True,  description='Activates support for Boost')
    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)')

    # Virtual dependencies
    depends_on('blas')
    depends_on('lapack')
    depends_on('mpi', when='+mpi')

    # Build dependencies
    depends_on('python @2.6:2.7')

    # Other dependencies
    depends_on('boost', when='+boost')
    depends_on('metis@5:', when='+metis')

    depends_on('hdf5+mpi', when='+hdf5+mpi')
    depends_on('parmetis', when='+metis+mpi')
    # Hypre does not support complex numbers.
    # Also PETSc prefer to build it without internal superlu, likely due to
    # conflict in headers see
    # https://bitbucket.org/petsc/petsc/src/90564b43f6b05485163c147b464b5d6d28cde3ef/config/BuildSystem/config/packages/hypre.py  # NOQA: ignore=E501
    depends_on('hypre~internal-superlu', when='+hypre+mpi~complex')
    depends_on('superlu-dist@:4.3', when='@:3.6.4+superlu-dist+mpi')
    depends_on('superlu-dist@5.0.0:', when='@3.7:+superlu-dist+mpi')
    depends_on('mumps+mpi', when='+mumps+mpi')
    depends_on('scalapack', when='+mumps+mpi')

    def mpi_dependent_options(self):
        if '~mpi' in self.spec:
            compiler_opts = [
                '--with-cc=%s' % os.environ['CC'],
                '--with-cxx=%s' % (os.environ['CXX'] if self.compiler.cxx is not None else '0'),  # NOQA: ignore=E501
                '--with-fc=%s' % (os.environ['FC'] if self.compiler.fc is not None else '0'),  # NOQA: ignore=E501
                '--with-mpi=0'
            ]
            error_message_fmt = '\t{library} support requires "+mpi" to be activated'  # NOQA: ignore=E501

            # If mpi is disabled (~mpi), it's an error to have any of these
            # enabled. This generates a list of any such errors.
            errors = [error_message_fmt.format(library=x)
                      for x in ('hdf5', 'hypre', 'parmetis', 'mumps', 'superlu-dist')  # NOQA: ignore=E501
                      if ('+' + x) in self.spec]
            if errors:
                errors = ['incompatible variants given'] + errors
                raise RuntimeError('\n'.join(errors))
        else:
            compiler_opts = [
                '--with-mpi=1',
                '--with-mpi-dir=%s' % self.spec['mpi'].prefix,
            ]
        return compiler_opts

    def install(self, spec, prefix):
        options = ['--with-ssl=0']
        options.extend(self.mpi_dependent_options())
        options.extend([
            '--with-precision=%s' % ('double' if '+double' in spec else 'single'),  # NOQA: ignore=E501
            '--with-scalar-type=%s' % ('complex' if '+complex' in spec else 'real'),  # NOQA: ignore=E501
            '--with-shared-libraries=%s' % ('1' if '+shared' in spec else '0'),
            '--with-debugging=%s' % ('1' if '+debug' in spec else '0'),
            '--with-blas-lapack-dir=%s' % spec['lapack'].prefix
        ])
        # Activates library support if needed
        for library in ('metis', 'boost', 'hdf5', 'hypre', 'parmetis',
                        'mumps', 'scalapack'):
            options.append(
                '--with-{library}={value}'.format(library=library, value=('1' if library in spec else '0'))  # NOQA: ignore=E501
            )
            if library in spec:
                options.append(
                    '--with-{library}-dir={path}'.format(library=library, path=spec[library].prefix)  # NOQA: ignore=E501
                )
        # PETSc does not pick up SuperluDist from the dir as they look for
        # superlu_dist_4.1.a
        if 'superlu-dist' in spec:
            options.extend([
                '--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'),
                '--with-superlu_dist=1'
            ])
        else:
            options.append(
                '--with-superlu_dist=0'
            )

        configure('--prefix=%s' % prefix, *options)

        # PETSc has its own way of doing parallel make.
        make('MAKE_NP=%s' % make_jobs, parallel=False)
        make("install")

        # solve Poisson equation in 2D to make sure nothing is broken:
        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,
                   '-lpetsc', '-lm', '-o', 'ex50')
                run = Executable(join_path(spec['mpi'].prefix.bin, 'mpirun'))
                run('ex50', '-da_grid_x', '4', '-da_grid_y', '4')
                if 'superlu-dist' in spec:
                    run('ex50', '-da_grid_x', '4', '-da_grid_y', '4', '-pc_type', 'lu', '-pc_factor_mat_solver_package', 'superlu_dist')  # NOQA: ignore=E501

                if 'mumps' in spec:
                    run('ex50', '-da_grid_x', '4', '-da_grid_y', '4', '-pc_type', 'lu', '-pc_factor_mat_solver_package', 'mumps')  # NOQA: ignore=E501

                if 'hypre' in spec:
                    run('ex50', '-da_grid_x', '4', '-da_grid_y', '4', '-pc_type', 'hypre', '-pc_hypre_type', 'boomeramg')  # NOQA: ignore=E501

    def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
        # set up PETSC_DIR for everyone using PETSc package
        spack_env.set('PETSC_DIR', self.prefix)