2010-05-27 10:48:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# ========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
# \\ / F ield | foam-extend: Open Source CFD
|
2010-05-27 10:48:11 +00:00
|
|
|
# \\ / O peration |
|
2013-12-11 16:09:41 +00:00
|
|
|
# \\ / A nd | For copyright notice see file Copyright
|
2010-05-27 10:48:11 +00:00
|
|
|
# \\/ M anipulation |
|
2010-12-27 11:44:51 +00:00
|
|
|
#------------------------------------------------------------------------------
|
2010-05-27 10:48:11 +00:00
|
|
|
# License
|
2013-12-11 16:09:41 +00:00
|
|
|
# This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
#
|
2013-12-11 16:09:41 +00:00
|
|
|
# foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-27 10:48:11 +00:00
|
|
|
# under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
# Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-27 10:48:11 +00:00
|
|
|
# option) any later version.
|
|
|
|
#
|
2013-12-11 16:09:41 +00:00
|
|
|
# foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
2010-05-27 10:48:11 +00:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
# along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-27 10:48:11 +00:00
|
|
|
#
|
|
|
|
# Script
|
|
|
|
# mpirunDebug
|
|
|
|
#
|
|
|
|
# Description
|
|
|
|
# Driver script to run mpi jobs with the processes in separate
|
|
|
|
# windows or to separate log files.
|
|
|
|
# Requires bash on all processors.
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
if [ `uname -s` = Linux ]
|
|
|
|
then
|
|
|
|
ECHO='echo -e'
|
2010-05-12 13:27:55 +00:00
|
|
|
else
|
2010-05-27 10:48:11 +00:00
|
|
|
ECHO='echo'
|
2010-05-12 13:27:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
printUsage() {
|
2010-05-27 10:48:11 +00:00
|
|
|
echo ""
|
|
|
|
echo "Usage: ${0##*/} -np <dd> <executable> <args>"
|
|
|
|
echo ""
|
|
|
|
echo "This will run like mpirun but with each process in an xterm"
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nProcs=''
|
|
|
|
exec=''
|
|
|
|
args=''
|
|
|
|
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
echo "$1"
|
|
|
|
case $1 in
|
|
|
|
-np)
|
2010-05-27 10:48:11 +00:00
|
|
|
nProcs=$2
|
|
|
|
shift
|
2010-05-12 13:27:55 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ ! "$exec" ]; then
|
|
|
|
exec=$1
|
|
|
|
elif [ ! "$args" ]; then
|
|
|
|
args="\"$1\""
|
|
|
|
else
|
|
|
|
args="$args \"$1\""
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "nProcs=$nProcs"
|
|
|
|
echo "exec=$exec"
|
|
|
|
echo "args=$args"
|
|
|
|
|
|
|
|
if [ ! "$nProcs" ]; then
|
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! "$args" ]; then
|
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! "$exec" ]; then
|
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
exec=`which $exec`
|
|
|
|
if [ ! -x "$exec" ]; then
|
|
|
|
echo "Cannot find executable $exec or is not executable"
|
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-05-27 10:48:11 +00:00
|
|
|
if [ ! "$PWD" ]; then
|
|
|
|
PWD=`pwd`
|
|
|
|
fi
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-05-27 10:48:11 +00:00
|
|
|
echo "run $args" > $PWD/gdbCommands
|
|
|
|
echo "where" >> $PWD/gdbCommands
|
|
|
|
echo "Constructed gdb initialization file $PWD/gdbCommands"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-12-02 17:04:28 +00:00
|
|
|
$ECHO "Choose running method: 0)normal 1)gdb+xterm 2)gdb 3)log 4)log+xterm 5)xterm+valgrind 6)nemiver: \c"
|
2010-05-12 13:27:55 +00:00
|
|
|
read method
|
2010-12-02 17:04:28 +00:00
|
|
|
if [ "$method" -ne 0 -a "$method" -ne 1 -a "$method" -ne 2 -a "$method" -ne 3 -a "$method" -ne 4 -a "$method" -ne 5 -a "$method" -ne 6 ]; then
|
2010-05-12 13:27:55 +00:00
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
$ECHO "Run all processes local or distributed? 1)local 2)remote: \c"
|
|
|
|
read spawn
|
|
|
|
if [ "$spawn" -ne 1 -a "$spawn" -ne 2 ]; then
|
|
|
|
printUsage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check ~/.$WM_PROJECT/$WM_PROJECT_VERSION/
|
|
|
|
# check ~/.$WM_PROJECT/
|
|
|
|
# check <installedProject>/etc/
|
|
|
|
if [ "$WM_PROJECT" ]; then
|
|
|
|
|
|
|
|
for i in \
|
|
|
|
$HOME/.WM_PROJECT/$WM_PROJECT_VERSION \
|
|
|
|
$HOME/.WM_PROJECT \
|
|
|
|
$WM_PROJECT_DIR/etc \
|
|
|
|
;
|
|
|
|
do
|
|
|
|
if [ -f "$i/bashrc" ]; then
|
|
|
|
sourceFoam="$i/bashrc"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Construct test string for remote execution.
|
|
|
|
# Source OpenFOAM settings if OpenFOAM environment not set.
|
|
|
|
# attempt to preserve the installation directory 'FOAM_INST_DIR'
|
|
|
|
if [ "$FOAM_INST_DIR" ]; then
|
|
|
|
sourceFoam='[ "$WM_PROJECT" ] || '"FOAM_INST_DIR=$FOAM_INST_DIR . $sourceFoam"
|
|
|
|
else
|
|
|
|
sourceFoam='[ "$WM_PROJECT" ] || '". $sourceFoam"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "**sourceFoam:$sourceFoam"
|
|
|
|
|
2010-05-27 10:48:11 +00:00
|
|
|
rm -f $PWD/mpirun.schema
|
|
|
|
touch $PWD/mpirun.schema
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
proc=0
|
|
|
|
xpos=0
|
|
|
|
ypos=0
|
|
|
|
for ((proc=0; proc<$nProcs; proc++))
|
|
|
|
do
|
2010-05-27 10:48:11 +00:00
|
|
|
procCmdFile="$PWD/processor${proc}.sh"
|
2010-05-12 13:27:55 +00:00
|
|
|
procLog="processor${proc}.log"
|
|
|
|
geom="-geometry 120x20+$xpos+$ypos"
|
|
|
|
node=""
|
|
|
|
|
|
|
|
if [ .$WM_MPLIB = .OPENMPI ]; then
|
|
|
|
node="-np 1 "
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "#!/bin/sh" > $procCmdFile
|
2010-05-27 10:48:11 +00:00
|
|
|
if [ "$method" -eq 0 ]; then
|
|
|
|
echo "$sourceFoam; cd $PWD; $exec $args | tee $procLog" >> $procCmdFile
|
|
|
|
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
|
|
|
|
elif [ "$method" -eq 1 ]; then
|
|
|
|
echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands $exec 2>&1 | tee $procLog; read dummy" >> $procCmdFile
|
2010-05-12 13:27:55 +00:00
|
|
|
#echo "$sourceFoam; cd $PWD; $exec $args; read dummy" >> $procCmdFile
|
2010-05-27 10:48:11 +00:00
|
|
|
echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
|
2010-05-12 13:27:55 +00:00
|
|
|
elif [ "$method" -eq 2 ]; then
|
2010-05-27 10:48:11 +00:00
|
|
|
echo "$sourceFoam; cd $PWD; gdb -command $PWD/gdbCommands >& $procLog" >> $procCmdFile
|
|
|
|
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
|
2010-05-12 13:27:55 +00:00
|
|
|
elif [ "$method" -eq 3 ]; then
|
|
|
|
echo "$sourceFoam; cd $PWD; $exec $args >& $procLog" >> $procCmdFile
|
2010-05-27 10:48:11 +00:00
|
|
|
echo "${node}$procCmdFile" >> $PWD/mpirun.schema
|
2010-05-12 13:27:55 +00:00
|
|
|
elif [ "$method" -eq 4 ]; then
|
2010-05-27 10:48:11 +00:00
|
|
|
echo "$sourceFoam; cd $PWD; $exec $args 2>&1 | tee $procLog; read dummy" >> $procCmdFile
|
|
|
|
echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
|
|
|
|
elif [ "$method" -eq 5 ]; then
|
2010-05-12 13:27:55 +00:00
|
|
|
echo "$sourceFoam; cd $PWD; valgrind $exec $args; read dummy" >> $procCmdFile
|
2010-05-27 10:48:11 +00:00
|
|
|
echo "${node}xterm -font fixed -title 'processor'$proc $geom -e $procCmdFile" >> $PWD/mpirun.schema
|
2010-12-02 17:04:28 +00:00
|
|
|
elif [ "$method" -eq 6 ]; then
|
|
|
|
## maybe one could use nemiver sessions for reloading breakpoints --session=<N> or --last
|
|
|
|
# echo "$sourceFoam; cd $PWD; nemiver --last $exec $args; read dummy" >> $procCmdFile
|
|
|
|
echo "$sourceFoam; cd $PWD; nemiver $exec $args; read dummy" >> $procCmdFile
|
|
|
|
# echo "$sourceFoam; cd $PWD; ddd --args $exec $args; read dummy" >> $procCmdFile
|
|
|
|
echo "${node} $procCmdFile" >> $PWD/mpirun.schema
|
2010-05-12 13:27:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
chmod +x $procCmdFile
|
|
|
|
|
|
|
|
let column=proc%6
|
|
|
|
if [ $proc -ne 0 -a $column -eq 0 ]; then
|
|
|
|
((xpos+=600))
|
|
|
|
((ypos=0))
|
|
|
|
else
|
|
|
|
((ypos+=200))
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for ((proc=0; proc<$nProcs; proc++))
|
|
|
|
do
|
|
|
|
procLog="processor${proc}.log"
|
|
|
|
echo " tail -f $procLog"
|
|
|
|
done
|
|
|
|
|
2010-05-27 10:48:11 +00:00
|
|
|
cmd=""
|
2010-05-12 13:27:55 +00:00
|
|
|
if [ .$WM_MPLIB = .OPENMPI ]; then
|
2010-05-27 10:48:11 +00:00
|
|
|
cmd="mpirun -app $PWD/mpirun.schema </dev/null"
|
|
|
|
elif [ .$WM_MPLIB = .MPICH ]; then
|
|
|
|
cmd="mpiexec"
|
|
|
|
for ((proc=0; proc<$nProcs; proc++))
|
|
|
|
do
|
|
|
|
read procCmd
|
|
|
|
|
|
|
|
procXtermCmdFile="$PWD/processor${proc}Xterm.sh"
|
|
|
|
echo "#!/bin/sh" > $procXtermCmdFile
|
|
|
|
echo "$procCmd" >> $procXtermCmdFile
|
|
|
|
chmod +x $procXtermCmdFile
|
|
|
|
if [ $proc -ne 0 ]; then
|
|
|
|
cmd="${cmd} :"
|
|
|
|
fi
|
|
|
|
cmd="${cmd} -n 1 ${procXtermCmdFile}"
|
|
|
|
done < $PWD/mpirun.schema
|
2010-05-12 13:27:55 +00:00
|
|
|
fi
|
2010-05-27 10:48:11 +00:00
|
|
|
|
|
|
|
echo "Constructed $PWD/mpirun.schema file."
|
|
|
|
echo ""
|
|
|
|
echo " $cmd"
|
|
|
|
echo ""
|
|
|
|
$ECHO "Press return to execute.\c"
|
|
|
|
read dummy
|
|
|
|
exec $cmd
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|