source: TOOLS/PACK_IPSL/launch_and_measureTime.sh @ 1867

Last change on this file since 1867 was 1864, checked in by gpincka, 12 years ago

gestion (a ameliorer) des echecs ncrcat + check automatiques et aleatoires + resolution bug sur outil visu avancement + suppr liste 'manquant' vides

  • Property svn:executable set to *
File size: 14.8 KB
Line 
1#!/bin/bash
2
3function update_tasks_list
4{
5   local tasksListFile=$1 # fichier contenant la nouvelle liste de cmds
6   touch $tasksListFile
7   local logFileOfPrevPack=$2 # fichier log de relatif a l'execution de la derniere liste de cmds
8   local tasksListFileOfPrevPack=$3 # fichier contenant la derniere liste de cmds
9   
10   > $tasksListFile
11   
12   old_IFS=$IFS     # sauvegarde du séparateur de champ 
13   IFS=$'\n'     # nouveau séparateur de champ, le caractère fin de ligne   
14   for cmdReport in $( cat $logFileOfPrevPack )
15   do 
16       hasCmdGoodFormat=`echo $cmdReport | grep -e '^#executed by process' | wc -l `
17       if [ "x${hasCmdGoodFormat}" == "x0" ]
18       then
19           continue
20       fi
21       
22       local resCmd=`echo $cmdReport | awk '{print $9}' `
23       
24       if [ "x$resCmd" !=  "x0" ]
25       then
26           local cmdToPrint=`echo $cmdReport | awk '{print $NF}' `
27           case "x$resCmd" in
28           x5)
29               newCmdToPrint=`echo $cmdToPrint | sed 's;output_ncrcat;output_tar;' `
30               echo "./process_list.sh $newCmdToPrint" >> ${tasksListFile}
31           ;;
32           x10)
33               echo "./process_list.sh $cmdToPrint" >> ${tasksListFile}       
34               newCmdToPrint=`echo $cmdToPrint | sed 's;output_ncrcat;output_tar;' `
35               echo "./process_list.sh $newCmdToPrint" >> ${tasksListFile}
36           ;;
37           x50)
38               # ne fait rien, la liste, au depart a concatener, a ete taree
39               # car echec de la concatenation 
40           ;;
41           *)
42               echo "./process_list.sh $cmdToPrint" >> ${tasksListFile}
43           ;;
44           esac
45       fi
46   done
47   IFS=$old_IFS     # rétablissement du séparateur de champ par défaut
48   
49   # Il faut aussi rajouter les cmds qui n'ont pas ete traitees du tout,
50   # par exemple en cas d'interruption du calculateur
51   # Pour cela, on boucle sur la derniere liste de cmds et on cherche dans le
52   # fichier log associe si certaines sont absentes. On remet ces commandes (absentes)
53   # dans la nouvelle liste
54   old_IFS=$IFS     # sauvegarde du séparateur de champ 
55   IFS=$'\n'     # nouveau séparateur de champ, le caractère fin de ligne   
56   for cmd in $( cat $tasksListFileOfPrevPack )
57   do 
58       local list=`echo $cmd | awk '{print $NF}' `
59       hasListBeenTreated=`grep $list $logFileOfPrevPack | wc -l `
60       if [ "x${hasListBeenTreated}" == "x0" ]
61       then
62           echo $cmd  >> ${tasksListFile}
63       fi
64       
65 
66   done
67   IFS=$old_IFS     # rétablissement du séparateur de champ par défaut
68   
69   # Il peut arriver que 2 listes soient identiques, on empeche ce cas
70   cat ${tasksListFile} | sort | uniq > taskFile.txt
71   cat taskFile.txt > ${tasksListFile} 
72
73}
74
75function getNumeroOfCurrentTry
76{
77   local num_try="1"
78   tryNumFile=${USER_OUTPUT_PROGRESS}/numero_current_try.txt
79   if [ ! -e $tryNumFile ]
80   then
81       echo "Le fichier :" >> $badFailureFile
82       echo "$tryNumFile" >> $badFailureFile
83       echo "doit etre present dans le repertoire :" >> $badFailureFile
84       echo "${USER_OUTPUT_PROGRESS}" >> $badFailureFile
85       echo "et il doit contenir un numero d'essai" >> $badFailureFile
86       exit 1
87   fi
88   num_try=`head -n 1 $tryNumFile `
89   echo $num_try
90   
91}
92
93function getNumeroOfLastInstance
94{
95    local num_instance="0"
96    local numTry=$1
97    ici=$PWD
98    local progressDirectory="${USER_OUTPUT_PROGRESS}/TRY__${numTry}"
99    if [ ! -e $progressDirectory ]
100    then
101        echo "fonction getNumeroOfLastInstance :" >> $badFailureFile
102        echo "Le repertoire :" >> $badFailureFile
103        echo "$progressDirectory" >> $badFailureFile
104        echo "devrait exister. Il n'existe pas." >> $badFailureFile
105        exit 1
106    fi   
107    cd $progressDirectory
108   
109    listFiles=`ls | grep -e "inputCmd__try__${numTry}__instance__[[:digit:]]\{1,2\}.list" `
110    for listFile in $listFiles
111    do
112       num=`echo $listFile | awk -F"__" '{print $NF}' | awk -F"." '{print $1}' `
113       if [ $num -gt $num_instance ]
114       then
115           num_instance=$num 
116       fi
117    done 
118    cd $ici
119    echo $num_instance
120
121
122}
123
124
125function check_progress
126{
127   local file1=$1
128   local file2=$2
129   if [ "x${file1}" == "x" ] || [ "x${file2}" == "x" ]
130   then
131       echo "check_progress : Le nom d'au moins 1 des 2 fichiers d'entree est vide" >> $badFailureFile
132       exit 1
133   fi
134     
135   if [ ! -e $file1 ] || [ ! -e $file2 ]
136   then
137       echo "check_progress : au moins un des 2 fichiers suivants n'existe pas :" >> $badFailureFile
138       echo "$file1"
139       echo "$file2"
140       exit 1
141   fi
142   local nbLineFile1=`cat $file1 | wc -l `
143   local nbLineFile1=`cat $file2 | wc -l `
144   if [ $nbLineFile1 -ne $nbLineFile1 ]
145   then
146       echo 1
147       return
148   fi
149   
150   old_IFS=$IFS     # sauvegarde du séparateur de champ 
151   IFS=$'\n'     # nouveau séparateur de champ, le caractère fin de ligne   
152   for line in $( cat $file1 )
153   do
154       # echo $line
155       local isLineInFile2=`grep $line $file2 | wc -l `
156       if [ $isLineInFile2 -eq 0 ]
157       then
158           echo 1
159           return
160       fi
161   done
162   IFS=$old_IFS     # rétablissement du séparateur de champ par défaut   
163   echo 0
164}
165
166
167function update_report
168{ 
169    > $reportFile # on vide le fichier rapport
170    echo "Execution of tasks :" >> $reportFile
171    echo "------------------" >> $reportFile
172    cat $inputCmd >> $reportFile
173    echo >> $reportFile
174    echo "Results of tasks :" >> $reportFile 
175    echo "----------------" >> $reportFile
176    cat $output >> $reportFile
177    echo >> $reportFile
178    echo >> $reportFile
179
180}
181
182export RANDOM=$$ # random seed
183function gives_random_number
184{
185   lim=$1
186   bit=-1
187   let "bit = RANDOM % $lim"
188   bit=$(( $bit + 1 )) # nb entre 1 et $limit
189   echo $bit
190}
191
192########## batch directives : begin ##########
193#MSUB -r pack_ipsl          # Nom du job               
194### mutable directives ###
195#MSUB -o /ccc/dmfbuf/import_data.2/ccrt/dmnfs12/cont003/bacasable/GUILLAUME/PSEUDO_DMNFS_PROGRESS/zIGCM_OUT/detailed_pack_output/pack_ipsl_%I.o
196#MSUB -e /ccc/dmfbuf/import_data.2/ccrt/dmnfs12/cont003/bacasable/GUILLAUME/PSEUDO_DMNFS_PROGRESS/zIGCM_OUT/detailed_pack_output/pack_ipsl_%I.e
197#MSUB -n 7
198#MSUB -T 900
199#MSUB -A tgcc0013
200#MSUB -q standard
201#MSUB -Qos test
202########## batch directives : end ##########
203
204export JOB_DIR=${LS_SUBCWD:-${PWD}}
205export EXE_DIR=${JOB_DIR}
206source ${EXE_DIR}/DEM_utilities.sh
207
208export badFailureFile=${USER_OUTPUT_PROGRESS}/badFailure.txt
209
210export numCurrentTry=$( getNumeroOfCurrentTry )
211export progressDir="${USER_OUTPUT_PROGRESS}/TRY__${numCurrentTry}"
212if [ ! -e $progressDir ]
213then
214   echo "Le repertoire de suivi :" >> $badFailureFile
215   echo "$progressDir" >> $badFailureFile
216   echo "n'existe pas. STOP." >> $badFailureFile   
217   exit 1
218fi
219export numPrevInstance=$( getNumeroOfLastInstance $numCurrentTry )
220export numNewInstance=$(( $numPrevInstance + 1 ))
221
222export inputCmd="${progressDir}/inputCmd__try__${numCurrentTry}__instance__${numNewInstance}.list"
223export nextInputCmd="${progressDir}/nextInputCmd__try__${numCurrentTry}__instance__${numNewInstance}.list"
224export output="${progressDir}/packOutput__try__${numCurrentTry}__instance__${numNewInstance}.log"
225export reportFile="${progressDir}/report__try__${numCurrentTry}__instance__${numNewInstance}.log"
226export checkFile="${progressDir}/check__try__${numCurrentTry}__instance__${numNewInstance}.log"
227export checkFileTmp="checkTmp__try__${numCurrentTry}__instance__${numNewInstance}.txt"
228
229export noInterruptFile="${progressDir}/noInterrupt__try__${numCurrentTry}__instance__${numNewInstance}.txt"
230
231
232# a virer
233#echo "inputCmd=$inputCmd" >> $badFailureFile
234#echo "nextInputCmd=$nextInputCmd" >> $badFailureFile
235#echo "output=$nextInputCmd" >> $badFailureFile
236#echo "reportFile=$nextInputCmd" >> $badFailureFile
237#echo "noInterruptFile=$noInterruptFile" >> $badFailureFile
238
239# exit 0 # a virer
240
241# a virer
242#if [ ${numNewInstance} -ge 4 ]
243#then
244#    echo "inputCmd=$inputCmd" >> $badFailureFile
245#    echo "nextInputCmd=$nextInputCmd" >> $badFailureFile
246#    echo "output=$nextInputCmd" >> $badFailureFile
247#    echo "reportFile=$nextInputCmd" >> $badFailureFile
248#    echo "noInterruptFile=$noInterruptFile" >> $badFailureFile
249#    echo >> $badFailureFile
250#fi
251
252if [ ${numCurrentTry} -le 1 ] && [ ${numNewInstance} -le 1 ]
253then
254    # C'est le tout premier essai
255    # on construit la liste des taches a effectuer en inventoriant les fichiers *.liste
256    # dans les rep contenus dans le fichier "config_card.liste"
257    > ${inputCmd}
258    for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) ; do
259   
260       PATH_SIMU=$( dirname $CONFIG )
261       # echo "PATH_SIMU=$PATH_SIMU"
262
263       setOfListFiles=`find $PATH_SIMU -type f -name "*.list" `
264       for file in $setOfListFiles
265       do
266            echo "./process_list.sh $file" >> ${inputCmd}
267       done     
268    done
269   
270else
271    # if try > 1 && inst == 1 ==> construction liste cmd avec fichiers try - 1, derniere instance
272    #                             dans ce dernier cas, gerer une eventuelle interruption au try - 1
273    # if try > 1 && inst > 1  ==> construction liste cmd avec fichiers try, instance precedente
274    if [ ${numNewInstance} -ge 2 ]
275    then
276        nextInputCmd_of_PrevInst="${progressDir}/nextInputCmd__try__${numCurrentTry}__instance__${numPrevInstance}.list"
277        if [ ! -e $nextInputCmd_of_PrevInst ]
278        then
279            echo "Le fichier suivant :" >> $badFailureFile
280            echo "$nextInputCmd_of_PrevInst" >> $badFailureFile
281            echo "n'existe pas. Il devrait exister. STOP." >> $badFailureFile
282            exit 1
283        fi
284        cat $nextInputCmd_of_PrevInst > ${inputCmd}
285   
286    else # numNewInstance == 1
287        numPrevTry=$(( $numCurrentTry - 1 ))
288        # echo "numCurrentTry=$numCurrentTry" >> $badFailureFile # a virer
289        # echo "numPrevTry=$numPrevTry" >> $badFailureFile # a virer
290        # exit 1 # a virer
291        numLastInstInstanceInPrevTry=$( getNumeroOfLastInstance $numPrevTry )
292        noInterruptFile="${progressDir}/noInterrupt__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.txt"
293        if [ ! -e $noInterruptFile ]
294        then
295            # il y a eu interruption non prevue au dernier essai, il faut recomposer la liste des cmds avec les resultats
296            # de l'essai precedent, derniere instance
297            prevProgressDir="${USER_OUTPUT_PROGRESS}/TRY__${numPrevTry}"
298            nextInputCmd_of_LastInst="${prevProgressDir}/nextInputCmd__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.list"
299            output_of_LastInst="${prevProgressDir}/packOutput__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.log"
300            inputCmd_of_LastInst="${prevProgressDir}/inputCmd__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.list"
301            if [ ! -e $output_of_LastInst ] || [ ! -e $inputCmd_of_LastInst ]
302            then
303                echo "Les fichiers suivants :" >> $badFailureFile
304                echo "$output_of_LastInst" >> $badFailureFile
305                echo "$inputCmd_of_LastInst" >> $badFailureFile
306                echo "n'existent pas. Il devrait exister. STOP." >> $badFailureFile
307                exit 1
308            fi
309           
310            update_tasks_list ${nextInputCmd_of_LastInst} ${output_of_LastInst} ${inputCmd_of_LastInst}
311            cat $nextInputCmd_of_LastInst > ${inputCmd}
312        else
313            nextInputCmd_of_LastInst="${progressDir}/nextInputCmd__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.list"
314            if [ ! -e $nextInputCmd_of_LastInst ]
315            then
316                echo "Le fichier suivant :" >> $badFailureFile
317                echo "$nextInputCmd_of_LastInst" >> $badFailureFile
318                echo "n'existe pas. Il devrait exister. STOP." >> $badFailureFile
319                exit 1
320            fi
321            cat $nextInputCmd_of_LastInst > ${inputCmd}
322        fi
323       
324    fi
325fi
326
327# Initialisation du rapport : par defaut, les calculs ont ete interrompus
328echo "No report. Le computation must have interrupted." > $reportFile
329
330# exit 0 # a virer
331
332# a virer #########################################
333if [ ${numNewInstance} -ge 10 ]
334then
335    echo >> $badFailureFile
336    echo "10eme instance. STOP." >> $badFailureFile
337    exit 1
338fi
339###################################################
340# startTime=$( getDateMilliSeconds ) # suppr
341# echo "start time:$startTime" >> $timeHandlingFile # suppr
342> $timeEndFile # added
343
344ccc_mprun  ./glost_launch -R $timeLimitBeforeEnd ${inputCmd} 2>${output}
345
346### ccc_mprun  ./cmd_launch.exe ${inputCmd} 2>${output}
347
348###    ./cmd_launch.exe ${inputCmd} 2>${output}
349###    ccc_mprun -p standard -n ${BRIDGE_MSUB_NPROC} ./cmd_launch.exe ${inputCmd} 2>myIO/output.log
350###    mpirun -n 4 ./cmd_launch.exe myIO/inputCmd10.list 2>myIO/output.log
351
352# meantime=$( getTimeDiffSeconds $startTime ) # suppr
353
354endExecutionTime=$( getDateMilliSeconds )
355echo "end time:$endExecutionTime" >> $timeEndFile
356
357
358
359# echo "meantime ncrcat = $meantime"
360
361# exit 0 # a virer
362
363# Gestion des reprises :
364# --------------------
365
366update_report
367
368update_tasks_list $nextInputCmd $output $inputCmd
369
370# Verifications sur qq listes (dont le traitement semble correct) :
371# ----------------------------------------------------------------------------------------
372if [ "x${nbListsToCheck}" == "x" ]
373then
374    echo "nbre de listes a checker absent" >> $checkFile
375    echo "nbre de listes a checker absent" >> $badFailureFile
376    exit 1
377fi
378> $checkFileTmp
379# ensemble des listes concatenees correctement
380set_of_good_lists=`cat $output | grep -e '^#executed by process' | awk '{ if ($9==0){print $12} }' | grep "output_ncrcat" `
381
382# envoi des cmds de check dans fichier tmp
383for lst in $set_of_good_lists
384do
385   echo "./check_ncrcat_list.sh $lst" >> $checkFileTmp
386done
387
388# nombre de listes concatenees correctement
389nb_of_good_lists=`cat $checkFileTmp | wc -l `
390
391# le nb de listes a checker ne peut exceder le nb de listes disponibles pour le check
392if [ $nbListsToCheck -ge $nb_of_good_lists ]
393then
394    nbListsToCheck=$nb_of_good_lists
395fi
396nbLstToCheck_tmp=$nbListsToCheck
397
398while [ $nbLstToCheck_tmp -gt 0 ]
399do
400    random_number=$( gives_random_number $nbLstToCheck_tmp ) # nb aleatoire entre 1 et $nbLstToCheck_tmp
401    checkCmd=`sed -n "${random_number}p" $checkFileTmp `
402    $checkCmd # on envoie la cmd de check
403    resCmd=$?
404    if [ "x${resCmd}" != "x0" ]
405    then
406        echo "$checkCmd ==> not OK ==> stop everything." >> $checkFile
407        echo "$checkCmd ==> not OK ==> stop everything." >> $badFailureFile
408        # exit 1 # a retablir
409    else
410        echo "$checkCmd ==> OK" >> $checkFile
411    fi
412    sed -i "${random_number}d" $checkFileTmp # on retire la cmd qui vient d'etre effectuee du fichier tmp
413    nbLstToCheck_tmp=$(( $nbLstToCheck_tmp - 1 ))
414done
415
416
417rm $checkFileTmp
418# ----- Fin verif ------------------------------------------------------------------------
419
420echo "no interruption has occured" > ${noInterruptFile}
421
422# exit 0 # a virer
423
424# Tout s'est bien passe
425# ----------------------
426everythingOK=`cat $nextInputCmd | wc -l `
427if [ "x${everythingOK}" == "x0" ]
428then
429    echo "Tout s'est fini correctement" >> $badFailureFile
430    exit 0
431fi
432
433# y a t il progression ?
434# ----------------------
435resDiff=$( check_progress $inputCmd $nextInputCmd )
436# resDiff == 1 : fichiers differents
437# resDiff == 0 : fichiers identiques
438if [ "x${resDiff}" == "x0" ]
439then
440    echo "Il n'y pas plus de progression" >> $badFailureFile
441    exit 1
442fi
443
444# On enchaine avec le meme script
445ccc_msub launch_and_measureTime.sh
Note: See TracBrowser for help on using the repository browser.