From 0b324cc371152886eec3910c2ca77fb3dd9096ff Mon Sep 17 00:00:00 2001 From: qbisi Date: Sat, 26 Oct 2024 23:54:27 +0800 Subject: [PATCH] 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