N_MPI=`nproc`

export OMPI_MCA_plm_rsh_agent=/bin/false
export OMPI_MCA_rmaps_base_oversubscribe=1

PETSC_DIR=/usr/lib/petsc
echo "Running petsc4py demos using PETSC_DIR=${PETSC_DIR}"

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

echo "Run demos (single processor) with python2"
make PETSC_DIR=${PETSC_DIR} -C test-demos all

echo "Run demos (MPI) with python2"
make PETSC_DIR=${PETSC_DIR} MPIEXEC="mpiexec -n ${N_MPI}" -C test-demos all-mpi

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

echo "Run demos (MPI) with python3"
make PETSC_DIR=${PETSC_DIR} PYTHON=python3 F2PY=f2py3 MPIEXEC="mpiexec -n ${N_MPI}" -C test-demos all-mpi
