Difference between revisions of "Manchester mpirun.sh"

From GridPP Wiki
Jump to: navigation, search
 
(No difference)

Latest revision as of 15:11, 10 August 2007

NOTE: This has not been extensively tested.

#!/bin/sh
#
# this parameter is the binary to be executed
EXE=$1
# this parameter is the number of CPU's to be reserved for parallel execution
CPU_NEEDED=$2
echo "*************************************"
echo "PBS Nodefile: $PBS_NODEFILE "
cat $PBS_NODEFILE
echo "*************************************"

HOST_NODEFILE=
# prints the name of the master node
echo "Running on: $HOSTNAME"
echo "*************************************"
if [ -f "$PWD/.BrokerInfo" ] ; then
       echo 'BrokerInfo exists'
       TEST_LSF=`edg-brokerinfo getCE | cut -d/ -f2 | grep lsf`
else
       echo "BrokerInfo doesn't exist"
       TEST_LSF=`ps -ef | grep sbatchd | grep -v grep`
fi
echo 'Test for LSF: ->${TEST_LSF}<- '
if [ "x${TEST_LSF}" = "x" ] ; then
       echo "Test_LSF clear"
fi
if [ "x${TEST_LSF}" = "x" ] ; then
       # prints the name of the file containing the nodes allocated for parallel execution
       echo " TEST_LSF empty: PBS Nodefile: $PBS_NODEFILE"
       # print the names of the nodes allocated for parallel execution
       cat $PBS_NODEFILE
       echo "*************************************"
       HOST_NODEFILE="$PBS_NODEFILE"
       echo "host_nodefile : \${HOST_NODEFILE}"
       cat \${HOST_NODEFILE}
       echo "*************************************"
fi

echo "*************************************"
echo "Current dir: $PWD"
echo "*************************************"
echo "host_nodefile : \${HOST_NODEFILE}"
cat \${HOST_NODEFILE}
echo "*************************************"

for i in \`cat \${HOST_NODEFILE}\` ; do
       echo "Mirroring via SSH to $i"
       # creates the working directories on all the nodes allocated for parallel execution
       ssh \$i mkdir -p `pwd`
       # copies the needed files on all the nodes allocated for parallel execution
       /usr/bin/scp -rp ./* \$i:`pwd`
       # checks that all files are present on all the nodes allocated for parallel execution
       echo "*********************************"
       echo "pwd" `pwd`
       echo "*********************************"
       ssh  \$i ls `pwd`
       # sets the permissions of the files
       ssh  \$i chmod 755 `pwd`/$EXE
       ssh  \$i ls -alR `pwd`
       echo "@@@@@@@@@@@@@@@"
done

# execute the parallel job with mpirun
echo "*********************************"
echo "Executing $EXE"
chmod 755 $EXE
ls -l
mpirun -np $CPU_NEEDED -machinefile \${HOST_NODEFILE} `pwd`/$EXE > executable.out
echo "*********************************"