head	1.11;
access;
symbols
	charm6_1:1.11
	charm_6_0_1:1.11
	charm6_0_1:1.11
	charm6_0:1.11
	ChaNGa_1-0:1.11
	charm5_9:1.9;
locks; strict;
comment	@# @;


1.11
date	2005.09.07.02.56.53;	author gzheng;	state Exp;
branches;
next	1.10;

1.10
date	2005.08.22.19.56.17;	author gzheng;	state Exp;
branches;
next	1.9;

1.9
date	2005.02.08.09.20.23;	author gzheng;	state Exp;
branches;
next	1.8;

1.8
date	2005.02.06.19.00.05;	author gzheng;	state Exp;
branches;
next	1.7;

1.7
date	2005.01.06.17.41.44;	author gzheng;	state Exp;
branches;
next	1.6;

1.6
date	2004.08.19.22.11.49;	author olawlor;	state Exp;
branches;
next	1.5;

1.5
date	2003.12.10.07.19.49;	author gzheng;	state Exp;
branches;
next	1.4;

1.4
date	2003.07.09.16.25.24;	author olawlor;	state Exp;
branches;
next	1.3;

1.3
date	2002.10.23.21.11.29;	author olawlor;	state Exp;
branches;
next	1.2;

1.2
date	2002.10.22.17.34.40;	author olawlor;	state Exp;
branches;
next	1.1;

1.1
date	2002.04.26.19.11.08;	author milind;	state Exp;
branches;
next	;


desc
@@


1.11
log
@better handling of making nodes and cpus out of ++p cpus. Ctl-c get rid of the job.
@
text
@#!/bin/sh
#
# Conv-host for HP/Compaq prun-style Supercomputers:
#  Translates +pN-style charmrun options into prun options

args=""
pes=1

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

# Try to guess the number of nodes
nodes=$pes
ppn=0
if [ ! "$RMS_NODES" = "" ] 
then
  ppn=`expr $RMS_PROCS / $RMS_NODES`
  test $pes -gt $RMS_NODES && nodes=$RMS_NODES
fi
for i in 4 2 3
do
  [ $ppn -ne 0 -a $i -gt $ppn ] && continue
  if [ `expr $pes / $i '*' $i` -eq $pes ]
  then
	nodes=`expr $pes / $i`
	break
  fi
done

extra="-N $nodes -n $pes "

# Prepend path to executable
args=`pwd`/"$args"

if [ ! "$RMS_NODES" = "" ]
then
# Running from a batch script: just use prun
	if test $pes -gt $RMS_PROCS
        then
	  echo "Charmrun> too many processors requested!"
        fi
	echo "Charmrun running> prun $extra $args"
	prun $extra $args	
else
# Interactive mode: create, and submit a batch job
	script="charmrun_script.$$.sh"
	indir=`pwd`
	output="./charmrun_script.$$.stdout"
	echo "Submitting batch job for> prun $extra $args"
	echo " using the command> qsub $script"
	cat > $script << EOF
#!/bin/sh
# This is a charmrun-generated PBS batch job script.
# The lines starting with #PBS are queuing system flags:

# This determines the number of nodes and pes (here $nodes and $pes):
#PBS -l rmsnodes=$nodes:$pes

# This determines the wall-clock time limit (here 5 minutes):
#PBS -l walltime=10:00

# This specifies we don't want e-mail info. on this job:
#PBS -m n

# This combines stdout and stderr into one file:
#PBS -j oe

# This specifies the file to write stdout information to:
#PBS -o $output

# Change to the directory where charmrun was run:
cd $indir

# This is the actual command to run the job:
prun $extra $args > $output 2>&1
EOF
	chmod 755 $script
	jobid=`qsub $script`
	echo "Job enqueued under job ID $jobid"

End() {
        echo "autobuild> qdel $jobid ..."
        qdel $jobid
        rm -f $script
        exit $1
}

	trap 'End 1' 2 3
	retry=0
# Wait for the job to complete, by checking its status
	while [ true ]
	do
		qstat $jobid > tmp.$$
		exitstatus=$?
		if [ -f $output ]
		then
# The job is done-- print its output			
			rm tmp.$$ $script
			if `grep 'End of program' $output > /dev/null 2>&1`
                        then
                                exec cat $output
                        else
                                cat $output
                                rm $output
                                exit 1
                        fi
		fi
# The job is still queued or running-- print status and wait
		tail -1 tmp.$$
		rm tmp.$$
		if test $exitstatus -ne 0
                then
# retry a few times when error occurs
                        retry=`expr $retry + 1`
                        if test $retry -gt 6
                        then
                                echo "Charmrun> too many errors, abort!"
                                exit 1
                        else
                                sleep 15
                        fi
                else
# job still in queue
                        retry=0
                        sleep 20
                fi
	done
fi
@


1.10
log
@added back missing output.
@
text
@d29 5
a33 1
[ ! "$RMS_NODES" = "" ] && ppn=`expr $RMS_PROCS / $RMS_NODES`
d52 4
d94 9
@


1.9
log
@change the way output is generated.
@
text
@d75 1
a75 1
##PBS -o $output
@


1.8
log
@a few changes to make it more robust in face of errors.
@
text
@d54 1
a54 1
	output="$indir/charmrun_script.$$.stdout"
d66 1
a66 1
#PBS -l walltime=5:00
d75 1
a75 1
#PBS -o $output
d81 1
a81 1
prun $extra $args
@


1.7
log
@return correct status and does better cleanup
@
text
@d86 1
d91 2
a92 1
		if [ ! $? -eq 0 ]
d96 1
a96 1
			if `grep 'End of program' $output > /dev/null 2>/dev/null`
d108 16
a123 1
		sleep 5
@


1.6
log
@Put a "cd $currentdir" into the script charmrun generates.
    Without this, batch jobs (now?) run in $HOME by default.
@
text
@d93 9
a101 2
			rm tmp.$$
			exec cat $output
@


1.5
log
@when using charmrun, make sure the proc per node calcualted by the guess do not beyond the actual proc per node.
for example in situation like rmsnodes=2:2,
./charmrun +p2
should not be  prun -N1 -n2
but   prun -N2 -n2
@
text
@d53 2
a54 1
	output=`pwd`"charmrun_script.$$.stdout"
d77 3
@


1.4
log
@Fixes for LANL's QSC machine-- use RMS_NODES to
tell if we're called from a parallel partition or not.
@
text
@d28 2
d32 1
@


1.3
log
@Exit with proper error code.
@
text
@d3 1
a3 1
# Conv-host for Lemieux:
d42 1
a42 1
if [ ! "$PBS_JOBID" = "" ]
@


1.2
log
@Prepare a short-time-limit batch job if run in interactive mode.
This is convenient for ordinary users, but absolutely necessary
for automated testing.
@
text
@d85 1
a85 2
# The job is done-- print its output
			cat $output
d87 1
a87 1
			exit 1
a94 1

@


1.1
log
@added non-functional elan version. compiles but does not run.
@
text
@d42 32
a73 1
echo "Running> prun $extra $args"
d75 22
@

