1 | #!/usr/bin/env bash |
---|
2 | #--------------------------------------------------------------------------------# |
---|
3 | # This file is part of the PALM model system. |
---|
4 | # |
---|
5 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
6 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
7 | # either version 3 of the License, or (at your option) any later version. |
---|
8 | # |
---|
9 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
11 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
12 | # |
---|
13 | # You should have received a copy of the GNU General Public License along with |
---|
14 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | # |
---|
16 | # Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
17 | #--------------------------------------------------------------------------------# |
---|
18 | # |
---|
19 | # Current revisions: |
---|
20 | # ----------------- |
---|
21 | # |
---|
22 | # |
---|
23 | # Former revisions: |
---|
24 | # ----------------- |
---|
25 | # $Id: palm_simple_run 4481 2020-03-31 18:55:54Z maronga $ |
---|
26 | # bugfix: envpar namelist adjusted to current PALM revision |
---|
27 | # |
---|
28 | # 2875 2018-03-13 11:00:25Z knoop |
---|
29 | # made RUN dirs unique with timestamp again |
---|
30 | # |
---|
31 | # 2850 2018-03-05 14:24:40Z knoop |
---|
32 | # Refactoring of the palm_simple_ build and run scripts |
---|
33 | # |
---|
34 | # 2718 2018-01-02 08:49:38Z maronga |
---|
35 | # Corrected "Former revisions" section |
---|
36 | # |
---|
37 | # 2696 2017-12-14 17:12:51Z kanani |
---|
38 | # Change in file header (GPL part) |
---|
39 | # |
---|
40 | # 2225 2017-05-16 11:36:20Z raasch |
---|
41 | # shell changed to bash |
---|
42 | # |
---|
43 | # 1310 2014-03-14 08:01:56Z raasch |
---|
44 | # update GPL copyright |
---|
45 | # |
---|
46 | # 1221 2013-09-10 08:59:13Z raasch |
---|
47 | # setting of PGI_ACC_SYNCHRONOUS=1 for running with pgi-openacc |
---|
48 | # |
---|
49 | # 1172 2013-05-30 11:46:00Z raasch |
---|
50 | # for performance reasons set PGI_ACC_SYNCHRONOUS=1 for pgi/openacc execution |
---|
51 | # |
---|
52 | # 1171 2013-05-30 11:27:45Z raasch |
---|
53 | # new option -e which defines the execution command to be used to run PALM |
---|
54 | # |
---|
55 | # 1046 2012-11-09 14:38:45Z maronga |
---|
56 | # code put under GPL (PALM 3.9) |
---|
57 | # |
---|
58 | # 29/08/11 - BjornW - Adapted for lcflow (ForWind cluster in Oldenburg) |
---|
59 | # 18/03/10 - Siggi - Some comments changed |
---|
60 | # 25/01/10 - Siggi - Generating the first version |
---|
61 | |
---|
62 | |
---|
63 | #--------------------------------------------------------------------------------# |
---|
64 | # palm_simple_run - a simple method for running the palm code without |
---|
65 | # using the mrun script |
---|
66 | # |
---|
67 | # This script runs the palm code in a unique subdirectory (OUTPUT..., |
---|
68 | # current time/date and number of processors are part of the subdirectory |
---|
69 | # name). |
---|
70 | # It requires that palm has been installed with command |
---|
71 | # palm_simple_install and that the executable palm has been created |
---|
72 | # with make in directory ...../MAKE_DEPOSITORY_simple |
---|
73 | #--------------------------------------------------------------------------------# |
---|
74 | SOURCE="${BASH_SOURCE[0]}" |
---|
75 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink |
---|
76 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
---|
77 | SOURCE="$(readlink "$SOURCE")" |
---|
78 | # if $SOURCE was a relative symlink, we need to resolve it |
---|
79 | # relative to the path where the symlink file was located |
---|
80 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" |
---|
81 | done |
---|
82 | SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
---|
83 | |
---|
84 | working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../") |
---|
85 | trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../") |
---|
86 | |
---|
87 | # Variable declarations + default values |
---|
88 | build_config=unknown |
---|
89 | run_config=unknown |
---|
90 | test_case=unknown |
---|
91 | mpi_ranks=1 |
---|
92 | mpi_ranks_per_node=1 |
---|
93 | openmp_threads=1 |
---|
94 | localhost_realname=$(hostname) |
---|
95 | cpumax=999999 |
---|
96 | |
---|
97 | print_help() { |
---|
98 | echo "Usage: palm_simple_run -b <build-config> -c <run-config> -s <test-case>" |
---|
99 | echo " [-n <mpi-ranks-per-node>] [-p <mpi-ranks>]" |
---|
100 | echo " [-t <openmp-threads>]" |
---|
101 | echo "" |
---|
102 | echo "List of allowed option:" |
---|
103 | echo "" |
---|
104 | echo " -b <build-config> Suffix of any MAKE.inc.<build-config> file in the trunk/INSTALL dir." |
---|
105 | echo " -c <run-config> Suffix of any RUN.cmd.<run-config> file in the trunk/INSTALL dir." |
---|
106 | echo " -n <mpi-ranks-per-node> Number of MPI ranks per compute node." |
---|
107 | echo " -p <mpi-ranks> Number of MPI ranks in total." |
---|
108 | echo " -s <test-case> Prefix of any <test-case>_p3d file in the trunk/INSTALL dir." |
---|
109 | echo " -t <openmp-threads> Number of OpenMP threads" |
---|
110 | echo "" |
---|
111 | echo "" |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | # Read shellscript options |
---|
116 | while getopts :b:c:n:p:s:t:h option |
---|
117 | do |
---|
118 | case $option in |
---|
119 | (b) build_config=$OPTARG;; |
---|
120 | (c) run_config=$OPTARG;; |
---|
121 | (n) mpi_ranks_per_node=$OPTARG;; |
---|
122 | (p) mpi_ranks=$OPTARG;; |
---|
123 | (s) test_case=$OPTARG;; |
---|
124 | (t) openmp_threads=$OPTARG;; |
---|
125 | (h) print_help |
---|
126 | exit 0;; |
---|
127 | (\?) echo "Unknown option -$OPTARG" |
---|
128 | print_help |
---|
129 | exit 1;; |
---|
130 | esac |
---|
131 | done |
---|
132 | |
---|
133 | if [[ ${build_config} == "unknown" ]] |
---|
134 | then |
---|
135 | echo "Missing option -b <build-config>" |
---|
136 | print_help |
---|
137 | exit 1 |
---|
138 | fi |
---|
139 | |
---|
140 | if [[ ${run_config} == "unknown" ]] |
---|
141 | then |
---|
142 | echo "Missing option -c <run-config>" |
---|
143 | print_help |
---|
144 | exit 1 |
---|
145 | fi |
---|
146 | |
---|
147 | if [[ ${test_case} == "unknown" ]] |
---|
148 | then |
---|
149 | echo "Missing option -s <test-case>" |
---|
150 | print_help |
---|
151 | exit 1 |
---|
152 | fi |
---|
153 | |
---|
154 | build_dir=${working_dir}/BUILD_${build_config} |
---|
155 | |
---|
156 | if [[ ! -d ${build_dir} ]] |
---|
157 | then |
---|
158 | echo "+++ ERROR: No build for configuration ${build_config} exists! " |
---|
159 | echo " Please run \"palm_simple_install -b ${build_config}\"" |
---|
160 | echo " or specify a different build that this run should be based on" |
---|
161 | exit 1 |
---|
162 | fi |
---|
163 | |
---|
164 | # Check, if include file exists |
---|
165 | run_config_file=${trunk_dir}/INSTALL/RUN.cmd.${run_config} |
---|
166 | if [[ ! -f ${run_config_file} ]] |
---|
167 | then |
---|
168 | echo "+++ ERROR: no such run command file:" |
---|
169 | echo " \"${run_config_file}\"" |
---|
170 | exit 1 |
---|
171 | fi |
---|
172 | |
---|
173 | # Find out the global svn revision number |
---|
174 | global_revision=$(svnversion ${trunk_dir} 2>/dev/null) |
---|
175 | global_revision="Rev: $global_revision" |
---|
176 | |
---|
177 | |
---|
178 | # Generate unique directory/files for this run |
---|
179 | timedate="$(date +%F_%H:%M:%S)" |
---|
180 | suffix=${build_config}_${run_config}_${test_case}_${mpi_ranks}_${mpi_ranks_per_node}_${openmp_threads}_${timedate} |
---|
181 | execution_dir=${working_dir}/RUN_${suffix} |
---|
182 | |
---|
183 | if [[ ! -d ${execution_dir} ]] |
---|
184 | then |
---|
185 | mkdir -p ${execution_dir} |
---|
186 | echo "*** PALM running in directory ${execution_dir}" |
---|
187 | else |
---|
188 | echo "+++ ERROR: ${execution_dir} exists\! Must be unique. Exiting." |
---|
189 | exit 1 |
---|
190 | fi |
---|
191 | |
---|
192 | |
---|
193 | # Check if palm has been installed and copy executable into the run |
---|
194 | # directory |
---|
195 | if [[ ! -f ${build_dir}/palm ]] |
---|
196 | then |
---|
197 | echo "+++ ERROR: palm executable does not exist." |
---|
198 | echo " Please run \"palm_simple_install\"." |
---|
199 | exit 1 |
---|
200 | else |
---|
201 | cp ${build_dir}/palm ${execution_dir}/palm |
---|
202 | fi |
---|
203 | |
---|
204 | |
---|
205 | # Check, if parameter file exists and copy into the run directory |
---|
206 | if [[ ! -f ${trunk_dir}/INSTALL/${test_case}_p3d ]] |
---|
207 | then |
---|
208 | echo "+++ ERROR: parameter file" |
---|
209 | echo " \"${trunk_dir}/INSTALL/${test_case}_p3d\"" |
---|
210 | echo " does not exist." |
---|
211 | exit 1 |
---|
212 | else |
---|
213 | cp ${trunk_dir}/INSTALL/${test_case}_p3d ${execution_dir}/PARIN |
---|
214 | fi |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | |
---|
219 | # Create NAMELIST file containing environment values needed by palm |
---|
220 | cat > ${execution_dir}/ENVPAR << EOF |
---|
221 | &envpar run_identifier = '${test_case}', |
---|
222 | host = 'localhost', |
---|
223 | revision = '${global_revision}', |
---|
224 | tasks_per_node = ${mpi_ranks_per_node}, |
---|
225 | maximum_parallel_io_streams = ${mpi_ranks_per_node}, |
---|
226 | progress_bar_disabled = .TRUE., |
---|
227 | write_binary = .FALSE., |
---|
228 | maximum_cpu_time_allowed = ${cpumax}., |
---|
229 | local_dvrserver_running = .FALSE., |
---|
230 | / |
---|
231 | EOF |
---|
232 | |
---|
233 | |
---|
234 | # Coupled runs cannot be carried out with this simple run script |
---|
235 | echo "no_coupling" > ${execution_dir}/runfile_atmos |
---|
236 | |
---|
237 | |
---|
238 | # Generate hostfile (if neccessary) |
---|
239 | (( ii = 1 )) |
---|
240 | while (( ii <= $mpi_ranks )) |
---|
241 | do |
---|
242 | echo $localhost_realname >> ${execution_dir}/hostfile |
---|
243 | (( ii = ii + 1 )) |
---|
244 | done |
---|
245 | |
---|
246 | |
---|
247 | # Switch to run directory |
---|
248 | cd ${execution_dir} |
---|
249 | |
---|
250 | # Start palm run |
---|
251 | echo "*** PALM will be executed with configuration: ${run_config}" |
---|
252 | echo " MPI ranks in total: $mpi_ranks" |
---|
253 | echo " MPI ranks per node: $mpi_ranks_per_node" |
---|
254 | echo " OpenMP threads: $openmp_threads" |
---|
255 | |
---|
256 | # execute according to the run command file |
---|
257 | source ${run_config_file} |
---|
258 | |
---|
259 | echo "*** PALM execution finished. Results can be found in:" |
---|
260 | echo " \"${execution_dir}\"" |
---|
261 | exit 0 |
---|