source: palm/trunk/SCRIPTS/palm_simple_run @ 2868

Last change on this file since 2868 was 2850, checked in by knoop, 7 years ago

Refactoring of the palm_simple_ build and run scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 7.7 KB
RevLine 
[2850]1#!/usr/bin/env bash
[1046]2#--------------------------------------------------------------------------------#
[2696]3# This file is part of the PALM model system.
[1046]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#
[2718]16# Copyright 1997-2018  Leibniz Universitaet Hannover
[1046]17#--------------------------------------------------------------------------------#
18#
19# Current revisions:
20# -----------------
[2226]21#
[2716]22#
[1046]23# Former revisions:
24# -----------------
25# $Id: palm_simple_run 2850 2018-03-05 14:24:40Z hellstea $
[2850]26# Refactoring of the palm_simple_ build and run scripts
27#
28# 2718 2018-01-02 08:49:38Z maronga
[2716]29# Corrected "Former revisions" section
[1047]30#
[2716]31# 2696 2017-12-14 17:12:51Z kanani
32# Change in file header (GPL part)
33#
[2226]34# 2225 2017-05-16 11:36:20Z raasch
35# shell changed to bash
36#
[2716]37# 1310 2014-03-14 08:01:56Z raasch
38# update GPL copyright
39#
[1222]40# 1221 2013-09-10 08:59:13Z raasch
41# setting of PGI_ACC_SYNCHRONOUS=1 for running with pgi-openacc
42#
[1221]43# 1172 2013-05-30 11:46:00Z raasch
44# for performance reasons set PGI_ACC_SYNCHRONOUS=1 for pgi/openacc execution
45#
[1172]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#
[1047]49# 1046 2012-11-09 14:38:45Z maronga
50# code put under GPL (PALM 3.9)
[1171]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
[1046]55
[1171]56
57#--------------------------------------------------------------------------------#
[421]58# palm_simple_run - a simple method for running the palm code without
59#                   using the mrun script
[1171]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#--------------------------------------------------------------------------------#
[2850]68SOURCE="${BASH_SOURCE[0]}"
69while [ -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"
75done
76SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
[421]77
[2850]78working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
79trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
[421]80
[2850]81# Variable declarations + default values
82build_config=unknown
83run_config=unknown
84test_case=unknown
85mpi_ranks=1
86mpi_ranks_per_node=1
87openmp_threads=1
88localhost_realname=$(hostname)
89cpumax=999999
[421]90
[2850]91print_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}
[421]107
108
[2850]109   # Read shellscript options
110while  getopts  :b:c:n:p:s:t:h  option
111do
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
125done
[421]126
[2850]127if [[ ${build_config} == "unknown" ]]
128then
129   echo "Missing option -b <build-config>"
130   print_help
131   exit 1
132fi
[421]133
[2850]134if [[ ${run_config} == "unknown" ]]
135then
136   echo "Missing option -c <run-config>"
137   print_help
138   exit 1
139fi
[421]140
[2850]141if [[ ${test_case} == "unknown" ]]
142then
143   echo "Missing option -s <test-case>"
144   print_help
145   exit 1
146fi
[421]147
[2850]148build_dir=${working_dir}/BUILD_${build_config}
[421]149
[2850]150if [[ ! -d ${build_dir} ]]
151then
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
156fi
[421]157
[2850]158   # Check, if include file exists
159run_config_file=${trunk_dir}/INSTALL/RUN.cmd.${run_config}
160if [[ ! -f ${run_config_file} ]]
161then
162   echo "+++ ERROR: no such run command file:"
163   echo "    \"${run_config_file}\""
164   exit 1
165fi
[421]166
[2850]167   # Find out the global svn revision number
168global_revision=$(svnversion ${trunk_dir}  2>/dev/null)
169global_revision="Rev: $global_revision"
[421]170
171
[2850]172   # Generate unique directory/files for this run
173#timedate="$(date +%F_%H:%M:%S)"
174suffix=${build_config}_${run_config}_${test_case}_${mpi_ranks}_${mpi_ranks_per_node}_${openmp_threads}
175execution_dir=${working_dir}/RUN_${suffix}
[421]176
[2850]177if [[ ! -d ${execution_dir} ]]
178then
179   mkdir -p ${execution_dir}
180   echo "*** PALM running in directory ${execution_dir}"
181else
182   echo "+++ ERROR: ${execution_dir} exists\!   Must be unique.  Exiting."
183   exit 1
184fi
[421]185
186
[2850]187# Check if palm has been installed and copy executable into the run
188# directory
189if [[ ! -f ${build_dir}/palm ]]
190then
191   echo "+++ ERROR: palm executable does not exist."
192   echo "           Please run \"palm_simple_install\"."
193   exit 1
194else
195   cp  ${build_dir}/palm  ${execution_dir}/palm
196fi
[421]197
198
[2850]199# Check, if parameter file exists and copy into the run directory
200if [[ ! -f ${trunk_dir}/INSTALL/${test_case}_p3d ]]
201then
202   echo "+++ ERROR: parameter file"
203   echo "           \"${trunk_dir}/INSTALL/${test_case}_p3d\""
204   echo "           does not exist."
205   exit 1
206else
207   cp  ${trunk_dir}/INSTALL/${test_case}_p3d  ${execution_dir}/PARIN
208fi
[421]209
210
211
212
[2850]213# Create NAMELIST file containing environment values needed by palm
214cat  >  ${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/
225EOF
[421]226
227
[2850]228# Coupled runs cannot be carried out with this simple run script
229echo "no_coupling"  >  ${execution_dir}/runfile_atmos
[421]230
231
[2850]232# Generate hostfile (if neccessary)
233(( ii = 1 ))
234while (( ii <= $mpi_ranks ))
235do
236   echo  $localhost_realname  >>  ${execution_dir}/hostfile
237   (( ii = ii + 1 ))
238done
[421]239
240
[2850]241# Switch to run directory
242cd  ${execution_dir}
[421]243
[2850]244# Start palm run
245echo "*** PALM will be executed with configuration: ${run_config}"
246echo "       MPI ranks in total: $mpi_ranks"
247echo "       MPI ranks per node: $mpi_ranks_per_node"
248echo "       OpenMP threads:     $openmp_threads"
[421]249
[2850]250# execute according to the run command file
251source ${run_config_file}
[421]252
[2850]253echo "*** PALM execution finished. Results can be found in:"
254echo "    \"${execution_dir}\""
255exit 0
Note: See TracBrowser for help on using the repository browser.