mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
wmakeLnIncludeAll: Added -j option for parallel operation
This commit is contained in:
@ -39,7 +39,12 @@ usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
|
||||
Usage: $Script [dir1 .. dirN]
|
||||
Usage: $Script [OPTION] [dir1 .. dirN]
|
||||
|
||||
options:
|
||||
-j Compile using all local cores/hyperthreads
|
||||
-jN or -j N Compile using N cores/hyperthreads
|
||||
-h | -help Print the usage
|
||||
|
||||
Find directories with a 'Make/files' that contains a 'LIB =' directive
|
||||
and execute 'wmakeLnInclude -update' for each one
|
||||
@ -54,6 +59,7 @@ USAGE
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
findName=lnInclude
|
||||
nCores=0
|
||||
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
@ -61,6 +67,18 @@ do
|
||||
-h | -help) # Provide immediate help
|
||||
usage
|
||||
;;
|
||||
# Parallel execution on WM_NCOMPPROCS cores
|
||||
-j)
|
||||
nCores=$WM_NCOMPPROCS
|
||||
test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
|
||||
&& shift && nCores=$1
|
||||
echo "$Script: enabled on $nCores cores"
|
||||
;;
|
||||
# Parallel compilation on specified number of cores
|
||||
-j*)
|
||||
nCores=${1#-j}
|
||||
echo "$Script: enabled on $nCores cores"
|
||||
;;
|
||||
-*)
|
||||
usage "unknown option: '$*'"
|
||||
;;
|
||||
@ -68,9 +86,13 @@ do
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
FAIL=0
|
||||
echo "$Script: starting wmakeLnInclude processes"
|
||||
|
||||
# Default to searching from CWD
|
||||
[ "$#" -gt 0 ] || set -- .
|
||||
|
||||
@ -93,7 +115,20 @@ do
|
||||
then
|
||||
if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1
|
||||
then
|
||||
# If running in parallel start wmakeLnInclude on nCores
|
||||
# and more as the cores become free
|
||||
if [ "$nCores" -gt 0 ]
|
||||
then
|
||||
joblist=($(jobs -p))
|
||||
while (( ${#joblist[*]} > $nCores ))
|
||||
do
|
||||
sleep 0.01
|
||||
joblist=($(jobs -p))
|
||||
done
|
||||
wmakeLnInclude -update $topDir &
|
||||
else
|
||||
wmakeLnInclude -update $topDir
|
||||
fi
|
||||
elif [ -d "$topDir/lnInclude" ]
|
||||
then
|
||||
echo "removing spurious $topDir/lnInclude"
|
||||
@ -103,6 +138,22 @@ do
|
||||
done
|
||||
done
|
||||
|
||||
# If running in parallel wait until all wmakeLnInclude jobs are complete
|
||||
if [ "$nCores" -gt 0 ]
|
||||
then
|
||||
for job in $(jobs -p)
|
||||
do
|
||||
echo $job
|
||||
wait $job || let "FAIL+=1"
|
||||
done
|
||||
|
||||
if [ "$FAIL" == "0" ];
|
||||
then
|
||||
echo "$Script: completed wmakeLnInclude processes"
|
||||
else
|
||||
echo "$Script: failed ($FAIL)"
|
||||
fi
|
||||
fi
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Cleanup local variables and functions
|
||||
|
||||
Reference in New Issue
Block a user