Friday, August 7, 2009

Poor Man's Cluster - Step 4

Poor Man's Cluster - Step 4
Topic: LinuxClusters

My students wrote a shell script called chopsplit.sh to scatter/gather the jobs.  We rendered several ray tracings using povray with this script (see zazzle site listed in my sig).  This file, chopsplit.sh, has to be in /home/cluster on the master node with permissions 755 (use chmod as root to change this).  You can write the following script in any text editor:
#!/bin/bash
#Arguments should be:
#pov file
#width
#height
#output file
#machines
if [[ $# -lt 5 ]]; then
echo "Usage: $0 scene width height output machines"
exit
fi
prefix=/home/cluster/povray-3.6/
imgdir=/home/cluster/distimg/
myip=`ip addr show | grep inet\ 10.5.129 | cut -f6- -d\ | cut -f-1 -d/`
if [[ ${1:0:1} == / ]]; then
scene=$1
else
scene=${1#scenes/}
fi
width=$2
height=$3
output=${4%.ppm}".ppm"
shift 4
tprocs=$(( $#*2 ))
procs=0
rm -f ${imgdir}/*
for a in $@; do
addr="10.5.129."${a#10.5.129.}
addr=${addr/10.5.129.self/127.0.0.1}
addr=${addr/10.5.129.localhost/127.0.0.1}
addr=${addr/10.5.129.127.0.0.1/127.0.0.1}
echo Starting $addr-1
ssh -x cluster@$addr "$prefix/povray +i$prefix/scenes/$scene -v -d -p +fp +w$width +h$height +sr$((procs*height/tprocs+1)) +er$(((procs+1)*height/tprocs)) +a0.3 +L$prefix/include +L$prefix/scenes/${scene%/*} +o- 2>/dev/null | chop - - $((9+${#width}+${#height})) && echo $addr-3 done 1>&2" >$imgdir/3$a${output} &
sizes[procs]=$((((procs+1)*height/tprocs-procs*height/tprocs)*3*width))
procs=$((procs+1))
echo Starting $addr-2
ssh -x cluster@$addr "$prefix/povray +i$prefix/scenes/$scene -v -d -p +fp +w$width +h$height +sr$((procs*height/tprocs+1)) +er$(((procs+1)*height/tprocs)) +a0.3 +L$prefix/include +L$prefix/scenes/${scene%/*} +o- 2>/dev/null | chop - - $((9+${#width}+${#height})) && echo $addr-4 done 1>&2" >$imgdir/4$a${output} &
sizes[procs]=$((((procs+1)*height/tprocs-procs*height/tprocs)*3*width))
procs=$((procs+1))
# echo $addr
done
echo ${sizes[@]}
procs=0
echo -e "P6\n$width $height\n255" > $output
for a in $@; do
until [[ `du -b $imgdir/3$a${output} 2>/dev/null | cut -f-1` -eq ${sizes[procs]} ]]; do
sleep 1
done
echo $a$output-3
cat $imgdir/3$a${output} >> $output
procs=$((procs+1))
until [[ `du -b $imgdir/4$a${output} 2>/dev/null | cut -f-1` -eq ${sizes[procs]} ]]; do
sleep 1
done
echo $a$output-4
cat $imgdir/4$a${output} >> $output
procs=$((procs+1))
done
echo $output built successfully!
Good Luck,

No comments:

Post a Comment