···11+# mpiCheckPhaseHook {#setup-hook-mpi-check}
22+33+44+This hook can be used to setup a check phase that
55+requires running a MPI application. It detects the
66+used present MPI implementaion type and exports
77+the neceesary environment variables to use
88+`mpirun` and `mpiexec` in a Nix sandbox.
99+1010+1111+Example:
1212+1313+```nix
1414+ { mpiCheckPhaseHook, mpi, ... }:
1515+1616+ ...
1717+1818+ nativeCheckInputs = [
1919+ openssh
2020+ mpiCheckPhaseHook
2121+ ];
2222+```
2323+2424+
···11+preCheckHooks+=('setupMpiCheck')
22+preInstallCheckHooks+=('setupMpiCheck')
33+44+55+setupMpiCheck() {
66+ # Find out which MPI implementation we are using
77+ # and set safe defaults that are guaranteed to run
88+ # on any build machine
99+1010+ mpiType="NONE"
1111+1212+ # OpenMPI signature
1313+ if command ompi_info &> /dev/null; then
1414+ mpiType="openmpi"
1515+ fi
1616+1717+ # MPICH based implementations
1818+ if command mpichversion &> /dev/null; then
1919+ if [ "$mpiType" != "NONE" ]; then
2020+ echo "WARNING: found OpenMPI and MPICH/MVAPICH executables"
2121+ fi
2222+2323+ version=$(mpichversion)
2424+ if [[ "$version" == *"MPICH"* ]]; then
2525+ mpiType="MPICH"
2626+ fi
2727+ if [[ "$version" == *"MVAPICH"* ]]; then
2828+ mpiType="MVAPICH"
2929+ fi
3030+ fi
3131+3232+ echo "Found MPI implementation: $mpiType"
3333+3434+ case $mpiType in
3535+ openmpi)
3636+ # make sure the test starts even if we have less than the requested amount of cores
3737+ export OMPI_MCA_rmaps_base_oversubscribe=1
3838+ # Disable CPU pinning
3939+ export OMPI_MCA_hwloc_base_binding_policy=none
4040+ ;;
4141+ MPICH)
4242+ # Fix to make mpich run in a sandbox
4343+ export HYDRA_IFACE=lo
4444+ ;;
4545+ MVAPICH)
4646+ # Disable CPU pinning
4747+ export MV2_ENABLE_AFFINITY=0
4848+ ;;
4949+ esac
5050+5151+ # Limit number of OpenMP threads. Default is "all cores".
5252+ export OMP_NUM_THREADS=1
5353+}
5454+
+4-9
pkgs/development/libraries/elpa/default.nix
···11-{ lib, stdenv, fetchurl, autoreconfHook, gfortran, perl
22-, mpi, blas, lapack, scalapack, openssh
11+{ lib, stdenv, fetchurl, autoreconfHook, mpiCheckPhaseHook
22+, gfortran, perl, mpi, blas, lapack, scalapack, openssh
33# CPU optimizations
44, avxSupport ? stdenv.hostPlatform.avxSupport
55, avx2Support ? stdenv.hostPlatform.avx2Support
···4141 substituteInPlace Makefile.am --replace '#!/bin/bash' '#!${stdenv.shell}'
4242 '';
43434444- nativeBuildInputs = [ autoreconfHook perl openssh ];
4444+ nativeBuildInputs = [ autoreconfHook perl ];
45454646 buildInputs = [ mpi blas lapack scalapack ]
4747 ++ lib.optional enableCuda cudatoolkit;
···76767777 doCheck = true;
78787979+ nativeCheckInputs = [ mpiCheckPhaseHook openssh ];
7980 preCheck = ''
8081 #patchShebangs ./
8181-8282- # make sure the test starts even if we have less than 4 cores
8383- export OMPI_MCA_rmaps_base_oversubscribe=1
8484-8585- # Fix to make mpich run in a sandbox
8686- export HYDRA_IFACE=lo
87828883 # Run dual threaded
8984 export OMP_NUM_THREADS=2