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_CNRS18_TRUST/NEMOGCM/TRUST/inc – NEMO

source: branches/2015/dev_r5092_CNRS18_TRUST/NEMOGCM/TRUST/inc/trusting_func.sh @ 5929

Last change on this file since 5929 was 5929, checked in by nicolasmartin, 8 years ago

dev_r5092_CNRS18_TRUST Last commits before merging to trunk

  • Property eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Rev URL
File size: 12.5 KB
Line 
1#!/bin/bash
2
3
4## Messenger filenames
5FILE_DATE=mesg_01_date_$PATTERNAME.txt  ; FILE_RSLT=mesg_02_result_$PATTERNAME.txt
6FILE_STAT=mesg_03_state_$PATTERNAME.txt ; FILE_NEMO=mesg_04_nemo_$PATTERNAME.txt
7FILE_XIOS=mesg_05_xios_$PATTERNAME.txt  ; FILE_CMPF=mesg_06_compiler_$PATTERNAME.txt
8FILE_LMPI=mesg_07_mpi_$PATTERNAME.txt   ; FILE_NCDF=mesg_08_netcdf_$PATTERNAME.txt
9FILE_INPT=mesg_09_inputs_$PATTERNAME.txt; FILE_TIME=mesg_10_time_$PATTERNAME.txt
10FILE_MEMY=mesg_11_memory_$PATTERNAME.txt; FILE_NOTE=mesg_12_comments_$PATTERNAME.txt
11
12## Trusting timestamped logfile & archive
13TRUS_FILE=trusting_${DATE}_$PATTERNAME.txt; TRUS_ARCH=trusting_${DATE}_$PATTERNAME.tgz
14
15
16## Functions in order of use
17print_step() {
18    local char_nb=$( echo "$1" | wc -c )
19    local outline=$( printf "%${char_nb}s" )
20
21    printf "\nStep.....\n%s\n%s\n" "$1" ${outline// /-}
22}
23
24init_files() {
25    echo 'Date'               > ${FILE_DATE}; echo 'Result'           > ${FILE_RSLT}
26    echo 'State'              > ${FILE_STAT}; echo 'NEMOGCM rev.'     > ${FILE_NEMO}
27    echo 'XIOS rev.'          > ${FILE_XIOS}; echo 'Fortran compiler' > ${FILE_CMPF}
28    echo 'MPI libs'           > ${FILE_LMPI}; echo 'NetCDF libs'      > ${FILE_NCDF}
29    echo 'Input files'        > ${FILE_INPT}; echo 'Elapsed time'     > ${FILE_TIME}
30    echo 'Memory usage (P/V)' > ${FILE_MEMY}; echo 'Comments'         > ${FILE_NOTE}
31
32    ## 'Failed' status with 'Unknown error' by default
33    echo ${TRUS_RSLT}      \
34   >> ${FILE_RSLT}
35    echo 'Unknown error' \
36   >> ${FILE_STAT}
37}
38
39get_date() {
40    ## UTC time zone for timestamping
41    local dat=$( date -ud "${DATE}" +"%F %R %Z" )
42
43    echo $dat           \
44   >> ${FILE_DATE}
45}
46
47get_nemo_rev() {
48    local dir rev_loc
49    local rev=0
50
51    ## Loop on essential NEMO directories
52    for dir in ${TRUS_CKOT} ${TRUS_XIOS}; do
53
54   ## For time being, just get revision from XIOS with no action on directory
55   if [ $dir == ${TRUS_XIOS} ]; then
56       rev_loc=$( svn info $dir | awk '/Last Changed Rev/ {print $NF}' )
57       echo 'XIOS '${rev_loc} \
58      >> model.log
59       echo "<a href=\"https://forge.ipsl.jussieu.fr/ioserver/changeset/${rev_loc}\" target=\"_blank\">${rev_loc}</a>" \
60      >> ${FILE_XIOS}
61       continue
62   fi
63
64   echo $dir && ${TRUS_SVNA} ${TRUS_NGCM}/$dir
65   rev_loc=$( svn info ${TRUS_NGCM}/$dir | awk '/Last Changed Rev/ {print $NF}' )
66
67   ## Keep last rev. nb
68   [ ${rev_loc} -gt $rev ] && rev=${rev_loc}
69    done
70
71    echo 'NEMOGCM '$rev \
72   >> model.log
73    echo "<a href=\"https://forge.ipsl.jussieu.fr/nemo/changeset/$rev\" target=\"_blank\">$rev</a>" \
74   >> ${FILE_NEMO}
75}
76
77get_soft_rel() {
78    local soft_rel str
79
80    if [ -n "${TRUS_ENVI}" ]; then
81        ## Sourcing environment modulefile (.env) only if module function is set
82   if [[  -e ${TRUS_ENVI}.env && $( declare -F | grep ' module' ) ]]; then
83       . ${TRUS_ENVI}.env
84   else
85       [ -e ${TRUS_ENVI}.path ] && . ${TRUS_ENVI}.path || . ${TRUS_ENVI}
86   fi
87    fi
88
89    ## Problem with `prepend-path` of modulefile that use ':' instead of ' ' as delimiter on LDFLAGS variables
90    [ $TRUS_HPCC == 'X64_ADA' ] && WRAPPER_LDFLAGS='-L/smplocal/pub/IdrMemMPI/1.4/lib -lidrmem '${WRAPPER_LDFLAGS}
91
92    for str in ${TRUS_CMPV} ${TRUS_MPIR} ${TRUS_CDFR} ${TRUS_CDOR}; do
93   [ -z "$str" ] && continue
94   soft_rel=''
95
96   ## Software release: next word after "$soft" in $PATH (case-insensitive)
97   soft_rel=$( echo $PATH | sed "s#.*$str\([0-9.a-z_]*\).*#\1#i" )
98
99   ## option --version would work for main compilers (gfortran, intel, pgfortran, ...)
100   [ $str == ${TRUS_CMPV} ] && soft_rel=$( $str --version | grep -m1 -oe '\<[0-9. ]*\>' )
101
102   ## Cleaning characters string to display proper soft name
103   str=$( echo $str | sed 's#\\##g; s#[/-]$##' )
104
105   echo $str ${soft_rel} \
106       >> model.log
107    done
108
109    sed -n 3p model.log \
110   >> ${FILE_CMPF}
111    sed -n 4p model.log \
112   >> ${FILE_LMPI}
113    sed -n 5p model.log \
114   >> ${FILE_NCDF}
115}
116
117get_inputs() {
118    ## Extract archive or copy files in case of personal inputs
119    [ -z "${TRUS_TARF}" ] && get_io="cp ${TRUS_FORC}/* ." || get_io="tar -vxf ${TRUS_FORC}/${TRUS_TARF}"
120
121    ${get_io} > /dev/null
122    [ $? -ne 0 ] && get_out 3 || echo 'Success'
123    [ $( find -name '*.gz' -print -quit ) ] && gunzip *.gz
124
125    ls -lh > inputs_list.txt
126}
127
128diff_inputs() {
129    local dif file
130    local files_list='' mesg='Same' 
131
132    ## Simple diff
133    for file in 'inputs_list.txt' *namelist_* *.xml cpp_*; do
134   dif=''
135
136   ## Continue even if input file is not in here (see after)
137   if [ -e ${TRUS_STOR}/$file ]; then dif=$( diff -q $file ${TRUS_STOR}/$file ); else dif=0; fi
138
139   ## Pass over useless file omission in benckmark directory
140   [[ -n "$dif" && "$dif" != '0' ]] && { mesg='Different'; echo $dif; files_list+=$file' '; }
141    done
142
143    [ $mesg == 'Same' ] && echo $mesg
144    echo $mesg          \
145   >> ${FILE_INPT}
146
147    ## List different files for web comment
148    [ -n "${files_list}" ] && echo 'Inputs  : '${files_list}'differ<br>' \
149   >> temp_${FILE_NOTE}
150}
151
152job_pending() {
153    local outline=$( printf "%100s" ) time_elapsed=0 time_increment=30
154
155    sleep ${time_increment}
156
157    ## Append a log file while pending
158    while [[ $( eval ${TRUS_JSTA} ) && ${time_elapsed} -lt ${TRUS_TOUT} ]]; do
159   printf "\n%s\n" ${outline// /#}          \
160       >> computation.log
161   [ -n "${TRUS_JINF}" ] && eval ${JOB_INFO} \
162       >> computation.log
163   sleep ${time_increment}
164   time_elapsed=$(( ${time_elapsed} + ${time_increment} ))
165    done
166
167    sleep ${time_increment}
168
169    ## Kill remaining job & stop the test if it's too long
170    [ ${time_elapsed} -eq ${TRUS_TOUT} ] && { eval ${JOB_DELE} &> /dev/null; get_out 6; }
171}
172
173diff_results() {
174    local file
175    local files_list='' mesg='Same'
176
177    ## Simple diff
178    for file in 'ocean.output' *.stat; do
179   ## Stop if no benchmark files (ocean.output, eventual stat files)
180   [ ! -e ${TRUS_STOR}/$file ] && { TRUS_RSLT='FAILED'; get_out 7; }
181
182   diff -q $file ${TRUS_STOR}/$file
183
184   ## Continue even if it differs
185   [ $? -ne 0 ] && { TRUS_RSLT='FAILED'; mesg='Different'; files_list+=$file' '; }
186    done
187
188    [ $mesg == 'Same' ] && echo $mesg
189
190    ## List different files for web comment
191    [ -n "${files_list}" ] && echo 'Results : '${files_list}'differ<br>' \
192   >> temp_${FILE_NOTE}
193}
194
195diff_restart() {
196    local base_name comp dif file list_comp list_tmsp nb_dom time_step tmsp
197    local files_list='' dift=0
198
199    ## Stop if no benchmark files (ie time.step)
200    [ ! -e ${TRUS_STOR}/time.step ] && { TRUS_RSLT='FAILED'; get_out 7; }
201    time_step=$( cat ${TRUS_STOR}/time.step | tr -d [:space:] )
202
203    ## Find all restart files to rebuild
204    if [ $( find -regex ".*_restart.*[0-9]\.nc" -print -quit ) ]; then
205   base_name=$( find -regex ".*_restart.*[0-9]\.nc"                       \
206                | sed "s#^\./\(.*\)_[0-9]*_restart.*#\1#"       | sort -u  )
207   list_comp=$( find -regex ".*_restart.*[0-9]\.nc"                       \
208                | sed "s#^.*\(restart[a-z_]*\)_[0-9].*\.nc#\1#" | sort -u  )
209   list_tmsp=$( find -regex ".*_restart.*[0-9]\.nc"                       \
210                | sed "s#^.*\([0-9]\{8\}\)_restart.*#\1#"       | sort -u  )
211
212   ## Loop on each time step
213   for tmsp in ${list_tmsp}; do
214
215       for comp in ${list_comp}; do
216      file=${base_name}_${tmsp}_${comp}
217      nb_dom=$( find -name "${file}_[0-9]*.nc" | wc -l | awk '{ print $1 }' )
218
219      if   [ ${nb_dom} -gt 1 ]; then
220          ${TRUS_NGCM}/TOOLS/REBUILD_NEMO/rebuild_nemo -t ${TRUS_NPRO} $file ${nb_dom} \
221         > /dev/null
222      elif [ ${nb_dom} -eq 0 ]; then
223          TRUS_RSLT='FAILED' && get_out 8
224      fi
225
226      ## Compare restart files at same time step
227      if [ $tmsp -eq ${time_step} ]; then
228
229                    ## Stop if no benchmark files (restart file)
230          if [ -e ${TRUS_STOR}/$file.nc ]; then
231
232                   ## UNIX `cmp` not suitable (timestamp in .nc file)
233         dif=$( $TRUS_CDOD $file.nc ${TRUS_STOR}/$file.nc 2> /dev/null          \
234                | awk '/records/ {print $0}' | sed '2 s/^/,/' | tr -d '\n' )
235
236         ## CDO can return void stdout with no difference
237         if [[ -n "$dif" && $( echo $dif | awk '{print $1}' ) -ne 0 ]]; then
238             TRUS_RSLT='FAILED'
239             files_list+=$comp' ' && let dif_sum+=$( echo $dif | awk '{print $1}' )
240             echo $file.nc': '$dif
241         fi
242
243          else
244         TRUS_RSLT='FAILED' && get_out 7
245          fi
246
247      else
248          continue
249      fi
250
251       done
252
253   done
254
255        ## List different files for web comment with sum of different parameters
256   if [ ${dif_sum} -ne 0 ]; then
257       echo 'Restarts: '${files_list}${dif_sum}' record(s) differ<br>' \
258      >> temp_${FILE_NOTE}
259   else
260       echo 'Same'
261   fi
262
263    else
264   TRUS_RSLT='FAILED'
265    fi
266
267}
268
269get_time() {
270    [ -z "${TRUS_JTIM}" ] && return
271
272    ## Interest for checking unusual time computation
273    local time_cpu=$( eval ${TRUS_JTIM} )
274
275    printf "Elapsed time: "
276    echo ${time_cpu} | tee -a ${FILE_TIME}
277}
278
279get_memy() {
280    [[ -z "${TRUS_JPME}" && -z "${TRUS_JVME}" ]] && return
281
282    ## Interest for checking unusual memory usage
283    local memory_pmax=$( eval ${TRUS_JPME} ) memory_vmax=$( eval ${TRUS_JVME} )
284
285    printf "Memory max usage (physical/virtual): "
286    echo ${memory_pmax}' / '${memory_vmax} | tee -a ${FILE_MEMY}
287}
288
289comments() {
290    local opat
291    local line='' state=$1
292
293    if [ -e ocean.output ]; then
294        ## 'W A R N I N G' pattern by default
295   opat="-A2 \"^ $state\""
296   [ "$state" == 'E R R O R' ] && opat="-A4 \"$state\""
297
298        ## Select first occurence for web comment
299   line=$( eval grep -m1 $opat ocean.output | tr -d '\n' )
300    fi
301
302    [ -n "$line" ] && ( echo $line; printf "$line<br>" \
303   >> temp_${FILE_NOTE} )
304}
305
306log_make() {
307    ## Format comments for web
308    [ -e temp_${FILE_NOTE} ] && cat temp_${FILE_NOTE} | tr -d '\n' | sed 's/<br>$//' \
309   >> ${FILE_NOTE}
310
311    ## Construct txt file with all messenger files
312    paste -d ';' mesg_*.txt | tee ${TRUS_FILE}
313}
314
315prod_publish() {
316    local cmd
317    local rev=$( awk '/NEMOGCM/ {print $NF}' model.log )
318
319    ## Production mode (-p|--prod)
320    if [ ${TRUS_PROD} -eq 1 ]; then
321
322   ## Create or append trusting logfile
323   if [ -f ${TRUS_STOR}/trusting_$PATTERNAME.txt ]; then cmd='tail -1'; else cmd='cat'; fi
324
325   $cmd ${TRUS_FILE}                            \
326       >> ${TRUS_STOR}/trusting_$PATTERNAME.txt
327
328        ## Send mail only when FAILED
329   if [[ ! -z "${TRUS_MAIL}" && ${TRUS_RSLT} == 'FAILED' ]]; then
330
331       ## Content
332       cat <<END_MAIL      \
333      > trusting.mail
334Dear all,
335
336
337The trusting sequence has not completed successfully on new configuration ${TRUS_CONF} based on ${TRUS_REFE}.
338
339Here is the model summary:
340`cat model.log`
341
342First checking would be on the trusting environment files:
343${TRUS_USER}.cfg & ${TRUS_HPCC}.cfg
344
345For more details, look into the testing folder at:
346${TRUS_SCRA}
347
348An archive has been created to share the questionable configuration for further studies:
349${TRUS_STOR}/${TRUS_ARCH}
350
351END_MAIL
352
353       ## Send with detailed subject
354       mail -s "[NEMO Trusting][$rev][${TRUS_BRAN}][${TRUS_REFE}] ${TRUS_RSLT} ${TRUS_RORR}" ${TRUS_MAIL} \
355      <  trusting.mail
356   fi
357
358    fi
359}
360
361get_out() {
362    local time_step=0
363
364    TRUS_RORR=$1
365
366    printf "\n\nEnd of test\n"
367
368    ## In case of compilation error
369    cd ${TRUS_SCRA}
370
371    if [ ${TRUS_RSLT} == 'FAILED' ]; then
372   echo 'Failure'
373
374        ## Error identification
375   case ${TRUS_RORR} in
376            ## Compilation
377       '1') TRUS_RORR='XIOS compilation failed' ;; '2') TRUS_RORR='NEMO compilation failed';;
378       ## Submission
379       '3') TRUS_RORR='Missing input files'     ;; '4') TRUS_RORR='Job submission error'   ;;
380       ## Computation
381       '5') TRUS_RORR='Crashed at time step'    ;; '6') TRUS_RORR='Exceeded time limit'    ;;
382       ## Results
383       '7') TRUS_RORR='Missing previous outputs';; '8') TRUS_RORR='New outputs differ'     ;;
384       ## Other
385       '*') TRUS_RORR='Unknown error'           ;;
386   esac
387
388    else
389   echo 'Success' && TRUS_RORR='Code is reliable'
390    fi
391
392    ## Eventual comments from ocean.output
393    if [ "${TRUS_RORR}" == 'Crashed at time step' ]; then
394   comments 'E R R O R'
395   [ -e time.step ] && time_step=$( grep -o [0-9]* time.step )
396   TRUS_RORR+=' '$time_step
397    else
398   comments 'W A R N I N G'
399   [ "${TRUS_RORR}" == 'Exceeded time limit' ] && TRUS_RORR+=' '$(( ${TRUS_TOUT}/3600 ))'h'
400    fi
401
402    ## Last messenger files
403    #export TRUS_RORR
404    sed -i "2 s/.*/$TRUS_RSLT/" ${FILE_RSLT}; sed -i "2 s/.*/$TRUS_RORR/" ${FILE_STAT}
405
406    ## Save tested configuration if trusting failed in production mode (-p|--prod)
407    if [[ ${TRUS_RSLT} == 'FAILED' && ${TRUS_PROD} -eq 1 ]]; then
408   echo 'Creating archive '${TRUS_ARCH}' under '${TRUS_STOR}
409   tar -czf ${TRUS_STOR}/${TRUS_ARCH}               *                    \
410       -C   ${TRUS_NGCM}/CONFIG/${TRUS_CONF}/MY_SRC .                    \
411       -C   ${TRUS_NGCM}/CONFIG/${TRUS_CONF}        cpp_${TRUS_CONF}.fcm
412    fi
413
414    ## Logfile construct & eventual sending of notification email
415    printf "\nTrusting digest:\n----------------\n"
416    log_make
417    prod_publish
418
419    exit 0
420}
Note: See TracBrowser for help on using the repository browser.