From 72c23a3469732cd0f0d649a85083ce75cc6f5a81 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Wed, 30 Jun 2021 17:54:45 +0200 Subject: [PATCH 01/11] petsc: refactor using mpi and p4est --- .../libraries/science/math/petsc/default.nix | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index f06a028fe64..e64df8eb51b 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -1,5 +1,23 @@ -{ lib, stdenv , darwin , fetchurl , blas , gfortran , lapack , python }: +{ lib +, stdenv +, fetchurl +, darwin +, gfortran +, python +, blas +, lapack +, mpi # generic mpi dependency +, openmpi # to compare against mpi +, openssh # required for openmpi tests +, petsc-withp4est ? true +, p4est +, zlib # propagated by p4est but required by petsc +}: +let + mpiSupport = !withp4est || p4est.mpiSupport; + withp4est = petsc-withp4est; +in stdenv.mkDerivation rec { pname = "petsc"; version = "3.14.2"; @@ -9,7 +27,12 @@ stdenv.mkDerivation rec { sha256 = "04vy3qyakikslc58qyv8c9qrwlivix3w6znc993i37cvfg99dch9"; }; - nativeBuildInputs = [ blas gfortran gfortran.cc.lib lapack python ]; + nativeBuildInputs = [ python gfortran gfortran.cc.lib ]; + buildInputs = [ blas lapack ] + ++ lib.optional mpiSupport mpi + ++ lib.optional (mpiSupport && mpi == openmpi) openssh + ++ lib.optional withp4est p4est + ; # Upstream does some hot she-py-bang stuff, this change streamlines that # process. The original script in upstream is both a shell script and a @@ -30,23 +53,35 @@ stdenv.mkDerivation rec { patchShebangs . configureFlagsArray=( $configureFlagsArray - "--CC=$CC" - "--with-cxx=$CXX" - "--with-fc=$FC" - "--with-mpi=0" + ${if !mpiSupport then '' + "--CC=$CC" + "--with-cxx=$CXX" + "--with-fc=$FC" + "--with-mpi=0" + '' else '' + "--CC=mpicc" + "--with-cxx=mpicxx" + "--with-fc=mpif90" + "--with-mpi=1" + ''} + ${if withp4est then '' + "--with-p4est=1" + "--with-zlib-include=${zlib.dev}/include" + "--with-zlib-lib=-L${zlib}/lib -lz" + '' else ""} "--with-blas-lib=[${blas}/lib/libblas.so,${gfortran.cc.lib}/lib/libgfortran.a]" "--with-lapack-lib=[${lapack}/lib/liblapack.so,${gfortran.cc.lib}/lib/libgfortran.a]" ) ''; + inherit mpiSupport withp4est; + enableParallelBuilding = true; + doCheck = stdenv.hostPlatform == stdenv.buildPlatform; + meta = with lib; { - description = '' - Library of linear algebra algorithms for solving partial differential - equations - ''; + description = "Linear algebra algorithms for solving partial differential equations"; homepage = "https://www.mcs.anl.gov/petsc/index.html"; license = licenses.bsd2; - maintainers = with maintainers; [ wucke13 ]; - platforms = platforms.all; + maintainers = with maintainers; [ wucke13 cburstedde ]; }; } From 8834c5399c218701c36193f2ca11f3ae0298c162 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Thu, 1 Jul 2021 22:16:53 +0200 Subject: [PATCH 02/11] petsc: address couple suggestions --- .../libraries/science/math/petsc/default.nix | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index e64df8eb51b..2e10df1c967 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -7,17 +7,12 @@ , blas , lapack , mpi # generic mpi dependency -, openmpi # to compare against mpi , openssh # required for openmpi tests , petsc-withp4est ? true , p4est , zlib # propagated by p4est but required by petsc }: -let - mpiSupport = !withp4est || p4est.mpiSupport; - withp4est = petsc-withp4est; -in stdenv.mkDerivation rec { pname = "petsc"; version = "3.14.2"; @@ -27,10 +22,13 @@ stdenv.mkDerivation rec { sha256 = "04vy3qyakikslc58qyv8c9qrwlivix3w6znc993i37cvfg99dch9"; }; + mpiSupport = !withp4est || p4est.mpiSupport; + withp4est = petsc-withp4est; + nativeBuildInputs = [ python gfortran gfortran.cc.lib ]; buildInputs = [ blas lapack ] ++ lib.optional mpiSupport mpi - ++ lib.optional (mpiSupport && mpi == openmpi) openssh + ++ lib.optional (mpiSupport && mpi.pname == "openmpi") openssh ++ lib.optional withp4est p4est ; @@ -74,12 +72,11 @@ stdenv.mkDerivation rec { ) ''; - inherit mpiSupport withp4est; enableParallelBuilding = true; doCheck = stdenv.hostPlatform == stdenv.buildPlatform; meta = with lib; { - description = "Linear algebra algorithms for solving partial differential equations"; + description = "Portable Extensible Toolkit for Scientific computation"; homepage = "https://www.mcs.anl.gov/petsc/index.html"; license = licenses.bsd2; maintainers = with maintainers; [ wucke13 cburstedde ]; From dbf58984625ca1e2e35c40cb89cd4ee41d0fdc8a Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Thu, 1 Jul 2021 22:27:03 +0200 Subject: [PATCH 03/11] petsc: simplify blas, lapack dependencies --- pkgs/development/libraries/science/math/petsc/default.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 2e10df1c967..426a4a8f915 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -25,7 +25,7 @@ stdenv.mkDerivation rec { mpiSupport = !withp4est || p4est.mpiSupport; withp4est = petsc-withp4est; - nativeBuildInputs = [ python gfortran gfortran.cc.lib ]; + nativeBuildInputs = [ python gfortran ]; buildInputs = [ blas lapack ] ++ lib.optional mpiSupport mpi ++ lib.optional (mpiSupport && mpi.pname == "openmpi") openssh @@ -67,8 +67,8 @@ stdenv.mkDerivation rec { "--with-zlib-include=${zlib.dev}/include" "--with-zlib-lib=-L${zlib}/lib -lz" '' else ""} - "--with-blas-lib=[${blas}/lib/libblas.so,${gfortran.cc.lib}/lib/libgfortran.a]" - "--with-lapack-lib=[${lapack}/lib/liblapack.so,${gfortran.cc.lib}/lib/libgfortran.a]" + "--with-blas=1" + "--with-lapack=1" ) ''; From ce30d367c1427ac39d583daf814f0a23eaf4afd4 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Thu, 1 Jul 2021 22:37:52 +0200 Subject: [PATCH 04/11] petsc: assert requirement for p4est.mpiSupport --- pkgs/development/libraries/science/math/petsc/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 426a4a8f915..900ea76e284 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -13,6 +13,9 @@ , zlib # propagated by p4est but required by petsc }: +# This version of PETSc does not support a non-MPI p4est build +assert petsc-withp4est -> p4est.mpiSupport; + stdenv.mkDerivation rec { pname = "petsc"; version = "3.14.2"; From bcf9629def740946f74e56d0cf0fd1dfd6772d9a Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Thu, 1 Jul 2021 22:50:54 +0200 Subject: [PATCH 05/11] petsc: remove unnecessary configure options --- pkgs/development/libraries/science/math/petsc/default.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 900ea76e284..921ac859b1b 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -55,9 +55,6 @@ stdenv.mkDerivation rec { configureFlagsArray=( $configureFlagsArray ${if !mpiSupport then '' - "--CC=$CC" - "--with-cxx=$CXX" - "--with-fc=$FC" "--with-mpi=0" '' else '' "--CC=mpicc" From 870b2847a42822384b55e13ed6317d9714e20407 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Thu, 1 Jul 2021 22:31:19 +0200 Subject: [PATCH 06/11] getdp: align with latest petsc dependency --- pkgs/applications/science/math/getdp/default.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkgs/applications/science/math/getdp/default.nix b/pkgs/applications/science/math/getdp/default.nix index 39d9c866cae..5ea3550d08a 100644 --- a/pkgs/applications/science/math/getdp/default.nix +++ b/pkgs/applications/science/math/getdp/default.nix @@ -1,15 +1,19 @@ { lib, stdenv, fetchurl, cmake, gfortran, blas, lapack, mpi, petsc, python3 }: stdenv.mkDerivation rec { - name = "getdp-${version}"; + pname = "getdp"; version = "3.3.0"; src = fetchurl { url = "http://getdp.info/src/getdp-${version}-source.tgz"; sha256 = "1pfviy2bw8z5y6c15czvlvyjjg9pvpgrj9fr54xfi2gmvs7zkgpf"; }; - nativeBuildInputs = [ cmake gfortran ]; - buildInputs = [ blas lapack mpi petsc python3 ]; + inherit (petsc) mpiSupport; + nativeBuildInputs = [ cmake python3 ]; + buildInputs = [ gfortran blas lapack petsc ] + ++ lib.optional mpiSupport mpi + ; + cmakeFlags = lib.optional mpiSupport "-DENABLE_MPI=1"; meta = with lib; { description = "A General Environment for the Treatment of Discrete Problems"; From 87da2a041474a275c1ed6838916a700cd045df05 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Mon, 5 Jul 2021 15:39:02 +0200 Subject: [PATCH 07/11] petsc: do not build with p4est on aarch64 --- pkgs/development/libraries/science/math/petsc/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 921ac859b1b..87689ddb827 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { }; mpiSupport = !withp4est || p4est.mpiSupport; - withp4est = petsc-withp4est; + withp4est = !stdenv.isAarch64 && petsc-withp4est; nativeBuildInputs = [ python gfortran ]; buildInputs = [ blas lapack ] From c99a5b9a60ae5c5204a3f41f5d65b642093d1b82 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Mon, 5 Jul 2021 16:58:59 +0200 Subject: [PATCH 08/11] petsc: do not build with p4est on darwin --- pkgs/development/libraries/science/math/petsc/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 87689ddb827..8cea4026d9e 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { }; mpiSupport = !withp4est || p4est.mpiSupport; - withp4est = !stdenv.isAarch64 && petsc-withp4est; + withp4est = !(stdenv.isAarch64 || stdenv.isDarwin) && petsc-withp4est; nativeBuildInputs = [ python gfortran ]; buildInputs = [ blas lapack ] From 27b512299f1a9e5e1fb5801d195f9cb98e75dc73 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Tue, 6 Jul 2021 07:13:59 +0200 Subject: [PATCH 09/11] petsc: restrict patchSheBang; use configureScript The configure script can be called with python via configureScript. This leaves only ./lib/petsc/bin to be patched. --- pkgs/development/libraries/science/math/petsc/default.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 8cea4026d9e..e72b2912f4d 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -51,7 +51,7 @@ stdenv.mkDerivation rec { preConfigure = '' export FC="${gfortran}/bin/gfortran" F77="${gfortran}/bin/gfortran" - patchShebangs . + patchShebangs ./lib/petsc/bin configureFlagsArray=( $configureFlagsArray ${if !mpiSupport then '' @@ -71,6 +71,7 @@ stdenv.mkDerivation rec { "--with-lapack=1" ) ''; + configureScript = "python ./configure"; enableParallelBuilding = true; doCheck = stdenv.hostPlatform == stdenv.buildPlatform; From 80697bfb8e32b9169ee6db4079dff88da733c0f9 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Tue, 6 Jul 2021 07:20:21 +0200 Subject: [PATCH 10/11] petsc: build with p4est for all platforms Recent master updates make p4est build on aarch64 and darwin. Undo their deactivation in the petsc build. --- pkgs/development/libraries/science/math/petsc/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index e72b2912f4d..3fed81fa34a 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -26,7 +26,7 @@ stdenv.mkDerivation rec { }; mpiSupport = !withp4est || p4est.mpiSupport; - withp4est = !(stdenv.isAarch64 || stdenv.isDarwin) && petsc-withp4est; + withp4est = petsc-withp4est; nativeBuildInputs = [ python gfortran ]; buildInputs = [ blas lapack ] From cf4b4bdbeafdae01ba309b0fc3cbba7aa3df1593 Mon Sep 17 00:00:00 2001 From: Carsten Burstedde Date: Tue, 6 Jul 2021 23:10:19 +0200 Subject: [PATCH 11/11] petsc: specify python3 and remove unneeded patch --- .../libraries/science/math/petsc/default.nix | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pkgs/development/libraries/science/math/petsc/default.nix b/pkgs/development/libraries/science/math/petsc/default.nix index 3fed81fa34a..ee495deedc1 100644 --- a/pkgs/development/libraries/science/math/petsc/default.nix +++ b/pkgs/development/libraries/science/math/petsc/default.nix @@ -3,7 +3,7 @@ , fetchurl , darwin , gfortran -, python +, python3 , blas , lapack , mpi # generic mpi dependency @@ -28,23 +28,14 @@ stdenv.mkDerivation rec { mpiSupport = !withp4est || p4est.mpiSupport; withp4est = petsc-withp4est; - nativeBuildInputs = [ python gfortran ]; + nativeBuildInputs = [ python3 gfortran ]; buildInputs = [ blas lapack ] ++ lib.optional mpiSupport mpi ++ lib.optional (mpiSupport && mpi.pname == "openmpi") openssh ++ lib.optional withp4est p4est ; - # Upstream does some hot she-py-bang stuff, this change streamlines that - # process. The original script in upstream is both a shell script and a - # python script, where the shellscript just finds a suitable python - # interpreter to execute the python script. See - # https://github.com/NixOS/nixpkgs/pull/89299#discussion_r450203444 - # for more details. - prePatch = '' - substituteInPlace configure \ - --replace /bin/sh /usr/bin/python - '' + lib.optionalString stdenv.isDarwin '' + prePatch = lib.optionalString stdenv.isDarwin '' substituteInPlace config/install.py \ --replace /usr/bin/install_name_tool ${darwin.cctools}/bin/install_name_tool ''; @@ -71,6 +62,7 @@ stdenv.mkDerivation rec { "--with-lapack=1" ) ''; + configureScript = "python ./configure"; enableParallelBuilding = true;