export OMPI_MCA_plm_rsh_agent=/bin/false
export OMPI_MCA_rmaps_base_oversubscribe=1

# testing on 5 processes is recommended by mpi4py upstream where possible
# and is safe to oversubscribe with OpenMPI
# (but oversubscribing might be a problem  - runs slow - with mpich)
# But the kspsolve demo requires a power of 2, so use 4 processes not 5.
N_MPI=4


PETSC_DIR=/usr/lib/petsc64
echo "Running 64-bit petsc4py demos using PETSC_DIR=${PETSC_DIR}"

# test demos as installed
cp -r /usr/share/doc/python-petsc4py-doc/examples/demo test-demos
gunzip -r test-demos

echo "Run 64-bit demos (single processor) with python3"
make PETSC_DIR=${PETSC_DIR} PYTHON=python3 F2PY=f2py3 -C test-demos all

echo "Run 64-bit demos (MPI) with python3"
echo "skipping wrap-swig and wrap-f2py MPI tests with 64-bit PETSc"
# Is it a clash with 32-bit MPI? Revisit once 64-bit MPI is available.
sed '0,/wrap-swig/!{s/\(.*wrap-swig\)/#\1/}; 0,/wrap-f2py/!{s/\(.*wrap-f2py\)/#\1/; }' -i test-demos/makefile
make PETSC_DIR=${PETSC_DIR} PYTHON=python3 F2PY=f2py3 MPIEXEC="mpiexec -n ${N_MPI}" -C test-demos all-mpi
