#! /bin/csh
#
# Run goptest to get communication performance and scalability
#
# Set defaults
set MAXNP   = 8
set SIZE    = "-tgoal 0.1"
set fname   = "-fname gop.out"
set system  = "MPI"
set NATIVE  = ""
set BCAST   = 1
set DSUM    = 1
set SYNC    = 1
set MULT    = 2
set ADD     = 0
set PLOT    = "Cit"
set MPIRUNOPT = ""
set MPIRUN  = "mpirun"
if ($#argv > 0) then
    if ("$1" == "-help") then 
        echo "Run goptest for collective operations"
	echo "Output goes to stdout"
	echo " "
	echo "rungoptest [ -help ] [ -short ] [ -long ] [ -vlong ] "
        echo "           [ -maxnp n ] [ -fname file ]"
	echo "           [ -gnuplot ] [ -sync ] [ -dsum ] [ -bcast ]"
        echo "           [ -add ] [ -mpirun options ]"
	echo "           [ -mpirunpgm program ]"
        echo " An fname of -stdout will write all output to stdout"
	echo " -add choses nodes of the form 2*k instead of 2**k"
	echo " -mpirunpgm chooses a different version of mpirun"
        exit
    endif
    while ( $#argv > 0 ) 
        switch ($1)

	case -short:
	shift
	set SIZE = "-size 0 1024 256 -tgoal 0.1"
	breaksw

	case -long:
	shift
	set SIZE = "-size 1024 16384 2048 -tgoal 0.1"
	breaksw

	case -vlong:
	shift
	set SIZE = "-size 16384 65536 16384 -reps 100 -tgoal 0.5"
        breaksw

	case -maxnp:
	shift
	set MAXNP = $1
	shift
	breaksw

	case -fname:
	shift
        if ( "$1" == "-stdout" ) then
	    set fname = ""
	else 
	    set fname = "-fname $1"
	endif
	if ( "$PLOT" == "gnuplot" ) then
	    set fname = "-gnuplot $fname"
        endif
	shift
	breaksw

	case -gnuplot:
	shift
	set fname = "-gnuplot $fname"
	set PLOT  = "gnuplot"
	breaksw

	case -sync:
	shift
	set DSUM    = 0
	set BCAST   = 0
	breaksw

	case -bcast:
	shift
	set SYNC = 0
	set DSUM = 0
	breaksw
	
	case -dsum:
	shift
	set SYNC = 0
	set BCAST = 0
	breaksw

	case -add:
	shift
	set ADD = 2
	set MULT = 1
	breaksw 

	case -mpirun:
	shift
	set MPIRUNOPT = "$1"
	shift
	breaksw
	
	case -mpirunpgm:
	shift
	set MPIRUN = "$1"
	shift
	breaksw
	
	default:
	echo "Unknown option $1"
	shift 

	endsw
    end
endif
#
# SP1 systems require this and it does not hurt other systems
setenv PWD `pwd | sed 's%/tmp_mnt/%/%g'`
set GRAPH     = "$fname"
set GRAPHHEAD = ""
set GRAPHTAIL = "-notail"
#
# Choose the system to run with ...
set NP = 2
while ($NP <= $MAXNP) 
    setenv MP_PROCS $NP
    set GOPTEST = "$MPIRUN $MPIRUNOPT -np $NP goptest"
    set MPP = ""
    #
    # Begin the tests
    #
    # Round-trip times, blocking (from 0 to 1 MBytes)
    if ( $SYNC == 1 ) then
        if ($NP == 2) echo "# Synchronization time"
        $GOPTEST $GRAPH -tgoal 0.1 $GRAPHHEAD $GRAPHTAIL -sync
    endif
    #
    if ( $BCAST == 1 ) then
        #
        # Broadcast tsets
        if ($NP == 2) echo "# Broadcast tests"
        $GOPTEST $GRAPH -bcast $SIZE $GRAPHHEAD $GRAPHTAIL
    endif
    #
    # Collective operation tests
    #
    if ( $DSUM == 1 ) then
        if ($NP == 2) echo "# Reduction tests"
        #
        # We set sizes on these since they are with respect to either ints or 
        # doubles, not bytes
        $GOPTEST $GRAPH -dsum $SIZE $GRAPHHEAD $GRAPHTAIL
    endif
    #
    # End of the while on NP
    @ NP = $NP * $MULT + $ADD
    set GRAPHHEAD = "-nohead"
    # If we are the second to last iteration, remove the -notail option.
    if ($NP * $MULT + $ADD > $MAXNP) set GRAPHTAIL = ""
end 
