#! /bin/ksh function message { echo "$*" 1>&2 } function die { message "$*" exit 2 } set -x case Q"$MP_PGMMODEL" in Q[mM][pP][mM][dD]) if [[ -z "$MP_CMDFILE" ]] ; then die "BY GOLLY!! You have not set the \$MP_CMDFILE variable. Either fill one in, or use SPMD. ABORTING" fi if [[ ! -s "$MP_CMDFILE" ]] ; then die "GOLLY GEE!! Your \$MP_CMDFILE (\"$MP_CMDFILE\") is empty or non-existant. Don't know what to do. ABORTING" fi if [[ ! -z "$TOTAL_TASKS" ]] ; then them_lines=$( cat "$MP_CMDFILE" | perl -ne '/^\s*$/ and next; $x++; END { print "$x\n" }' ) if [[ "$them_lines" != "$TOTAL_TASKS" ]] ; then die "WHOA NELLY!! Your \$MP_CMDFILE (\"$MP_CMDFILE\") has $them_lines lines, but \$TOTAL_TASKS=$TOTAL_TASKS!! You had better fix that in the kick_script. ABORTING" fi fi # Run sync to ensure we're using the most up-to-date copy of # the command file (to get around Jet's aggressive file # caching): sync # For MPMD, we have to do some extra work. The below perl # command generates an "mpiexec ..." command that the 'exec' # command will execute. exec $( cat "$MP_CMDFILE" | perl -ne ' chomp; # remove end-of-line char /^\s*$/ and next; # discard blank lines if($#c>=0 && $c[$#c] eq $_) { # This command is the same as the previous, so just increment that # commands -np N instead of inserting a new command: $n[$#n]++; } else { # Add this command to the list with -np 1 push @c, $_; push @n, 1; } END { # Now that we have read in the input, generate a command. print "mpiexec "; for($i=0; $i<=$#n; $i++) { # loop over all print "-np $n[$i] -envall $c[$i]"; if($i<$#n) { print " : "; } } } ' ) ;; *) # If we're not doing MPMD, assume SPMD if ( echo "$1" | grep / > /dev/null ) ; then # Caller specified the path to an executable, so make sure # that executable exists, is non-empty and is executable if [[ ! -e "$1" ]] ; then message "SLIVERING SNAKES!! Your program \"$1\" does not seem to exist! I'll try executing it anyway but this will probably fail..." elif [[ ! -s "$1" ]] ; then message "WHOPPING WILLABIES!! Your program \"$1\" seems to be empty! I'll try executing it anyway but this will probably fail..." elif [[ ! -x "$1" ]] ; then message "BUCKING BRONCOS!! Your program \"$1\" does not seem to be executable. I'll try executing it anyway but this will probably fail..." fi fi if [[ "$TOTAL_TASKS" -gt 1 ]] ; then exec mpiexec -envall -np "$TOTAL_TASKS" $* elif [[ "$TOTAL_TASKS" == 1 ]] ; then message "WARNING: RUNNING ONLY ONE TASK SO RUNNING IT DIRECTLY INSTEAD OF USING MPIRUN (TO WORK AROUND A JET BUG)." exec $* die "OOPES!! Unable to run $*. ABORTING" else message "WARNING: \$TOTAL_TASKS IS NOT SPECIFIED OR IS NOT A POSITIVE NUMBER, SO I WILL NOT SPECIFY -np WHEN RUNNING mpiexec" exec mpiexec -envall $* fi esac # Should never get here. exit 99