source: TOOLS/PACK_IPSL/launch_and_measureTime.sh @ 1863

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

Traitement des listes ncrcat_output ==> output_tar + modif affichage du bilan dans showPack + suppression de IGCM_DEM dans launch_ipsl_pack

  • Property svn:executable set to *
File size: 12.4 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           *)
38               echo "./process_list.sh $cmdToPrint" >> ${tasksListFile}
39           ;;
40           esac
41       fi
42   done
43   IFS=$old_IFS     # rétablissement du séparateur de champ par défaut
44   
45   # Il faut aussi rajouter les cmds qui n'ont pas ete traitees du tout,
46   # par exemple en cas d'interruption du calculateur
47   # Pour cela, on boucle sur la derniere liste de cmds et on cherche dans le
48   # fichier log associe si certaines sont absentes. On remet ces commandes (absentes)
49   # dans la nouvelle liste
50   old_IFS=$IFS     # sauvegarde du séparateur de champ 
51   IFS=$'\n'     # nouveau séparateur de champ, le caractère fin de ligne   
52   for cmd in $( cat $tasksListFileOfPrevPack )
53   do 
54       local list=`echo $cmd | awk '{print $NF}' `
55       hasListBeenTreated=`grep $list $logFileOfPrevPack | wc -l `
56       if [ "x${hasListBeenTreated}" == "x0" ]
57       then
58           echo $cmd  >> ${tasksListFile}
59       fi
60       
61 
62   done
63   IFS=$old_IFS     # rétablissement du séparateur de champ par défaut     
64
65}
66
67function getNumeroOfCurrentTry
68{
69   local num_try="1"
70   tryNumFile=${USER_OUTPUT_PROGRESS}/numero_current_try.txt
71   if [ ! -e $tryNumFile ]
72   then
73       echo "Le fichier :" >> $badFailureFile
74       echo "$tryNumFile" >> $badFailureFile
75       echo "doit etre present dans le repertoire :" >> $badFailureFile
76       echo "${USER_OUTPUT_PROGRESS}" >> $badFailureFile
77       echo "et il doit contenir un numero d'essai" >> $badFailureFile
78       exit 1
79   fi
80   num_try=`head -n 1 $tryNumFile `
81   echo $num_try
82   
83}
84
85function getNumeroOfLastInstance
86{
87    local num_instance="0"
88    local numTry=$1
89    ici=$PWD
90    local progressDirectory="${USER_OUTPUT_PROGRESS}/TRY__${numTry}"
91    if [ ! -e $progressDirectory ]
92    then
93        echo "fonction getNumeroOfLastInstance :" >> $badFailureFile
94        echo "Le repertoire :" >> $badFailureFile
95        echo "$progressDirectory" >> $badFailureFile
96        echo "devrait exister. Il n'existe pas." >> $badFailureFile
97        exit 1
98    fi   
99    cd $progressDirectory
100   
101    listFiles=`ls | grep -e "inputCmd__try__${numTry}__instance__[[:digit:]]\{1,2\}.list" `
102    for listFile in $listFiles
103    do
104       num=`echo $listFile | awk -F"__" '{print $NF}' | awk -F"." '{print $1}' `
105       if [ $num -gt $num_instance ]
106       then
107           num_instance=$num 
108       fi
109    done 
110    cd $ici
111    echo $num_instance
112
113
114}
115
116
117function check_progress
118{
119   local file1=$1
120   local file2=$2
121   if [ "x${file1}" == "x" ] || [ "x${file2}" == "x" ]
122   then
123       echo "check_progress : Le nom d'au moins 1 des 2 fichiers d'entree est vide" >> $badFailureFile
124       exit 1
125   fi
126     
127   if [ ! -e $file1 ] || [ ! -e $file2 ]
128   then
129       echo "check_progress : au moins un des 2 fichiers suivants n'existe pas :" >> $badFailureFile
130       echo "$file1"
131       echo "$file2"
132       exit 1
133   fi
134   local nbLineFile1=`cat $file1 | wc -l `
135   local nbLineFile1=`cat $file2 | wc -l `
136   if [ $nbLineFile1 -ne $nbLineFile1 ]
137   then
138       echo 1
139       return
140   fi
141   
142   old_IFS=$IFS     # sauvegarde du séparateur de champ 
143   IFS=$'\n'     # nouveau séparateur de champ, le caractère fin de ligne   
144   for line in $( cat $file1 )
145   do
146       # echo $line
147       local isLineInFile2=`grep $line $file2 | wc -l `
148       if [ $isLineInFile2 -eq 0 ]
149       then
150           echo 1
151           return
152       fi
153   done
154   IFS=$old_IFS     # rétablissement du séparateur de champ par défaut   
155   echo 0
156}
157
158
159function update_report
160{ 
161    > $reportFile # on vide le fichier rapport
162    echo "Execution of tasks :" >> $reportFile
163    echo "------------------" >> $reportFile
164    cat $inputCmd >> $reportFile
165    echo >> $reportFile
166    echo "Results of tasks :" >> $reportFile 
167    echo "----------------" >> $reportFile
168    cat $output >> $reportFile
169    echo >> $reportFile
170    echo >> $reportFile
171
172}
173
174########## batch directives : begin ##########
175#MSUB -r pack_ipsl          # Nom du job               
176### mutable directives ###
177#MSUB -o /ccc/dmfbuf/import_data.2/ccrt/dmnfs12/cont003/bacasable/GUILLAUME/PSEUDO_DMNFS_PROGRESS/zIGCM_OUT/detailed_pack_output/pack_ipsl_%I.o
178#MSUB -e /ccc/dmfbuf/import_data.2/ccrt/dmnfs12/cont003/bacasable/GUILLAUME/PSEUDO_DMNFS_PROGRESS/zIGCM_OUT/detailed_pack_output/pack_ipsl_%I.e
179#MSUB -n 7
180#MSUB -T 900
181#MSUB -A tgcc0013
182#MSUB -q standard
183#MSUB -Qos test
184########## batch directives : end ##########
185
186export JOB_DIR=${LS_SUBCWD:-${PWD}}
187export EXE_DIR=${JOB_DIR}
188source ${EXE_DIR}/DEM_utilities.sh
189
190export badFailureFile=${USER_OUTPUT_PROGRESS}/badFailure.txt
191
192export numCurrentTry=$( getNumeroOfCurrentTry )
193export progressDir="${USER_OUTPUT_PROGRESS}/TRY__${numCurrentTry}"
194if [ ! -e $progressDir ]
195then
196   echo "Le repertoire de suivi :" >> $badFailureFile
197   echo "$progressDir" >> $badFailureFile
198   echo "n'existe pas. STOP." >> $badFailureFile   
199   exit 1
200fi
201export numPrevInstance=$( getNumeroOfLastInstance $numCurrentTry )
202export numNewInstance=$(( $numPrevInstance + 1 ))
203
204export inputCmd="${progressDir}/inputCmd__try__${numCurrentTry}__instance__${numNewInstance}.list"
205export nextInputCmd="${progressDir}/nextInputCmd__try__${numCurrentTry}__instance__${numNewInstance}.list"
206export output="${progressDir}/packOutput__try__${numCurrentTry}__instance__${numNewInstance}.log"
207export reportFile="${progressDir}/report__try__${numCurrentTry}__instance__${numNewInstance}.log"
208
209
210export noInterruptFile="${progressDir}/noInterrupt__try__${numCurrentTry}__instance__${numNewInstance}.txt"
211
212
213# a virer
214#echo "inputCmd=$inputCmd" >> $badFailureFile
215#echo "nextInputCmd=$nextInputCmd" >> $badFailureFile
216#echo "output=$nextInputCmd" >> $badFailureFile
217#echo "reportFile=$nextInputCmd" >> $badFailureFile
218#echo "noInterruptFile=$noInterruptFile" >> $badFailureFile
219
220# exit 0 # a virer
221
222# a virer
223#if [ ${numNewInstance} -ge 4 ]
224#then
225#    echo "inputCmd=$inputCmd" >> $badFailureFile
226#    echo "nextInputCmd=$nextInputCmd" >> $badFailureFile
227#    echo "output=$nextInputCmd" >> $badFailureFile
228#    echo "reportFile=$nextInputCmd" >> $badFailureFile
229#    echo "noInterruptFile=$noInterruptFile" >> $badFailureFile
230#    echo >> $badFailureFile
231#fi
232
233if [ ${numCurrentTry} -le 1 ] && [ ${numNewInstance} -le 1 ]
234then
235    # C'est le tout premier essai
236    # on construit la liste des taches a effectuer en inventoriant les fichiers *.liste
237    # dans les rep contenus dans le fichier "config_card.liste"
238    > ${inputCmd}
239    for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) ; do
240   
241       PATH_SIMU=$( dirname $CONFIG )
242       # echo "PATH_SIMU=$PATH_SIMU"
243
244       setOfListFiles=`find $PATH_SIMU -type f -name "*.list" `
245       for file in $setOfListFiles
246       do
247            echo "./process_list.sh $file" >> ${inputCmd}
248       done     
249    done
250   
251else
252    # if try > 1 && inst == 1 ==> construction liste cmd avec fichiers try - 1, derniere instance
253    #                             dans ce dernier cas, gerer une eventuelle interruption au try - 1
254    # if try > 1 && inst > 1  ==> construction liste cmd avec fichiers try, instance precedente
255    if [ ${numNewInstance} -ge 2 ]
256    then
257        nextInputCmd_of_PrevInst="${progressDir}/nextInputCmd__try__${numCurrentTry}__instance__${numPrevInstance}.list"
258        if [ ! -e $nextInputCmd_of_PrevInst ]
259        then
260            echo "Le fichier suivant :" >> $badFailureFile
261            echo "$nextInputCmd_of_PrevInst" >> $badFailureFile
262            echo "n'existe pas. Il devrait exister. STOP." >> $badFailureFile
263            exit 1
264        fi
265        cat $nextInputCmd_of_PrevInst > ${inputCmd}
266   
267    else # numNewInstance == 1
268        numPrevTry=$(( $numCurrentTry - 1 ))
269        # echo "numCurrentTry=$numCurrentTry" >> $badFailureFile # a virer
270        # echo "numPrevTry=$numPrevTry" >> $badFailureFile # a virer
271        # exit 1 # a virer
272        numLastInstInstanceInPrevTry=$( getNumeroOfLastInstance $numPrevTry )
273        noInterruptFile="${progressDir}/noInterrupt__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.txt"
274        if [ ! -e $noInterruptFile ]
275        then
276            # il y a eu interruption non prevue au dernier essai, il faut recomposer la liste des cmds avec les resultats
277            # de l'essai precedent, derniere instance
278            prevProgressDir="${USER_OUTPUT_PROGRESS}/TRY__${numPrevTry}"
279            nextInputCmd_of_LastInst="${prevProgressDir}/nextInputCmd__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.list"
280            output_of_LastInst="${prevProgressDir}/packOutput__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.log"
281            inputCmd_of_LastInst="${prevProgressDir}/inputCmd__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.list"
282            if [ ! -e $output_of_LastInst ] || [ ! -e $inputCmd_of_LastInst ]
283            then
284                echo "Les fichiers suivants :" >> $badFailureFile
285                echo "$output_of_LastInst" >> $badFailureFile
286                echo "$inputCmd_of_LastInst" >> $badFailureFile
287                echo "n'existent pas. Il devrait exister. STOP." >> $badFailureFile
288                exit 1
289            fi
290           
291            update_tasks_list ${nextInputCmd_of_LastInst} ${output_of_LastInst} ${inputCmd_of_LastInst}
292            cat $nextInputCmd_of_LastInst > ${inputCmd}
293        else
294            nextInputCmd_of_LastInst="${progressDir}/nextInputCmd__try__${numPrevTry}__instance__${numLastInstInstanceInPrevTry}.list"
295            if [ ! -e $nextInputCmd_of_LastInst ]
296            then
297                echo "Le fichier suivant :" >> $badFailureFile
298                echo "$nextInputCmd_of_LastInst" >> $badFailureFile
299                echo "n'existe pas. Il devrait exister. STOP." >> $badFailureFile
300                exit 1
301            fi
302            cat $nextInputCmd_of_LastInst > ${inputCmd}
303        fi
304       
305    fi
306fi
307
308# Initialisation du rapport : par defaut, les calculs ont ete interrompus
309echo "No report. Le computation must have interrupted." > $reportFile
310
311# exit 0 # a virer
312
313# a virer #########################################
314if [ ${numNewInstance} -ge 10 ]
315then
316    echo >> $badFailureFile
317    echo "10eme instance. STOP." >> $badFailureFile
318    exit 1
319fi
320###################################################
321# startTime=$( getDateMilliSeconds ) # suppr
322# echo "start time:$startTime" >> $timeHandlingFile # suppr
323> $timeEndFile # added
324
325ccc_mprun  ./glost_launch -R $timeLimitBeforeEnd ${inputCmd} 2>${output}
326
327### ccc_mprun  ./cmd_launch.exe ${inputCmd} 2>${output}
328
329###    ./cmd_launch.exe ${inputCmd} 2>${output}
330###    ccc_mprun -p standard -n ${BRIDGE_MSUB_NPROC} ./cmd_launch.exe ${inputCmd} 2>myIO/output.log
331###    mpirun -n 4 ./cmd_launch.exe myIO/inputCmd10.list 2>myIO/output.log
332
333# meantime=$( getTimeDiffSeconds $startTime ) # suppr
334
335endExecutionTime=$( getDateMilliSeconds )
336echo "end time:$endExecutionTime" >> $timeEndFile
337
338
339
340# echo "meantime ncrcat = $meantime"
341
342# exit 0 # a virer
343
344# Gestion des reprises :
345# --------------------
346
347update_report
348
349update_tasks_list $nextInputCmd $output $inputCmd
350
351echo "no interruption has occured" > ${noInterruptFile}
352
353# Tout s'est bien passe
354# ----------------------
355everythingOK=`cat $nextInputCmd | wc -l `
356if [ "x${everythingOK}" == "x0"]
357then
358    echo "Tout s'est fini correctement" >> $badFailureFile
359    exit 1
360fi
361
362# y a t il progression ?
363# ----------------------
364resDiff=$( check_progress $inputCmd $nextInputCmd )
365# resDiff == 1 : fichiers differents
366# resDiff == 0 : fichiers identiques
367if [ "x${resDiff}" == "x0" ]
368then
369    echo "Il n'y pas plus de progression" >> $badFailureFile
370    exit 1
371fi
372
373# On enchaine avec le meme script
374ccc_msub launch_and_measureTime.sh
Note: See TracBrowser for help on using the repository browser.