Ignore:
Timestamp:
Mar 5, 2018 2:24:40 PM (3 years ago)
Author:
knoop
Message:

Refactoring of the palm_simple_ build and run scripts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SCRIPTS/palm_simple_run

    r2718 r2850  
    1 #!/bin/bash
     1#!/usr/bin/env bash
    22#--------------------------------------------------------------------------------#
    33# This file is part of the PALM model system.
     
    2424# -----------------
    2525# $Id$
     26# Refactoring of the palm_simple_ build and run scripts
     27#
     28# 2718 2018-01-02 08:49:38Z maronga
    2629# Corrected "Former revisions" section
    2730#
     
    6366# with make in directory  ...../MAKE_DEPOSITORY_simple
    6467#--------------------------------------------------------------------------------#
    65 
    66 
    67     # Variable declarations + default values
    68  case=example_cbl
    69  cpumax=999999
    70  execute_for=unknown
    71  localhost=unknown
    72  localhost_realname=$(hostname)
    73  mpi_procs=1
    74  mpi_procs_per_node=1
    75  openmp_threads=1
    76 
    77  typeset -i  ii
    78 
    79 
    80     # Read shellscript options
    81  while  getopts  :c:e:l:n:p:t:  option
    82  do
    83    case  $option  in
    84        (c)   case=$OPTARG;;
    85        (e)   execute_for=$OPTARG;;
    86        (l)   localhost=$OPTARG;;
    87        (n)   mpi_procs_per_node=$OPTARG;;
    88        (p)   mpi_procs=$OPTARG;;
    89        (t)   openmp_threads=$OPTARG;;
    90        (\?)  printf "\n  +++ unknown option $OPTARG \n"
    91              printf "\n      allowed option are -c, -e, -l, -n, -p, -t \n"
    92              exit;;
    93    esac
    94  done
    95 
    96 
    97     # Find out the global svn revision number
    98  global_revision=`svnversion ${palm_dir}trunk  2>/dev/null`
    99  global_revision="Rev: $global_revision"
    100 
    101 
    102     # Generate unique directory/files for this run
    103  timedate="`date +%d.%b_%H:%M:%S`"
    104  suffix=$case+$mpi_procs+$timedate
    105  RUNDIR=OUTPUT.$suffix/
    106 
    107  if [[ ! -d $RUNDIR ]]
    108  then
    109     mkdir $RUNDIR
    110     echo "*** running in directory $RUNDIR"
    111  else
    112     echo "+++ ERROR: $RUNDIR exists\!   Must be unique.  Exiting."
    113     exit
    114  fi
    115 
    116 
    117     # Check if palm has been installed and copy executable into the run
    118     # directory
    119  if [[ ! -f ${palm_dir}MAKE_DEPOSITORY_simple/palm ]]
    120  then
    121     echo "+++ ERROR: palm executable does not exist."
    122     echo "           Please run \"palm_simple_install\"."
    123     exit
    124  else
    125     cp  ${palm_dir}MAKE_DEPOSITORY_simple/palm  $RUNDIR/palm
    126  fi
    127 
    128 
    129     # Check, if parameter file exists and copy into the run directory
    130  if [[ ! -f ${palm_dir}JOBS/${case}/INPUT/${case}_p3d ]]
    131  then
    132     echo "+++ ERROR: parameter file"
    133     echo "           \"${palm_dir}JOBS/${case}/INPUT/${case}_p3d\""
    134     echo "           does not exist."
    135     exit
    136  else
    137     cp  ${palm_dir}JOBS/${case}/INPUT/${case}_p3d  $RUNDIR/PARIN
    138  fi
    139 
    140 
    141     # Switch to run directory
    142  cd  $RUNDIR
    143 
    144 
    145 
    146     # Create NAMELIST file containing environment values needed by palm
    147  cat  >  ENVPAR  <<  %%END%%
    148  &envpar  run_identifier = '$case', host = '$localhost',
    149           write_binary = 'false', tasks_per_node = $mpi_procs_per_node,
    150           maximum_cpu_time_allowed = ${cpumax}.,
    151           revision = '$global_revision',
    152           local_dvrserver_running = .FALSE. /
    153 
    154 %%END%%
    155 
    156 
    157     # Coupled runs cannot be carried out with this simple run script
    158  echo "no_coupling"  >  runfile_atmos
    159 
    160 
    161     # Generate hostfile (if neccessary)
    162  (( ii = 1 ))
    163  while (( ii <= $mpi_procs ))
    164  do
    165     echo  $localhost_realname  >>  hostfile
    166     (( ii = ii + 1 ))
    167  done
    168 
    169 
    170     # Set number of OpenMP threads
    171  export OMP_NUM_THREADS=$openmp_threads
    172 
    173 
    174 
    175     # Start palm run
    176  echo "*** palm will be run:  MPI tasks: $mpi_procs   OpenMP thread: $OMP_NUM_THREADS"
    177 
    178  case $execute_for in
    179 
    180     (imuk)         mpiexec  -machinefile hostfile  -n $mpi_procs  ./palm  < runfile_atmos;;
    181     (sgi-mpt)      mpiexec_mpt  -np $mpi_procs  ./palm  < runfile_atmos;;
    182     (hpc-flow)     mpiexec  -machinefile $TMPDIR/machines -n $mpi_procs  -env I_MPI_FABRICS shm:ofa ./palm  < runfile_atmos;;
    183     (pgi-openacc)  export PGI_ACC_SYNCHRONOUS=1; ./palm;;
    184     (*)      echo "+++ -e option to define execution command is missing";;
    185 
    186  esac
    187 
    188  echo "*** palm finished"
    189  echo "*** see"
    190  echo "    \"$RUNDIR\""
    191  echo "    for results"
     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 )"
     77
     78working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
     79trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
     80
     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
     90
     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}
     107
     108
     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
     126
     127if [[ ${build_config} == "unknown" ]]
     128then
     129   echo "Missing option -b <build-config>"
     130   print_help
     131   exit 1
     132fi
     133
     134if [[ ${run_config} == "unknown" ]]
     135then
     136   echo "Missing option -c <run-config>"
     137   print_help
     138   exit 1
     139fi
     140
     141if [[ ${test_case} == "unknown" ]]
     142then
     143   echo "Missing option -s <test-case>"
     144   print_help
     145   exit 1
     146fi
     147
     148build_dir=${working_dir}/BUILD_${build_config}
     149
     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
     157
     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
     166
     167   # Find out the global svn revision number
     168global_revision=$(svnversion ${trunk_dir}  2>/dev/null)
     169global_revision="Rev: $global_revision"
     170
     171
     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}
     176
     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
     185
     186
     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
     197
     198
     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
     209
     210
     211
     212
     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
     226
     227
     228# Coupled runs cannot be carried out with this simple run script
     229echo "no_coupling"  >  ${execution_dir}/runfile_atmos
     230
     231
     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
     239
     240
     241# Switch to run directory
     242cd  ${execution_dir}
     243
     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"
     249
     250# execute according to the run command file
     251source ${run_config_file}
     252
     253echo "*** PALM execution finished. Results can be found in:"
     254echo "    \"${execution_dir}\""
     255exit 0
Note: See TracChangeset for help on using the changeset viewer.