# run MPI tests are set up to run on no more than 3 processes
NPROC=$( nproc )
if [[ $NPROC > 2 ]]; then
  N_MPI=3
else
  N_MPI=2
fi
# and only 2 processes for unit tests
N_MPI_UNITTEST=2

export OMPI_MCA_plm_rsh_agent=/bin/false
export OMPI_MCA_rmaps_base_oversubscribe=1
export OMPI_MCA_btl_base_warn_component_unused=0

echo "== running python demos =="
cd python/demo

# help CI tests run a little faster
export DOLFINX_JIT_CFLAGS="-g0 -O2"

# static-condensation-elasticity.py uses numba,
# currently python3.8 only so handle separately
NUMBA_DEMO="condensation"
echo '{ "cache_dir": ".cache_fenicx_python3.8" }' >mixed-elasticity-sc/dolfinx_jit_parameters.json

TESTS_SKIPPED="cahn"
OTHER_TESTS_SKIPPED="gmsh"

MULTIPLE_SLOW_DEMO="hood"

case " i386 armhf " in \
  *\ ${DEB_HOST_ARCH}\ *) EXTRA_SLOW_DEMO="helmholtz";; \
esac

for test in $NUMBA_DEMO $MULTIPLE_SLOW_DEMO $EXTRA_SLOW_DEMO $OTHER_TESTS_SKIPPED; do
  TESTS_SKIPPED="$TESTS_SKIPPED or $test"
done
TEST_KEYWORDS="not ( $TESTS_SKIPPED )"


echo "=== python demo test (serial) ==="
python3 -m pytest -v --durations=20 -k "${TEST_KEYWORDS}" test.py

echo "=== python demo test (MPI using ${N_MPI} processors out of $NPROC)) ==="
python3 -m pytest -v -m mpi --durations=20 -k "${TEST_KEYWORDS}" test.py --mpiexec=mpiexec --num-proc=${N_MPI} --with-mpi
