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