From 66d928e812e237967609679b3cc42df3f8f08db4 Mon Sep 17 00:00:00 2001 From: qbisi Date: Wed, 23 Oct 2024 07:46:26 +0800 Subject: [PATCH 1/8] mumps: enable parallel building --- pkgs/by-name/mu/mumps/package.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index 7d0e3e154cb4..41894f9dcd0f 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -42,6 +42,8 @@ stdenv.mkDerivation (finalAttrs: { cp Make.inc/Makefile.debian.SEQ ./Makefile.inc ''; + enableParallelBuilding = true; + makeFlags = lib.optionals stdenv.hostPlatform.isDarwin [ "SONAME=" From c9997c4e36c4193a883f555744adadad3692edc8 Mon Sep 17 00:00:00 2001 From: qbisi Date: Wed, 23 Oct 2024 08:24:45 +0800 Subject: [PATCH 2/8] mumps: remove unnecessary patch from coin-or-mumps The coin-or project ipopt use a thirdparty-mumps, this variant renames `libseq/mpi.h` to `libseq/mumps_mpi.h` to avoid conflicts when building in a MPI environment. See https://github.com/coin-or/Ipopt/blob/stable/3.14/ChangeLog.md?plain=1#L582. Nix packagers don't need to worry about this cause we build in a sandbox environment. For parrallel version of mumps built with mpi support, libseq is not needed and there will be no conflicts. --- pkgs/by-name/mu/mumps/package.nix | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index 41894f9dcd0f..e031266cd857 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -18,25 +18,11 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-ZnIfAuvOBJDYqCtKGlWs0r39nG6X2lAVRuUmeIJenZw="; }; - patches = [ - # Compatibility with coin-or-mumps version - (fetchpatch { - url = "https://raw.githubusercontent.com/coin-or-tools/ThirdParty-Mumps/bd0bdf9baa3f3677bd34fb36ce63b2b32cc6cc7d/mumps_mpi.patch"; - hash = "sha256-70qZUKBVBpJOSRxYxng5Y6ct1fdCUQUGur3chDhGabQ="; - }) - ]; - - postPatch = - '' - # Compatibility with coin-or-mumps version - # https://github.com/coin-or-tools/ThirdParty-Mumps/blob/stable/3.0/get.Mumps#L66 - cp libseq/mpi.h libseq/mumps_mpi.h - '' - + lib.optionalString stdenv.hostPlatform.isDarwin '' - substituteInPlace src/Makefile --replace-fail \ - "-Wl,\''$(SONAME),libmumps_common" \ - "-Wl,-install_name,$out/lib/libmumps_common" - ''; + postPatch = lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace src/Makefile --replace-fail \ + "-Wl,\''$(SONAME),libmumps_common" \ + "-Wl,-install_name,$out/lib/libmumps_common" + ''; configurePhase = '' cp Make.inc/Makefile.debian.SEQ ./Makefile.inc @@ -63,7 +49,7 @@ stdenv.mkDerivation (finalAttrs: { # Add some compatibility with coin-or-mumps ln -s $out/include $out/include/mumps - cp libseq/mumps_mpi.h $out/include + cp libseq/mpi.h $out/include/mumps_mpi.h ''; nativeBuildInputs = [ gfortran ]; From bf5d835e6e3593e0dca4926a70cc84f6b958dca5 Mon Sep 17 00:00:00 2001 From: qbisi Date: Thu, 24 Oct 2024 07:37:00 +0800 Subject: [PATCH 3/8] mumps: install mumps libseq headers to include/mumps_seq Directory libseq contains dummy MPI/BLACS/ScaLAPACK symbols to allow linking/running MUMPS on a platform where MPI is not installed. The install directory name mumps_seq comes from Debian source package and Aur pkgbuild. See - https://sources.debian.org/src/mumps/5.7.3-2/debian/libmumps-headers-dev.install - https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mumps-seq --- pkgs/by-name/mu/mumps/package.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index e031266cd857..0b078b97d281 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -47,9 +47,12 @@ stdenv.mkDerivation (finalAttrs: { mkdir $out cp -r include lib $out + # Install mumps_seq headers + install -Dm 444 -t $out/include/mumps_seq libseq/*.h + # Add some compatibility with coin-or-mumps ln -s $out/include $out/include/mumps - cp libseq/mpi.h $out/include/mumps_mpi.h + ln -s $out/include/mumps_seq/mpi.h $out/include/mumps_mpi.h ''; nativeBuildInputs = [ gfortran ]; From 0f8d273ca5ff7b3c4a1cc2a3effe2f53c472f8a1 Mon Sep 17 00:00:00 2001 From: qbisi Date: Thu, 24 Oct 2024 10:46:05 +0800 Subject: [PATCH 4/8] mumps: headers remove symlink to subdir With the upstream patch to casadi (https://github.com/casadi/casadi/pull/3899), There is no need for nixpkgs#mumps to symlink header files to subdir mumps. Nix packagers should manualy specify the include directory and link libraries for the coinmumps required project like nipxkgs#libopt. --- pkgs/by-name/ca/casadi/package.nix | 14 +++++++++----- pkgs/by-name/mu/mumps/package.nix | 1 - 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/by-name/ca/casadi/package.nix b/pkgs/by-name/ca/casadi/package.nix index 5cd35b064342..891b423d9e7a 100644 --- a/pkgs/by-name/ca/casadi/package.nix +++ b/pkgs/by-name/ca/casadi/package.nix @@ -10,6 +10,7 @@ cplex, fatrop, fetchFromGitHub, + fetchpatch, gurobi, highs, hpipm, @@ -45,6 +46,14 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-Mft0qhjdAbU82RgjYuKue5p7EqbTbt3ii5yXSsCFHrQ="; }; + patches = [ + (fetchpatch { + name = "fix-FindMUMPS.cmake.patch"; + url = "https://github.com/casadi/casadi/pull/3899/commits/274f4b23f73e60c5302bec0479fe1e92682b63d2.patch"; + hash = "sha256-3GWEWlN8dKLD6htpnOQLChldcT3hE09JWLeuCfAhY+4="; + }) + ]; + postPatch = '' # fix case of hpipmConfig.cmake @@ -57,11 +66,6 @@ stdenv.mkDerivation (finalAttrs: { '$'{CLANG_LLVM_LIB_DIR} \ ${llvmPackages_17.libclang.lib}/lib - # fix mumps lib name. No idea where this comes from. - substituteInPlace cmake/FindMUMPS.cmake --replace-fail \ - "mumps_seq" \ - "mumps" - # help casadi find its own libs substituteInPlace casadi/core/casadi_os.cpp --replace-fail \ "std::vector search_paths;" \ diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index 0b078b97d281..7c70fef7ad79 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -51,7 +51,6 @@ stdenv.mkDerivation (finalAttrs: { install -Dm 444 -t $out/include/mumps_seq libseq/*.h # Add some compatibility with coin-or-mumps - ln -s $out/include $out/include/mumps ln -s $out/include/mumps_seq/mpi.h $out/include/mumps_mpi.h ''; From 8f2c8168e749eb599e80224ac2c89e2ba5e10913 Mon Sep 17 00:00:00 2001 From: qbisi Date: Fri, 25 Oct 2024 06:45:08 +0800 Subject: [PATCH 5/8] mumps: add some checks --- pkgs/by-name/mu/mumps/package.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index 7c70fef7ad79..7ed502b0fd32 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -112,6 +112,27 @@ stdenv.mkDerivation (finalAttrs: { $out/lib/libpord.dylib ''; + doInstallCheck = true; + installCheckPhase = + lib.optionalString stdenv.hostPlatform.isDarwin '' + export DYLD_LIBRARY_PATH=$out/lib + '' + + '' + cd examples + make all + ./ssimpletest Date: Fri, 25 Oct 2024 06:45:49 +0800 Subject: [PATCH 6/8] mumps: simplify fixupphase with fixDarwinDylibNames --- pkgs/by-name/mu/mumps/package.nix | 58 +++++-------------------------- 1 file changed, 8 insertions(+), 50 deletions(-) diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index 7ed502b0fd32..5c74e85b301b 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -8,6 +8,7 @@ metis, scotch, stdenv, + fixDarwinDylibNames, }: stdenv.mkDerivation (finalAttrs: { name = "mumps"; @@ -54,7 +55,13 @@ stdenv.mkDerivation (finalAttrs: { ln -s $out/include/mumps_seq/mpi.h $out/include/mumps_mpi.h ''; - nativeBuildInputs = [ gfortran ]; + nativeBuildInputs = + lib.optionals stdenv.hostPlatform.isDarwin [ + fixDarwinDylibNames + ] + ++ [ + gfortran + ]; buildInputs = [ blas @@ -63,55 +70,6 @@ stdenv.mkDerivation (finalAttrs: { scotch ]; - preFixup = lib.optionalString stdenv.hostPlatform.isDarwin '' - install_name_tool \ - -change libmpiseq.dylib \ - $out/lib/libmpiseq.dylib \ - -change libpord.dylib \ - $out/lib/libpord.dylib \ - $out/lib/libmumps_common.dylib - install_name_tool \ - -change libmpiseq.dylib \ - $out/lib/libmpiseq.dylib \ - -change libpord.dylib \ - $out/lib/libpord.dylib \ - -id \ - $out/lib/libcmumps.dylib \ - $out/lib/libcmumps.dylib - install_name_tool \ - -change libmpiseq.dylib \ - $out/lib/libmpiseq.dylib \ - -change libpord.dylib \ - $out/lib/libpord.dylib \ - -id \ - $out/lib/libdmumps.dylib \ - $out/lib/libdmumps.dylib - install_name_tool \ - -change libmpiseq.dylib \ - $out/lib/libmpiseq.dylib \ - -change libpord.dylib \ - $out/lib/libpord.dylib \ - -id \ - $out/lib/libsmumps.dylib \ - $out/lib/libsmumps.dylib - install_name_tool \ - -change libmpiseq.dylib \ - $out/lib/libmpiseq.dylib \ - -change libpord.dylib \ - $out/lib/libpord.dylib \ - -id \ - $out/lib/libzmumps.dylib \ - $out/lib/libzmumps.dylib - install_name_tool \ - -id \ - $out/lib/libmpiseq.dylib \ - $out/lib/libmpiseq.dylib - install_name_tool \ - -id \ - $out/lib/libpord.dylib \ - $out/lib/libpord.dylib - ''; - doInstallCheck = true; installCheckPhase = lib.optionalString stdenv.hostPlatform.isDarwin '' From 4df3489270545e5f152406ad86631ff322b3942f Mon Sep 17 00:00:00 2001 From: qbisi Date: Sun, 27 Oct 2024 04:03:19 +0800 Subject: [PATCH 7/8] maintainers: add qbisi --- maintainers/maintainer-list.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maintainers/maintainer-list.nix b/maintainers/maintainer-list.nix index e201d359f1b1..882756c157e2 100644 --- a/maintainers/maintainer-list.nix +++ b/maintainers/maintainer-list.nix @@ -17629,6 +17629,12 @@ githubId = 12017109; name = "Rabindra Dhakal"; }; + qbisi = { + name = "qbisicwate"; + email = "qbisicwate@gmail.com"; + github = "qbisi"; + githubId = 84267544; + }; qbit = { name = "Aaron Bieber"; email = "aaron@bolddaemon.com"; From 0b324cc371152886eec3910c2ca77fb3dd9096ff Mon Sep 17 00:00:00 2001 From: qbisi Date: Sat, 26 Oct 2024 23:54:27 +0800 Subject: [PATCH 8/8] mumps: add variant mumps_par with mpi support --- pkgs/by-name/mu/mumps/package.nix | 149 +++++++++++++++++++++--------- pkgs/top-level/all-packages.nix | 2 + 2 files changed, 106 insertions(+), 45 deletions(-) diff --git a/pkgs/by-name/mu/mumps/package.nix b/pkgs/by-name/mu/mumps/package.nix index 5c74e85b301b..2620d5b602b5 100644 --- a/pkgs/by-name/mu/mumps/package.nix +++ b/pkgs/by-name/mu/mumps/package.nix @@ -6,10 +6,55 @@ lapack, lib, metis, + parmetis, + withParmetis ? false, # default to false due to unfree license scotch, + withPtScotch ? mpiSupport, stdenv, fixDarwinDylibNames, + mpi, + mpiSupport ? false, + mpiCheckPhaseHook, + scalapack, }: +assert withParmetis -> mpiSupport; +assert withPtScotch -> mpiSupport; +let + profile = if mpiSupport then "debian.PAR" else "debian.SEQ"; + metisFlags = + if withParmetis then + '' + IMETIS="-I${parmetis}/include -I${metis}/include" \ + LMETIS="-L${parmetis}/lib -lparmetis -L${metis}/lib -lmetis" + '' + else + '' + IMETIS=-I${metis}/include \ + LMETIS="-L${metis}/lib -lmetis" + ''; + scotchFlags = + if withPtScotch then + '' + ISCOTCH=-I${scotch.dev}/include \ + LSCOTCH="-L${scotch}/lib -lptscotch -lptesmumps -lptscotcherr" + '' + else + '' + ISCOTCH=-I${scotch.dev}/include \ + LSCOTCH="-L${scotch}/lib -lesmumps -lscotch -lscotcherr" + ''; + macroFlags = + "-Dmetis -Dpord -Dscotch" + + lib.optionalString withParmetis " -Dparmetis" + + lib.optionalString withPtScotch " -Dptscotch"; + # Optimized options + # Disable -fopenmp in lines below to benefit from OpenMP + optFlags = '' + OPTF="-O3 -fallow-argument-mismatch" \ + OPTL="-O3" \ + OPTC="-O3" + ''; +in stdenv.mkDerivation (finalAttrs: { name = "mumps"; version = "5.7.3"; @@ -26,75 +71,89 @@ stdenv.mkDerivation (finalAttrs: { ''; configurePhase = '' - cp Make.inc/Makefile.debian.SEQ ./Makefile.inc + cp Make.inc/Makefile.${profile} ./Makefile.inc ''; enableParallelBuilding = true; + preBuild = '' + makeFlagsArray+=(${metisFlags} ${scotchFlags} ORDERINGSF="${macroFlags}" ${optFlags}) + ''; + makeFlags = lib.optionals stdenv.hostPlatform.isDarwin [ "SONAME=" "LIBEXT_SHARED=.dylib" ] ++ [ - "LSCOTCHDIR=${scotch}/lib" - "ISCOTCH=-I${scotch.dev}/include" - "LMETISDIR=${metis}/lib" - "IMETIS=-I${metis}/include" + "SCALAP=-lscalapack" "allshared" ]; - installPhase = '' - mkdir $out - cp -r include lib $out + installPhase = + '' + mkdir $out + cp -r include lib $out + '' + + lib.optionalString (!mpiSupport) '' + # Install mumps_seq headers + install -Dm 444 -t $out/include/mumps_seq libseq/*.h - # Install mumps_seq headers - install -Dm 444 -t $out/include/mumps_seq libseq/*.h + # Add some compatibility with coin-or-mumps + ln -s $out/include/mumps_seq/mpi.h $out/include/mumps_mpi.h + ''; - # Add some compatibility with coin-or-mumps - ln -s $out/include/mumps_seq/mpi.h $out/include/mumps_mpi.h - ''; + nativeBuildInputs = [ + gfortran + ] ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames ++ lib.optional mpiSupport mpi; - nativeBuildInputs = - lib.optionals stdenv.hostPlatform.isDarwin [ - fixDarwinDylibNames - ] + # Parmetis should be placed before scotch to avoid conflict of header file "parmetis.h" + buildInputs = + lib.optional withParmetis parmetis + ++ lib.optional mpiSupport scalapack ++ [ - gfortran + blas + lapack + metis + scotch ]; - buildInputs = [ - blas - lapack - metis - scotch - ]; - doInstallCheck = true; - installCheckPhase = - lib.optionalString stdenv.hostPlatform.isDarwin '' - export DYLD_LIBRARY_PATH=$out/lib - '' - + '' - cd examples - make all - ./ssimpletest