#!/bin/sh
#
# This script runs the available preconditioners twice,
# once with setup from the source code, once with command line
# options overriding the setup in the source.
#
echo "Preliminary cleanup .."
make clean_examples > /dev/null
rm -f Test.*
touch Test.out
#
# Following are the command line options that are used in the second
# run of the various methods.
#
aschwarz_options="-pc_halo_size 3 -sub_pc_type lu" \
    export aschwarz_options
mschwarz_options="-pc_pipeline sequential -sub_pc_type lu" \
    export aschwarz_options
gbssor_options="-pc_noglobal_fac -sub_pc_type sor -sub_pc_sor_symmetric -pc_pipeline none" \
    export aschwarz_options
#
# Loop over the available methods, calling each twice.
#
for method in none jacobi aschwarz mschwarz gbssor mlevel ; 
do  echo $method ".."
    make $method 1>/dev/null
    mpirun -np 2 $method -size 20 \
        | tee Test.$method.out.0 \
        | awk '/Number of iterations/ {print method,$4}' method=$method \
        | tee Test.tmp
        if [ -f Test.tmp ] ; then cat >>Test.out < Test.tmp; fi
    if [ $method != "none" -a $method != "jacobi" \
                -a $method != "mlevel" ] ; then \
      eval mpirun -np 2 $method -size 20 \$${method}_options \
          | tee Test.$method.out.1 \
          | awk '/Number of iterations/ {print method,$4}' method=$method \
          | tee Test.tmp
          if [ -f Test.tmp ] ; then cat >>Test.out < Test.tmp; fi \
    elif [ $method = "mlevel" ] ; then \
      for ver in 1 2 3 4 ; \
      do \
        eval mpirun -np 2 $method -size 20 -method $ver \
          | tee Test.$method.out.$ver \
          | awk '/Number of iterations/ {print method,$4}' method=$method \
          | tee Test.tmp
          if [ -f Test.tmp ] ; then cat >>Test.out < Test.tmp; fi \
      done ; \
    fi
done

echo "There were" `diff Test.out Reference | wc -l` "errors"
