#!/bin/bash
#
#   Syntax:  GrepTimings Counter NumProcs Filename
#
#   where Filename is an ML output file containing performance numbers
#         NumProcs is the number of processors used to generate the output
#         Counter  indicates which one in the sequence of scaling this 
#         file corresponds to. That is, GrepTimings is normally used
#         repeatedly on a series of files. For the first file, Counter is
#         1, and the second file it is 2, etc.
#
# Note: GrepTimings is used by Output2Matlab
#
/bin/rm -f  t1
echo "Proc($1) = $2;"
grep Amat_ $3 | grep -v artition | grep "apply+comm" > t1
grep min t1 | sed "s/Operator Amat_/AvMinTotal/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"
grep max t1 | sed "s/Operator Amat_/AvMaxTotal/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"

grep Rmat_ $3 | grep -v artition | grep "apply+comm" > t1
grep min t1 | sed "s/Operator Rmat_/RMin/" | sed "s/:.*=/($1)=/"  | sed "s/$/;/"
grep max t1 | sed "s/Operator Rmat_/RMax/" | sed "s/:.*=/($1)=/"  | sed "s/$/;/"

grep Pmat_ $3 | grep -v artition | grep "apply+comm" > t1
grep min t1 | sed "s/Operator Pmat_/PMin/" | sed "s/:.*=/($1)=/"  | sed "s/$/;/"
grep max t1 | sed "s/Operator Pmat_/PMax/" | sed "s/:.*=/($1)=/"  | sed "s/$/;/"

grep Amat_ $3 | grep -v artition | grep "exchange boundary time" > t1
grep min t1 | sed "s/Operator Amat_/AvMinComm/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"
grep max t1 | sed "s/Operator Amat_/AvMaxComm/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"

grep Rmat_ $3 | grep -v artition | grep "exchange boundary time" > t1
grep min t1 | sed "s/Operator Rmat_/RMinComm/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"
grep max t1 | sed "s/Operator Rmat_/RMaxComm/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"

grep Pmat_ $3 | grep -v artition | grep "exchange boundary time" > t1
grep min t1 | sed "s/Operator Pmat_/PMinComm/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"
grep max t1 | sed "s/Operator Pmat_/PMaxComm/" | sed "s/:.*=/($1)=/" | sed "s/$/;/"


