#! /bin/csh
#
# Run mpptest to get communication performance.  
#
# Set defaults
set NP	    = 2
set SHORT   = 0
set LONG    = 0
set fname   = "-fname mpp.out"
set fbname  = "mpp.out"
set system  = "MPI"
set NATIVE  = ""
set PAIR    = 1
set OVERLAP = 1
set GOP	    = 1
set BISECT  = 1
set PLOT    = "Cit"
set GIVEDY  = ""
set MPIRUNOPT = ""
set BLOCKING = 1
set NONBLOCKING = 1
set mpirun = "mpirun"
if ($#argv > 0) then
    if ("$1" == "-help") then 
        echo "Run mpptest for round-trip messages from 0 to 1 MByte."
	echo "Output goes to stdout"
	echo " "
	echo "runmpptest [ -help ] [ -short ] [ -long ] [ -fname file ] [-gnuplot]"
	echo " [ -pair ] [ -gop ] [ -overlap ] [ -bisect ]"
	echo " [ -blocking ] [ -nonblocking ]"
	echo " [ -givedy ] "
	echo " [ -mpirun options ] [ -np n ]"
        exit
    endif
    while ( $#argv > 0 ) 
        switch ($1)

	case -short:
	shift
	set SHORT = 1
	breaksw

	case -long:
	shift
	set LONG = 1
        set SHORT = 0
	breaksw

	case -blocking:
	shift
	set NONBLOCKING = 0
	breaksw

	case -givedy:
	shift
	set GIVEDY  = "-givedy"
	breaksw

	case -nonblocking:
	shift
	set BLOCKING = 0
	breaksw

	case -np:
	shift
	set NP=$1
	shift
	breaksw

	case -fname:
	shift
        if ( "$1" == "-stdout" ) then
	    set fname = ""
	    set fbname = ""
	else 
	    set fname = "-fname $1"
	    set fbname = "$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 -pair:
	shift
	set BISECT  = 0
	set GOP     = 0
	set OVERLAP = 0
	breaksw

	case -bisect:
	shift
	set PAIR = 0
	set GOP = 0
	set OVERLAP = 0
	breaksw
	
	case -gop:
	shift
	set PAIR = 0
	set BISECT = 0
	set OVERLAP = 0
	breaksw

	case -overlap:
	shift
	set PAIR = 0
	set BISECT = 0
	set GOP = 0
	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'`
setenv MP_PROCS $NP
set GRAPH   = "$fname"
if ( $SHORT == 0 && $PLOT == "Cit") then
    set GRAPH11 = "-wx 1 2 -wy 2 2 $fname"
    set GRAPH12 = "-wx 2 2 -wy 2 2 $fname"
    set GRAPH21 = "-wx 1 2 -wy 1 2 $fname"
    set GRAPH22 = "-wx 2 2 -wy 1 2 $fname -lastwindow"
else
    set GRAPH11 = "$fname"
    set GRAPH12 = "$fname"
    set GRAPH21 = "$fname"
    set GRAPH22 = "$fname"
endif
#
# Choose the system to run with ...
set MPPTEST = "$mpirun $MPIRUNOPT -np $NP mpptest"
#
#
# Begin the tests
#
# Round-trip times, blocking (from 0 to 1 MBytes)
if ( $PAIR == 1 ) then
if ( $BLOCKING == 1 ) then
echo "Round trip tests-blocking"
if ( $LONG == 0 ) then
    $MPPTEST $GRAPH11 $GIVEDY -np 2 -tgoal 0.1 -auto 
endif
if ( $SHORT == 0 ) then 
    if ( $LONG == 0 ) then
    $MPPTEST $GRAPH12 $GIVEDY -np 2 -tgoal 0.1 -auto \
	    -size 1024 16384  256    -autodx 128 
    endif
    $MPPTEST $GRAPH21 $GIVEDY -np 2 -tgoal 0.5 -auto \
	    -size 16384 65536 1024   -autodx 512 -reps 100 
    if ( $LONG == 0 ) then
    $MPPTEST $GRAPH22 $GIVEDY -np 2 -tgoal 1.0 -auto \
	    -size 65536 1048576 8192 -autodx 8192 -reps 25
    endif
endif
endif
#
#
# Nonblocking times
if ( $NONBLOCKING == 1 ) then
echo "Round trip tests-nonblocking"
if ( $LONG == 0 ) then
    $MPPTEST $GRAPH11 $GIVEDY -async -np 2 -tgoal 0.1 -auto 
endif
if ( $SHORT == 0 ) then
    if ( $LONG == 0 ) then
    $MPPTEST $GRAPH12 $GIVEDY -async -np 2 -tgoal 0.1 -auto \
	    -size 1024 16384  256    -autodx 128 
    endif
    $MPPTEST $GRAPH21 $GIVEDY -async -np 2 -tgoal 0.5 -auto \
	    -size 16384 65536 1024   -autodx 512 -reps 100 
    if ( $LONG == 0 ) then
    $MPPTEST $GRAPH22 $GIVEDY -async -np 2 -tgoal 1.0 -auto \
	    -size 65536 1048576 8192 -autodx 8192 -reps 25
    endif
endif
endif
endif
#
if ( $BISECT == 1 ) then
#
# Bisection and contention tests
# Round-trip times, blocking (from 0 to 1 MBytes)
set BISECT = "-bisect -distance -nbrdbl"
if ( "$PLOT" == "gnuplot" ) then
    # Gnuplot doesn't have a nice way to handle multipage output in a single 
    # file, so we turn off the variable distance feature
    set BISECT = "-bisect"
endif
if ( $BLOCKING == 1 ) then
echo "Bisection tests-blocking"
if ( $LONG == 0 ) then
    $MPPTEST $GRAPH11 $BISECT -np $NP -tgoal 0.1 -auto 
endif
if ( $SHORT == 0 ) then 
    if ( $LONG == 0 ) then
    $MPPTEST $GRAPH12 $BISECT -np $NP -tgoal 0.1 -auto \
		-size 1024 16384  256    -autodx 128 
    endif
    $MPPTEST $GRAPH21 $BISECT -np $NP -tgoal 0.5 -auto \
	-size 16384 65536 1024   -autodx 512 -reps 100 
    #if ( $LONG == 0 ) then
    #$MPPTEST $GRAPH22 $BISECT -np $NP -tgoal 1.0 -auto \
    #	-size 65536 1048576 8192 -autodx 8192 -reps 25
    #endif
endif
endif
#
# Nonblocking times-bisection
if ( $NONBLOCKING == 1 ) then
echo "Bisection tests-nonblocking"
$MPPTEST $GRAPH11 $BISECT -async -np $NP -tgoal 0.1 -auto 
if ( $SHORT == 0 ) then
    $MPPTEST $GRAPH12 $BISECT -async -np $NP -tgoal 0.1 -auto \
	    -size 1024 16384  256    -autodx 128 
    $MPPTEST $GRAPH21 $BISECT -async -np $NP -tgoal 0.5 -auto \
	    -size 16384 65536 1024   -autodx 512 -reps 100 
    #$MPPTEST $GRAPH22 $BISECT -async -np $NP -tgoal 1.0 -auto \
    #	-size 65536 1048576 8192 -autodx 8192 -reps 25
endif
endif
endif
#
# Collective operation tests
#
if ( $GOP == 1 ) then
echo "Collective operation tests"
set COLL = "-gop $NATIVE"
$MPPTEST $COLL $fname -sync -np $NP -size 0 0 0
#
# We set sizes on these since they are with respect to either ints or 
# doubles, not bytes
foreach gop ( dsum col scatter )
    $MPPTEST $GRAPH11 $COLL -$gop -np $NP -tgoal 0.1 -auto \
	-size 0 256 8
    if ( $SHORT == 0 ) then
        $MPPTEST $GRAPH12 $COLL -$gop -np $NP -tgoal 0.1 -auto \
		-size 256 4096 64 -autodx 128 
    endif
end
endif
#
# Floating point overlap tests
#
if ( $OVERLAP == 1 ) then
echo "Round trip-floating-point overlaps tests-blocking"
set SIZE = "-overlapauto -autodx 64"
foreach msgsize ( -1 0 128 1024 2048 )
    $MPPTEST $GRAPH -sync -overlap -overlapmsgsize $msgsize -np 2 \
	-tgoal 0.1 -auto $SIZE
end
echo "Round trip-floating-point overlaps tests-nonblocking"
foreach msgsize ( 0 128 1024 2048 )
    $MPPTEST $GRAPH -async -overlap -overlapmsgsize $msgsize -np 2 \
	-tgoal 0.1 -auto $SIZE
end
endif

