| 1 |
# Copyright Spack Project Developers. See COPYRIGHT file for details. |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: (Apache-2.0 OR MIT) |
| 4 |
|
| 5 |
from spack_repo.builtin.build_systems import cmake, makefile |
| 6 |
from spack_repo.builtin.build_systems.cmake import CMakePackage |
| 7 |
from spack_repo.builtin.build_systems.makefile import MakefilePackage |
| 8 |
|
| 9 |
from spack.package import * |
| 10 |
|
| 11 |
|
| 12 |
class Pexsi(MakefilePackage, CMakePackage): |
| 13 |
"""The PEXSI library is written in C++, and uses message passing interface |
| 14 |
(MPI) to parallelize the computation on distributed memory computing |
| 15 |
systems and achieve scalability on more than 10,000 processors. |
| 16 |
|
| 17 |
The Pole EXpansion and Selected Inversion (PEXSI) method is a fast |
| 18 |
method for electronic structure calculation based on Kohn-Sham density |
| 19 |
functional theory. It efficiently evaluates certain selected elements |
| 20 |
of matrix functions, e.g., the Fermi-Dirac function of the KS Hamiltonian, |
| 21 |
which yields a density matrix. It can be used as an alternative to |
| 22 |
diagonalization methods for obtaining the density, energy and forces |
| 23 |
in electronic structure calculations. |
| 24 |
""" |
| 25 |
|
| 26 |
homepage = "https://math.berkeley.edu/~linlin/pexsi/index.html" |
| 27 |
|
| 28 |
build_system( |
| 29 |
conditional("cmake", when="@1:"), conditional("makefile", when="@0"), default="cmake" |
| 30 |
) |
| 31 |
|
| 32 |
license("BSD-3-Clause-LBNL") |
| 33 |
|
| 34 |
version("2.0.0", sha256="c5c83c2931b2bd0c68a462a49eeec983e78b5aaa1f17dd0454de4e27b91ca11f") |
| 35 |
version("1.2.0", sha256="8bfad6ec6866c6a29e1cc87fb1c17a39809795e79ede98373c8ba9a3aaf820dd") |
| 36 |
version("0.10.2", sha256="8714c71b76542e096211b537a9cb1ffb2c28f53eea4f5a92f94cc1ca1e7b499f") |
| 37 |
version("0.9.0", sha256="e5efe0c129013392cdac3234e37f1f4fea641c139b1fbea47618b4b839d05029") |
| 38 |
|
| 39 |
patch("fujitsu-add-link-flags.patch", when="%fj") |
| 40 |
|
| 41 |
depends_on("c", type="build") # generated |
| 42 |
depends_on("cxx", type="build") # generated |
| 43 |
depends_on("fortran", type="build") # generated |
| 44 |
|
| 45 |
depends_on("parmetis") |
| 46 |
depends_on("[email protected]:5.3", when="@0.10.2:0") |
| 47 |
depends_on("superlu-dist@:6.1.0", when="@1") # Upper limit from CP2K toolchain |
| 48 |
depends_on("superlu-dist@7", when="@2") |
| 49 |
|
| 50 |
with when("build_system=cmake"): |
| 51 |
depends_on("[email protected]:", type="build") |
| 52 |
depends_on("[email protected]:", type="build", when="@2:") |
| 53 |
|
| 54 |
variant("openmp", default=False, description="Build with OpenMP support", when="@1.2") |
| 55 |
variant("fortran", default=False, description="Builds the Fortran interface") |
| 56 |
variant("pic", default=True, description="Compile position independent code (PIC)") |
| 57 |
|
| 58 |
def url_for_version(self, version): |
| 59 |
if version == Version("0"): |
| 60 |
return f"https://math.berkeley.edu/~linlin/pexsi/download/pexsi_v{version}.tar.gz" |
| 61 |
|
| 62 |
return f"https://bitbucket.org/berkeleylab/pexsi/downloads/pexsi_v{version}.tar.gz" |
| 63 |
|
| 64 |
|
| 65 |
class MakefileBuilder(makefile.MakefileBuilder): |
| 66 |
parallel = False |
| 67 |
|
| 68 |
def edit(self, pkg, spec, prefix): |
| 69 |
substitutions = [ |
| 70 |
("@MPICC", spec["mpi"].mpicc), |
| 71 |
("@MPICXX_LIB", spec["mpi:cxx"].libs.joined()), |
| 72 |
("@MPICXX", spec["mpi"].mpicxx), |
| 73 |
("@MPIFC", spec["mpi"].mpifc), |
| 74 |
("@RANLIB", "ranlib"), |
| 75 |
("@PEXSI_STAGE", pkg.stage.source_path), |
| 76 |
("@SUPERLU_PREFIX", spec["superlu-dist"].prefix), |
| 77 |
("@METIS_PREFIX", spec["metis"].prefix), |
| 78 |
("@PARMETIS_PREFIX", spec["parmetis"].prefix), |
| 79 |
("@LAPACK_PREFIX", spec["lapack"].prefix), |
| 80 |
("@BLAS_PREFIX", spec["blas"].prefix), |
| 81 |
("@LAPACK_LIBS", spec["lapack"].libs.joined()), |
| 82 |
("@BLAS_LIBS", spec["blas"].libs.joined()), |
| 83 |
# FIXME : what to do with compiler provided libraries ? |
| 84 |
("@STDCXX_LIB", " ".join(pkg.compiler.stdcxx_libs)), |
| 85 |
] |
| 86 |
|
| 87 |
fldflags = "" |
| 88 |
if "@0.9.2" in spec: |
| 89 |
fldflags += " -Wl,--allow-multiple-definition" |
| 90 |
|
| 91 |
if "^superlu +openmp" in spec or "^openblas threads=openmp" in spec: |
| 92 |
fldflags += " " + pkg.compiler.openmp_flag |
| 93 |
|
| 94 |
substitutions.append(("@FLDFLAGS", fldflags.lstrip())) |
| 95 |
|
| 96 |
template = join_path(os.path.dirname(__file__), "make.inc") |
| 97 |
makefile = join_path(pkg.stage.source_path, "make.inc") |
| 98 |
copy(template, makefile) |
| 99 |
for key, value in substitutions: |
| 100 |
filter_file(key, value, makefile) |
| 101 |
|
| 102 |
def build(self, pkg, spec, prefix): |
| 103 |
super().build(pkg, spec, prefix) |
| 104 |
if "+fortran" in spec: |
| 105 |
make("-C", "fortran") |
| 106 |
|
| 107 |
def install(self, pkg, spec, prefix): |
| 108 |
# 'make install' does not exist, despite what documentation says |
| 109 |
mkdirp(pkg.prefix.lib) |
| 110 |
|
| 111 |
install( |
| 112 |
join_path(pkg.stage.source_path, "src", "libpexsi_linux.a"), |
| 113 |
join_path(pkg.prefix.lib, "libpexsi.a"), |
| 114 |
) |
| 115 |
|
| 116 |
install_tree(join_path(pkg.stage.source_path, "include"), pkg.prefix.include) |
| 117 |
|
| 118 |
# fortran "interface" |
| 119 |
if "+fortran" in spec: |
| 120 |
install_tree( |
| 121 |
join_path(pkg.stage.source_path, "fortran"), join_path(pkg.prefix, "fortran") |
| 122 |
) |
| 123 |
|
| 124 |
|
| 125 |
class CMakeBuilder(cmake.CMakeBuilder): |
| 126 |
def cmake_args(self): |
| 127 |
args = [ |
| 128 |
self.define_from_variant("PEXSI_ENABLE_FORTRAN", "fortran"), |
| 129 |
self.define_from_variant("PEXSI_ENABLE_OPENMP ", "openmp"), |
| 130 |
self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"), |
| 131 |
] |
| 132 |
|
| 133 |
if self.spec.satisfies("%fj"): |
| 134 |
args.append(self.define("BLAS_LIBRARIES", self.spec["blas"].libs.link_flags)) |
| 135 |
|
| 136 |
return args |