# =============================================================================
# Check all matrices in "../mat_test" directory.
# =============================================================================
echo " "

numProcs=4

DIR=../mat_smallset_a

# Remove previous results.
rm -f ${DIR}/*.out

# Process every matrix in ${DIR} directory.
for i in $( ls ${DIR}/atest*.in )
do
  echo -n "Testing file: " $i
  fileOut=${i%.in}.out
  #### echo "Output file is: " $fileOut
  mpiexec --hostfile hostfile -n $numProcs ./test_crc.x $i > $fileOut
  #### grep "Distance of input matrix:" $fileOut

  # Get the initial distance (the one in the name of the file).
  distInitial=$( echo $i | sed 's/^.*x//' | sed 's/\.in//' )
  #### echo "distInitial: " $distInitial

  # Get the computed distance by the code.
  distComputed=$( grep "Distance of input matrix:" $fileOut | \
                  sed 's/Distance of input matrix://' )
  #### echo "distComputed: " $distComputed

  # Get the number of end-of-program messages.
  numEndsOfProgram=$( grep "^% Process: .* End of Program" $fileOut | wc -l )
  #### echo "numEndsOfProgram: " $numEndsOfProgram

  # Check if everything is ok.
  if [ "$distInitial" -eq "$distComputed" ] && \
     [ "$numProcs" -eq "$numEndsOfProgram" ]
  then
    # Result was ok.
    resultOfTest="Ok"
    echo "    " $resultOfTest
  else
    # Failure.
    resultOfTest="!!! Failure !!!"
    echo "    " $resultOfTest
    #### echo "  "
  fi

  # Remove output file.
  #### rm $fileOut
done
echo

