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.
trusting_func.sh in branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST – NEMO

source: branches/2015/dev_r5092_CNRS_SETTE/NEMOGCM/TRUST/trusting_func.sh @ 5528

Last change on this file since 5528 was 5528, checked in by nicolasmartin, 9 years ago

dev_r5092_CNRS_SETTE Bugfixes

  • Property eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Rev URL
File size: 8.7 KB
Line 
1#!/bin/bash
2
3
4comments() {
5    state=$1; LAST_TIME_STEP=0
6
7    if [ "$state" == 'E R R O R' ]; then
8   [ -e time.step ] && LAST_TIME_STEP=$( cat time.step | tr -d [:space:] )
9   export ${LAST_TIME_STEP}
10    fi
11
12    [ -e ocean.output ] && line=$( grep -m1 -A5 "$state" ocean.output | tr -d '\n' )
13
14    if [[ -e ${REFE_DIR}/model.log && $( diff -q model.log ${REFE_DIR}/model.log ) ]]; then
15   line=$( diff model.log ${REFE_DIR}/model.log  | grep '>' )
16    fi
17
18    printf "Comments\n$line\n" | tee mesg_11_comments_${CFG_USER}_${CFG_ARCH}.txt
19}
20
21
22diff_inputs() {
23    mesg='Same'
24    for file in inputs_list.txt $( ls namelist_* ) $( ls *.xml ); do
25   diff -q $file ${REFE_DIR}/$file > /dev/null
26   [ $? -ne 0 ] && mesg='Different'
27    done
28
29    printf "Input files\n$mesg\n" | tee mesg_09_inputs_${CFG_USER}_${CFG_ARCH}.txt
30}
31
32diff_results() {
33    for file in ocean.output $( ls *.stat ); do
34   [ ! -e ${REFE_DIR}/$file ] && export ST='FAILED' && get_out 7
35   diff -q $file ${REFE_DIR}/$file
36   [ $? -ne 0 ] && export ST='FAILED'
37    done
38}
39
40diff_restart() {
41    [ ! -e  ${REFE_DIR}/time.step ] && export ST='FAILED' && get_out 9
42
43    export LAST_TIME_STEP=$( cat ${REFE_DIR}/time.step | tr -d [:space:] )
44    echo 'Last time step of standard run: '${LAST_TIME_STEP}
45
46#    if [ $( find -name "*${LAST_TIME_STEP}_restart*.nc" -print -quit ) ]; then
47    if [ $( find -regex ".*_0+${LAST_TIME_STEP}_restart.*\.nc" -print -quit ) ]; then
48#  base_name=$( find -name "*${LAST_TIME_STEP}_restart*.nc" -print -quit | awk -F/ '{print $NF}' \
49#               | sed "s/^\(.*\)$LAST_TIME_STEP\_restart.*/\1$LAST_TIME_STEP\_/"                  )
50   base_name=$( find -regex ".*_0+${LAST_TIME_STEP}_restart.*\.nc" -print -quit | awk -F/ '{print $NF}' \
51                | sed "s/^\(.*\)$LAST_TIME_STEP\_restart.*/\1$LAST_TIME_STEP\_/"                         )
52
53   for comp in restart restart_ice restart_trc; do
54       file=${base_name}${comp} && printf "$file.nc: "
55
56       nb_dom=$( find -name "${file}_[0-9]*.nc" | wc -l | awk '{print $1}' )
57       if   [ ${nb_dom} -gt 1 ]; then
58      ${NEMO_TRBD}/rebuild_nemo -t $NPROC $file ${nb_dom} > /dev/null
59      [ $? -eq 0 ] && rm -f ${base_name}${comp}_[0-9]*.nc > /dev/null
60       elif [ ${nb_dom} -eq 0 ]; then
61      export ST='FAILED' && get_out 10
62       fi
63
64       if [ -e ${REFE_DIR}/$file.nc ]; then
65       # UNIX `cmp` not suitable (filename & timestamp in .nc file)
66      nc_diff=$( $CDO diffn $file.nc ${REFE_DIR}/$file.nc 2> /dev/null \
67                 | awk '/records/ {print $1}'                           )
68
69      if [ ${nc_diff} -ne 0 ]; then
70          export ST='FAILED'
71          printf "$CDO ${nc_diff}\n"
72      else
73          printf "identical\n"
74      fi
75
76       else
77      export ST='FAILED' && get_out 9
78       fi
79
80   done
81
82    else
83   export ST='FAILED'
84    fi
85
86}
87
88get_cpu_time() {
89    real_cpu_time=$( eval ${JOB_TIME} )
90    printf "Real CPU time\n${real_cpu_time}\n" | tee mesg_10_cputime_${CFG_USER}_${CFG_ARCH}.txt
91}
92
93get_inputs() {
94    if [ ! -z "${FORC_TAR}" ]; then
95   cmd_iol="tar -tvf ${NEMO_FORC}/${FORC_TAR}"; cmd_iof="tar -vxf ${NEMO_FORC}/${FORC_TAR}"
96    else
97   cmd_iol="ls ${NEMO_FORC}/*"                ; cmd_iof="\cp ${NEMO_FORC}/* ."
98    fi
99
100    ${cmd_iol} > inputs_list.txt
101    ${cmd_iof} > /dev/null
102}
103
104get_soft_rel() {
105    for rel in $CDO $COMPILER $MPI $NETCDF; do
106                                     arch_rel=$( echo $LOADEDMODULES | sed  "s#.*$rel/\([^:]*\).*#\1#" )
107   [ -z "${arch_rel}"  ]     && arch_rel=$( echo $PATH          | sed  "s#.*$rel/\([^/]*\).*#\1#" )
108   [ "$rel" == "$COMPILER" ] && arch_rel=$( $rel --version      | grep -m1 -o ' [0-9.]* '         )
109   echo $rel ${arch_rel} >> model.log
110    done
111
112    sed -n 4p model.log | sed 'i\Fortran compiler' > mesg_06_compiler_${CFG_USER}_${CFG_ARCH}.txt
113    sed -n 5p model.log | sed 'i\MPI libs'         > mesg_07_mpi_${CFG_USER}_${CFG_ARCH}.txt
114    sed -n 6p model.log | sed 'i\NetCDF libs'      > mesg_08_netcdf_${CFG_USER}_${CFG_ARCH}.txt
115}
116
117get_nemo_rev() {
118    svn_opt='status'
119
120    # If -v|--version option has been set, modify svn command
121    if   [ $( echo ${NEMO_VERS} | grep  "HEAD\|up\|update"   ) ]; then
122   svn_cmd='svn update -r HEAD'
123    elif [ $( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) ]; then
124   svn_cmd='svn update -r '$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' )
125    else
126   svn_cmd='svn '${svn_opt}
127    fi
128
129    rev=0
130    for dir in ${NEMO_ARCH} ${NEMO_CONF} ${NEMO_ENGI} \
131               ${NEMO_EIOI} ${NEMO_EFCM}              \
132          ${NEMO_TCMP} ${NEMO_TRBD}              \
133          ${DIR_XIOS}                             ; do
134
135   # For time being, just get revision number from XIOS
136   if [ "$dir" == "${DIR_XIOS}" ]; then
137       rev_loc=$( svn info $dir | awk '(NR == 5) {print $NF}' )
138       echo   'XIOS '${rev_loc} >> model.log
139       printf "XIOS rev.\n"     >  mesg_05_xios_${CFG_USER}_${CFG_ARCH}.txt
140       printf "<a href=\"https://forge.ipsl.jussieu.fr/ioserver/changeset/${rev_loc}\" target=\"_blank\">${rev_loc}</a>" \
141                                >> mesg_05_xios_${CFG_USER}_${CFG_ARCH}.txt
142       continue
143   fi
144
145   echo ${svn_cmd} $dir': '$( ${svn_cmd} $dir )
146   rev_loc=$( svn info $dir | awk '(NR == 5) {print $NF}' )
147   (( ${rev_loc} >= $rev )) && rev=${rev_loc}
148    done
149
150    echo   'NEMOGCM '$rev   >> model.log
151    printf "NEMOGCM rev.\n" >  mesg_04_nemogcm_${CFG_USER}_${CFG_ARCH}.txt
152    printf "<a href=\"https://forge.ipsl.jussieu.fr/nemo/changeset/$rev\" target=\"_blank\">$rev</a>" \
153                       >> mesg_04_nemogcm_${CFG_USER}_${CFG_ARCH}.txt
154}
155
156mesg_make() {
157    paste -d ';' mesg_*_${CFG_USER}_${CFG_ARCH}.txt > trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt
158    cat                                               trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt
159}
160
161mesg_publish() {
162 
163if [ $PUBLISH -eq 1 ]; then
164
165  if [ -f ${REFE_DIR}/trusting_${CFG_USER}_${CFG_ARCH}.txt ]; then cmd='tail -1'; else cmd='cat'; fi
166
167  $cmd trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt >> ${REFE_DIR}/trusting_${CFG_USER}_${CFG_ARCH}.txt
168
169  # Send mail only when FAILED
170  if [[ ! -z $EMAIL && "$ST" == 'FAILED' ]]; then
171      cat << END_MAIL > trusting.mail
172XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
173
174Dear $USER,
175
176The trusting sequence for ${REFE_CONF} has failed.
177Directory: ${TEST_DIR}
178Archive: ${REFE_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.tar.gz
179
180XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
181
182END_MAIL
183
184      if [ -e ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt ]; then
185     cat ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt  >> trusting.mail
186      fi
187      mail -s "[trusting ${REFE_CONF}] $ST $ERR" $EMAIL  <  trusting.mail
188  fi
189
190fi
191}
192
193print_step() { printf "Step.....\n$1\n"; }
194
195get_out() {
196    ERR=$1
197
198    printf "Status\n$ST\n"  > mesg_02_status_${CFG_USER}_${CFG_ARCH}.txt
199
200    if [ "$ST" == 'FAILED' ]; then
201   cd ${TEST_DIR}
202
203   if [ ! -e mesg_09_inputs_${CFG_USER}_${CFG_ARCH}.txt ]; then
204       printf "Input files\n\n"   > mesg_09_inputs_${CFG_USER}_${CFG_ARCH}.txt
205   fi
206
207   if [ ! -e mesg_10_cputime_${CFG_USER}_${CFG_ARCH}.txt ]; then
208       printf "Real CPU time\n\n" > mesg_10_cputime_${CFG_USER}_${CFG_ARCH}.txt
209   fi
210
211   if [ ! -e mesg_11_comments_${CFG_USER}_${CFG_ARCH}.txt ]; then
212       printf "Comments\n\n"      > mesg_11_comments_${CFG_USER}_${CFG_ARCH}.txt
213   fi
214
215        # Error identification
216   case $ERR in
217       # Compilation
218       1) ERR='XIOS compilation failed'            ;;  2) ERR='NEMO compilation failed'            ;;
219       # Submission
220       3) ERR='Missing input files'                 ;;  4) ERR='Job submission error'               ;;
221       # Running
222       5) ERR='nemo.exe crashed at '${LAST_TIME_ERR};;  6) ERR='Exceeded time limit '${TIME_LIMI}'h';;
223       # Results
224       7) ERR='Missing previous outputs '           ;;  8) ERR='New outputs  differ/missing'        ;;
225       9) ERR='Missing previous restarts'           ;; 10) ERR='New restarts differ/missing'        ;;
226       # Undefined
227       *) ERR='Unknown error'                       ;;
228   esac
229
230   export ERR
231    fi
232
233    printf "Result.....\n$ERR\n" > mesg_03_result_${CFG_USER}_${CFG_ARCH}.txt
234
235    # Save tested configuration if trusting failed
236    [ "$ST" == 'FAILED' ] && tar -czf ${REFE_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.tar.gz *
237
238    mesg_make
239    mesg_publish
240
241    exit 1
242}
243
244job_pending() {
245    time_elapsed=0; time_increment=30
246
247    sleep ${time_increment}
248    while [[ $( ${JOB_LIST} | grep ${JOB_ID} ) && ${time_elapsed} -lt ${TIME_LIMI} ]]; do
249   printf "\n####################################################\n" >> computation.log
250   ${JOB_INFO} ${JOB_ID}                                             >> computation.log
251   sleep ${time_increment}
252   time_elapsed=$(( ${time_elapsed} + ${time_increment} ))
253    done
254    sleep ${time_increment}
255
256    if [ ${time_elapsed} -eq ${TIME_LIMI} ]; then
257   ${JOB_DELE} ${JOB_ID} &> /dev/null
258   TIME_LIMIT=$(( ${TIME_LIMI} / 3600 ))
259   export ${TIME_LIMIT}
260   get_out $ST ERR=6
261    fi
262}
Note: See TracBrowser for help on using the repository browser.