1 | ##################################################### |
---|
2 | # Author : Italo Epicoco for NEMO |
---|
3 | # Contact : italo.epicoco@unisalento.it |
---|
4 | # |
---|
5 | # Some scripts called by sette.sh |
---|
6 | # prepare_job.sh : create the job script for running job |
---|
7 | ###################################################### |
---|
8 | #set -vx |
---|
9 | set -o posix |
---|
10 | #set -u |
---|
11 | #set -e |
---|
12 | #+ |
---|
13 | # |
---|
14 | # ================ |
---|
15 | # prepare_job.sh |
---|
16 | # ================ |
---|
17 | # |
---|
18 | # -------------------------- |
---|
19 | # create the job script for NEMO tests |
---|
20 | # -------------------------- |
---|
21 | # |
---|
22 | # SYNOPSIS |
---|
23 | # ======== |
---|
24 | # |
---|
25 | # :: |
---|
26 | # |
---|
27 | # $ ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG JOB_FILE |
---|
28 | # |
---|
29 | # |
---|
30 | # DESCRIPTION |
---|
31 | # =========== |
---|
32 | # |
---|
33 | # Part of the SETTE package to run tests for NEMO |
---|
34 | # |
---|
35 | # prepare the script $JOB_FILE to run the tests |
---|
36 | # |
---|
37 | # EXAMPLES |
---|
38 | # ======== |
---|
39 | # |
---|
40 | # :: |
---|
41 | # |
---|
42 | # $ ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG $JOB_FILE |
---|
43 | # |
---|
44 | # prepare the $JOB_FILE for execution |
---|
45 | # |
---|
46 | # |
---|
47 | # TODO |
---|
48 | # ==== |
---|
49 | # |
---|
50 | # option debug |
---|
51 | # |
---|
52 | # |
---|
53 | # EVOLUTIONS |
---|
54 | # ========== |
---|
55 | # |
---|
56 | # $Id: prepare_job.sh 3050 2011-11-07 14:11:34Z acc $ |
---|
57 | # |
---|
58 | # |
---|
59 | # |
---|
60 | # * creation |
---|
61 | # |
---|
62 | #- |
---|
63 | # |
---|
64 | |
---|
65 | usage=" Usage : ./prepare_job.sh INPUT_FILE_CONFIG_NAME NUMBER_PROC TEST_NAME MPI_FLAG JOB_FILE" |
---|
66 | usage=" example : ./prepare_job.sh input_ORCA2_LIM_PISCES.cfg 8 SHORT no/yes $JOB_FILE" |
---|
67 | |
---|
68 | |
---|
69 | minargcount=5 |
---|
70 | if [ ${#} -lt ${minargcount} ] |
---|
71 | then |
---|
72 | echo "not enough arguments for prepare_job.sh script" |
---|
73 | echo "control number of argument of prepare_job.sh in sette.sh" |
---|
74 | echo "${usage}" |
---|
75 | exit 1 |
---|
76 | fi |
---|
77 | unset minargcount |
---|
78 | if [ ! -f ${SETTE_DIR}/output.sette ] ; then |
---|
79 | touch ${SETTE_DIR}/output.sette |
---|
80 | fi |
---|
81 | |
---|
82 | # |
---|
83 | # set and export TEST_NAME. It will be used within the post_test_tidyup function |
---|
84 | # |
---|
85 | INPUTARFILE=$1 |
---|
86 | NB_PROC=$2 |
---|
87 | TEST_NAME=$3 |
---|
88 | MPI_FLAG=$4 |
---|
89 | JOB_FILE=$5 |
---|
90 | |
---|
91 | # export EXE_DIR. This directory is used to execute model |
---|
92 | # |
---|
93 | export EXE_DIR |
---|
94 | # |
---|
95 | # |
---|
96 | echo "date: `date`" >> ${SETTE_DIR}/output.sette |
---|
97 | echo "" >> ${SETTE_DIR}/output.sette |
---|
98 | echo "running config: ${NEW_CONF}" >> ${SETTE_DIR}/output.sette |
---|
99 | echo "" >> ${SETTE_DIR}/output.sette |
---|
100 | echo "list of cpp_keys: " >> ${SETTE_DIR}/output.sette |
---|
101 | echo "`more ${SETTE_DIR}/../CONFIG/${NEW_CONF}/cpp_${NEW_CONF}.fcm`" >> ${SETTE_DIR}/output.sette |
---|
102 | echo "" >> ${SETTE_DIR}/output.sette |
---|
103 | echo "compiling with: ${CMP_NAM}" >> ${SETTE_DIR}/output.sette |
---|
104 | echo "" >> ${SETTE_DIR}/output.sette |
---|
105 | echo "executing script : \"fcm_job $@\" " >> ${SETTE_DIR}/output.sette |
---|
106 | echo " " >> ${SETTE_DIR}/output.sette |
---|
107 | |
---|
108 | ################################################################ |
---|
109 | # SET INPUT |
---|
110 | # get the input tarfile if needed |
---|
111 | tar_file=$(sed -ne "1,1p" ${SETTE_DIR}/$INPUTARFILE) |
---|
112 | if [ "$(cat ${SETTE_DIR}/$INPUTARFILE | grep -c ".tar" )" -ne 0 ] ; then |
---|
113 | echo "looking for tar file" >> ${SETTE_DIR}/output.sette |
---|
114 | echo " " >> ${SETTE_DIR}/output.sette |
---|
115 | cp ${FORCING_DIR}/${tar_file} ${INPUT_DIR}/. |
---|
116 | echo "file in ${INPUT_DIR}" |
---|
117 | if [ ! -f ${INPUT_DIR}/${tar_file} ] ; then |
---|
118 | echo "PROBLEM during copy of tar file" >> ${SETTE_DIR}/output.sette |
---|
119 | echo "tar file IS NOT present in ${INPUT_DIR} directory " >> ${SETTE_DIR}/output.sette |
---|
120 | echo " " >> ${SETTE_DIR}/output.sette |
---|
121 | echo "PROBLEM during copy of tar file" |
---|
122 | exit 1 |
---|
123 | else |
---|
124 | cd ${EXE_DIR} ; tar xvof ${INPUT_DIR}/*.tar ; gunzip -f *gz |
---|
125 | fi |
---|
126 | fi |
---|
127 | |
---|
128 | if [ ! -f ${EXE_DIR}/namelist_ice ] ; then |
---|
129 | if [ -f ${EXE_DIR}/namelist_ice_lim2 ] ; then |
---|
130 | echo "choosing for namelist ice " >> ${SETTE_DIR}/output.sette |
---|
131 | echo " " >> ${SETTE_DIR}/output.sette |
---|
132 | cp ${EXE_DIR}/namelist_ice_lim2 ${EXE_DIR}/namelist_ice |
---|
133 | elif [ -f ${EXE_DIR}/namelist_ice_lim3 ] ; then |
---|
134 | cp ${EXE_DIR}/namelist_ice_lim3 ${EXE_DIR}/namelist_ice |
---|
135 | fi |
---|
136 | fi |
---|
137 | |
---|
138 | |
---|
139 | if [ "$(cat ${CONFIG_DIR}/${NEW_CONF}/cpp_${NEW_CONF}.fcm | grep -c "agrif" )" -ne 0 ] ; then |
---|
140 | #- Namelist for ocean and ice (agrif fine grid) |
---|
141 | echo "choosing for namelist for AGRIF" >> ${SETTE_DIR}/output.sette |
---|
142 | echo " " >> ${SETTE_DIR}/output.sette |
---|
143 | cp ${EXE_DIR}/1_namelist_ice_lim2 ${EXE_DIR}/1_namelist_ice |
---|
144 | fi |
---|
145 | ################################################################ |
---|
146 | |
---|
147 | ################################################################ |
---|
148 | # RUN OPA |
---|
149 | cd ${EXE_DIR} |
---|
150 | if [ ! -r ${EXE_DIR}/opa ] |
---|
151 | then |
---|
152 | echo "executable opa does not exist" |
---|
153 | echo "executable opa does not exist, exit" >> ${SETTE_DIR}/output.sette |
---|
154 | exit 1 |
---|
155 | fi |
---|
156 | |
---|
157 | # example for NOCS Altix system using PBS batch submission (requires ${SETTE_DIR}/sette_batch_template file) |
---|
158 | # |
---|
159 | # if [ ${MPI_FLAG} == "no" ] ; then |
---|
160 | case ${COMPILER} in |
---|
161 | ALTIX_NAUTILUS_MPT) |
---|
162 | NB_REM=$( echo $NB_PROC | awk '{print $1 % 4}') |
---|
163 | if [ ${NB_REM} == 0 ] ; then |
---|
164 | # number of processes required is an integer multiple of 4 |
---|
165 | # |
---|
166 | NB_NODES=$( echo $NB_PROC | awk '{print $1 / 4}') |
---|
167 | else |
---|
168 | # |
---|
169 | # number of processes required is not an integer multiple of 4 |
---|
170 | # round up the number of nodes required. |
---|
171 | # |
---|
172 | NB_NODES=$( echo $NB_PROC | awk '{printf("%d",$1 / 4 + 1 )}') |
---|
173 | fi |
---|
174 | ;; |
---|
175 | *) |
---|
176 | NB_NODES=${NB_PROC} |
---|
177 | ;; |
---|
178 | |
---|
179 | esac |
---|
180 | # |
---|
181 | # Pass settings into job file by using sed to edit predefined strings |
---|
182 | # |
---|
183 | cat ${SETTE_DIR}/job_batch_template | sed -e"s/NODES/${NB_NODES}/" -e"s/NPROCS/${NB_PROC}/" \ |
---|
184 | -e"s:DEF_SETTE_DIR:${SETTE_DIR}:" -e"s:DEF_INPUT_DIR:${INPUT_DIR}:" \ |
---|
185 | -e"s:DEF_EXE_DIR:${EXE_DIR}:" \ |
---|
186 | -e"s:DEF_CONFIG_DIR:${CONFIG_DIR}:" \ |
---|
187 | -e"s:MPI_FLAG:${MPI_FLAG}:" \ |
---|
188 | -e"s:DEF_NEMO_VALIDATION:${NEMO_VALIDATION_DIR}:" -e"s:DEF_NEW_CONF:${NEW_CONF}:" \ |
---|
189 | -e"s:DEF_CMP_NAM:${CMP_NAM}:" -e"s:DEF_TEST_NAME:${TEST_NAME}:" > run_sette_test.job |
---|
190 | |
---|
191 | # |
---|
192 | # create the unique submission job script |
---|
193 | # |
---|
194 | if [ ! -f $JOB_FILE ] ; then |
---|
195 | mv run_sette_test.job $JOB_FILE |
---|
196 | else |
---|
197 | e=`grep -n "# END_BODY" ${JOB_FILE} | cut -d : -f 1` |
---|
198 | e=$(($e - 1)) |
---|
199 | head -$e $JOB_FILE > ${JOB_FILE}_new |
---|
200 | mv ${JOB_FILE}_new ${JOB_FILE} |
---|
201 | l=`wc -l run_sette_test.job | sed -e "s:run_sette_test.job::"` |
---|
202 | b=`grep -n "# BODY" run_sette_test.job | cut -d : -f 1` |
---|
203 | t=$(($l - $b)) |
---|
204 | tail -$t run_sette_test.job >> $JOB_FILE |
---|
205 | fi |
---|
206 | |
---|
207 | chmod a+x $JOB_FILE ; echo "$JOB_FILE is ready" |
---|
208 | |
---|
209 | #fi |
---|