#! /bin/sh
#
# Run the tests for the pingpong test
#
#MACH=anlsp2
MACH=`uname -s`
Show=eval
OPT="-O"
donopoll=1
do_html=0
#PATH=/usr/local/mpi/lib/rs6000/ch_mpl:$PATH
#PATH=/home/MPI/mpich/lib/rs6000/ch_mpl:$PATH
#export PATH
do_base=0
do_update=0
mpirunargs=""
#
for arg in "$@" ; do
    case $arg in 
	-echo) set -x ;;
        -np=*) NPLIST=`echo a$arg | sed "s/a-np=//"` ;;
	-base) do_base=1 ;;
	-show) Show=echo ;;
	-mach=*) MACH=`echo a$arg | sed "s/a-mach=//"` ;;
	-nopoll) mpirunargs="-nopoll" ;;
	-update) do_update=1 ;;
	-html) do_html=1 ;;
        -logs) echo "No logfiles for pingpong" ; exit 0 ;;
        *) echo "Unrecognized argument $arg" ; exit 1 ;;
    esac
done
#
if [ -z "$MPIEXMPL_MAX_NP" ] ; then MPIEXMPL_MAX_NP=16 ; fi
if [ $do_base = 1 ] ; then 
    if [ -s related.lst ] ; then 
	dirs=". `cat related.lst`"
    else
	dirs="."
    fi
    for dir in $dirs ; do
	( cd $dir ; \
	if [ $do_html = 1 ] ; then \
	    echo "<H2>`cat title.txt`</H2>" ; \
	    echo "<PRE>" ; \
	else cat title.txt ; fi ; \
	$Show make pingpong ; \
	  if [ -s maxnp ] ; then maxnp=`cat maxnp` ; \
	   if [ $MPIEXMPL_MAX_NP -lt $maxnp ] ; then maxnp=$MPIEXMPL_MAX_NP ; \
	   fi ; \
          else maxnp=2 ; fi ; \
	    np=2 ; \
	   while [ $np -le $maxnp ] ; do
	  $Show mpirun $mpirunargs -np $np -mvhome pingpong ; \
	   np=`expr 2 \* $np` ; done )
	if [ $do_html = 1 ] ; then
	    echo "</PRE>"
	fi
    done
    exit 0
fi
