Skip to content

Commit 1e1a0c9

Browse files
committed
Move RunFunctions from staneuski/dotfiles
staneuski/staneuski@3644838
1 parent 4c461e8 commit 1e1a0c9

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

bin/tools/RunFunctions

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#---------------------------------*- sh -*-------------------------------------
2+
# ========= |
3+
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4+
# \\ / O peration | Website: https://openfoam.org
5+
# \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6+
# \\/ M anipulation |
7+
#------------------------------------------------------------------------------
8+
# License
9+
# This file is originating from OpenFOAM and modified by the authors
10+
# described below.
11+
#
12+
# OpenFOAM is free software: you can redistribute it and/or modify it
13+
# under the terms of the GNU General Public License as published by
14+
# the Free Software Foundation, either version 3 of the License, or
15+
# (at your option) any later version.
16+
#
17+
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20+
# for more details.
21+
#
22+
# You should have received a copy of the GNU General Public License
23+
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24+
#
25+
# Script
26+
# RunFunctions
27+
#
28+
# Description
29+
# Miscellaneous functions for running tutorial cases
30+
#
31+
# Authors
32+
# Stanislau Stasheuski, Aalto University, 2023.
33+
34+
#
35+
# Henry Weller, CFD-Direct, 2023.
36+
#
37+
#------------------------------------------------------------------------------
38+
39+
runParallel()
40+
{
41+
APP_RUN=
42+
LOG_IGNORE=false
43+
LOG_APPEND=false
44+
LOG_SUFFIX=
45+
nProcs=$(getNumberOfProcessors)
46+
47+
# Parse options and executable
48+
while [ $# -gt 0 ] && [ -z "$APP_RUN" ]; do
49+
key="$1"
50+
case "$key" in
51+
-append|-a)
52+
LOG_IGNORE=true
53+
LOG_APPEND=true
54+
;;
55+
-overwrite|-o)
56+
LOG_IGNORE=true
57+
;;
58+
-suffix|-s)
59+
LOG_SUFFIX=".$2"
60+
shift
61+
;;
62+
-np|-n)
63+
nProcs="$2"
64+
shift
65+
;;
66+
*)
67+
APP_RUN="$key"
68+
APP_NAME="${key##*/}"
69+
LOG_SUFFIX="${APP_NAME}${LOG_SUFFIX}"
70+
;;
71+
esac
72+
73+
shift
74+
done
75+
76+
if [ -f log.$LOG_SUFFIX ] && [ "$LOG_IGNORE" = "false" ]
77+
then
78+
echo "$APP_NAME already run on $PWD:" \
79+
"remove log file 'log.$LOG_SUFFIX' to re-run"
80+
else
81+
echo "Running $APP_RUN in parallel on $PWD using $nProcs processes"
82+
if [ "$LOG_APPEND" = "true" ]; then
83+
( srun $APP_RUN -parallel "$@" < /dev/null >> log.$LOG_SUFFIX 2>&1 )
84+
else
85+
( srun $APP_RUN -parallel "$@" < /dev/null > log.$LOG_SUFFIX 2>&1 )
86+
fi
87+
fi
88+
}
89+
90+
#------------------------------------------------------------------------------

0 commit comments

Comments
 (0)