Skip to content

Commit 7bf025e

Browse files
authored
petsc: refactor and add petsc4py support (#379406)
2 parents 23b9ffb + 120cb83 commit 7bf025e

File tree

4 files changed

+155
-68
lines changed

4 files changed

+155
-68
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/config/BuildSystem/config/packages/petsc4py.py b/config/BuildSystem/config/packages/petsc4py.py
2+
index 4a58243..831aa04 100644
3+
--- a/config/BuildSystem/config/packages/petsc4py.py
4+
+++ b/config/BuildSystem/config/packages/petsc4py.py
5+
@@ -37,7 +37,7 @@ class Configure(config.package.Package):
6+
7+
def Install(self):
8+
import os
9+
- installLibPath = os.path.join(self.installDir, 'lib')
10+
+ installLibPath = os.path.join(self.installDir, 'lib', '@PYTHON_SITEPACKAGES@')
11+
if self.setCompilers.isDarwin(self.log):
12+
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'
13+
else:
14+
@@ -70,7 +70,7 @@ class Configure(config.package.Package):
15+
newdir += 'NUMPY_INCLUDE="'+numpy_include+'" '
16+
17+
self.addDefine('HAVE_PETSC4PY',1)
18+
- self.addDefine('PETSC4PY_INSTALL_PATH','"'+os.path.join(self.installdir.dir,'lib')+'"')
19+
+ self.addDefine('PETSC4PY_INSTALL_PATH','"'+installLibPath+'"')
20+
self.addMakeMacro('PETSC4PY','yes')
21+
self.addMakeRule('petsc4pybuild','', \
22+
['@echo "*** Building petsc4py ***"',\

pkgs/by-name/pe/petsc/package.nix

Lines changed: 126 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,52 @@
44
fetchzip,
55
cctools,
66
gfortran,
7+
replaceVars,
78
python3,
9+
python3Packages,
810
blas,
911
lapack,
10-
mpiSupport ? true,
12+
zlib, # propagated by p4est but required by petsc
1113
mpi, # generic mpi dependency
1214
mpiCheckPhaseHook,
13-
petsc-withp4est ? false,
14-
hdf5-support ? false,
15-
hdf5,
15+
16+
# Build options
17+
petsc-optimized ? true,
18+
petsc-scalar-type ? "real",
19+
petsc-precision ? "double",
20+
mpiSupport ? true,
21+
withPetsc4py ? false, # petsc python binding
22+
withFullDeps ? false, # full External libraries support
23+
24+
# External libraries options
25+
withHdf5 ? true,
26+
withMetis ? withFullDeps,
27+
withParmetis ? false, # parmetis is unfree and should be enabled manualy
28+
withPtscotch ? withFullDeps,
29+
withScalapack ? withFullDeps,
30+
withMumps ? withFullDeps,
31+
withP4est ? withFullDeps,
32+
33+
# External libraries
34+
hdf5-fortran-mpi,
1635
metis,
1736
parmetis,
18-
withParmetis ? false,
37+
scotch,
38+
scalapack,
39+
mumps_par,
1940
pkg-config,
2041
p4est,
21-
zlib, # propagated by p4est but required by petsc
22-
petsc-optimized ? false,
23-
petsc-scalar-type ? "real",
24-
petsc-precision ? "double",
2542
}:
2643

2744
# This version of PETSc does not support a non-MPI p4est build
28-
assert petsc-withp4est -> p4est.mpiSupport;
45+
assert withP4est -> (p4est.mpiSupport && mpiSupport);
46+
47+
# Package parmetis depend on metis and mpi support
48+
assert withParmetis -> (withMetis && mpiSupport);
49+
50+
assert withPtscotch -> mpiSupport;
51+
assert withScalapack -> mpiSupport;
52+
assert withMumps -> withScalapack;
2953

3054
stdenv.mkDerivation rec {
3155
pname = "petsc";
@@ -37,59 +61,102 @@ stdenv.mkDerivation rec {
3761
};
3862

3963
strictDeps = true;
40-
nativeBuildInputs = [
41-
python3
42-
gfortran
43-
pkg-config
44-
] ++ lib.optional mpiSupport mpi;
45-
buildInputs = [
46-
blas
47-
lapack
48-
] ++ lib.optional hdf5-support hdf5 ++ lib.optional petsc-withp4est p4est ++ lib.optionals withParmetis [ metis parmetis ];
49-
50-
prePatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
51-
substituteInPlace config/install.py \
52-
--replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool
53-
'';
54-
55-
configureFlags = [
56-
"--with-blas=1"
57-
"--with-lapack=1"
58-
"--with-scalar-type=${petsc-scalar-type}"
59-
"--with-precision=${petsc-precision}"
60-
"--with-mpi=${if mpiSupport then "1" else "0"}"
61-
] ++ lib.optionals mpiSupport [
62-
"--CC=mpicc"
63-
"--with-cxx=mpicxx"
64-
"--with-fc=mpif90"
65-
] ++ lib.optionals (mpiSupport && withParmetis) [
66-
"--with-metis=1"
67-
"--with-metis-dir=${metis}"
68-
"--with-parmetis=1"
69-
"--with-parmetis-dir=${parmetis}"
70-
] ++ lib.optionals petsc-optimized [
71-
"--with-debugging=0"
72-
"COPTFLAGS=-O3"
73-
"FOPTFLAGS=-O3"
74-
"CXXOPTFLAGS=-O3"
75-
"CXXFLAGS=-O3"
64+
65+
nativeBuildInputs =
66+
[
67+
python3
68+
gfortran
69+
pkg-config
70+
]
71+
++ lib.optional mpiSupport mpi
72+
++ lib.optionals withPetsc4py [
73+
python3Packages.setuptools
74+
python3Packages.cython
75+
];
76+
77+
buildInputs =
78+
[
79+
blas
80+
lapack
81+
]
82+
++ lib.optional withHdf5 hdf5-fortran-mpi
83+
++ lib.optional withP4est p4est
84+
++ lib.optional withMetis metis
85+
++ lib.optional withParmetis parmetis
86+
++ lib.optional withPtscotch scotch
87+
++ lib.optional withScalapack scalapack
88+
++ lib.optional withMumps mumps_par;
89+
90+
propagatedBuildInputs = lib.optional withPetsc4py python3Packages.numpy;
91+
92+
patches = [
93+
(replaceVars ./fix-petsc4py-install-prefix.patch {
94+
PYTHON_SITEPACKAGES = python3.sitePackages;
95+
})
7696
];
77-
preConfigure = ''
78-
patchShebangs ./lib/petsc/bin
79-
'' + lib.optionalString petsc-withp4est ''
80-
configureFlagsArray+=(
97+
98+
postPatch =
99+
''
100+
patchShebangs ./lib/petsc/bin
101+
''
102+
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
103+
substituteInPlace config/install.py \
104+
--replace /usr/bin/install_name_tool ${cctools}/bin/install_name_tool
105+
'';
106+
107+
configureFlags =
108+
[
109+
"--with-blas=1"
110+
"--with-lapack=1"
111+
"--with-scalar-type=${petsc-scalar-type}"
112+
"--with-precision=${petsc-precision}"
113+
"--with-mpi=${if mpiSupport then "1" else "0"}"
114+
]
115+
++ lib.optional withPetsc4py "--with-petsc4py=1"
116+
++ lib.optionals mpiSupport [
117+
"--CC=mpicc"
118+
"--with-cxx=mpicxx"
119+
"--with-fc=mpif90"
120+
]
121+
++ lib.optionals withMetis [
122+
"--with-metis=1"
123+
"--with-metis-dir=${metis}"
124+
]
125+
++ lib.optionals withParmetis [
126+
"--with-parmetis=1"
127+
"--with-parmetis-dir=${parmetis}"
128+
]
129+
++ lib.optionals withPtscotch [
130+
"--with-ptscotch=1"
131+
"--with-ptscotch-include=${lib.getDev scotch}/include"
132+
"--with-ptscotch-lib=[-L${lib.getLib scotch}/lib,-lptscotch,-lptesmumps,-lptscotchparmetisv3,-lptscotcherr,-lesmumps,-lscotch,-lscotcherr]"
133+
]
134+
++ lib.optionals withScalapack [
135+
"--with-scalapack=1"
136+
"--with-scalapack-dir=${scalapack}"
137+
]
138+
++ lib.optionals withMumps [
139+
"--with-mumps=1"
140+
"--with-mumps-dir=${mumps_par}"
141+
]
142+
++ lib.optionals withP4est [
81143
"--with-p4est=1"
82-
"--with-zlib-include=${zlib.dev}/include"
83-
"--with-zlib-lib=-L${zlib}/lib -lz"
84-
)
85-
'' + lib.optionalString hdf5-support ''
86-
configureFlagsArray+=(
144+
"--with-zlib-include=${lib.getDev zlib}/include"
145+
"--with-zlib-lib=[-L${lib.getLib zlib}/lib,-lz]"
146+
]
147+
++ lib.optionals withHdf5 [
87148
"--with-hdf5=1"
88149
"--with-hdf5-fortran-bindings=1"
89-
"--with-hdf5-include=${hdf5.dev}/include"
90-
"--with-hdf5-lib=-L${hdf5}/lib -lhdf5"
91-
)
92-
'';
150+
"--with-hdf5-include=${lib.getDev hdf5-fortran-mpi}/include"
151+
"--with-hdf5-lib=[-L${lib.getLib hdf5-fortran-mpi}/lib,-lhdf5]"
152+
]
153+
++ lib.optionals petsc-optimized [
154+
"--with-debugging=0"
155+
"COPTFLAGS=-O3"
156+
"FOPTFLAGS=-O3"
157+
"CXXOPTFLAGS=-O3"
158+
"CXXFLAGS=-O3"
159+
];
93160

94161
hardeningDisable = lib.optionals (!petsc-optimized) [
95162
"fortify"

pkgs/top-level/all-packages.nix

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17025,15 +17025,6 @@ with pkgs;
1702517025

1702617026
### SCIENCE/PROGRAMMING
1702717027

17028-
### SCIENCE/GEOLOGY
17029-
pflotran = callPackage ../by-name/pf/pflotran/package.nix {
17030-
petsc = petsc.override {
17031-
hdf5-support = true;
17032-
hdf5 = hdf5-fortran-mpi;
17033-
petsc-optimized = true;
17034-
};
17035-
};
17036-
1703717028
### SCIENCE/LOGIC
1703817029

1703917030
abella = callPackage ../applications/science/logic/abella {

pkgs/top-level/python-packages.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10348,6 +10348,13 @@ self: super: with self; {
1034810348

1034910349
pesq = callPackage ../development/python-modules/pesq { };
1035010350

10351+
petsc4py = toPythonModule (pkgs.petsc.override {
10352+
python3 = python;
10353+
python3Packages = self;
10354+
withPetsc4py = true;
10355+
withFullDeps = true;
10356+
});
10357+
1035110358
pex = callPackage ../development/python-modules/pex { };
1035210359

1035310360
pexif = callPackage ../development/python-modules/pexif { };

0 commit comments

Comments
 (0)