<commit_before>##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by <NAME>, <EMAIL>, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files 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 inspect
import os.path
import shutil

from spack import *


class Pexsi(MakefilePackage):
    """The PEXSI library is written in C++, and uses message passing interface
    (MPI) to parallelize the computation on distributed memory computing
    systems and achieve scalability on more than 10,000 processors.

    The Pole EXpansion and Selected Inversion (PEXSI) method is a fast
    method for electronic structure calculation based on Kohn-Sham density
    functional theory. It efficiently evaluates certain selected elements
    of matrix functions, e.g., the Fermi-Dirac function of the KS Hamiltonian,
    which yields a density matrix. It can be used as an alternative to
    diagonalization methods for obtaining the density, energy and forces
    in electronic structure calculations.
    """
    homepage = 'https://math.berkeley.edu/~linlin/pexsi/index.html'
    url = 'https://math.berkeley.edu/~linlin/pexsi/download/pexsi_v0.9.0.tar.gz'

    # version('1.0', '4600b03e235935fe623acf500df0edfa')
    version('0.10.2', '012f6800098671ec39c2ed7b38935e27')
    version('0.9.2', '0ce491a3a922d271c4edf9b20aa93076')
    version('0.9.0', '0c1a2de891ba1445dfc184b2fa270ed8')

    depends_on('parmetis')
    depends_on('superlu-dist@3.3:3.999', when='@:0.9.0')
    depends_on('superlu-dist@4.3:4.999', when='@0.9.2')
    depends_on('superlu-dist@5.1.2:', when='@0.10.2:')

    variant(
        'fortran', default=False, description='Builds the Fortran interface'
    )

    parallel = False

    def edit(self, spec, prefix):

        substitutions = {
            '@MPICC': self.spec['mpi'].mpicc,
            '@MPICXX': self.spec['mpi'].mpicxx,
            '@MPIFC': self.spec['mpi'].mpifc,
            '@MPICXX_LIB': self.spec['mpi:cxx'].libs.joined(),
            '@RANLIB': 'ranlib',
            '@PEXSI_STAGE': self.stage.source_path,
            '@SUPERLU_PREFIX': self.spec['superlu-dist'].prefix,
            '@METIS_PREFIX': self.spec['metis'].prefix,
            '@PARMETIS_PREFIX': self.spec['parmetis'].prefix,
            '@LAPACK_PREFIX': self.spec['lapack'].prefix,
            '@BLAS_PREFIX': self.spec['blas'].prefix,
            '@LAPACK_LIBS': self.spec['lapack'].libs.joined(),
            '@BLAS_LIBS': self.spec['blas'].libs.joined(),
            # FIXME : what to do with compiler provided libraries ?
            '@STDCXX_LIB': ' '.join(self.compiler.stdcxx_libs),
            '@FLDFLAGS': ''
        }

        if '@0.9.2' in self.spec:
            substitutions['@FLDFLAGS'] = '-Wl,--allow-multiple-definition'

        template = join_path(
            os.path.dirname(inspect.getmodule(self).__file__),
            'make.inc'
        )
        makefile = join_path(
            self.stage.source_path,
            'make.inc'
        )
        shutil.copy(template, makefile)
        for key, value in substitutions.items():
            filter_file(key, value, makefile)
<commit_msg>Update and Bugfix for pexsi/package.py (#8822)<commit_after>##############################################################################
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by <NAME>, <EMAIL>, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files 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 inspect
import os.path
import shutil

from spack import *


class Pexsi(MakefilePackage):
    """The PEXSI library is written in C++, and uses message passing interface
    (MPI) to parallelize the computation on distributed memory computing
    systems and achieve scalability on more than 10,000 processors.

    The Pole EXpansion and Selected Inversion (PEXSI) method is a fast
    method for electronic structure calculation based on Kohn-Sham density
    functional theory. It efficiently evaluates certain selected elements
    of matrix functions, e.g., the Fermi-Dirac function of the KS Hamiltonian,
    which yields a density matrix. It can be used as an alternative to
    diagonalization methods for obtaining the density, energy and forces
    in electronic structure calculations.
    """
    homepage = 'https://math.berkeley.edu/~linlin/pexsi/index.html'
    url = 'https://math.berkeley.edu/~linlin/pexsi/download/pexsi_v0.9.0.tar.gz'

    # version('1.0', '4600b03e235935fe623acf500df0edfa')
    version('0.10.2', '012f6800098671ec39c2ed7b38935e27')
    version('0.9.2', '0ce491a3a922d271c4edf9b20aa93076')
    version('0.9.0', '0c1a2de891ba1445dfc184b2fa270ed8')

    depends_on('parmetis')
    depends_on('superlu-dist@3.3:3.999', when='@:0.9.0')
    depends_on('superlu-dist@4.3:4.999', when='@0.9.2')
    depends_on('superlu-dist@5.1.2:5.3.999', when='@0.10.2:')

    variant(
        'fortran', default=False, description='Builds the Fortran interface'
    )

    parallel = False

    def edit(self, spec, prefix):

        substitutions = [
            ('@MPICC', self.spec['mpi'].mpicc),
            ('@MPICXX_LIB', self.spec['mpi:cxx'].libs.joined()),
            ('@MPICXX', self.spec['mpi'].mpicxx),
            ('@MPIFC', self.spec['mpi'].mpifc),
            ('@RANLIB', 'ranlib'),
            ('@PEXSI_STAGE', self.stage.source_path),
            ('@SUPERLU_PREFIX', self.spec['superlu-dist'].prefix),
            ('@METIS_PREFIX', self.spec['metis'].prefix),
            ('@PARMETIS_PREFIX', self.spec['parmetis'].prefix),
            ('@LAPACK_PREFIX', self.spec['lapack'].prefix),
            ('@BLAS_PREFIX', self.spec['blas'].prefix),
            ('@LAPACK_LIBS', self.spec['lapack'].libs.joined()),
            ('@BLAS_LIBS', self.spec['blas'].libs.joined()),
            # FIXME : what to do with compiler provided libraries ?
            ('@STDCXX_LIB', ' '.join(self.compiler.stdcxx_libs))
        ]

        if '@0.9.2' in self.spec:
            substitutions.append(
                ('@FLDFLAGS', '-Wl,--allow-multiple-definition')
            )
        else:
            substitutions.append(
                ('@FLDFLAGS', '')
            )

        template = join_path(
            os.path.dirname(inspect.getmodule(self).__file__),
            'make.inc'
        )
        makefile = join_path(
            self.stage.source_path,
            'make.inc'
        )
        shutil.copy(template, makefile)
        for key, value in substitutions:
            filter_file(key, value, makefile)

{'fraction_non_alphanumeric': 0.1510901591043017, 'fraction_numerical': 0.03948143783146729, 'mean_word_length': 3.161844041196665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6195980', 'n_tokens_mistral': 2735, 'n_tokens_neox': 2509, 'n_words': 728}