petsc: refactor and add petsc4py support (#379406)

Changed files
+153 -66
pkgs
+22
pkgs/by-name/pe/petsc/fix-petsc4py-install-prefix.patch
···
+
diff --git a/config/BuildSystem/config/packages/petsc4py.py b/config/BuildSystem/config/packages/petsc4py.py
+
index 4a58243..831aa04 100644
+
--- a/config/BuildSystem/config/packages/petsc4py.py
+
+++ b/config/BuildSystem/config/packages/petsc4py.py
+
@@ -37,7 +37,7 @@ class Configure(config.package.Package):
+
+
def Install(self):
+
import os
+
- installLibPath = os.path.join(self.installDir, 'lib')
+
+ installLibPath = os.path.join(self.installDir, 'lib', '@PYTHON_SITEPACKAGES@')
+
if self.setCompilers.isDarwin(self.log):
+
apple = 'You may need to\n (csh/tcsh) setenv MACOSX_DEPLOYMENT_TARGET 10.X\n (sh/bash) MACOSX_DEPLOYMENT_TARGET=10.X; export MACOSX_DEPLOYMENT_TARGET\nbefore running make on PETSc'
+
else:
+
@@ -70,7 +70,7 @@ class Configure(config.package.Package):
+
newdir += 'NUMPY_INCLUDE="'+numpy_include+'" '
+
+
self.addDefine('HAVE_PETSC4PY',1)
+
- self.addDefine('PETSC4PY_INSTALL_PATH','"'+os.path.join(self.installdir.dir,'lib')+'"')
+
+ self.addDefine('PETSC4PY_INSTALL_PATH','"'+installLibPath+'"')
+
self.addMakeMacro('PETSC4PY','yes')
+
self.addMakeRule('petsc4pybuild','', \
+
['@echo "*** Building petsc4py ***"',\
+124 -57
pkgs/by-name/pe/petsc/package.nix
···
fetchzip,
cctools,
gfortran,
+
replaceVars,
python3,
+
python3Packages,
blas,
lapack,
-
mpiSupport ? true,
+
zlib, # propagated by p4est but required by petsc
mpi, # generic mpi dependency
mpiCheckPhaseHook,
-
petsc-withp4est ? false,
-
hdf5-support ? false,
-
hdf5,
+
+
# Build options
+
petsc-optimized ? true,
+
petsc-scalar-type ? "real",
+
petsc-precision ? "double",
+
mpiSupport ? true,
+
withPetsc4py ? false, # petsc python binding
+
withFullDeps ? false, # full External libraries support
+
+
# External libraries options
+
withHdf5 ? true,
+
withMetis ? withFullDeps,
+
withParmetis ? false, # parmetis is unfree and should be enabled manualy
+
withPtscotch ? withFullDeps,
+
withScalapack ? withFullDeps,
+
withMumps ? withFullDeps,
+
withP4est ? withFullDeps,
+
+
# External libraries
+
hdf5-fortran-mpi,
metis,
parmetis,
-
withParmetis ? false,
+
scotch,
+
scalapack,
+
mumps_par,
pkg-config,
p4est,
-
zlib, # propagated by p4est but required by petsc
-
petsc-optimized ? false,
-
petsc-scalar-type ? "real",
-
petsc-precision ? "double",
}:
# This version of PETSc does not support a non-MPI p4est build
-
assert petsc-withp4est -> p4est.mpiSupport;
+
assert withP4est -> (p4est.mpiSupport && mpiSupport);
+
+
# Package parmetis depend on metis and mpi support
+
assert withParmetis -> (withMetis && mpiSupport);
+
+
assert withPtscotch -> mpiSupport;
+
assert withScalapack -> mpiSupport;
+
assert withMumps -> withScalapack;
stdenv.mkDerivation rec {
pname = "petsc";
···
};
strictDeps = true;
-
nativeBuildInputs = [
-
python3
-
gfortran
-
pkg-config
-
] ++ lib.optional mpiSupport mpi;
-
buildInputs = [
-
blas
-
lapack
-
] ++ lib.optional hdf5-support hdf5 ++ lib.optional petsc-withp4est p4est ++ lib.optionals withParmetis [ metis parmetis ];
+
+
nativeBuildInputs =
+
[
+
python3
+
gfortran
+
pkg-config
+
]
+
++ lib.optional mpiSupport mpi
+
++ lib.optionals withPetsc4py [
+
python3Packages.setuptools
+
python3Packages.cython
+
];
+
+
buildInputs =
+
[
+
blas
+
lapack
+
]
+
++ lib.optional withHdf5 hdf5-fortran-mpi
+
++ lib.optional withP4est p4est
+
++ lib.optional withMetis metis
+
++ lib.optional withParmetis parmetis
+
++ lib.optional withPtscotch scotch
+
++ lib.optional withScalapack scalapack
+
++ lib.optional withMumps mumps_par;
-
prePatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
-
substituteInPlace config/install.py \
-
--replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool
-
'';
+
propagatedBuildInputs = lib.optional withPetsc4py python3Packages.numpy;
-
configureFlags = [
-
"--with-blas=1"
-
"--with-lapack=1"
-
"--with-scalar-type=${petsc-scalar-type}"
-
"--with-precision=${petsc-precision}"
-
"--with-mpi=${if mpiSupport then "1" else "0"}"
-
] ++ lib.optionals mpiSupport [
-
"--CC=mpicc"
-
"--with-cxx=mpicxx"
-
"--with-fc=mpif90"
-
] ++ lib.optionals (mpiSupport && withParmetis) [
-
"--with-metis=1"
-
"--with-metis-dir=${metis}"
-
"--with-parmetis=1"
-
"--with-parmetis-dir=${parmetis}"
-
] ++ lib.optionals petsc-optimized [
-
"--with-debugging=0"
-
"COPTFLAGS=-O3"
-
"FOPTFLAGS=-O3"
-
"CXXOPTFLAGS=-O3"
-
"CXXFLAGS=-O3"
+
patches = [
+
(replaceVars ./fix-petsc4py-install-prefix.patch {
+
PYTHON_SITEPACKAGES = python3.sitePackages;
+
})
];
-
preConfigure = ''
-
patchShebangs ./lib/petsc/bin
-
'' + lib.optionalString petsc-withp4est ''
-
configureFlagsArray+=(
+
+
postPatch =
+
''
+
patchShebangs ./lib/petsc/bin
+
''
+
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
+
substituteInPlace config/install.py \
+
--replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool
+
'';
+
+
configureFlags =
+
[
+
"--with-blas=1"
+
"--with-lapack=1"
+
"--with-scalar-type=${petsc-scalar-type}"
+
"--with-precision=${petsc-precision}"
+
"--with-mpi=${if mpiSupport then "1" else "0"}"
+
]
+
++ lib.optional withPetsc4py "--with-petsc4py=1"
+
++ lib.optionals mpiSupport [
+
"--CC=mpicc"
+
"--with-cxx=mpicxx"
+
"--with-fc=mpif90"
+
]
+
++ lib.optionals withMetis [
+
"--with-metis=1"
+
"--with-metis-dir=${metis}"
+
]
+
++ lib.optionals withParmetis [
+
"--with-parmetis=1"
+
"--with-parmetis-dir=${parmetis}"
+
]
+
++ lib.optionals withPtscotch [
+
"--with-ptscotch=1"
+
"--with-ptscotch-include=${lib.getDev scotch}/include"
+
"--with-ptscotch-lib=[-L${lib.getLib scotch}/lib,-lptscotch,-lptesmumps,-lptscotchparmetisv3,-lptscotcherr,-lesmumps,-lscotch,-lscotcherr]"
+
]
+
++ lib.optionals withScalapack [
+
"--with-scalapack=1"
+
"--with-scalapack-dir=${scalapack}"
+
]
+
++ lib.optionals withMumps [
+
"--with-mumps=1"
+
"--with-mumps-dir=${mumps_par}"
+
]
+
++ lib.optionals withP4est [
"--with-p4est=1"
-
"--with-zlib-include=${zlib.dev}/include"
-
"--with-zlib-lib=-L${zlib}/lib -lz"
-
)
-
'' + lib.optionalString hdf5-support ''
-
configureFlagsArray+=(
+
"--with-zlib-include=${lib.getDev zlib}/include"
+
"--with-zlib-lib=[-L${lib.getLib zlib}/lib,-lz]"
+
]
+
++ lib.optionals withHdf5 [
"--with-hdf5=1"
"--with-hdf5-fortran-bindings=1"
-
"--with-hdf5-include=${hdf5.dev}/include"
-
"--with-hdf5-lib=-L${hdf5}/lib -lhdf5"
-
)
-
'';
+
"--with-hdf5-include=${lib.getDev hdf5-fortran-mpi}/include"
+
"--with-hdf5-lib=[-L${lib.getLib hdf5-fortran-mpi}/lib,-lhdf5]"
+
]
+
++ lib.optionals petsc-optimized [
+
"--with-debugging=0"
+
"COPTFLAGS=-O3"
+
"FOPTFLAGS=-O3"
+
"CXXOPTFLAGS=-O3"
+
"CXXFLAGS=-O3"
+
];
hardeningDisable = lib.optionals (!petsc-optimized) [
"fortify"
-9
pkgs/top-level/all-packages.nix
···
### SCIENCE/PROGRAMMING
-
### SCIENCE/GEOLOGY
-
pflotran = callPackage ../by-name/pf/pflotran/package.nix {
-
petsc = petsc.override {
-
hdf5-support = true;
-
hdf5 = hdf5-fortran-mpi;
-
petsc-optimized = true;
-
};
-
};
-
### SCIENCE/LOGIC
abella = callPackage ../applications/science/logic/abella {
+7
pkgs/top-level/python-packages.nix
···
pesq = callPackage ../development/python-modules/pesq { };
+
petsc4py = toPythonModule (pkgs.petsc.override {
+
python3 = python;
+
python3Packages = self;
+
withPetsc4py = true;
+
withFullDeps = true;
+
});
+
pex = callPackage ../development/python-modules/pex { };
pexif = callPackage ../development/python-modules/pexif { };