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
3054stdenv . 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"
0 commit comments