#!/bin/sh
# charmrun wrapper for blrun on BlueGene/L
# Translate charmrun command into blrun command: 
# blrun version "Jun 20 2005 09:05:02"
# usage:
# blrun
#      [--block <blockPattern>]
#      [--virtualNodeMode]
#      [--uid <userId>]
#      [--gid <groupId>]
#      [--home <homeDirectory>]
#      [--np <numProcessors>]
#      [--env <name=value>]*
#      [--timeout <numSeconds>]
#      [--debug <logicalRank>]
#      [--verbose]
#      [--noBoot]
#      [--noShutdown]
#      <program> [<arg>]*
#
# Currently (06/28/05) support --verbose, --virtualNodeMode, --timeout <s> and --np <P>
# Usage:
# ./charmrun +verbose +virtualNodeMode +timeout<s> +p<P> <program> [<arg>]*

args=""
timeout=120
pes=1

while [ $# -gt 0 ]
do
	case $1 in
	+verbose)
		args=$args" --verbose"
		;;
	+virtualNodeMode)
		args=$args" --virtualNodeMode"
		;;
	+timeout*)
		timeout=`echo $1 | awk '{print substr($1,9)}'`
		;;
	+p*)
		pes=`echo $1 | awk '{print substr($1,3)}'`
		;;
	*)
		args=$args" "$1
		;;
	esac
	shift
done

printf "\nRunning on $pes processors: timeout=$timeout args=$args\n"

blrun --np $pes --timeout $timeout $args 

if [ $? -ne 0 ] 
then 
  printf "\nHey, why don't you just try blrun???\n\n"
fi

