#!/bin/sh 

# MPIRUN
# This script tries to start jobs on whatever kind of machine you're on.
# Strategy - This program is built with a default device it uses in
# certain ways. The user can override this default from the command line.
#
# This sh script is designed to use other scripts to provide the commands
# to run each system, using the . filename.sh mechanism

#set verbose
MPIR_HOME=#MPIR_HOME#
if [ "$MPIR_HOME" = "#""MPIR_HOME""#" ] ; then
    MPIR_HOME=`pwd`/..
fi
#
# This is complicated by the fact that we want to use EITHER bin (for 
# single device installations) or lib/#LARCH#/#DEVICE# for multiple
# device installations.
if [ "#MPIRUN_BIN#" = "#""MPIRUN_BIN""#" ] ; then 
    MPIRUN_HOME=$MPIR_HOME/bin
else
    MPIRUN_HOME=$MPIR_HOME/#MPIRUN_BIN#
fi
#
# Local routines
#
# End of routine

#
#
# Special, system specific values
#
# polling_mode is for systems that can select between polling and 
# interrupt-driven operation.  Currently, only IBM POE is so supported
# (TMC CMMD has some support for this choice of mode)
polling_mode=1

# Parse command line arguments
# The ultimate goal is to determine what kind of parallel machine this
# is we are running on. Then we know how to start jobs...
#
# Process common arguments (currently does ALL, but should pass unrecognized
# ones to called files)
#
hasprinthelp=1
. $MPIRUN_HOME/mpirun.args
argsset=1

#
# Jump to the correct code for the device (by pseudo machine)
#
mpirun_version=""
case $machine in
    ch_cmmd)
	mpirun_version=$MPIRUN_HOME/mpirun.ch_cmmd
	;;
    ibmspx|ch_eui|ch_mpl)
	mpirun_version=$MPIRUN_HOME/mpirun.ch_mpl
	;;
    anlspx)
	mpirun_version=$MPIRUN_HOME/mpirun.anlspx
	;;
    ch_meiko|meiko)
	mpirun_version=$MPIRUN_HOME/mpirun.meiko
	;;
    cray_t3d|t3d)
	mpirun_version=$MPIRUN_HOME/mpirun.t3d
	;;
    ch_nc)
	mpirun_version=$MPIRUN_HOME/mpirun.ch_nc
	;;
    paragon|ch_nx|nx)
	mpirun_version=$MPIRUN_HOME/mpirun.paragon
	;;
    inteldelta)
	mpirun_version=$MPIRUN_HOME/mpirun.delta
	;;
    i860|ipsc860)
	mpirun_version=$MPIRUN_HOME/mpirun.i860
	;;
    p4|ch_p4|sgi_mp)
	mpirun_version=$MPIRUN_HOME/mpirun.ch_p4
	;;
    execer)
	mpirun_version=$MPIRUN_HOME/mpirun.execer
	;;
    ch_shmem|ch_spp|smp|convex_spp)
	# sgi_mp is reserved for the p4 version
	mpirun_version=$MPIRUN_HOME/mpirun.ch_shmem
    	;;
    ksr|symm_ptx)
	mpirun_version=$MPIRUN_HOME/mpirun.p4shmem
	;;
    ch_tcp|tcp)
	mpirun_version=$MPIRUN_HOME/mpirun.ch_tcp
	;;
    ch_nexus|nexus)
	mpirun_version=$MPIRUN_HOME/mpirun.nexus
	;;
    chameleon)
	mpirun_version=$MPIRUN_HOME/mpirun.ch
	;;
    *)    
	#
	# This allows us to add a device without changing the base mpirun
	# code
	if [ -x $MPIRUN_HOME/mpirun.$device ] ; then
	    mpirun_version=$MPIRUN_HOME/mpirun.$device
	elif [ -x $MPIRUN_HOME/mpirun.$default_device ] ; then
	    mpirun_version=$MPIRUN_HOME/mpirun.$default_device
	    device=$default_device
	else
	    echo "Cannot find MPIRUN machine file for machine $machine"
	    echo "and architecture $arch ."
            if [ -n "$device" ] ; then
	        echo "(Looking for $MPIRUN_HOME/mpirun.$device)"
	    else
	        echo "(No device specified.)"
            fi
	    # . $MPIRUN_HOME/mpirun.default
	    exit 1
	fi
  	;;
esac
if [ -n "$mpirun_version" ] ; then
    if [ -x $mpirun_version ] ; then
        . $mpirun_version
    else
       	echo "$mpirun_version is not available."
	    exit 1
    fi
else
    echo "No mpirun script for this configuration!"
    exit 1
fi
exit 0

