New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
prepare_job.sh in trunk/NEMOGCM/SETTE – NEMO

source: trunk/NEMOGCM/SETTE/prepare_job.sh @ 7715

Last change on this file since 7715 was 7715, checked in by flavoni, 7 years ago

#1850 commit new list of REFERENCE CONFIGURATIONS, and SETTE tests

  • Property svn:executable set to *
File size: 14.7 KB
RevLine 
[3520]1#####################################################
2# Author : Simona Flavoni for NEMO
3# Contact : sflod@locean-ipsl.upmc.fr
4#
5# ----------------------------------------------------------------------
6# NEMO/SETTE , NEMO Consortium (2010)
7# Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
8# ----------------------------------------------------------------------
9#
10# Some scripts called by sette.sh
11# prepare_job.sh   : creates the job script for running job
12######################################################
[3661]13#set -vx
[3520]14set -o posix
15#set -u
16#set -e
[3661]17#+
[3520]18#
19# ================
20# prepare_job.sh
21# ================
22#
23# -------------------------------------------------
24# script that creates the job script for NEMO tests
25# -------------------------------------------------
26#
27# SYNOPSIS
28# ========
29#
30# ::
31#
[3661]32#  $ ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG JOB_FILE
[3520]33#
34#
35# DESCRIPTION
36# ===========
37#
[3661]38# Part of the SETTE package to run tests for NEMO
[3520]39#
[3661]40# prepare the script $JOB_FILE to run the tests
[3520]41#
42# EXAMPLES
43# ========
44#
45# ::
46#
[3661]47#  $ ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG $JOB_FILE
[3520]48#
[3661]49# prepare the $JOB_FILE for execution
[3520]50#
51#
52# TODO
53# ====
54#
55# option debug
56#
57#
58# EVOLUTIONS
59# ==========
60#
[3661]61# $Id: prepare_job.sh 3050 2011-11-07 14:11:34Z acc $
[3520]62#
63#
64#
65#   * creation
66#
67#-
68#
69
[7698]70usage=" Usage : ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG JOB_FILE NUM_XIO_SERVERS NUM_OMP_THREADS"
71usage=" example : ./prepare_job.sh input_ORCA2_LIM_PISCES.cfg 8 SHORT no/yes $JOB_FILE 0 2"
[3520]72
73
[4245]74minargcount=6
[3520]75        if [ ${#} -lt ${minargcount} ]
76        then
[3661]77                echo "not enough arguments for prepare_job.sh script"
78                echo "control number of argument of prepare_job.sh in sette.sh"
[3520]79                echo "${usage}"
80        exit 1
81        fi
82        unset minargcount
83   if [ ! -f ${SETTE_DIR}/output.sette ] ; then
84           touch ${SETTE_DIR}/output.sette
85   fi
86       
87#
88# set and export TEST_NAME. It will be used within the post_test_tidyup function
89#
90INPUTARFILE=$1
91NB_PROC=$2
92TEST_NAME=$3
93MPI_FLAG=$4
94JOB_FILE=$5
[4245]95NXIO_PROC=$6
[7698]96NOMP_THR=$7
[3520]97
98# export EXE_DIR. This directory is used to execute model
99#
100#
101#
102echo "date: `date`" >> ${SETTE_DIR}/output.sette
103echo "" >> ${SETTE_DIR}/output.sette
104echo "running config: ${NEW_CONF}" >> ${SETTE_DIR}/output.sette
105echo "" >> ${SETTE_DIR}/output.sette
106echo "list of cpp_keys: " >> ${SETTE_DIR}/output.sette
[7715]107echo "`more ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm`" >> ${SETTE_DIR}/output.sette
[3520]108echo "" >> ${SETTE_DIR}/output.sette
109echo "compiling with: ${CMP_NAM}" >> ${SETTE_DIR}/output.sette
110echo "" >> ${SETTE_DIR}/output.sette
111echo "executing script : \"fcm_job $@\" " >> ${SETTE_DIR}/output.sette
112echo "            " >> ${SETTE_DIR}/output.sette
113
114################################################################
[4147]115# SET INPUT
[3520]116# get the input tarfile if needed
[4147]117if [ "$(cat ${SETTE_DIR}/$INPUTARFILE | wc -w)" -ne 0 ] ; then
118   echo "looking for input files in ${SETTE_DIR}/$INPUTARFILE " >> ${SETTE_DIR}/output.sette
119# number of tarfiles: NBTAR
120   NBTAR=`cat ${SETTE_DIR}/$INPUTARFILE |wc -l` 
121   echo "NB of tarfiles ${NBTAR} " >> ${SETTE_DIR}/output.sette
122# loop on tarfiles
123# read file name and directory
124while read tar_file dir_conf_forc
125do
126      echo looking for tarfile ${tar_file} and directory ${FORCING_DIR}/${dir_conf_forc} ; echo looking for tarfile ${tar_file} and directory ${FORCING_DIR}/${dir_conf_forc} >> ${SETTE_DIR}/output.sette
127      if [ -f ${FORCING_DIR}/${tar_file} ] && [ -d ${FORCING_DIR}/${dir_conf_forc} ] ; then
128# Tarfile and input dir ar there, only check the links
129         echo "Tarfile and input dir ar there, only check the links" >> ${SETTE_DIR}/output.sette
130# extract tarfile
131      else
[3520]132
[4147]133if [ ! -f ${FORCING_DIR}/${tar_file} ] ; then 
134     echo "tarfile  ${FORCING_DIR}/${tar_file} cannot be found we stop " ; exit 2 ; fi
[3520]135
[4147]136echo "mkdir ${FORCING_DIR}/${dir_conf_forc}" >> ${SETTE_DIR}/output.sette
137         mkdir ${FORCING_DIR}/${dir_conf_forc} 
138         cd    ${FORCING_DIR}/${dir_conf_forc}
139echo " extract from tarfile ${FORCING_DIR}/${tar_file} in  ${FORCING_DIR}/${dir_conf_forc}" >> ${SETTE_DIR}/output.sette
140         tar xvof ${FORCING_DIR}/${tar_file} ; gunzip -f `find . -name "*.gz"` 
141      fi
142# Tarfile and input dir ar there, only check the links
143      cd ${FORCING_DIR}/${dir_conf_forc}
144      for fida in *
145         do
146           [ -f ${EXE_DIR}/${fida} ] || ln -s ${FORCING_DIR}/${dir_conf_forc}/${fida} ${EXE_DIR}/${fida}
147         done
148    done < ${SETTE_DIR}/$INPUTARFILE
[3520]149
[4147]150else
151  echo "no input file to be searched "
[3520]152fi
153################################################################
154
[3680]155##########################################################################
156# COPY RESTART FILES (if needed; i.e. only for SHORT job in RESTART TESTS)
157# get the input tarfile if needed
158# SF : not ok for the moment because at this point is needed cn_exp variable,
159# SF : here it it not known.
160#\cd ${EXE_DIR}
161#if [ "$(echo ${TEST_NAME} | grep -c "SHORT" )" -ne 0 ] ; then
162#    for (( i=1; i<=${NB_PROC}; ${NB_PROC}++)) ; do
163#        L_NPROC=`printf "%04d\n" $i`
164#        ln -sf ../LONG/${NEW_CONF}_00000060_restart_${L_NPROC-1}.nc .
165#    done
166#fi
167## SF : other way
168##      for file in ../LONG/${NEW_CONF}_*restart_0*.nc ; do
169##              ncpu=`echo $file | awk -F '_' '{print $NF}' | cut -f 1 -d '.'`
170##              ln -sf ${file}  .
171##      done
172##fi
173##########################################################################
174
[3520]175################################################################
176# RUN OPA
177cd ${EXE_DIR}
178if [ ! -r ${EXE_DIR}/opa ]
179    then
180    echo "executable opa does not exist"
181    echo "executable opa does not exist, exit"  >> ${SETTE_DIR}/output.sette
182    exit 1
183fi
184
[4687]185# example for NOCS ClusterVision system using SLURM batch submission (requires ${SETTE_DIR}/sette_batch_template file)
[3520]186#
[3661]187  #  if [ ${MPI_FLAG} == "no" ] ; then
[3520]188      case ${COMPILER} in
[4687]189         X64_MOBILIS)
190                                NB_REM=$( echo $NB_PROC $NXIO_PROC | awk '{print ( $1 + $2 ) % 16}')
[3520]191               if [ ${NB_REM} == 0 ] ; then
[4687]192               # number of processes required is an integer multiple of 16
[3520]193               #
[4687]194               NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1 + $2 ) / 16}')
[3520]195            else
196               #
[4687]197               # number of processes required is not an integer multiple of 16
[3520]198               # round up the number of nodes required.
199               #
[4687]200               NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{printf("%d",($1 + $2 ) / 16 + 1 )}')
[3520]201                  fi
202            ;;
[4814]203                        XC_ARCHER_INTEL)
204                                # ocean cores are packed 24 to a node
205                                NB_REM=$( echo $NB_PROC | awk '{print ( $1 % 24 ) }')
206                                if [ ${NB_REM} == 0 ] ; then
207                                        # number of processes required is an integer multiple of 24
208                                        #
209                                        NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1) / 24}')
210                                else
211                                        #
212                                        # number of processes required is not an integer multiple of 24
213                                        # round up the number of nodes required.
214                                        #
215                                        NB_NODES=$( echo $NB_PROC | awk '{printf("%d",($1) / 24 + 1 )}')
216                                fi
217                                # xios cores are sparsely packed at 4 to a node
218                                # but can not share nodes with the ocean cores
219                                NB_REM=$( echo $NXIO_PROC | awk '{print ( $2 % 4 ) }')
220                                if [ ${NB_REM} == 0 ] ; then
221                                        # number of processes required is an integer multiple of 4                           
222                                        #
223                                        NB_NODES=$( echo $NB_NODES $NXIO_PROC | awk '{print ($1 + ( $2 / 4 ))}')                   
224                                else
225                                        #
226                                        # number of processes required is not an integer multiple of 4                             
227                                        # round up the number of nodes required.
228                                        #
[5480]229                                        NB_NODES=$( echo $NB_NODES $NXIO_PROC | awk '{print ($1 + ( $2 / 4 ) + 1)}') 
[4814]230                                fi
231                                ;;
[5480]232                        XC40_METO*) #Setup for Met Office XC40 with any compiler
233                                # ocean cores are packed 32 to a node
234                                # If we need more than one node then have to use parallel queue and XIOS must have a node to itself
235                                NB_REM=$( echo $NB_PROC | awk '{print ( $1 % 32 ) }')
236                                if [ ${NB_REM} == 0 ] ; then
237                                        # number of processes required is an integer multiple of 32
238                                        #
239                                        NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1) / 32}')
240                                else
241                                        #
242                                        # number of processes required is not an integer multiple of 32
243                                        # round up the number of nodes required.
244                                        #
245                                        NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{printf("%d",($1) / 32 + 1 )}')
246                                fi
247                                # xios cores are sparsely packed at 4 to a node
248                                if [ $NXIO_PROC == 0 ] ; then
249                                    NB_XNODES=0
250                                else
251                                    NB_REM=$( echo $NXIO_PROC | awk '{print ( $1 % 4 ) }')
252                                    if [ ${NB_REM} == 0 ] ; then
253                                            # number of processes required is an integer multiple of 4                           
254                                            #
255                                            NB_XNODES=$( echo $NXIO_PROC | awk '{print (( $1 / 4 ) + 1)}') 
256                                    else
257                                            #
258                                            # number of processes required is not an integer multiple of 4                             
259                                            # round up the number of nodes required.
260                                            #
261                                            NB_XNODES=$( echo $NXIO_PROC | awk '{printf("%d",($1) / 4 + 1) }')                   
262                                    fi
263                                fi
264                                if [ ${NB_XNODES} -ge 1 ] ; then
265                                   NB_NODES=$((NB_NODES+NB_XNODES))
266                                fi
267                                echo NB_XNODES=${NB_XNODES} 
268                                echo Total NB_NODES=${NB_NODES}
[6140]269                                QUEUE=normal
270                                SELECT="select=$NB_NODES"
271                                module unload cray-snplauncher #Make sure snplauncher module is not loaded
[5480]272                                ;;
[5559]273                        openmpi_NAVITI_MERCATOR)
[3651]274                                echo NB_PROCS ${NB_PROC}
275                                echo NB_NODES ${NB_NODES}
[3661]276                                echo  NB_PROC ${NB_PROC}
[3651]277                                if [ ${NB_PROC} -eq 1 ] ; then
278                                   NB_NODES=1
279                                   QUEUE=monoproc
[3661]280                                   NB_PROC_NODE=${NB_PROC}
[3651]281                                else
[5559]282                                   if [ ${NB_PROC} -le 16 ] ; then
[3651]283                                      NB_NODES=1
284                                      QUEUE=mono
[3661]285                                      NB_PROC_NODE=${NB_PROC}
[3651]286                                   else
[5559]287                                      NB_NODES=$( echo $NB_PROC | awk '{print $1 - $1 % 16}'  | awk '{print $1 / 16 }')
[3651]288                                      QUEUE=multi
[5559]289                                      NB_PROC_NODE=16
[3661]290                                  fi
291                                fi
[3651]292                                echo NB_PROCS     ${NB_PROC}
293                                echo NB_NODES     ${NB_NODES}
[3661]294                                echo NB_PROC_NODE ${NB_PROC_NODE}
295                                ;;
[7698]296                        ifort_athena_*)
297                                NB_PROC_NODE=$(( 16 / NOMP_THR ))
298            ;;
[3520]299         *)
300            NB_NODES=${NB_PROC}
301            ;;
302
303      esac
304#
305# Pass settings into job file by using sed to edit predefined strings
306#
[4373]307        TOTAL_NPROCS=$(( $NB_PROC + $NXIO_PROC ))
[4245]308        cat ${SETTE_DIR}/job_batch_template | sed -e"s/NODES/${NB_NODES}/" \
[4373]309             -e"s/TOTAL_NPROCS/${TOTAL_NPROCS}/" \
[4245]310             -e"s/NPROCS/${NB_PROC}/" \
[7698]311             -e"s/OMP_NTHR/${NOMP_THR}/" \
[4245]312             -e"s/NXIOPROCS/${NXIO_PROC}/" \
[3520]313             -e"s:DEF_SETTE_DIR:${SETTE_DIR}:" -e"s:DEF_INPUT_DIR:${INPUT_DIR}:" \
314             -e"s:DEF_EXE_DIR:${EXE_DIR}:" \
315             -e"s:DEF_CONFIG_DIR:${CONFIG_DIR}:" \
316             -e"s:MPI_FLAG:${MPI_FLAG}:" \
317             -e"s:DEF_NEMO_VALIDATION:${NEMO_VALIDATION_DIR}:" -e"s:DEF_NEW_CONF:${NEW_CONF}:" \
318             -e"s:DEF_CMP_NAM:${CMP_NAM}:" -e"s:DEF_TEST_NAME:${TEST_NAME}:" > run_sette_test.job
[3661]319
[3665]320        case ${COMPILER} in
[5559]321              openmpi_NAVITI_MERCATOR)
[3665]322                    cat run_sette_test.job | sed -e"s/NPROC_NODE/${NB_PROC_NODE}/" \
323                                                 -e"s:QUEUE:${QUEUE}:" > run_sette_test1.job
324                    mv run_sette_test1.job run_sette_test.job
325                    ;;
[5480]326              XC40_METO*)
[6140]327                    cat run_sette_test.job | sed -e"s/SELECT/${SELECT}/" > run_sette_test1.job
[5480]328                    mv run_sette_test1.job run_sette_test.job
329                    ;;
[7698]330              ifort_athena_*)
331                    cat run_sette_test.job | sed -e"s/NPROC_NODE/${NB_PROC_NODE}/" > run_sette_test1.job
332                    mv run_sette_test1.job run_sette_test.job
333                    ;;
[3665]334   esac
[3520]335#
336# create the unique submission job script
337#
338   if [ ! -f $JOB_FILE ] ; then
339      mv run_sette_test.job $JOB_FILE
340   else
341       e=`grep -n "# END_BODY" ${JOB_FILE} | cut -d : -f 1`
342            e=$(($e - 1))
343       head -$e $JOB_FILE > ${JOB_FILE}_new
344       mv ${JOB_FILE}_new ${JOB_FILE}
345       l=`wc -l run_sette_test.job | sed -e "s:run_sette_test.job::"`
346       b=`grep -n "# BODY" run_sette_test.job | cut -d : -f 1`
347       t=$(($l - $b))
348       tail -$t run_sette_test.job >> $JOB_FILE
349   fi
350   
[3661]351   chmod a+x $JOB_FILE ; echo "$JOB_FILE is ready"
[3520]352
353#fi
Note: See TracBrowser for help on using the repository browser.