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 branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/SETTE – NEMO

source: branches/2013/dev_MERCATOR_UKMO_2013/NEMOGCM/SETTE/prepare_job.sh @ 8129

Last change on this file since 8129 was 4233, checked in by cbricaud, 11 years ago

commit dev_r3948_NOC_FK into dev_MERCATOR_UKMO_2013

  • Property svn:executable set to *
File size: 9.1 KB
Line 
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######################################################
13#set -vx
14set -o posix
15#set -u
16#set -e
17#+
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#
32#  $ ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG JOB_FILE
33#
34#
35# DESCRIPTION
36# ===========
37#
38# Part of the SETTE package to run tests for NEMO
39#
40# prepare the script $JOB_FILE to run the tests
41#
42# EXAMPLES
43# ========
44#
45# ::
46#
47#  $ ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG $JOB_FILE
48#
49# prepare the $JOB_FILE for execution
50#
51#
52# TODO
53# ====
54#
55# option debug
56#
57#
58# EVOLUTIONS
59# ==========
60#
61# $Id: prepare_job.sh 3050 2011-11-07 14:11:34Z acc $
62#
63#
64#
65#   * creation
66#
67#-
68#
69
70usage=" Usage : ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG JOB_FILE NUM_XIO_SERVERS"
71usage=" example : ./prepare_job.sh input_ORCA2_LIM_PISCES.cfg 8 SHORT no/yes $JOB_FILE 0"
72
73
74minargcount=6
75        if [ ${#} -lt ${minargcount} ]
76        then
77                echo "not enough arguments for prepare_job.sh script"
78                echo "control number of argument of prepare_job.sh in sette.sh"
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
95NXIO_PROC=$6
96
97# export EXE_DIR. This directory is used to execute model
98#
99export EXE_DIR
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
107echo "`more ${SETTE_DIR}/../CONFIG/${NEW_CONF}/cpp_${NEW_CONF}.fcm`" >> ${SETTE_DIR}/output.sette
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################################################################
115# SET INPUT
116# get the input tarfile if needed
117tar_file=$(sed -ne "1,1p" ${SETTE_DIR}/$INPUTARFILE)
118if [ "$(cat ${SETTE_DIR}/$INPUTARFILE | grep -c ".tar" )" -ne 0 ] ; then
119   echo "looking for tar file" >> ${SETTE_DIR}/output.sette
120   echo "            " >> ${SETTE_DIR}/output.sette
121   cp ${FORCING_DIR}/${tar_file} ${INPUT_DIR}/.
122   echo "file in ${INPUT_DIR}"
123   if [ ! -f ${INPUT_DIR}/${tar_file} ] ; then
124      echo "PROBLEM during copy of tar file" >> ${SETTE_DIR}/output.sette
125      echo "tar file IS NOT present in ${INPUT_DIR} directory " >> ${SETTE_DIR}/output.sette
126      echo "            " >> ${SETTE_DIR}/output.sette
127      echo "PROBLEM during copy of tar file" 
128      exit 1
129   else 
130      cd ${EXE_DIR} ; tar xvof ${INPUT_DIR}/*.tar ; gunzip -f *gz
131   fi
132fi
133
134if [ ! -f ${EXE_DIR}/namelist_ice ] ; then
135if [ -f ${EXE_DIR}/namelist_ice_lim2 ] ; then
136   echo "choosing for namelist ice " >> ${SETTE_DIR}/output.sette
137   echo "            " >> ${SETTE_DIR}/output.sette
138   cp ${EXE_DIR}/namelist_ice_lim2 ${EXE_DIR}/namelist_ice
139elif  [ -f ${EXE_DIR}/namelist_ice_lim3 ] ; then
140   cp ${EXE_DIR}/namelist_ice_lim3 ${EXE_DIR}/namelist_ice
141fi
142fi
143
144
145if [ "$(cat ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm | grep -c "agrif" )" -ne 0 ] ; then
146   #- Namelist for ocean and ice (agrif fine grid)
147      echo "choosing for namelist for AGRIF" >> ${SETTE_DIR}/output.sette
148      echo "            " >> ${SETTE_DIR}/output.sette
149   cp ${EXE_DIR}/1_namelist_ice_lim2 ${EXE_DIR}/1_namelist_ice
150fi
151################################################################
152
153##########################################################################
154# COPY RESTART FILES (if needed; i.e. only for SHORT job in RESTART TESTS)
155# get the input tarfile if needed
156# SF : not ok for the moment because at this point is needed cn_exp variable,
157# SF : here it it not known.
158#\cd ${EXE_DIR}
159#if [ "$(echo ${TEST_NAME} | grep -c "SHORT" )" -ne 0 ] ; then
160#    for (( i=1; i<=${NB_PROC}; ${NB_PROC}++)) ; do
161#        L_NPROC=`printf "%04d\n" $i`
162#        ln -sf ../LONG/${NEW_CONF}_00000060_restart_${L_NPROC-1}.nc .
163#    done
164#fi
165## SF : other way
166##      for file in ../LONG/${NEW_CONF}_*restart_0*.nc ; do
167##              ncpu=`echo $file | awk -F '_' '{print $NF}' | cut -f 1 -d '.'`
168##              ln -sf ${file}  .
169##      done
170##fi
171##########################################################################
172
173################################################################
174# RUN OPA
175cd ${EXE_DIR}
176if [ ! -r ${EXE_DIR}/opa ]
177    then
178    echo "executable opa does not exist"
179    echo "executable opa does not exist, exit"  >> ${SETTE_DIR}/output.sette
180    exit 1
181fi
182
183# example for NOCS Altix system using PBS batch submission (requires ${SETTE_DIR}/sette_batch_template file)
184#
185  #  if [ ${MPI_FLAG} == "no" ] ; then
186      case ${COMPILER} in
187         ALTIX_NAUTILUS_MPT)
188                                NB_REM=$( echo $NB_PROC $NXIO_PROC | awk '{print ( $1 + $2 ) % 4}')
189               if [ ${NB_REM} == 0 ] ; then
190               # number of processes required is an integer multiple of 4
191               #
192               NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{print ($1 + $2 ) / 4}')
193            else
194               #
195               # number of processes required is not an integer multiple of 4
196               # round up the number of nodes required.
197               #
198               NB_NODES=$( echo $NB_PROC $NXIO_PROC | awk '{printf("%d",($1 + $2 ) / 4 + 1 )}')
199                  fi
200            ;;
201                        ifort_MERCATOR_CLUSTER)
202                                echo NB_PROCS ${NB_PROC}
203                                echo NB_NODES ${NB_NODES}
204                                echo  NB_PROC ${NB_PROC}
205                                if [ ${NB_PROC} -eq 1 ] ; then
206                                   NB_NODES=1
207                                   QUEUE=monoproc
208                                   NB_PROC_NODE=${NB_PROC}
209                                else
210                                   if [ ${NB_PROC} -le 8 ] ; then
211                                      NB_NODES=1
212                                      QUEUE=mono
213                                      NB_PROC_NODE=${NB_PROC}
214                                   else
215                                      NB_NODES=$( echo $NB_PROC | awk '{print $1 - $1 % 8}'  | awk '{print $1 / 8 }')
216                                      QUEUE=multi
217                                      NB_PROC_NODE=8
218                                  fi
219                                fi
220                                echo NB_PROCS     ${NB_PROC}
221                                echo NB_NODES     ${NB_NODES}
222                                echo NB_PROC_NODE ${NB_PROC_NODE}
223                                ;;
224         *)
225            NB_NODES=${NB_PROC}
226            ;;
227
228      esac
229#
230# Pass settings into job file by using sed to edit predefined strings
231#
232        cat ${SETTE_DIR}/job_batch_template | sed -e"s/NODES/${NB_NODES}/" \
233             -e"s/NPROCS/${NB_PROC}/" \
234             -e"s/NXIOPROCS/${NXIO_PROC}/" \
235             -e"s:DEF_SETTE_DIR:${SETTE_DIR}:" -e"s:DEF_INPUT_DIR:${INPUT_DIR}:" \
236             -e"s:DEF_EXE_DIR:${EXE_DIR}:" \
237             -e"s:DEF_CONFIG_DIR:${CONFIG_DIR}:" \
238             -e"s:MPI_FLAG:${MPI_FLAG}:" \
239             -e"s:DEF_NEMO_VALIDATION:${NEMO_VALIDATION_DIR}:" -e"s:DEF_NEW_CONF:${NEW_CONF}:" \
240             -e"s:DEF_CMP_NAM:${CMP_NAM}:" -e"s:DEF_TEST_NAME:${TEST_NAME}:" > run_sette_test.job
241
242        case ${COMPILER} in
243              ifort_MERCATOR_CLUSTER)
244                    #cat run_sette_test.job | sed -e"s:QUEUE:${QUEUE}:" > run_sette_test1.job
245                    #cat run_sette_test.job | sed -e"s/NPROC_NODE/${NB_PROC_NODE}/" > run_sette_test1.job
246                                                 #-e"s/NPROC_NODE/${NB_PROC_NODE}/" > run_sette_test1.job
247                    cat run_sette_test.job | sed -e"s/NPROC_NODE/${NB_PROC_NODE}/" \
248                                                 -e"s:QUEUE:${QUEUE}:" > run_sette_test1.job
249                    mv run_sette_test1.job run_sette_test.job
250                    ;;
251   esac
252#
253# create the unique submission job script
254#
255   if [ ! -f $JOB_FILE ] ; then
256      mv run_sette_test.job $JOB_FILE
257   else
258       e=`grep -n "# END_BODY" ${JOB_FILE} | cut -d : -f 1`
259            e=$(($e - 1))
260       head -$e $JOB_FILE > ${JOB_FILE}_new
261       mv ${JOB_FILE}_new ${JOB_FILE}
262       l=`wc -l run_sette_test.job | sed -e "s:run_sette_test.job::"`
263       b=`grep -n "# BODY" run_sette_test.job | cut -d : -f 1`
264       t=$(($l - $b))
265       tail -$t run_sette_test.job >> $JOB_FILE
266   fi
267   
268   chmod a+x $JOB_FILE ; echo "$JOB_FILE is ready"
269
270#fi
Note: See TracBrowser for help on using the repository browser.