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 @ 5527

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

dev_r5092_CNRS_SETTE First trusting release for Ada

  • 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 -name "*${LAST_TIME_STEP}_restart*.nc" -print -quit ) ]; then
47   base_name=$( find -name "*${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 | tail -1 )
64
65      if [ ! -z "${nc_diff}" ]; then
66          export ST='FAILED'
67          printf "$CDO ${nc_diff}\n"
68      else
69          printf "identical\n"
70      fi
71
72       else
73      export ST='FAILED' && get_out 9
74       fi
75
76   done
77
78    else
79   export ST='FAILED'
80    fi
81
82}
83
84get_cpu_time() {
85    real_cpu_time=$( eval ${JOB_TIME} )
86    printf "Real CPU time\n${real_cpu_time}\n" | tee mesg_10_cputime_${CFG_USER}_${CFG_ARCH}.txt
87}
88
89get_inputs() {
90    if [ ! -z "${FORC_TAR}" ]; then
91   cmd_iol="tar -tvf ${NEMO_FORC}/${FORC_TAR}"; cmd_iof="tar -vxf ${NEMO_FORC}/${FORC_TAR}"
92    else
93   cmd_iol="ls ${NEMO_FORC}/*"                ; cmd_iof="\cp ${NEMO_FORC}/* ."
94    fi
95
96    ${cmd_iol} > inputs_list.txt
97    ${cmd_iof} > /dev/null
98}
99
100get_soft_rel() {
101    for rel in $CDO $COMPILER $MPI $NETCDF; do
102                                     arch_rel=$( echo $LOADEDMODULES | sed  "s#.*$rel/\([^:]*\).*#\1#" )
103   [ -z "${arch_rel}"  ]     && arch_rel=$( echo $PATH          | sed  "s#.*$rel/\([^/]*\).*#\1#" )
104   [ "$rel" == "$COMPILER" ] && arch_rel=$( $rel --version      | grep -m1 -o ' [0-9.]* '         )
105   echo $rel ${arch_rel} >> model.log
106    done
107
108    sed -n 4p model.log | sed 'i\Fortran compiler' > mesg_06_compiler_${CFG_USER}_${CFG_ARCH}.txt
109    sed -n 5p model.log | sed 'i\MPI libs'         > mesg_07_mpi_${CFG_USER}_${CFG_ARCH}.txt
110    sed -n 6p model.log | sed 'i\NetCDF libs'      > mesg_08_netcdf_${CFG_USER}_${CFG_ARCH}.txt
111}
112
113get_nemo_rev() {
114    svn_opt='status'
115
116    # If -v|--version option has been set, modify svn command
117    if   [ $( echo ${NEMO_VERS} | grep  "HEAD\|up\|update"   ) ]; then
118   svn_cmd='svn update -r HEAD'
119    elif [ $( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' ) ]; then
120   svn_cmd='svn update -r '$( echo ${NEMO_VERS} | tr -d '[:alpha:][:punct:]' )
121    else
122   svn_cmd='svn '${svn_opt}
123    fi
124
125    rev=0
126    for dir in ${NEMO_ARCH} ${NEMO_CONF} ${NEMO_ENGI} \
127               ${NEMO_EIOI} ${NEMO_EFCM}              \
128          ${NEMO_TCMP} ${NEMO_TRBD}              \
129          ${DIR_XIOS}                             ; do
130
131   # For time being, just get revision number from XIOS
132   if [ "$dir" == "${DIR_XIOS}" ]; then
133       rev_loc=$( svn info $dir | awk '(NR == 5) {print $NF}' )
134       echo   'XIOS '${rev_loc} >> model.log
135       printf "XIOS rev.\n"     >  mesg_05_xios_${CFG_USER}_${CFG_ARCH}.txt
136       printf "<a href=\"https://forge.ipsl.jussieu.fr/ioserver/changeset/${rev_loc}\" target=\"_blank\">${rev_loc}</a>" \
137                                >> mesg_05_xios_${CFG_USER}_${CFG_ARCH}.txt
138       continue
139   fi
140
141   echo ${svn_cmd} $dir': '$( ${svn_cmd} $dir )
142   rev_loc=$( svn info $dir | awk '(NR == 5) {print $NF}' )
143   (( ${rev_loc} >= $rev )) && rev=${rev_loc}
144    done
145
146    echo   'NEMOGCM '$rev   >> model.log
147    printf "NEMOGCM rev.\n" >  mesg_04_nemogcm_${CFG_USER}_${CFG_ARCH}.txt
148    printf "<a href=\"https://forge.ipsl.jussieu.fr/nemo/changeset/$rev\" target=\"_blank\">$rev</a>" \
149                       >> mesg_04_nemogcm_${CFG_USER}_${CFG_ARCH}.txt
150}
151
152mesg_make() {
153    paste -d ';' mesg_*_${CFG_USER}_${CFG_ARCH}.txt > trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt
154    cat                                               trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt
155}
156
157mesg_publish() {
158 
159if [ $PUBLISH -eq 1 ]; then
160
161  if [ -f ${REFE_DIR}/trusting_${CFG_USER}_${CFG_ARCH}.txt ]; then cmd='tail -1'; else cmd='cat'; fi
162
163  $cmd trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt >> ${REFE_DIR}/trusting_${CFG_USER}_${CFG_ARCH}.txt
164
165  # Send mail only when FAILED
166  if [[ ! -z $EMAIL && "$ST" == 'FAILED' ]]; then
167      cat << END_MAIL > trusting.mail
168XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
169
170Dear $USER,
171
172The trusting sequence for ${REFE_CONF} has failed.
173Directory: ${TEST_DIR}
174Archive: ${REFE_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.tar.gz
175
176XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
177
178END_MAIL
179
180      if [ -e ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt ]; then
181     cat ${TEST_DIR}/trusting_${DATESTR}_${CFG_USER}_${CFG_ARCH}.txt  >> trusting.mail
182      fi
183      mail -s "[trusting ${REFE_CONF}] $ST $ERR" $EMAIL  <  trusting.mail
184  fi
185
186fi
187}
188
189print_step() { printf "Step.....\n$1\n"; }
190
191get_out() {
192    ERR=$1
193
194    printf "Status\n$ST\n"  > mesg_02_status_${CFG_USER}_${CFG_ARCH}.txt
195
196    if [ "$ST" == 'FAILED' ]; then
197   cd ${TEST_DIR}
198
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_ERR};;  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.