#!/bin/sh -e

DEFAULT_MPI=$( grep ARCH_DEFAULT_MPI_IMPL /usr/share/mpi-default-dev/debian_defaults | sed "s/ARCH_DEFAULT_MPI_IMPL=//" )
NPROC=$( /usr/bin/nproc )

cd examples

if [ ! -x ./c_example ]; then
  cp ../debian/tests/Makefile.inc ..
  make MUMPS_MPI=${DEFAULT_MPI} all
fi

echo "\n=== running c_example (serial) ==="
./c_example
./c_example_save_restore

echo "\n\n=== running running c_example (MPI) ==="
mpirun -n $NPROC ./c_example
mpirun -n $NPROC ./c_example_save_restore

echo "\n\n=== running simple test: real, single precision, serial ==="
./ssimpletest < input_simpletest_real
./ssimpletest_save_restore < input_simpletest_real

echo "\n\n=== running simple test: real, double precision, serial ==="
./dsimpletest < input_simpletest_real
./dsimpletest_save_restore < input_simpletest_real

echo "\n\n=== running simple test: real, single precision, MPI ==="
mpirun -n $NPROC ./ssimpletest < input_simpletest_real
mpirun -n $NPROC ./ssimpletest_save_restore < input_simpletest_real

echo "\n\n=== running simple test: real, double precision, MPI ==="
mpirun -n $NPROC ./dsimpletest < input_simpletest_real
mpirun -n $NPROC ./dsimpletest_save_restore < input_simpletest_real

echo "\n\n=== running simple test: complex, single precision, serial ==="
./csimpletest < input_simpletest_cmplx
./csimpletest_save_restore < input_simpletest_cmplx

echo "\n\n=== running simple test: complex, double precision, serial ==="
./zsimpletest < input_simpletest_cmplx
./zsimpletest_save_restore < input_simpletest_cmplx

echo "\n\n=== running simple test: complex, single precision, MPI ==="
mpirun -n $NPROC ./csimpletest < input_simpletest_cmplx
mpirun -n $NPROC ./csimpletest_save_restore < input_simpletest_cmplx

echo "\n\n=== running simple test: complex, double precision, MPI ==="
mpirun -n $NPROC ./zsimpletest < input_simpletest_cmplx
mpirun -n $NPROC ./zsimpletest_save_restore < input_simpletest_cmplx
