#!/bin/sh -f # #this to prevent open from complaining # FORTRAN_OPENED_UNITS=200 [ "$TMPDIR" = "" ] && TMPDIR=/var/tmp VMDSCRATCH=$TMPDIR/$USER exported="TMPDIR VMDSCRATCH FORTRAN_OPENED_UNITS" [ -d $VMDSCRATCH ] || mkdir $VMDSCRATCH [ -d $VMDSCRATCH/xplor ] || mkdir $VMDSCRATCH/xplor XPLOR_DIR=__XPLOR_DIR__ exported="$exported XPLOR_DIR" PATH="/usr/bin:/bin:$PATH"; export PATH ARCH=`uname -sr |sed 's/ /_/g'` if [ `uname` = "Linux" ]; then # # ugly Linux-specific semphore cleanup # SEM=`ipcs -s -c | grep $USER | sed -e 's/ .*//' | egrep '^[0-9]'` for sem in $SEM; do pid=`ipcs -s -i $sem | tail -2 | head -1 |\ sed 's/.* \([0-9][0-9]* *$\)/\1/'` [ -d /proc/$pid ] || ipcrm sem $sem done #refine ARCH ARCH=`uname -sr | sed 's/\( [0-9]*\.[0-9]*\)\..*$/\1_/' | \ sed 's/ /_/g'``uname -m` fi if [ `uname` = "Darwin" ]; then # the last two digits change way too fast... ARCH=`echo $ARCH|sed 's/\([0-9]*\)\.[0-9]*\.[0-9]*$/\1/'` proc=`uname -p` if [ $proc = "i386" ]; then ARCH=${ARCH}_x86 fi fi if [ -d $XPLOR_DIR/bin.$ARCH ]; then arch=$ARCH else #see if arch is in equivList arch=`grep ' '${ARCH}$ $XPLOR_DIR/arch/equivList|cut -d' ' -f1|tail -1` fi XPLOR_EXE=$XPLOR_DIR/bin.$arch/xplor exported="$exported XPLOR_EXE" [ -x $XPLOR_EXE ] || { echo "xplor not configured for platform: $ARCH"; exit 1; } EXEC=exec #fix for Solaris' /bin/sh forking behavior which can cause SGICHLD to be # send to xplor binary if truely exec'd [ `uname` = "SunOS" ] && EXEC= #if [ $arch = "Linux_2.4_i686" ]; then # # # # kludge for Redhat kernels with back-ported thread library. Enable this # # code on Fedora Core 2 and similar systems. # # # LD_ASSUME_KERNEL="2.4.19" # exported="$exported LD_ASSUME_KERNEL" #fi ARCH=$arch exported="$exported ARCH" LD_LIBPATH_VAR=LD_LIBRARY_PATH if [ `uname` = "Darwin" ]; then LD_LIBPATH_VAR=DYLD_LIBRARY_PATH fi if [ "$LD_LIBRARYN32_PATH" != "" -a `uname` = "IRIX64" ]; then #special handling for Irix LD_LIBPATH_VAR=LD_LIBRARYN32_PATH fi eval "$LD_LIBPATH_VAR=$XPLOR_DIR/bin.${arch}:\$$LD_LIBPATH_VAR" exported="$exported $LD_LIBPATH_VAR" TCL_LIBRARY=$XPLOR_DIR/tcl/bin.${arch}/tcl TK_LIBRARY=$XPLOR_DIR/tcl/bin.${arch}/tk TCLLIBPATH="$XPLOR_DIR/tcl/bin.${arch} $XPLOR_DIR/bin.${arch}" exported="$exported TCL_LIBRARY TCLLIBPATH TK_LIBRARY" if [ "$XPLORNIH_PYTHONHOME" != "" ]; then PYTHONHOME=$XPLORNIH_PYTHONHOME else PYTHONHOME=$XPLOR_DIR/python/bin.${ARCH} fi if [ -d $PYTHONHOME ]; then exported="$exported PYTHONHOME" else unset PYTHONHOME fi PYTHONOPTIMIZE=1 PYTHONPATH=$XPLOR_DIR/python/bin.${arch}:$PYTHONPATH PYTHONPATH=$XPLOR_DIR/python:$XPLOR_DIR/python/wrappers:$PYTHONPATH PYTHONPATH=.:$XPLOR_DIR/bin.${arch}:$PYTHONPATH exported="$exported PYTHONPATH PYTHONOPTIMIZE" XPLOR_HELPDIR=$XPLOR_DIR/helplib/ exported="$exported XPLOR_HELPDIR" #xplor database paths CHEMSHIFTTENS=$XPLOR_DIR/databases/chemShiftTens GAUSSIANS=$XPLOR_DIR/databases/torsions_gaussians QUARTS=$XPLOR_DIR/databases/torsions_quarts DNA_DNA_PAIRS=$XPLOR_DIR/databases/dna_dna_pairs RNA_RNA_PAIRS=$XPLOR_DIR/databases/rna_rna_pairs C13SHIFTS=$XPLOR_DIR/databases/c13shifts PROTSHIFTS=$XPLOR_DIR/databases/protshifts HBDB=$XPLOR_DIR/databases/hbdb SAXS=$XPLOR_DIR/databases/saxs SYMMETRY=$XPLOR_DIR/xtallib TOPPAR=$XPLOR_DIR/toppar TOPPAR_C22=$XPLOR_DIR/toppar/charmm22 exported="$exported GAUSSIANS QUARTS DNA_DNA_PAIRS RNA_RNA_PAIRS C13SHIFTS" exported="$exported PROTSHIFTS HBDB SAXS SYMMETRY TOPPAR TOPPAR_C22" exported="$exported CHEMSHIFTTENS" #on SGIs: to dump core on floating point exception #TRAP_FPE="UNDERFL=ZERO; OVERFL=ABORT;DIVZERO=ABORT;INVALID=ABORT" #export TRAP_FPE #hack under Darwin: to prevent dyld from complaining about multiply defined # symbols # DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_BIND_AT_LAUNCH=1 exported="$exported DYLD_FORCE_FLAT_NAMESPACE DYLD_BIND_AT_LAUNCH" GFORTRAN_UNBUFFERED_ALL=1 exported="$exported GFORTRAN_UNBUFFERED_ALL" # # under xlf compiler, to get proper mixed C/Fortran io behavior # XLFRTEOPTS="buffering=disable_preconn" exported="$exported XLFRTEOPTS" #for echoing commands XPLOR_TRACE_LEVEL=${XPLOR_TRACE_LEVEL:-1} exported="$exported XPLOR_TRACE_LEVEL" #process number for parallel jobs XPLOR_PROCESS=0 exported="$exported XPLOR_PROCESS" XPLOR_NUM_PROCESSES=1 exported="$exported XPLOR_NUM_PROCESSES" XPLOR_PPORT=${XPLOR_PPORT:-9021} exported="$exported XPLOR_PPORT" XPLOR_PHOST=localhost exported="$exported XPLOR_PHOST" XPLOR_ALLOWSTARTUPFAILURES=1 exported="$exported XPLOR_ALLOWSTARTUPFAILURES" #number of processes to use in ensembleSimulation calculations NUM_THREADS=${XPLOR_NUM_THREADS:-1} exported="$exported NUM_THREADS" #echo $PYTHONPATH parallel_mode=0 export $exported usage () { echo "$0: [option]" echo " where option is one of" echo " -help - print this message." echo " -version - print version info, and a list of features" echo " -debug - run xplor under debugger given by cmd" echo echo " -notrace - turn command echoing off (set echo=off)" echo " -quiet - turn off verbose output (set messages=NONE)" echo " -nice <#> - specify a nice (see man nice) increment" echo echo " options for VMD-XPLOR:" echo " -host - specify host on which VMD is running" echo " -port - specify port for connection to VMD" echo echo " options for parallel jobs:" echo " -num_threads <#> - number of processors to use in" echo " ensemble calculations" echo " -thread_filename - prefix for thread output" echo " (use for ensemble calculations)" echo " ensemble calculations" echo " -parallel - spawn multiple jobs on remote hosts" echo " -machines - list of machines on which to run" echo " -crash_on_startup - specify this flag if you wish a parallel" echo " calculation to fail at startup if any" echo " process fails to startup. The default" echo " behavior is to continue the full calculation" echo " using only those processes which start." echo " -pport - alternate port for parallel communication" echo " [default value: $XPLOR_PPORT]" echo " -scyld <#> - on a Scyld cluster, specify the number of" echo " structures to run in parallel." echo " -smp <#> - on a multiprocessor node, specify the number of" echo " structures to run in parallel." echo " -o - specify prefix for log file." echo " name will be file.XPLOR_PROCESS" echo echo " options for alternate scripting interfaces:" echo " -py - invoke the Python interpreter" echo " -tcl - invoke the TCL interpreter" echo " -pydoc [options] - invoke the pydoc help facility" echo " -csh-env - print csh commands to appropriately set" echo " environment to use Xplor-NIH as an extension" echo " try: eval \`xplor -csh-env\`" echo " -sh-env - same as above for Bourne-derived shells" } PROGNAME=$0 nice=$XPLOR_NICECMD #arguments passed to parallel jobs pargs="" while [ -n "$1" ]; do opt="$1" shift case "$opt" in -help|-h|--help) usage exit 0 ;; -csh-env) for var in $exported; do cmd="echo \$$var" echo "setenv $var \""`eval $cmd`\"\; done exit 0 ;; -sh-env) for var in $exported; do cmd="echo \$$var" echo "$var=\""`eval $cmd`\"\; echo "export $var"\; done exit 0 ;; -version) output=`echo 'cpython ""\ ctcl ""\ dyna inte end stop' | xplor` [ $? -ne 0 ] && exit $? echo $output | sed 's/\([0123456789.][0123456789.]*\).*/\1/' features="" echo $output | grep '%ERR: command not available' >/dev/null \ || features="$features C++" echo $output | grep '%ERR: PYTHon command not available' >/dev/null \ || features="$features PYTHON" echo $output | grep '%ERR: TCL command not available' >/dev/null \ || features="$features TCL" #echo $output echo "features: $features" #echo stop | $XPLOR_EXE | head -1 | sed 's/^[^A-Z]*//' exit 0 shift ;; -debug) XPLOR_EXE="$1 $XPLOR_EXE" shift ;; -port) DP_PORT=$1 export DP_PORT shift pargs="$pargs -port $DP_PORT" ;; -host) DP_HOST=$1 export DP_HOST shift pargs="$pargs -host $DP_HOST" ;; -pport) XPLOR_PPORT=$1 export XPLOR_PPORT shift ;; -nice) nice="nice -n $1" shift pargs="$pargs -nice $1" ;; -phost) XPLOR_PHOST=$1 export XPLOR_PHOST shift ;; -parallel) parallel_mode=1 ;; -crash_on_startup) XPLOR_ALLOWSTARTUPFAILURES=0 export XPLOR_ALLOWSTARTUPFAILURES ;; -ppid) XPLOR_PPID=$1 export XPLOR_PPID shift ;; -process) XPLOR_PROCESS=$1 export XPLOR_PROCESS shift ;; -num_processes) XPLOR_NUM_PROCESSES=$1 export XPLOR_NUM_PROCESSES shift ;; -num_threads) NUM_THREADS=$1 export NUM_THREADS shift ;; -thread_filename) THREAD_FILENAME=$1 export THREAD_FILENAME shift pargs="$pargs -thread_filename $THREAD_FILENAME" ;; -directory) cd $1 shift ;; -machines) MACHINES=$1 shift ;; -notrace) XPLOR_TRACE_LEVEL=0 export XPLOR_TRACE_LEVEL pargs="$pargs -notrace" args="$args -notrace" ;; -o) outFile=$1 [ "$LAMRANK" != "" ] && outFile="$outFile".$LAMRANK [ "$MPD_JRANK" != "" ] && outFile="$outFile".$MPD_JRANK shift ;; -p4pg) MPI_P4PG=$1 export MPI_P4PG shift ;; -p4wd) MPI_P4WD=$1 export MPI_P4WD shift ;; -pydoc) args="-quiet -notrace -py $XPLOR_DIR/python/xplorDoc.py" ;; -program_name) PROGNAME=$1 shift ;; -scyld) SCYLD_PROCESSES=$1 parallel_mode=1 shift ;; -smp) SMP_PROCESSES=$1 parallel_mode=1 shift ;; *) arg=`echo "$opt"|sed 's/[ ?&|()*"'\/']/\\\\&/g'` args="$args $arg" ;; esac done export PROGNAME if [ -f "$MACHINES" ]; then MACHINES=`grep -v ^# $MACHINES` fi if [ "$SMP_PROCESSES" != "" ]; then if [ "$MACHINES" = "" ]; then while [ $SMP_PROCESSES -gt 0 ]; do SMP_PROCESSES=`expr $SMP_PROCESSES - 1` MACHINES="$MACHINES localhost" done fi fi #host names or addresses corresponding to MACHINES MACHINE_HOSTS=$MACHINES if [ $parallel_mode -ne 0 -a "$SCYLD_PROCESSES" != "" ]; then parallel_mode=1 XPLOR_RSH=bpsh # MACHINES can be manually set # # idea behind the logic below: # if num_threads<2: pack the jobs on cluster nodes, one per processor # if num_threads>=2: run one job per node # if [ "$MACHINES" = "" ]; then if [ $NUM_THREADS -lt 2 ]; then allNodes=`beomap --nolocal --np $SCYLD_PROCESSES --all-nodes|\ sed 's/:/\n/g'|uniq` cnt=0 MACHINES= for node in $allNodes; do np=`beostat --node=$node --cpuinfo | \ grep "num processors" | sed 's/[^0-9]*\([0-9]*\)/\1/'` cnt1=0 while [ $cnt1 -lt $np ]; do MACHINES="$MACHINES $node" cnt1=`expr $cnt1 + 1` cnt=`expr $cnt + 1` [ $cnt -ge $SCYLD_PROCESSES ] && break 2 done done else MACHINES=`beomap --nolocal --np $SCYLD_PROCESSES|sed 's/:/ /g'` fi fi MACHINE_HOSTS="" for machine in $MACHINES; do addr=`bpstat -a $machine` MACHINE_HOSTS="$MACHINE_HOSTS $addr" done fi if [ $parallel_mode -ne 0 -a "$MACHINES" = "" ]; then echo "no machines specified. Disabling -parallel..." parallel_mode=0 fi if [ $parallel_mode -eq 0 ]; then [ "$outFile" = "" ] && eval "$EXEC $nice $XPLOR_EXE $args" 9>&1 [ "$outFile" != "" ] && \ eval "$EXEC $nice $XPLOR_EXE $args" 9>&1 > $outFile 2>&1 fi # # now in parallel mode # children="" # # read stdin if we can # if [ ! -t 0 ]; then inputFile=".xplorInput.$$" cat > $inputFile [ -s $inputFile ] || inputFile="" fi rsh="ssh -n -x" [ "$XPLOR_RSH" != "" ] && rsh=$XPLOR_RSH numProcs=0 allLocal=t for host in $MACHINE_HOSTS; do eval "host$numProcs=$host" numProcs=`expr $numProcs + 1` [ "$machine" != "localhost" ] && allLocal=f done # if there are nonlocal machines in $MACHINE_HOSTS, host0 # must be a proper host name. [ "$host0" = "localhost" -a "$allLocal" = "f" ] && host0=`hostname` [ "$outFile" = "" ] && outFile=xplor.log.$$ dir=`pwd` count=0 for machine in $MACHINES; do cmd="$0 -directory $dir " cmd="$cmd -ppid $$" cmd="$cmd -pport $XPLOR_PPORT -phost $host0" cmd="$cmd -process $count -num_processes $numProcs" if [ $XPLOR_ALLOWSTARTUPFAILURES -eq 0 ]; then cmd="$cmd -crash_on_startup" fi cmd="$cmd $pargs" cmd="$cmd -num_threads $NUM_THREADS $args" cmd="$cmd -o $outFile.$count" if [ "$inputFile" != "" ]; then cmd="$cmd `pwd`/$inputFile" fi if [ "$machine" = "localhost" ]; then eval "$cmd &" else eval "$rsh $machine $cmd &" fi children="$children $!" count=`expr $count + 1` done child0=`echo $children|cut -d' ' -f1` killChildren () { trap - INT kill $children } trap killChildren INT # # wait for first child to finish # wait $child0 [ "$inputFile" = "" ] || rm -f $inputFile