Commit 84fe7a7c authored by Mark Olesen's avatar Mark Olesen
Browse files

DEFEATURE: remove wmakeScheduler (issue #1178)

- was for parallel compilation across multiple hosts, but less useful
  with modern CPUs with higher number of cores and/or hyperthreading.

  Fragile use and dependent on a 'lockfile' utility that is not often
  installed.
parent a346dec7
......@@ -30,13 +30,6 @@ alias wmDP 'wmSet WM_PRECISION_OPTION=DP'
alias wmUnset 'source $WM_PROJECT_DIR/etc/config.csh/unset'
# Toggle wmakeScheduler on/off
# - also need to set WM_HOSTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias wmSchedOn 'setenv WM_SCHEDULER $WM_PROJECT_DIR/wmake/wmakeScheduler'
alias wmSchedOff 'unsetenv WM_SCHEDULER'
# Change directory aliases
# ~~~~~~~~~~~~~~~~~~~~~~~~
alias foam 'cd $WM_PROJECT_DIR'
......
......@@ -29,12 +29,6 @@ alias wmDP='wmSet WM_PRECISION_OPTION=DP'
# Clear env
alias wmUnset='. $WM_PROJECT_DIR/etc/config.sh/unset'
# Toggle wmakeScheduler on/off
# - also need to set WM_HOSTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias wmSchedOn='export WM_SCHEDULER=$WM_PROJECT_DIR/wmake/wmakeScheduler'
alias wmSchedOff='unset WM_SCHEDULER'
# Change directory aliases
# ~~~~~~~~~~~~~~~~~~~~~~~~
alias foam='cd $WM_PROJECT_DIR'
......
......@@ -3,7 +3,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2014-2017 OpenFOAM Foundation
# \\/ M anipulation |
# \\/ M anipulation | Copyright (C) 2019 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
......@@ -66,8 +66,8 @@ do
# If called from wmake (to avoid recursion)
fromWmake=true
;;
-k | -non-stop)
# Non-stop compilation, ignoring errors
-k | -keep-going | -non-stop)
# Keep going, ignoring errors
export WM_CONTINUE_ON_ERROR=true
continue # Permanently remove arg
;;
......
......@@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
# \\/ M anipulation | Copyright (C) 2017-2019 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
......@@ -68,10 +68,10 @@ options:
-s | -silent Quiet mode (does not echo commands)
-a | -all wmake all sub-directories, running Allwmake if present
-q | -queue wmakeCollect all sub-directories, running Allwmake if present
-k or -non-stop Compile without stopping when errors occur
-k | -keep-going Keep going without stopping when errors occur (-non-stop)
-j Compile using all local cores/hyperthreads
-jN or -j N Compile using N cores/hyperthreads
-no-scheduler Compile without wmakeScheduler
-no-scheduler Disable scheduled parallel compilation
-update Update lnInclude directories, dep files, remove deprecated
files and directories
-h | -help Print the usage
......@@ -151,8 +151,8 @@ do
export WM_NCOMPPROCS=${1#-j}
echo "Compiling enabled on $WM_NCOMPPROCS cores"
;;
# Non-stop compilation, ignoring errors
-k | -non-stop)
# Keep going, ignoring errors
-k | -keep-going | -non-stop)
export WM_CONTINUE_ON_ERROR=true
;;
# Disable scheduled parallel compilation
......@@ -205,27 +205,12 @@ checkEnv
# Setup parallel compilation
#------------------------------------------------------------------------------
# Set WM_NCOMPPROCS automatically when both WM_HOSTS and WM_SCHEDULER are set
if [ -z "$WM_NCOMPPROCS" -a -n "$WM_HOSTS" -a -n "$WM_SCHEDULER" ]
then
WM_NCOMPPROCS=$(wmakeScheduler -count) || unset WM_NCOMPPROCS
fi
if [ -n "$WM_NCOMPPROCS" ]
then
parOpt="-j $WM_NCOMPPROCS"
if [ "$WM_NCOMPPROCS" -gt 1 -a -z "$MAKEFLAGS" ]
then
lockDir=$HOME/.$WM_PROJECT/.wmake
if [ -d $lockDir ]
then
rm -f $lockDir/*
else
mkdir -p $lockDir
fi
make="$make --no-print-directory $parOpt"
fi
fi
......@@ -338,12 +323,12 @@ then
[ "$update" = true ] || wmakeLnIncludeAll $parOpt
(
export WM_COLLECT_DIR=$WM_PROJECT_DIR/build/${WM_OPTIONS}/${PWD////_}
export WM_SCHEDULER=wmakeCollect
export WM_COLLECT_DIR="$WM_PROJECT_DIR/build/${WM_OPTIONS}/${PWD////_}"
export WM_SCHEDULER="$WM_DIR/wmakeCollect"
trap '$WM_SCHEDULER -kill' TERM INT
$WM_SCHEDULER -clean \
"$WM_SCHEDULER" -clean \
&& wmake -all objects \
&& $WM_SCHEDULER
&& "$WM_SCHEDULER"
) && wmake -all
exit $?
fi
......
......@@ -42,17 +42,17 @@ usage() {
Usage: $Script [OPTION] <command>
options:
-clean Clean-up before compilation (removes old makefiles)
-kill Clean-up after termination (removes makefiles)
-h | -help Print the usage
-clean Cleanup before compilation (removes old makefiles)
-kill Cleanup after termination (removes makefiles)
-h | -help Print the usage
Collecting scheduler for fast parallel compilation of large numbers of object
files. Can be used in compiling OpenFOAM by setting the WM_SCHEDULER variable.
A collecting scheduler for fast parallel compilation of large numbers of
object files.
When called with a compilation command it is written into a file in the
directory $WM_COLLECT_DIR.
directory \$WM_COLLECT_DIR.
When called without a command the files in the $WM_COLLECT_DIR directory are
When called without a command the files in the \$WM_COLLECT_DIR directory are
combined into a single Makefile which is passed to make to compile all of the
object files efficiently in parallel.
......@@ -62,7 +62,7 @@ Typical usage for compiling OpenFOAM:
wmakeLnIncludeAll
- Compile all with this scheduler:
wmake -queue or wmake -q
wmake -queue
USAGE
exit 1
......@@ -77,18 +77,17 @@ do
-h | -help*)
usage
;;
-kill | -clean)
-clean | -kill)
cleanup=true
shift
;;
-*)
usage "unknown option: '$*'"
break
;;
*)
break
;;
esac
shift
done
......@@ -112,8 +111,8 @@ makefile="$WM_COLLECT_DIR.Makefile"
# Clean-up files and exit
if [ "$cleanup" = true ]
then
rm -rf $WM_COLLECT_DIR
rm -f $makefile
rm -rf "$WM_COLLECT_DIR"
rm -f "$makefile"
exit 0
fi
......@@ -121,26 +120,26 @@ fi
if [ "$#" -gt 0 ]
then
# Make sure directories exist
mkdir -p $WM_COLLECT_DIR
mkdir -p "$WM_COLLECT_DIR"
# The current source file
source="${@: -3:1}"
sourceFile="${@: -3:1}"
# The current target
object="${@: -1:1}"
objectFile="${@: -1:1}"
# Create a unique name for the makefile from the object path
file=$(mktemp $WM_COLLECT_DIR/XXXXXX)
file="$(mktemp $WM_COLLECT_DIR/XXXXXX)"
# Add the current target to the list of objects
echo "OBJECTS += $object" >> $file
echo "OBJECTS += $objectFile" >> $file
# Add the build rule for the current target
echo "$object: $makefile" >> $file
echo "$objectFile: $makefile" >> $file
[ -z "$E" ] ||
echo -e "\t@echo \" compiling: ${source##*/}\"" >> $file
echo -e "\t@echo \" compiling: ${sourceFile##*/}\"" >> $file
echo -e "\t$E cd $PWD && \\" >> $file
echo -e "\t${@:1:($#-1)} $object" >> $file
echo -e "\t${@:1:($#-1)} $objectFile" >> $file
echo >> $file
elif [ -d $WM_COLLECT_DIR ]
then
......@@ -151,12 +150,12 @@ then
echo 'all: $(OBJECTS)' >> $makefile
# Clear out all of the target makefiles
rm -rf $WM_COLLECT_DIR
rm -rf "$WM_COLLECT_DIR"
# Run make on the collected makefile
make -j $WM_NCOMPPROCS -f $makefile all
rm -f $makefile
rm -f "$makefile"
fi
exit 0 # clean exit
......
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM 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.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# wmakeScheduler
#
# Usage
# wmakeScheduler COMMAND
# run 'COMMAND' on one of the slots listed in WM_HOSTS
#
# wmakeScheduler -count
# count the total number of slots available in WM_HOSTS
# eg, export WM_NCOMPPROCS=$(wmakeScheduler -count)
#
# Description
# Scheduler for network distributed compilations using wmake.
# - WM_HOSTS contains a list of hosts and number of concurrent processes
# eg,
# export WM_HOSTS="hostA:1 hostB:2 hostC:1"
# - WM_COLOURS contains a list of colours to cycle through
# export WM_COLOURS="black blue green cyan red magenta yellow"
#
# Sources the relevant cshrc/bashrc if not set.
#
# Environment
# - FOAM_API
# - WM_PROJECT_DIR
# - WM_PROJECT (defaults to OpenFOAM)
#
#-------------------------------------------------------------------------------
Script="${0##*/}"
# Default project
[ -n "$WM_PROJECT" ] || WM_PROJECT=OpenFOAM
lockDir="$HOME/.$WM_PROJECT/.wmake"
# csh sets HOST, bash sets HOSTNAME
[ -n "$HOST" ] || HOST="$HOSTNAME"
# Fallback - 1 core on current host
[ -n "$WM_HOSTS" ] || WM_HOSTS="${HOST}:1"
# Count the total number of slots available and exit
if [ "$1" = "-count" ]
then
expr $(
for slotGroup in $WM_HOSTS
do
n=${slotGroup##*:}
[ "$n" = "${slotGroup%%:*}" ] && n=1 # missing ':'
echo "+ ${n:-1}"
done
)
exit 0
fi
# Where to source WM_PROJECT settings in a remote shell
# This code tries to figure out which cshrc or bashrc to execute.
# !! Assumes remote computer running same shell and startup files
# in same location
sourceFoam=false # Fallback command
case $SHELL in
*/csh | */tcsh ) # [t]csh vs bash|ksh|sh
shellRc=cshrc
;;
*)
shellRc=bashrc
;;
esac
# Same as foamEtcFile -mode=uo bashrc
#
# Check ~/.$WM_PROJECT/$FOAM_API/
# Check ~/.$WM_PROJECT/
# Check projectDir/etc/
if [ -n "$WM_PROJECT_DIR" ]
then
for i in \
"$HOME/.$WM_PROJECT/$FOAM_API" \
"$HOME/.$WM_PROJECT" \
"$WM_PROJECT_DIR/etc" \
;
do
if [ -f "$i/$shellRc" ]
then
sourceFoam="$i/$shellRc"
break
fi
done
fi
# Construct test string for remote execution.
# Source WM_PROJECT settings if WM_PROJECT environment not set.
# Use FOAM_SETTINGS to pass command-line settings
case "$sourceFoam" in
*/bashrc)
sourceFoam='[ -n "$WM_PROJECT_DIR" ] || '". $sourceFoam $FOAM_SETTINGS"
;;
*/cshrc)
sourceFoam='if ( ! $?WM_PROJECT_DIR ) source '"$sourceFoam $FOAM_SETTINGS"
;;
esac
# Quote double-quotes for remote command line
rcmd=$(echo $* | sed -e s/\"/\'\"\'/g)
# The same, without forking (not ksh, maybe not /bin/sh either)
# rcmd=$(while [ "$#" -gt 0 ]; do echo "${1//\"/'\"'}"; shift; done)
# Convert WM_COLOURS into an array
declare colourList
nColours=0
for col in $WM_COLOURS
do
colourList[$nColours]=$col
((nColours = $nColours + 1))
done
# Bashism: make pipe fail early.
# This ensures the return value of the command is returned and not of the
# colouring pipe etc.
set -o pipefail
#------------------------------------------------------------------------------
# Colour output by argument 1
#------------------------------------------------------------------------------
colourPipe()
{
if tty -s <&1 # [ "$1" ]
then
(
while read line
do
setterm -foreground $1
echo "$line"
done
setterm -foreground default
)
else
cat
fi
}
colourIndex=0
# Check for existence of lockfile binary
if ! type -p lockfile >/dev/null
then
echo "$Script: Could not find executable 'lockfile'"
exit 1
fi
while :
do
for slotGroup in $WM_HOSTS
do
# Split 'host:N', but catch 'host:' and 'host' too
host=${slotGroup%%:*}
n=${slotGroup##*:}
[ "$n" = "$host" ] && n=1 # missing ':'
: ${n:=1}
i=0
while [ "$i" -lt "$n" ]
do
lockFile="$lockDir/$host:$i"
if lockfile -r0 "$lockFile" 2>/dev/null
then
if [ "$nColours" -gt 0 ]
then
# Set colour
colour="${colourList[$colourIndex]}"
if [ "$host" = "$HOST" ]; then
eval $* 2>&1 | colourPipe "$colour"
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" \
2>&1 | colourPipe "$colour"
fi
retval=$?
else
if [ "$host" = "$HOST" ]; then
eval $* 2>&1
else
ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" \
2>&1
fi
retval=$?
fi
# Release lock
rm -f "$lockFile" 2>/dev/null
exit $retval
fi
i=$(expr $i + 1)
# Cycle through colours. Note: outside lock clause!
colourIndex=$(expr $colourIndex + 1)
[ "$colourIndex" -lt "$nColours" ] || colourIndex=0
done
done
# Did not find any free slots. Rest a bit.
sleep 1
done
if [ "$nColours" -gt 0 ]
then
setterm -foreground default
fi
exit 0 # clean exit
#------------------------------------------------------------------------------
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | Copyright (C) 2018-2019 OpenCFD Ltd.
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM 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.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# Script
# wmakeSchedulerUptime
#
# Usage
# wmakeSchedulerUptime COMMAND
# run 'COMMAND' on one of the slots listed in WM_HOSTS
#
# wmakeScheduler -count
# count the total number of slots available in WM_HOSTS
# eg, export WM_NCOMPPROCS=$(wmakeScheduler -count)
#
# Description
# Scheduler for network distributed compilations using wmake.
# - WM_HOSTS contains a list of hosts and number of concurrent processes
# eg,
# export WM_HOSTS="hostA:1 hostB:2 hostC:1"
# - WM_COLOURS contains a list of colours to cycle through
# export WM_COLOURS="black blue green cyan red magenta yellow"
#
# Sources the relevant cshrc/bashrc if not set.
#
# Environment
# - FOAM_API
# - WM_PROJECT_DIR
# - WM_PROJECT (defaults to OpenFOAM)
#
#-------------------------------------------------------------------------------
Script="${0##*/}"
# Default project
[ -n "$WM_PROJECT" ] || WM_PROJECT=OpenFOAM
lockDir="$HOME/.$WM_PROJECT/.wmake"
# csh sets HOST, bash sets HOSTNAME
[ -n "$HOST" ] || HOST="$HOSTNAME"
# Fallback - 1 core on current host
[ -n "$WM_HOSTS" ] || WM_HOSTS="${HOST}:1"
# Count the total number of slots available and exit
if [ "$1" = "-count" ]
then
expr $(
for slotGroup in $WM_HOSTS
do
n=${slotGroup##*:}
[ "$n" = "${slotGroup%%:*}" ] && n=1 # Missing ':'
echo "+ ${n:-1}"
done
)
exit 0
fi
# Where to source WM_PROJECT settings in a remote shell
# This code tries to figure out which cshrc or bashrc to execute.
# !! Assumes remote computer running same shell and startup files
# in same location
sourceFoam=false # Fallback command
case $SHELL in
*/csh | */tcsh ) # [t]csh vs bash|ksh|sh
shellRc=cshrc
;;
*)
shellRc=bashrc
;;
esac
# Same as foamEtcFile -mode=uo bashrc
#
# Check ~/.$WM_PROJECT/$FOAM_API/
# Check ~/.$WM_PROJECT/
# Check projectDir/etc/
if [ -n "$WM_PROJECT_DIR" ]
then
for i in \
"$HOME/.$WM_PROJECT/$FOAM_API" \
"$HOME/.$WM_PROJECT" \
"$WM_PROJECT_DIR/etc" \
;
do
if [ -f "$i/$shellRc" ]
then
sourceFoam="$i/$shellRc"
break
fi
done
fi
# Construct test string for remote execution.
# Source WM_PROJECT settings if WM_PROJECT environment not set.
# Use FOAM_SETTINGS to pass command-line settings
case "$sourceFoam" in
*/bashrc)
sourceFoam='[ -n "$WM_PROJECT_DIR" ] || '". $sourceFoam $FOAM_SETTINGS"
;;
*/cshrc)
sourceFoam='if ( ! $?WM_PROJECT_DIR ) source '"$sourceFoam $FOAM_SETTINGS"
;;
esac
# Quote double-quotes for remote command line
rcmd=$(echo $* | sed -e s/\"/\'\"\'/g)
# The same, without forking (not ksh, maybe not /bin/sh either)
# rcmd=$(while [ "$#" -gt 0 ]; do echo "${1//\"/'\"'}"; shift; done)
# Convert WM_COLOURS into an array
declare colourList
nColours=0
for col in $WM_COLOURS
do
colourList[$nColours]=$col
((nColours = $nColours + 1))
done
# Bashism: make pipe fail early.
# This ensures the return value of the command is returned and not of the
# colouring pipe etc.
set -o pipefail
#------------------------------------------------------------------------------
# Colour output by argument 1
#------------------------------------------------------------------------------
colourPipe()
{
if [ -n "$1" ]
then
(
while read line
do
setterm -foreground $1