Changeset 2850


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

Refactoring of the palm_simple_ build and run scripts

Location:
palm/trunk
Files:
1 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • palm/trunk/INSTALL/MAKE.inc.ifort.imuk

    r515 r2850  
    33# Please adjust compiling parameters as required for your system.
    44
    5 PROG=palm
    65F90=mpif90
    76COPT= -cpp -DMPI_REAL=MPI_DOUBLE_PRECISION -DMPI_2REAL=MPI_2DOUBLE_PRECISION -D__netcdf -D__lc -D__parallel
    8 F90FLAGS= -axW -O3 -r8 -nbs -convert little_endian -I /muksoft_64/packages/netcdf/3.6.3/include
    9 LDFLAGS= -axW -O3 -r8 -nbs -Vaxlib -L/muksoft_64/packages/netcdf/3.6.3/lib -lnetcdf
     7F90FLAGS= -openmp -fpe0 -O3 -xHost -fp-model source -ftz -fno-alias -no-prec-div -no-prec-sqrt -ip -nbs -I /muksoft/packages/fftw/3.3.4/include -I /muksoft/packages/netcdf/4_intel/include
     8LDFLAGS= -openmp -fpe0 -O3 -xHost -fp-model source -ftz -fno-alias -no-prec-div -no-prec-sqrt -ip -nbs  -L/muksoft/packages/fftw/3.3.4/lib64  -L/muksoft/packages/netcdf/4_intel/lib -lnetcdf -lnetcdff -lfftw3
  • palm/trunk/SCRIPTS/palm_simple_build

    r2849 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#
     
    4043# palm_simple_install - a script for simple installation and compilation of
    4144#                       the palm code without using mbuild
    42      # This script creates (from the working copy of the palm repository)
    43      # a subdirectory MAKE_DEPOSITORY_simple which contains a copy of the
    44      # palm source code and  a modified makefile which loads required compiler
    45      # and preprocessor settings via "include MAKE.inc"
     45# This script creates (from the working copy of the palm repository)
     46# a subdirectory MAKE_DEPOSITORY_simple which contains a copy of the
     47# palm source code and  a modified makefile which loads required compiler
     48# and preprocessor settings via "include MAKE.inc"
    4649
    47      # Options: -i <include file>
    48      #          one of the include files in ~/palm/current_version/trunk/INSTALL
     50# Options: -i <include file>
     51#          one of the include files in ~/palm/current_version/trunk/INSTALL
    4952
    50      # Last changes:
    51      # 25/01/10 - Siggi - Generating the first version
    52      # 18/03/10 - Siggi - switch to palm/current_version removed: working
    53      #                    copy can be in any directory
     53# Last changes:
     54# 25/01/10 - Siggi - Generating the first version
     55# 18/03/10 - Siggi - switch to palm/current_version removed: working
     56#                    copy can be in any directory
     57#------------------------------------------------------------------------------#
     58SOURCE="${BASH_SOURCE[0]}"
     59while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
     60  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
     61  SOURCE="$(readlink "$SOURCE")"
     62  # if $SOURCE was a relative symlink, we need to resolve it
     63  # relative to the path where the symlink file was located
     64  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
     65done
     66SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
     67
     68working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
     69trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
    5470
    5571
    56     # Variable declarations + default values
    57  include_file=unknown
     72get_number_of_cpu_cores() {
     73   {
     74      n=$(sysctl -n machdep.cpu.core_count 2> /dev/null)
     75   } || {
     76      n=$(grep -c ^processor /proc/cpuinfo 2> /dev/null)
     77   } || {
     78   if ! [[ $n =~ ^-?[0-9]+$ ]]; then
     79      n=1
     80   fi
     81   }
     82   echo $n
     83}
     84
     85print_help() {
     86   echo "Usage: palm_simple_run -b <build-config> [-x]"
     87   echo ""
     88   echo "List of allowed option:"
     89   echo ""
     90   echo "   -b <build-config>   Suffix of any MAKE.inc.<build-config> file in the trunk/INSTALL dir."
     91   echo "   -x                  Clean the build directory from last build attempts"
     92   echo ""
     93}
     94
     95build_config=unknown
     96clean="false"
     97
     98# Read shellscript options
     99while  getopts  :b:xh  option
     100do
     101  case  $option  in
     102      (b)   build_config=$OPTARG;;
     103      (x)   clean="true";;
     104      (h)   print_help
     105            exit 0;;
     106      (\?)  echo "Unknown option -$OPTARG"
     107            print_help
     108            exit 1;;
     109  esac
     110done
     111
     112if [[ ${build_config} == "unknown" ]]; then
     113   echo "Missing option -b <build-config>"
     114   print_help
     115   exit 1
     116fi
    58117
    59118
    60     # Read shellscript options
    61  while  getopts  :i:  option
    62  do
    63    case  $option  in
    64        (i)   include_file=$OPTARG;;
    65        (\?)  printf "\n  +++ unknown option $OPTARG \n"
    66              printf "\n      allowed option are -d, -f, -l, -s \n"
    67              exit;;
    68    esac
    69  done
     119build_dir=${working_dir}/MAKE_DEPOSITORY_$build_config
    70120
    71121
    72 
    73     # Check, if include file exists
    74  if [[ ! -f trunk/INSTALL/$include_file ]]
    75  then
    76     echo "+++ ERROR: include file"
    77     echo "    \"trunk/INSTALL/$include_file\""
    78     echo "    not found"
    79     exit
    80  fi
     122# Check, if include file exists
     123build_config_file=${trunk_dir}/INSTALL/MAKE.inc.$build_config
     124if [[ ! -f ${build_config_file} ]]; then
     125   echo "+++ ERROR: no such make include file:"
     126   echo "    \"${build_config_file}\""
     127   exit 1
     128fi
    81129
    82130
    83      # Create the make depository
    84  if [[ ! -d MAKE_DEPOSITORY_simple ]]
    85  then
    86     mkdir  MAKE_DEPOSITORY_simple
    87  else
    88     rm  MAKE_DEPOSITORY_simple/*
    89  fi
     131# Create the make depository
     132if [[ ! -d ${build_dir} ]]; then
     133   mkdir -p ${build_dir}
     134else
     135   if [[ ${clean} == "true" ]]; then
     136      echo "Cleaning the build directory..."
     137      rm -rf ${build_dir}/*
     138   fi
     139fi
    90140
    91141
    92      # Copy makefile and all source code files to make depository
    93  cp  trunk/SOURCE/Makefile        MAKE_DEPOSITORY_simple/Makefile_old
    94  cp  trunk/INSTALL/$include_file  MAKE_DEPOSITORY_simple/MAKE.inc
    95  cp  trunk/SOURCE/*.f90           MAKE_DEPOSITORY_simple
     142# Copy makefile and all source code files to make depository
     143cp -n ${trunk_dir}/SOURCE/Makefile  ${build_dir}/Makefile_in
     144cp -n ${build_config_file}          ${build_dir}/MAKE.inc
     145cp -n ${trunk_dir}/SOURCE/*.f90     ${build_dir}
    96146
    97147
    98      # Replace comment in makefile by include statement
    99  sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  MAKE_DEPOSITORY_simple/Makefile_old  >  MAKE_DEPOSITORY_simple/Makefile
    100  rm  MAKE_DEPOSITORY_simple/Makefile_old
     148# Replace comment in makefile by include statement
     149sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  ${build_dir}/Makefile_in  >  ${build_dir}/Makefile
     150rm  ${build_dir}/Makefile_in
     151
     152cd ${build_dir}
     153make -j $(get_number_of_cpu_cores)
     154cd ../
    101155
    102156
    103      # Create directory for input files
    104  if [[ ! -d JOBS/example_cbl/INPUT ]]
    105  then
    106     mkdir -p  JOBS/example_cbl/INPUT
    107     cp trunk/INSTALL/example_cbl_p3d  JOBS/example_cbl/INPUT
    108  fi
     157echo "*** PALM build finished. Executable can be found in:"
     158echo "    \"${build_dir}\""
     159exit 0
  • 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.