1 | #!/bin/bash |
---|
2 | |
---|
3 | |
---|
4 | comments() { |
---|
5 | state=$1 |
---|
6 | |
---|
7 | if [ $state == 'E R R O R' ]; then |
---|
8 | if [ -e ocean.output ]; then |
---|
9 | last_time_step=$( cat ${TEST_DIR}/time.step | tr -d [:space:] ) |
---|
10 | STEP='nemo.exe crashed at '${last_time_step} && export STEP |
---|
11 | line=$( grep -m1 -A5 "$state" ocean.output | tr -d '\n' ) |
---|
12 | else |
---|
13 | STEP='nemo.exe crashed at initialization' && export STEP |
---|
14 | return |
---|
15 | fi |
---|
16 | fi |
---|
17 | |
---|
18 | if [ $( diff -q model.log ${REFE_DIR}/model.log ) ]; then |
---|
19 | line=$( diff model.log ${REFE_DIR}/model.log | tr -d '\n' ) |
---|
20 | fi |
---|
21 | |
---|
22 | printf "Comments\n$line\n" | tee mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt |
---|
23 | } |
---|
24 | |
---|
25 | get_cpu_time() { |
---|
26 | # Portability ! |
---|
27 | real_cpu_time=$( ${JOB_VIEW} ${JOB_ID} | awk 'END{print $9}' ) |
---|
28 | printf "Real CPU time\n${real_cpu_time}\n" | tee mesg_09_realcputime_${CFG_USER}_${CFG_ARCH}.txt |
---|
29 | } |
---|
30 | |
---|
31 | get_inputs() { |
---|
32 | if [ ! -z "${FORC_TAR}" ]; then |
---|
33 | cmd_iol="tar -tvf ${NEMO_FORC}/${FORC_TAR}"; cmd_iof="tar -vxf ${NEMO_FORC}/${FORC_TAR}" |
---|
34 | else |
---|
35 | cmd_iol="ls ${NEMO_FORC}/*" ; cmd_iof="\cp ${NEMO_FORC}/* ." |
---|
36 | fi |
---|
37 | |
---|
38 | ${cmd_iol} > inputs_list.txt |
---|
39 | ${cmd_iof} > /dev/null |
---|
40 | } |
---|
41 | |
---|
42 | diff_inputs() { |
---|
43 | mesg='Same' |
---|
44 | |
---|
45 | for file in inputs_list.txt $( ls namelist_* ) $( ls *.xml ); do |
---|
46 | diff $file ${REFE_DIR}/$file |
---|
47 | [ $? -ne 0 ] && mesg='Different' |
---|
48 | done |
---|
49 | |
---|
50 | printf "Input files\n$mesg\n" | tee mesg_08_inputfiles_${CFG_USER}_${CFG_ARCH}.txt |
---|
51 | } |
---|
52 | |
---|
53 | diff_restart() { |
---|
54 | last_time_step=$( cat ${REFE_DIR}/time.step | tr -d [:space:] ) |
---|
55 | echo 'Last time step of standard run: '${last_time_step} |
---|
56 | |
---|
57 | if [ $( find ${TEST_DIR} -name "*${last_time_step}_restart*.nc" -print -quit ) ]; then |
---|
58 | base_name=$( find ${TEST_DIR} -name "*${last_time_step}_restart*.nc" -print -quit \ |
---|
59 | | awk -F/ '{print $NF}' | sed "s/^\(.*\)$last_time_step\_.*/\1$last_time_step/" ) |
---|
60 | |
---|
61 | for comp in restart restart_ice restart_trc; do |
---|
62 | printf "${base_name}_${comp}.nc: " |
---|
63 | |
---|
64 | nb_dom=$( find ${TEST_DIR} -name "${base_name}_${comp}_[0-9]*.nc" | wc -l | awk '{print $1}' ) |
---|
65 | if [ ${nb_dom} -gt 1 ]; then |
---|
66 | ${NEMO_TRBD}/rebuild_nemo -t $NPROC ${base_name}_$comp ${nb_dom} > /dev/null |
---|
67 | fi |
---|
68 | |
---|
69 | # UNIX `cmp` not suitable (filename & timestamp in .nc file) |
---|
70 | $CDO diffn ${TEST_DIR}/${base_name}_$comp.nc ${REFE_DIR}/${base_name}_$comp.nc 2> /dev/null |
---|
71 | if [ $? -ne 0 ]; then |
---|
72 | STATUS='FAILED'; STEP='Restart files different' |
---|
73 | #printf "$CDO diffn\n" |
---|
74 | else |
---|
75 | printf "identical\n" |
---|
76 | fi |
---|
77 | |
---|
78 | rm -f ${TEST_DIR}/${base_name}_${comp}_[0-9]*.nc &> /dev/null |
---|
79 | done |
---|
80 | |
---|
81 | else |
---|
82 | STATUS='FAILED'; STEP='No restart files found at last time step' |
---|
83 | printf "no restart files found for comparison\n" |
---|
84 | fi |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | diff_textfiles() { |
---|
89 | for file in ocean.output $( ls *.stat ); do |
---|
90 | diff $file ${REFE_DIR}/$file |
---|
91 | [ $? -ne 0 ] && STATUS='FAILED' && STEP='ASCII output file diff' |
---|
92 | done |
---|
93 | } |
---|
94 | |
---|
95 | get_soft_rel() { |
---|
96 | for rel in $CDO $COMPILER $MPI $NETCDF; do |
---|
97 | arch_rel=$( echo $LOADEDMODULES | sed "s#.*$rel/\([^:]*\).*#\1#" ) |
---|
98 | [ -z "${arch_rel}" ] && arch_rel=$( echo $PATH | sed "s#.*$rel/\([^/]*\).*#\1#" ) |
---|
99 | [ $rel == $COMPILER ] && arch_rel=$( $rel --version | grep -m1 -o ' [0-9.]* ' ) |
---|
100 | echo $rel ${arch_rel} >> model.log |
---|
101 | done |
---|
102 | |
---|
103 | sed -n 4p model.log | sed 'i\Compiler' > mesg_05_compiler_${CFG_USER}_${CFG_ARCH}.txt |
---|
104 | sed -n 5p model.log | sed 'i\MPI libs' > mesg_06_mpi_${CFG_USER}_${CFG_ARCH}.txt |
---|
105 | sed -n 6p model.log | sed 'i\NetCDF libs' > mesg_07_netcdf_${CFG_USER}_${CFG_ARCH}.txt |
---|
106 | } |
---|
107 | |
---|
108 | get_nemo_rev() { |
---|
109 | svn_opt='status' |
---|
110 | |
---|
111 | # If -v|--version option has been set, modify svn command |
---|
112 | if [[ $( echo ${NEMO_VERS} | grep "HEAD\|up\|update" ) \ |
---|
113 | || $( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) ]]; then |
---|
114 | rev=$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) || rev='HEAD' |
---|
115 | svn_cmd='svn update -r '$rev |
---|
116 | else |
---|
117 | svn_cmd='svn '${svn_opt} |
---|
118 | fi |
---|
119 | |
---|
120 | rev=0 |
---|
121 | for dir in ${NEMO_ARCH} ${NEMO_CONF} ${NEMO_ENGI} \ |
---|
122 | ${NEMO_EIOI} ${NEMO_EFCM} \ |
---|
123 | ${NEMO_TCMP} ${NEMO_TRBD} \ |
---|
124 | ${DIR_XIOS} ; do |
---|
125 | |
---|
126 | # For time being, just get revision number from XIOS |
---|
127 | if [ $dir == ${DIR_XIOS} ]; then |
---|
128 | echo 'XIOS '$( svn info $dir | awk '(NR == 5) {print $NF}' ) >> model.log |
---|
129 | continue |
---|
130 | fi |
---|
131 | |
---|
132 | ${svn_cmd} $dir |
---|
133 | rev_loc=$( svn info $dir | awk '(NR == 5) {print $NF}' ) |
---|
134 | (( ${rev_loc} >= $rev )) && rev=${rev_loc} |
---|
135 | done |
---|
136 | |
---|
137 | echo "NEMOGCM $rev" >> model.log |
---|
138 | printf "NEMOGCM rev.\n$rev\n" > mesg_02_nemogcm_${CFG_USER}_${CFG_ARCH}.txt |
---|
139 | } |
---|
140 | |
---|
141 | mesg_make() { |
---|
142 | paste -d ';' mesg_*_${CFG_USER}_${CFG_ARCH}.txt > trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt |
---|
143 | cat trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt |
---|
144 | } |
---|
145 | |
---|
146 | mesg_publish() { |
---|
147 | |
---|
148 | if [ $PUBLISH -eq 1 ]; then |
---|
149 | |
---|
150 | if [ -f ${REFE_DIR}/trusting_${CFG_USER}_${CFG_ARCH}.txt ]; then cmd='sed -n 2p'; else cmd='cat'; fi |
---|
151 | |
---|
152 | $cmd trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt >> ${REFE_DIR}/trusting_${CFG_USER}_${CFG_ARCH}.txt |
---|
153 | |
---|
154 | # Send mail only when FAILED |
---|
155 | if [[ ! -z $EMAIL && $STATUS == 'FAILED' ]]; then |
---|
156 | cat << END_MAIL > trusting.mail |
---|
157 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
---|
158 | Dear $USER, |
---|
159 | |
---|
160 | The trusting sequence for ${CONF_REF} has failed at step: |
---|
161 | `tail -n 1 ${TEST_DIR}/mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt` |
---|
162 | Directory : ${TEST_DIR} |
---|
163 | |
---|
164 | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
---|
165 | |
---|
166 | END_MAIL |
---|
167 | if [ -e ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt ]; then |
---|
168 | cat ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt >> trusting.mail |
---|
169 | fi |
---|
170 | mail -s "[trusting ${CONF_REF}] $STATUS $STEP" $EMAIL < trusting.mail |
---|
171 | fi |
---|
172 | |
---|
173 | fi |
---|
174 | } |
---|
175 | |
---|
176 | print_step() { |
---|
177 | [ ! -z "$1" ] && STEP=$1 |
---|
178 | export STEP && printf "Step.....\n$STEP\n" |
---|
179 | } |
---|
180 | |
---|
181 | get_out() { |
---|
182 | mesg_make; mesg_publish |
---|
183 | |
---|
184 | # Save tested configuration if trusting failed |
---|
185 | if [ $STATUS == 'FAILED' ]; then |
---|
186 | cd ${TEST_DIR} |
---|
187 | touch mesg_08_inputfiles_${CFG_USER}_${CFG_ARCH}.txt mesg_09_realcputime_${CFG_USER}_${CFG_ARCH}.txt \ |
---|
188 | mesg_10_comments_${CFG_USER}_${CFG_ARCH}.txt |
---|
189 | #tar -czf ${REFE_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.tar.gz * |
---|
190 | fi |
---|
191 | |
---|
192 | printf "Status\n$STATUS\n" > mesg_03_status_${CFG_USER}_${CFG_ARCH}.txt |
---|
193 | printf "Step.....\n$STEP\n" > mesg_04_step_${CFG_USER}_${CFG_ARCH}.txt |
---|
194 | |
---|
195 | exit 1 |
---|
196 | } |
---|
197 | |
---|
198 | job_pending() { |
---|
199 | time_elapsed=0; time_increment=30 |
---|
200 | sleep ${time_increment} |
---|
201 | |
---|
202 | while [[ $( ${JOB_LIST} | grep ${JOB_ID} ) && ${time_elapsed} -lt ${TIME_LIMI} ]]; do |
---|
203 | printf "\n####################################################" >> computation.log |
---|
204 | ${JOB_VIEW} ${JOB_ID} >> computation.log |
---|
205 | sleep ${time_increment} |
---|
206 | let time_elapsed+=${time_increment} |
---|
207 | done |
---|
208 | |
---|
209 | sleep ${time_increment} |
---|
210 | |
---|
211 | if [ ${time_elapsed} -eq ${TIME_LIMI} ]; then |
---|
212 | STEP='Exceeded time limit' |
---|
213 | |
---|
214 | if [ $( ${JOB_LIST} | grep ${JOB_ID} ) ]; then |
---|
215 | STEP='Job not finished on time: '$(( ${TIME_LIMI}/3600 ))'h' |
---|
216 | fi |
---|
217 | |
---|
218 | print_step |
---|
219 | ${JOB_DELE} ${JOB_ID} &> /dev/null |
---|
220 | get_out $STATUS $STEP |
---|
221 | fi |
---|
222 | } |
---|