petsc: refactor and add petsc4py support (#379406)

authored by Markus Kowalewski and committed by GitHub 7bf025e6 23b9ffb1

+153 -66
+22
pkgs/by-name/pe/petsc/fix-petsc4py-install-prefix.patch
··· 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 ***"',\
+124 -57
pkgs/by-name/pe/petsc/package.nix
··· 4 4 fetchzip, 5 5 cctools, 6 6 gfortran, 7 + replaceVars, 7 8 python3, 9 + python3Packages, 8 10 blas, 9 11 lapack, 10 - mpiSupport ? true, 12 + zlib, # propagated by p4est but required by petsc 11 13 mpi, # generic mpi dependency 12 14 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, 16 35 metis, 17 36 parmetis, 18 - withParmetis ? false, 37 + scotch, 38 + scalapack, 39 + mumps_par, 19 40 pkg-config, 20 41 p4est, 21 - zlib, # propagated by p4est but required by petsc 22 - petsc-optimized ? false, 23 - petsc-scalar-type ? "real", 24 - petsc-precision ? "double", 25 42 }: 26 43 27 44 # 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; 29 53 30 54 stdenv.mkDerivation rec { 31 55 pname = "petsc"; ··· 37 61 }; 38 62 39 63 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 ]; 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; 49 89 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 - ''; 90 + propagatedBuildInputs = lib.optional withPetsc4py python3Packages.numpy; 54 91 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" 92 + patches = [ 93 + (replaceVars ./fix-petsc4py-install-prefix.patch { 94 + PYTHON_SITEPACKAGES = python3.sitePackages; 95 + }) 76 96 ]; 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 [ 81 143 "--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 [ 87 148 "--with-hdf5=1" 88 149 "--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 + ]; 93 160 94 161 hardeningDisable = lib.optionals (!petsc-optimized) [ 95 162 "fortify"
-9
pkgs/top-level/all-packages.nix
··· 17025 17025 17026 17026 ### SCIENCE/PROGRAMMING 17027 17027 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 - 17037 17028 ### SCIENCE/LOGIC 17038 17029 17039 17030 abella = callPackage ../applications/science/logic/abella {
+7
pkgs/top-level/python-packages.nix
··· 10348 10348 10349 10349 pesq = callPackage ../development/python-modules/pesq { }; 10350 10350 10351 + petsc4py = toPythonModule (pkgs.petsc.override { 10352 + python3 = python; 10353 + python3Packages = self; 10354 + withPetsc4py = true; 10355 + withFullDeps = true; 10356 + }); 10357 + 10351 10358 pex = callPackage ../development/python-modules/pex { }; 10352 10359 10353 10360 pexif = callPackage ../development/python-modules/pexif { };