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

Last change on this file since 5542 was 5542, checked in by nicolasmartin, 5 years ago

dev_r5092_CNRS_SETTE Add script to install 'trusting' directory for a branch (checkout requested dirs && compile rebuild_nemo)

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