Skip to content

Instantly share code, notes, and snippets.

@aprell
Created November 8, 2011 17:52
Show Gist options
  • Save aprell/1348520 to your computer and use it in GitHub Desktop.
Save aprell/1348520 to your computer and use it in GitHub Desktop.
Script to install/update RCCE
#!/bin/bash
# Script to install/update RCCE
usage="rcceinstall [ emulator | SCC_LINUX | SCC_BAREMETAL ]"
RCCE_src_root=$HOME/RCCE_src
RCCE_root=$HOME/RCCE
RCCE_repo=http://marcbug.scc-dc.com/svn/repository/trunk/rcce
#RCCE_repo=http://marcbug.scc-dc.com/svn/repository/tags/RCCE_v1.1.0/
if [ $# -ne 1 ]; then
echo $usage
exit 0
fi
platform=$1
if [ "$platform" != "emulator" ] &&
[ "$platform" != "SCC_LINUX" ] &&
[ "$platform" != "SCC_BAREMETAL" ]; then
echo "Platform must be one of \"emulator\", \"SCC_LINUX\","\
"or \"SCC_BAREMETAL\""
echo $usage
exit 0
fi
echo "[1] Checking out latest revision from"
echo "$RCCE_repo"
svn checkout $RCCE_repo $RCCE_src_root
# Build the RCCE emulator with gcc instead of icc
if [ "$platform" == "emulator" ]; then
if [ ! -e "$RCCE_src_root/common/symbols.in.orig" ]; then
cp "$RCCE_src_root/common/symbols.in" "$RCCE_src_root/common/symbols.in.orig"
fi
# Build up one large string from the contents of the input file
text=""
while read; do
line=$REPLY
text+="$line"
# Line delimiter
text+=":"
done < "$RCCE_src_root/common/symbols.in"
# Search and replace
# No need for multiline pattern matching if we do it this way
echo "$text" | sed \
"s/# CCOMPILE=g++:# PLATFORMFLAGS=-fopenmp: CCOMPILE=icc: PLATFORMFLAGS=-openmp/"\
" CCOMPILE=gcc: PLATFORMFLAGS=-fopenmp:# CCOMPILE=icc:# PLATFORMFLAGS=-openmp/"\
> $RCCE_src_root/common/symbols.tmp
# Write output file
echo -n "" > "$RCCE_src_root/common/symbols.in"
OLDIFS=$IFS
IFS=":"
for line in `cat $RCCE_src_root/common/symbols.tmp`; do
echo "$line" >> "$RCCE_src_root/common/symbols.in"
done
IFS=$OLDIFS
rm $RCCE_src_root/common/symbols.tmp
fi
echo "[2] Configuring RCCE for $platform"
cd $RCCE_src_root
./configure $platform ADD_POWER_API
echo "[3] Building RCCE libraries"
./makeall > build.log 2>&1
if [ $? -ne 0 ]; then
echo "Error: Build failed"
echo "Please inspect $RCCE_src_root/build.log"
exit 1
fi
echo "[4] Installing RCCE in $RCCE_root"
mkdir -p $RCCE_root/bin $RCCE_root/hosts $RCCE_root/include $RCCE_root/lib
cp rccerun $RCCE_root/bin
ln -sf $RCCE_root/bin/rccerun $HOME/bin/rccerun
cp hosts/* $RCCE_root/hosts
cp include/* $RCCE_root/include
if [ "$platform" == "emulator" ]; then
cp bin/OMP/* $RCCE_root/lib
else
cp bin/$platform/*.a $RCCE_root/lib
cp bin/$platform/mpb $RCCE_root/bin
fi
echo "[5] Creating wrapper script for rccerun"
echo "\
#!/bin/bash
# Wrapper for rccerun
usage=\"run [-n number-of-cores] program [arguments]\"
RCCE_root=$RCCE_root
RCCE_hostfile=\$RCCE_root/hosts/rc.hosts.custom
RCCE_rccerun=\$RCCE_root/bin/rccerun
# Disable verbose error handling
while getopts :n: option
do
case \$option in
n) numcores=\$OPTARG
;;
?) echo \"Invalid option: -\$OPTARG\"
echo \$usage
exit 0
;;
esac
done
if [ \$OPTIND -gt \$# ]; then
echo \"Program needed\"
echo \$usage
exit 0
fi
if [ -z \"\$numcores\" ]; then
# Default: run on two cores
numcores=2
fi
shift \$((OPTIND-1))
prog=\$1
progname=\`basename \$prog\`
shift 1
args=\$@
if [ -z \"\$args\" ]; then
echo \"Running \\\"\$progname\\\" on \$numcores cores\"
else
echo \"Running \\\"\$progname \$args\\\" on \$numcores cores\"
fi
" > $RCCE_root/bin/run
if [ "$platform" == "SCC_LINUX" ] ||
[ "$platform" == "SCC_BAREMETAL" ]; then
echo -n "\
SHARED_root=/shared/\$USER
subdir=\$progname
mkdir -p \$SHARED_root/\$subdir
cp \$prog \$SHARED_root/\$subdir
# Make sure to execute rccerun under \$SHARED_root
cd \$SHARED_root/\$subdir
\$RCCE_rccerun -nue \$numcores -f \$RCCE_hostfile \$progname \$args
" >> $RCCE_root/bin/run
else # emulator
echo -n "\
\$RCCE_rccerun -nue \$numcores -f \$RCCE_hostfile \$prog \$args
" >> $RCCE_root/bin/run
fi
chmod u+x $RCCE_root/bin/run
ln -sf $RCCE_root/bin/run $HOME/bin/run
echo "[6] Creating script for generating custom hostfiles"
echo -n "\
#!/bin/bash
# Script to make a custom RCCE hostfile
# Example: rccehosts 10..12 26 6 creates a hostfile with lines
# 10
# 11
# 12
# 26
# 06
usage=\"rccehosts PID[..PID] ...\"
RCCE_root=$RCCE_root
RCCE_hostfile=\$RCCE_root/hosts/rc.hosts.custom
RCCE_hostfile_new=\$RCCE_hostfile.new
if [ \$# -eq 0 ]; then
echo \$usage
exit 0
fi
touch \$RCCE_hostfile_new
for exp in \$@; do
if [[ \"\$exp\" =~ \"..\" ]]; then
n1=\`echo \$exp | cut -d. -f1\`
n2=\`echo \$exp | cut -d. -f3\`
if [ \$n1 -gt \$n2 ] || [ \$n1 -lt 0 ] || [ \$n2 -lt 0 ]; then
echo \"Ignoring \$exp\"
continue
fi
if [ \$n2 -gt 47 ]; then
echo \"Changing \$exp to \$n1..47\"
n2=47
fi
for n in \`seq \$n1 \$n2\`; do
if [ \$n -lt 10 ]; then
echo 0\$n >> \$RCCE_hostfile_new
else
echo \$n >> \$RCCE_hostfile_new
fi
done
continue
fi
n=\$exp
if [ \$n -lt 0 ] || [ \$n -gt 47 ]; then
echo \"Ignoring \$n\"
continue
fi
if [ \$n -lt 10 ]; then
echo 0\$n >> \$RCCE_hostfile_new
else
echo \$n >> \$RCCE_hostfile_new
fi
done
mv \$RCCE_hostfile_new \$RCCE_hostfile
" > $RCCE_root/bin/rccehosts
chmod u+x $RCCE_root/bin/rccehosts
ln -sf $RCCE_root/bin/rccehosts $HOME/bin/rccehosts
# Create a custom hostfile equivalent to the standard rc.hosts
$HOME/bin/rccehosts 0..47
if [ "$platform" == "SCC_LINUX" ]; then
echo "[7] Creating script for killing processes on the SCC"
echo -n "\
#!/bin/bash
# Script to kill processes running on the cores of the SCC
usage=\"rccekill [-n number-of-cores] processname\"
RCCE_root=$RCCE_root
RCCE_hostfile=\$RCCE_root/hosts/rc.hosts.custom
SHARED_root=/shared/\$USER
PSSH_hostfile=\$SHARED_root/pssh.hosts.custom
killprog=\$SHARED_root/runpkill
# Disable verbose error handling
while getopts :n: option
do
case \$option in
n) numcores=\$OPTARG
;;
?) echo \"Invalid option: -\$OPTARG\"
echo \$usage
exit 0
;;
esac
done
if [ \$OPTIND -gt \$# ]; then
echo \"Process name needed\"
echo \$usage
exit 0
fi
if [ -z \"\$numcores\" ]; then
# Default: run on all cores
numcores=48
fi
shift \$((OPTIND-1))
processname=\$1
# Create custom killprog
# Note: we have no bash on the SCC
echo -n \"\\
#!/bin/sh
# Wrapper for pkill
if [ \\\$# -ne 1 ]; then
echo \\\"Need a process name\\\"
exit 1
fi
pkill -TERM \\\$1
if [ \\\$? -eq 1 ]; then
echo \\\"No process \\\\\\\"\\\$1\\\\\\\" on \\\`hostname\\\`\\\"
exit 0
fi
\" > \$killprog
chmod u+x \$killprog
# Create pssh hostfile from RCCE hostfile
echo -n \"\" > \$PSSH_hostfile
i=\$numcores
while read line && [ \$i -gt 0 ]; do
echo \"rck\$line root\" >> \$PSSH_hostfile
i=\$((i-1))
done < \$RCCE_hostfile
echo \"pssh -h \$PSSH_hostfile -P -p \$numcores \$killprog \$processname\"
pssh -h \$PSSH_hostfile -P -p \$numcores \$killprog \$processname
rm \$PSSH_hostfile
rm \$killprog
" > $RCCE_root/bin/rccekill
chmod u+x $RCCE_root/bin/rccekill
ln -sf $RCCE_root/bin/rccekill $HOME/bin/rccekill
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment