#!/bin/bash
set -e

# use only 2 processes for MPI unit tests
NP=2

# but report how many are available, in case there are MPI errors
echo "This system has `nproc` processors available."
echo "${NP} processors are used in MPI tests"

export PRTE_MCA_plm_ssh_agent=/bin/false
export PRTE_MCA_rmaps_default_mapping_policy=":oversubscribe"
export OMPI_MCA_btl_base_warn_component_unused=0

# mpich sends warning messages to stderr, at least on 32-bit arches
ARCH_DEFAULT_MPI_IMPL=`grep ARCH_DEFAULT_MPI_IMPL /usr/share/mpi-default-dev/debian_defaults | sed "s/^ARCH_DEFAULT_MPI_IMPL=//"`
if [ "x$ARCH_DEFAULT_MPI_IMPL" = "xmpich" ]; then
  error_out=/dev/stdout
else
  error_out=/dev/stderr
fi

for pyver in `py3versions -sv`; do
  mpirun -n $NP python$pyver -m pytest -v --color=no 2>${error_out}
done
