···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+
···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 '';
4344- nativeBuildInputs = [ autoreconfHook perl openssh ];
4546 buildInputs = [ mpi blas lapack scalapack ]
47 ++ lib.optional enableCuda cudatoolkit;
···7677 doCheck = true;
78079 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
8788 # Run dual threaded
89 export OMP_NUM_THREADS=2