Merge pull request #246867 from markuskowa/add-mpi-hook

add mpiCheckPhaseHook

authored by markuskowa and committed by GitHub 212d454c e0f0ecbc

+127 -57
+1
doc/hooks/index.md
··· 17 libiconv.section.md 18 libxml2.section.md 19 meson.section.md 20 ninja.section.md 21 patch-rc-path-hooks.section.md 22 perl.section.md
··· 17 libiconv.section.md 18 libxml2.section.md 19 meson.section.md 20 + mpi-check-hook.section.md 21 ninja.section.md 22 patch-rc-path-hooks.section.md 23 perl.section.md
+24
doc/hooks/mpi-check-hook.section.md
···
··· 1 + # mpiCheckPhaseHook {#setup-hook-mpi-check} 2 + 3 + 4 + This hook can be used to setup a check phase that 5 + requires running a MPI application. It detects the 6 + used present MPI implementaion type and exports 7 + the neceesary environment variables to use 8 + `mpirun` and `mpiexec` in a Nix sandbox. 9 + 10 + 11 + Example: 12 + 13 + ```nix 14 + { mpiCheckPhaseHook, mpi, ... }: 15 + 16 + ... 17 + 18 + nativeCheckInputs = [ 19 + openssh 20 + mpiCheckPhaseHook 21 + ]; 22 + ``` 23 + 24 +
+9 -5
pkgs/applications/science/chemistry/cp2k/default.nix
··· 1 - { lib, stdenv, fetchFromGitHub, python3, gfortran, blas, lapack 2 , fftw, libint, libvori, libxc, mpi, gsl, scalapack, openssh, makeWrapper 3 , libxsmm, spglib, which, pkg-config, plumed, zlib 4 , enableElpa ? false ··· 88 EOF 89 ''; 90 91 checkPhase = '' 92 - export OMP_NUM_THREADS=1 93 94 - export HYDRA_IFACE=lo # Fix to make mpich run in a sandbox 95 - export OMPI_MCA_rmaps_base_oversubscribe=1 96 export CP2K_DATA_DIR=data 97 98 - mpirun -np 2 exe/${arch}/libcp2k_unittest.${cp2kVersion} 99 ''; 100 101 installPhase = ''
··· 1 + { lib, stdenv, fetchFromGitHub, mpiCheckPhaseHook, python3, gfortran, blas, lapack 2 , fftw, libint, libvori, libxc, mpi, gsl, scalapack, openssh, makeWrapper 3 , libxsmm, spglib, which, pkg-config, plumed, zlib 4 , enableElpa ? false ··· 88 EOF 89 ''; 90 91 + nativeCheckInputs = [ 92 + mpiCheckPhaseHook 93 + openssh 94 + ]; 95 + 96 checkPhase = '' 97 + runHook preCheck 98 99 export CP2K_DATA_DIR=data 100 + mpirun -np 2 exe/${arch}/libcp2k_unittest.${cp2kVersion} 101 102 + runHook postCheck 103 ''; 104 105 installPhase = ''
+5 -5
pkgs/applications/science/chemistry/nwchem/default.nix
··· 3 , pkgs 4 , fetchFromGitHub 5 , fetchurl 6 , which 7 , openssh 8 , gcc ··· 190 doCheck = false; 191 192 doInstallCheck = true; 193 installCheckPhase = '' 194 - export OMP_NUM_THREADS=1 195 - 196 - # Fix to make mpich run in a sandbox 197 - export HYDRA_IFACE=lo 198 - export OMPI_MCA_rmaps_base_oversubscribe=1 199 200 # run a simple water test 201 mpirun -np 2 $out/bin/nwchem $out/share/nwchem/QA/tests/h2o/h2o.nw > h2o.out 202 grep "Total SCF energy" h2o.out | grep 76.010538 203 ''; 204 205 passthru = { inherit mpi; };
··· 3 , pkgs 4 , fetchFromGitHub 5 , fetchurl 6 + , mpiCheckPhaseHook 7 , which 8 , openssh 9 , gcc ··· 191 doCheck = false; 192 193 doInstallCheck = true; 194 + nativeCheckInputs = [ mpiCheckPhaseHook ]; 195 installCheckPhase = '' 196 + runHook preInstallCheck 197 198 # run a simple water test 199 mpirun -np 2 $out/bin/nwchem $out/share/nwchem/QA/tests/h2o/h2o.nw > h2o.out 200 grep "Total SCF energy" h2o.out | grep 76.010538 201 + 202 + runHook postInstallCheck 203 ''; 204 205 passthru = { inherit mpi; };
+5
pkgs/build-support/setup-hooks/mpi-check-hook/default.nix
···
··· 1 + { callPackage, makeSetupHook }: 2 + 3 + makeSetupHook { 4 + name = "mpi-checkPhase-hook"; 5 + } ./mpi-check-hook.sh
+54
pkgs/build-support/setup-hooks/mpi-check-hook/mpi-check-hook.sh
···
··· 1 + preCheckHooks+=('setupMpiCheck') 2 + preInstallCheckHooks+=('setupMpiCheck') 3 + 4 + 5 + setupMpiCheck() { 6 + # Find out which MPI implementation we are using 7 + # and set safe defaults that are guaranteed to run 8 + # on any build machine 9 + 10 + mpiType="NONE" 11 + 12 + # OpenMPI signature 13 + if command ompi_info &> /dev/null; then 14 + mpiType="openmpi" 15 + fi 16 + 17 + # MPICH based implementations 18 + if command mpichversion &> /dev/null; then 19 + if [ "$mpiType" != "NONE" ]; then 20 + echo "WARNING: found OpenMPI and MPICH/MVAPICH executables" 21 + fi 22 + 23 + version=$(mpichversion) 24 + if [[ "$version" == *"MPICH"* ]]; then 25 + mpiType="MPICH" 26 + fi 27 + if [[ "$version" == *"MVAPICH"* ]]; then 28 + mpiType="MVAPICH" 29 + fi 30 + fi 31 + 32 + echo "Found MPI implementation: $mpiType" 33 + 34 + case $mpiType in 35 + openmpi) 36 + # make sure the test starts even if we have less than the requested amount of cores 37 + export OMPI_MCA_rmaps_base_oversubscribe=1 38 + # Disable CPU pinning 39 + export OMPI_MCA_hwloc_base_binding_policy=none 40 + ;; 41 + MPICH) 42 + # Fix to make mpich run in a sandbox 43 + export HYDRA_IFACE=lo 44 + ;; 45 + MVAPICH) 46 + # Disable CPU pinning 47 + export MV2_ENABLE_AFFINITY=0 48 + ;; 49 + esac 50 + 51 + # Limit number of OpenMP threads. Default is "all cores". 52 + export OMP_NUM_THREADS=1 53 + } 54 +
+4 -9
pkgs/development/libraries/elpa/default.nix
··· 1 - { lib, stdenv, fetchurl, autoreconfHook, gfortran, perl 2 - , mpi, blas, lapack, scalapack, openssh 3 # CPU optimizations 4 , avxSupport ? stdenv.hostPlatform.avxSupport 5 , avx2Support ? stdenv.hostPlatform.avx2Support ··· 41 substituteInPlace Makefile.am --replace '#!/bin/bash' '#!${stdenv.shell}' 42 ''; 43 44 - nativeBuildInputs = [ autoreconfHook perl openssh ]; 45 46 buildInputs = [ mpi blas lapack scalapack ] 47 ++ lib.optional enableCuda cudatoolkit; ··· 76 77 doCheck = true; 78 79 preCheck = '' 80 #patchShebangs ./ 81 - 82 - # make sure the test starts even if we have less than 4 cores 83 - export OMPI_MCA_rmaps_base_oversubscribe=1 84 - 85 - # Fix to make mpich run in a sandbox 86 - export HYDRA_IFACE=lo 87 88 # Run dual threaded 89 export OMP_NUM_THREADS=2
··· 1 + { lib, stdenv, fetchurl, autoreconfHook, mpiCheckPhaseHook 2 + , gfortran, perl, mpi, blas, lapack, scalapack, openssh 3 # CPU optimizations 4 , avxSupport ? stdenv.hostPlatform.avxSupport 5 , avx2Support ? stdenv.hostPlatform.avx2Support ··· 41 substituteInPlace Makefile.am --replace '#!/bin/bash' '#!${stdenv.shell}' 42 ''; 43 44 + nativeBuildInputs = [ autoreconfHook perl ]; 45 46 buildInputs = [ mpi blas lapack scalapack ] 47 ++ lib.optional enableCuda cudatoolkit; ··· 76 77 doCheck = true; 78 79 + nativeCheckInputs = [ mpiCheckPhaseHook openssh ]; 80 preCheck = '' 81 #patchShebangs ./ 82 83 # Run dual threaded 84 export OMP_NUM_THREADS=2
+5 -5
pkgs/development/libraries/science/math/dbcsr/default.nix
··· 2 , lib 3 , fetchFromGitHub 4 , cmake 5 , pkg-config 6 , fypp 7 , gfortran ··· 64 "-DUSE_MPI=ON" 65 ]; 66 67 - checkInputs = [ openssh ]; 68 69 doCheck = true; 70 - preCheck = '' 71 - export HYDRA_IFACE=lo # Fix to make mpich run in a sandbox 72 - export OMPI_MCA_rmaps_base_oversubscribe=1 73 - ''; 74 75 meta = with lib; { 76 description = "Distributed Block Compressed Sparse Row matrix library";
··· 2 , lib 3 , fetchFromGitHub 4 , cmake 5 + , mpiCheckPhaseHook 6 , pkg-config 7 , fypp 8 , gfortran ··· 65 "-DUSE_MPI=ON" 66 ]; 67 68 + checkInputs = [ 69 + openssh 70 + mpiCheckPhaseHook 71 + ]; 72 73 doCheck = true; 74 75 meta = with lib; { 76 description = "Distributed Block Compressed Sparse Row matrix library";
+5 -5
pkgs/development/libraries/science/math/p4est-sc/default.nix
··· 1 - { lib, stdenv, fetchFromGitHub 2 , autoreconfHook, pkg-config 3 , p4est-sc-debugEnable ? true, p4est-sc-mpiSupport ? true 4 , mpi, openssh, zlib ··· 47 enableParallelBuilding = true; 48 makeFlags = [ "V=0" ]; 49 50 - preCheck = '' 51 - export OMPI_MCA_rmaps_base_oversubscribe=1 52 - export HYDRA_IFACE=lo 53 - ''; 54 55 # disallow Darwin checks due to prototype incompatibility of qsort_r 56 # to be fixed in a future version of the source code
··· 1 + { lib, stdenv, fetchFromGitHub, mpiCheckPhaseHook 2 , autoreconfHook, pkg-config 3 , p4est-sc-debugEnable ? true, p4est-sc-mpiSupport ? true 4 , mpi, openssh, zlib ··· 47 enableParallelBuilding = true; 48 makeFlags = [ "V=0" ]; 49 50 + nativeCheckInputs = lib.optionals mpiSupport [ 51 + mpiCheckPhaseHook 52 + openssh 53 + ]; 54 55 # disallow Darwin checks due to prototype incompatibility of qsort_r 56 # to be fixed in a future version of the source code
+1 -1
pkgs/development/libraries/science/math/p4est/default.nix
··· 46 ++ lib.optional withMetis "--with-metis" 47 ; 48 49 - inherit (p4est-sc) makeFlags dontDisableStatic enableParallelBuilding preCheck doCheck; 50 51 meta = { 52 branch = "prev3-develop";
··· 46 ++ lib.optional withMetis "--with-metis" 47 ; 48 49 + inherit (p4est-sc) makeFlags dontDisableStatic enableParallelBuilding doCheck; 50 51 meta = { 52 branch = "prev3-develop";
+3 -14
pkgs/development/libraries/science/math/scalapack/default.nix
··· 1 - { lib, stdenv, fetchFromGitHub, fetchpatch, cmake, openssh 2 - , mpi, blas, lapack 3 } : 4 5 assert blas.isILP64 == lapack.isILP64; ··· 35 ''; 36 37 nativeBuildInputs = [ cmake ]; 38 - nativeCheckInputs = [ openssh ]; 39 buildInputs = [ blas lapack ]; 40 propagatedBuildInputs = [ mpi ]; 41 hardeningDisable = lib.optionals (stdenv.isAarch64 && stdenv.isDarwin) [ "stackprotector" ]; ··· 60 # Increase individual test timeout from 1500s to 10000s because hydra's builds 61 # sometimes fail due to this 62 checkFlagsArray = [ "ARGS=--timeout 10000" ]; 63 - 64 - preCheck = '' 65 - # make sure the test starts even if we have less than 4 cores 66 - export OMPI_MCA_rmaps_base_oversubscribe=1 67 - 68 - # Fix to make mpich run in a sandbox 69 - export HYDRA_IFACE=lo 70 - 71 - # Run single threaded 72 - export OMP_NUM_THREADS=1 73 - ''; 74 75 meta = with lib; { 76 homepage = "http://www.netlib.org/scalapack/";
··· 1 + { lib, stdenv, fetchFromGitHub, fetchpatch, cmake 2 + , openssh, mpiCheckPhaseHook, mpi, blas, lapack 3 } : 4 5 assert blas.isILP64 == lapack.isILP64; ··· 35 ''; 36 37 nativeBuildInputs = [ cmake ]; 38 + nativeCheckInputs = [ openssh mpiCheckPhaseHook ]; 39 buildInputs = [ blas lapack ]; 40 propagatedBuildInputs = [ mpi ]; 41 hardeningDisable = lib.optionals (stdenv.isAarch64 && stdenv.isDarwin) [ "stackprotector" ]; ··· 60 # Increase individual test timeout from 1500s to 10000s because hydra's builds 61 # sometimes fail due to this 62 checkFlagsArray = [ "ARGS=--timeout 10000" ]; 63 64 meta = with lib; { 65 homepage = "http://www.netlib.org/scalapack/";
+6 -7
pkgs/development/python-modules/meep/default.nix
··· 4 , fetchFromGitHub 5 , autoreconfHook 6 , pkg-config 7 , gfortran 8 , mpi 9 , blas ··· 108 errors can be caught. 109 */ 110 doCheck = true; 111 checkPhase = '' 112 - export PATH=$PATH:${openssh}/bin 113 - export PYTHONPATH="$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH" 114 - 115 - export OMP_NUM_THREADS=1 116 117 - # Fix to make mpich run in a sandbox 118 - export HYDRA_IFACE=lo 119 - export OMPI_MCA_rmaps_base_oversubscribe=1 120 121 # Generate a python test script 122 cat > test.py << EOF ··· 139 EOF 140 141 ${mpi}/bin/mpiexec -np 2 python3 test.py 142 ''; 143 144 meta = with lib; {
··· 4 , fetchFromGitHub 5 , autoreconfHook 6 , pkg-config 7 + , mpiCheckPhaseHook 8 , gfortran 9 , mpi 10 , blas ··· 109 errors can be caught. 110 */ 111 doCheck = true; 112 + nativeCheckInputs = [ mpiCheckPhaseHook openssh ]; 113 checkPhase = '' 114 + runHook preCheck 115 116 + export PYTHONPATH="$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH" 117 118 # Generate a python test script 119 cat > test.py << EOF ··· 136 EOF 137 138 ${mpi}/bin/mpiexec -np 2 python3 test.py 139 + 140 + runHook postCheck 141 ''; 142 143 meta = with lib; {
+4 -6
pkgs/development/python-modules/mpi4py/default.nix
··· 1 - { lib, fetchPypi, fetchpatch, python, buildPythonPackage, mpi, openssh }: 2 3 buildPythonPackage rec { 4 pname = "mpi4py"; ··· 33 # sometimes packages specify where files should be installed outside the usual 34 # python lib prefix, we override that back so all infrastructure (setup hooks) 35 # work as expected 36 - 37 - # Needed to run the tests reliably. See: 38 - # https://bitbucket.org/mpi4py/mpi4py/issues/87/multiple-test-errors-with-openmpi-30 39 - export OMPI_MCA_rmaps_base_oversubscribe=yes 40 ''; 41 42 setupPyBuildFlags = ["--mpicc=${mpi}/bin/mpicc"]; ··· 45 46 __darwinAllowLocalNetworking = true; 47 48 - nativeCheckInputs = [ openssh ]; 49 50 meta = with lib; { 51 description = "Python bindings for the Message Passing Interface standard";
··· 1 + { lib, fetchPypi, fetchpatch, python, buildPythonPackage 2 + , mpi, mpiCheckPhaseHook, openssh 3 + }: 4 5 buildPythonPackage rec { 6 pname = "mpi4py"; ··· 35 # sometimes packages specify where files should be installed outside the usual 36 # python lib prefix, we override that back so all infrastructure (setup hooks) 37 # work as expected 38 ''; 39 40 setupPyBuildFlags = ["--mpicc=${mpi}/bin/mpicc"]; ··· 43 44 __darwinAllowLocalNetworking = true; 45 46 + nativeCheckInputs = [ openssh mpiCheckPhaseHook ]; 47 48 meta = with lib; { 49 description = "Python bindings for the Message Passing Interface standard";
+1
pkgs/top-level/all-packages.nix
··· 12323 outils = callPackage ../tools/misc/outils { }; 12324 12325 mpi = openmpi; # this attribute should used to build MPI applications 12326 12327 ucc = callPackage ../development/libraries/ucc { }; 12328
··· 12323 outils = callPackage ../tools/misc/outils { }; 12324 12325 mpi = openmpi; # this attribute should used to build MPI applications 12326 + mpiCheckPhaseHook = callPackage ../build-support/setup-hooks/mpi-check-hook { }; 12327 12328 ucc = callPackage ../development/libraries/ucc { }; 12329