1 | #!/bin/bash |
---|
2 | |
---|
3 | function insertDirectives |
---|
4 | { |
---|
5 | |
---|
6 | local batchFile="launch_and_measureTime.sh" |
---|
7 | local lineBeginMutableDrves=`grep -n "batch directives : begin" $batchFile | awk -F":" '{print $1}' ` |
---|
8 | local lineHeaderMutableDrves=`grep -n "mutable directives" $batchFile | awk -F":" '{print $1}' ` |
---|
9 | local lineEndMutableDrves=`grep -n "batch directives : end" $batchFile | awk -F":" '{print $1}' ` |
---|
10 | if [ "x${lineBeginMutableDrves}" == "x" ] || [ "x${lineHeaderMutableDrves}" == "x" ] || [ "x${lineEndMutableDrves}" == "x" ] |
---|
11 | then |
---|
12 | echo "Examen du fichier $batchFile :" |
---|
13 | echo "Il manque les balises commentees 'mutable directives' et 'batch directives : end' " |
---|
14 | exit 1 |
---|
15 | fi |
---|
16 | |
---|
17 | # echo "lineHeaderMutableDrves=$lineHeaderMutableDrves" |
---|
18 | # echo "lineEndMutableDrves=$lineEndMutableDrves" |
---|
19 | |
---|
20 | if [ $lineHeaderMutableDrves -ge $lineEndMutableDrves ] |
---|
21 | then |
---|
22 | echo "Examen du fichier $batchFile :" |
---|
23 | echo "les lignes 'mutable directives' et 'batch directives : end' n'existent pas ou ne sont" |
---|
24 | echo "pas bien placees l'une par rapport a l'autre ==> STOP." |
---|
25 | exit 1 |
---|
26 | fi |
---|
27 | |
---|
28 | # Suppression des anciennes directives |
---|
29 | local firstLineToMove=$(( $lineHeaderMutableDrves + 1 )) |
---|
30 | local lastLineToMove=$(( $lineEndMutableDrves - 1 )) |
---|
31 | if [ $firstLineToMove -lt $lineEndMutableDrves ] |
---|
32 | then |
---|
33 | sed -i "${firstLineToMove},${lastLineToMove}d" $batchFile |
---|
34 | fi |
---|
35 | |
---|
36 | # insertion des directives chargees a partir de "load_batch_directives.sh" |
---|
37 | local lineEndMutableDrves=`grep -n "batch directives : end" $batchFile | awk -F":" '{print $1}' ` |
---|
38 | sed -i "${lineEndMutableDrves}i\#MSUB -Qos $QosType" $batchFile |
---|
39 | sed -i "${lineEndMutableDrves}i\#MSUB -q $queueType" $batchFile |
---|
40 | sed -i "${lineEndMutableDrves}i\#MSUB -A $projectName" $batchFile |
---|
41 | sed -i "${lineEndMutableDrves}i\#MSUB -T $computationTime" $batchFile |
---|
42 | sed -i "${lineEndMutableDrves}i\#MSUB -n $nbProcs" $batchFile |
---|
43 | |
---|
44 | # insertion des directives specifiant les sorties des operations de pack |
---|
45 | sed -i "${lineEndMutableDrves}i\#MSUB -e ${DETAILLED_OUTPUT}/pack_ipsl_%I.e" $batchFile |
---|
46 | sed -i "${lineEndMutableDrves}i\#MSUB -o ${DETAILLED_OUTPUT}/pack_ipsl_%I.o" $batchFile |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | function check_machine |
---|
51 | { |
---|
52 | local host_name=`hostname ` |
---|
53 | local isMachineTitane=`echo $host_name | grep "titane" | wc -l ` |
---|
54 | local isMachineCurie=`echo $host_name | grep "curie" | wc -l ` |
---|
55 | |
---|
56 | if [ "x${isMachineTitane}" == "x0" ] && [ "x${isMachineCurie}" == "x0" ] |
---|
57 | then |
---|
58 | echo "Ce programme doit etre lance a partir 'curie' ou 'titane'. STOP." |
---|
59 | exit 1 |
---|
60 | fi |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | function check_glost_launch |
---|
65 | { |
---|
66 | local file_exec='glost_launch' |
---|
67 | if [ ! -e $file_exec ] |
---|
68 | then |
---|
69 | echo "Il n'y a pas l'executable glost_launch." |
---|
70 | echo "Vous devez compiler l'outil via make. " |
---|
71 | exit 1 |
---|
72 | fi |
---|
73 | } |
---|
74 | |
---|
75 | function checkParameters |
---|
76 | { |
---|
77 | isCheckVarOK=`echo $doYouWantCheck | grep -E '^(yes|no)$' | wc -l ` |
---|
78 | if [ "x${isCheckVarOK}" == "x0" ] |
---|
79 | then |
---|
80 | echo "La variable 'doYouWantCheck' doit etre yes ou no" |
---|
81 | exit 1 |
---|
82 | fi |
---|
83 | |
---|
84 | isRestartVarOK=`echo $forceRestartFromBegin | grep -E '^(yes|no)$' | wc -l ` |
---|
85 | if [ "x${isRestartVarOK}" == "x0" ] |
---|
86 | then |
---|
87 | echo "La variable 'forceRestartFromBegin' doit etre yes ou no" |
---|
88 | exit 1 |
---|
89 | fi |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | function getNumeroOfPreviousTry |
---|
94 | { |
---|
95 | local num_try="0" |
---|
96 | ici=$PWD |
---|
97 | cd $USER_OUTPUT_PROGRESS |
---|
98 | |
---|
99 | tryDirs=`ls | grep -e 'TRY__[[:digit:]]\{1,2\}$' ` |
---|
100 | for dir in $tryDirs |
---|
101 | do |
---|
102 | num=`echo $dir | awk -F"__" '{print $NF}' ` |
---|
103 | if [ $num -gt $num_try ] |
---|
104 | then |
---|
105 | num_try=$num |
---|
106 | fi |
---|
107 | done |
---|
108 | cd $ici |
---|
109 | echo $num_try |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | # indique si l'on recommence les traitement depuis le debut ou non |
---|
114 | restartExecFromZero=0 |
---|
115 | |
---|
116 | # On charge les variables d'environnement |
---|
117 | . load_ipslPack_env.sh |
---|
118 | |
---|
119 | # On charge les directives batch |
---|
120 | . load_batch_directives.sh |
---|
121 | |
---|
122 | # On charge les parametres |
---|
123 | . loadParameters.sh |
---|
124 | |
---|
125 | checkParameters |
---|
126 | |
---|
127 | if [ "x${forceRestartFromBegin}" == "xyes" ] |
---|
128 | then |
---|
129 | restartExecFromZero=1 |
---|
130 | fi |
---|
131 | |
---|
132 | |
---|
133 | # on verifie que la machine est 'curie' ou 'titane' |
---|
134 | check_machine |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | # on verifie que l outil glost a bien ete compile |
---|
139 | check_glost_launch |
---|
140 | |
---|
141 | |
---|
142 | ######## pour option -f ############# |
---|
143 | while [ $# -gt 0 ] |
---|
144 | do |
---|
145 | echo "boucle sur les arguments du script ..." |
---|
146 | echo "@=$@" |
---|
147 | case $1 in |
---|
148 | -f) restartExecFromZero=1 |
---|
149 | echo "force restart from the beginning ..." |
---|
150 | ;; |
---|
151 | -h|--help|-help) |
---|
152 | echo "---------------------------------------------------" |
---|
153 | echo "Usage: parallelPack.sh [-f]" |
---|
154 | echo "Description:" |
---|
155 | echo " Launches the simultaneous treatments (ncrcat, tar, cap) of" |
---|
156 | echo " file lists contained in the IGCM_DEM directory." |
---|
157 | echo " In case of machine crash, this script handle restarts from the point" |
---|
158 | echo " the machine crashed." |
---|
159 | echo |
---|
160 | echo "Options:" |
---|
161 | echo " -h, --help, -help" |
---|
162 | echo " Print this manual" |
---|
163 | echo " -f" |
---|
164 | echo " Force to restart the treatments from the beginning" |
---|
165 | echo "---------------------------------------------------" |
---|
166 | exit |
---|
167 | ;; |
---|
168 | esac |
---|
169 | shift |
---|
170 | done |
---|
171 | export restartExecFromZero=${restartExecFromZero} |
---|
172 | ###################################### |
---|
173 | |
---|
174 | ######### On insert les directives batch en en-tete du script "launch_and_measureTime.sh" ########## |
---|
175 | ######### lance plus loin. Seules les directives de nom du job et de sorties restent inchangees ########## |
---|
176 | |
---|
177 | insertDirectives |
---|
178 | |
---|
179 | # exit 0 # gpdebug : a virer |
---|
180 | |
---|
181 | # export inputCmd="${USER_OUTPUT_PROGRESS}/inputCmd.list" |
---|
182 | # export nextInputCmd="${USER_OUTPUT_PROGRESS}/nextInputCmd.list" |
---|
183 | # export output="${USER_OUTPUT_PROGRESS}/packOutput.log" |
---|
184 | # export reportFile="${USER_OUTPUT_PROGRESS}/report.log" |
---|
185 | |
---|
186 | ########## Si l'option -f est activee, on detruit tous les fichiers status ########## |
---|
187 | if [ "x$restartExecFromZero" == "x1" ] |
---|
188 | then |
---|
189 | echo "Deleting all status files ..." |
---|
190 | for CONFIG in $( awk '{print $1}' ${IGCM_DEM}/config_card.liste ) |
---|
191 | do |
---|
192 | PATH_SIMU=$( dirname $CONFIG ) |
---|
193 | ListStatFileInSimu=`find $PATH_SIMU -type f -name "*status" ` |
---|
194 | if [ "x$ListStatFileInSimu" != "x" ] |
---|
195 | then |
---|
196 | for file in $ListStatFileInSimu |
---|
197 | do |
---|
198 | if [ -e $file ] |
---|
199 | then |
---|
200 | rm -f $file |
---|
201 | fi |
---|
202 | |
---|
203 | done |
---|
204 | fi |
---|
205 | done |
---|
206 | echo "Deletion done." |
---|
207 | fi |
---|
208 | |
---|
209 | |
---|
210 | # Par ailleurs, on vide les fichiers de cmds, d'output et de rapport si option -f activee |
---|
211 | if [ "x${restartExecFromZero}" == "x1" ] |
---|
212 | then |
---|
213 | rm -rf ${USER_OUTPUT_PROGRESS}/TRY__* |
---|
214 | fi |
---|
215 | |
---|
216 | # exit 0 # a virer |
---|
217 | |
---|
218 | ##################################################################################### |
---|
219 | |
---|
220 | export JOB_DIR=${LS_SUBCWD:-${PWD}} |
---|
221 | export EXE_DIR=${JOB_DIR} |
---|
222 | source ${EXE_DIR}/DEM_utilities.sh |
---|
223 | |
---|
224 | ############## gpdebug : Pour gestion des erreurs ######################################### |
---|
225 | # Execute la function errorReceive() si reception d'un signal TERM |
---|
226 | trap 'DEM_errorReceive' TERM |
---|
227 | # liste des processus à détruire en cas d'erreur bloquante |
---|
228 | export listPID=$$ |
---|
229 | # fichier pour la transmission des messages d'erreur d'un fils au prog principal |
---|
230 | export errorMsgFile="${PWD}/errorMsg.txt" |
---|
231 | ############## gpdebug : fin ############################################################## |
---|
232 | |
---|
233 | check_nco_version # verification de la version de nco ####################### |
---|
234 | check_libccc_user # verif que le module libccc_user est charge ############## |
---|
235 | check_cdo # verif que le module cdo est charge ###################### |
---|
236 | |
---|
237 | # exit 0 # a virer |
---|
238 | |
---|
239 | export badFailureFile=${USER_OUTPUT_PROGRESS}/badFailure.txt |
---|
240 | > $badFailureFile # nouvel essai, on vide le fichier d'erreur |
---|
241 | tryNumFile=${USER_OUTPUT_PROGRESS}/numero_current_try.txt |
---|
242 | numPreviousTry=$( getNumeroOfPreviousTry ) |
---|
243 | # echo "numPreviousTry=$numPreviousTry" |
---|
244 | numNewTry=$(( $numPreviousTry + 1 )) |
---|
245 | |
---|
246 | # Pas de 4eme essai permis |
---|
247 | # ---------------------------- |
---|
248 | if [ $numNewTry -ge 4 ] |
---|
249 | then |
---|
250 | echo "Pas de 4eme essai permis" |
---|
251 | exit 1 |
---|
252 | fi |
---|
253 | |
---|
254 | # echo "numNewTry=$numNewTry" |
---|
255 | mkdir -p ${USER_OUTPUT_PROGRESS}/TRY__${numNewTry} |
---|
256 | echo $numNewTry > $tryNumFile |
---|
257 | |
---|
258 | # exit 0 # a virer |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | export timeLaunchStartFile="${USER_OUTPUT_PROGRESS}/timeLaunchStartFile.txt" |
---|
263 | > $timeLaunchStartFile |
---|
264 | startTime=$( getDateMilliSeconds ) |
---|
265 | echo "launch time:$startTime" > $timeLaunchStartFile |
---|
266 | |
---|
267 | export timeEndFile="${USER_OUTPUT_PROGRESS}/timeEndFile.txt" |
---|
268 | > $timeEndFile |
---|
269 | |
---|
270 | SCRIPT_NAME=$(basename ${0} ) |
---|
271 | |
---|
272 | DEM_log -0 "Demarrage de ${SCRIPT_NAME}" |
---|
273 | |
---|
274 | # ccc_msub -A tgcc0013 launch_and_measureTime.sh |
---|
275 | ccc_msub launch_and_measureTime.sh |
---|
276 | |
---|
277 | DEM_log -0 "Fin de ${SCRIPT_NAME}" |
---|
278 | |
---|
279 | |
---|
280 | elapsedTime=0 |
---|
281 | while [ $elapsedTime -lt 500 ] |
---|
282 | do |
---|
283 | sleep 5 |
---|
284 | elapsedTime=$(( $elapsedTime + 5 )) |
---|
285 | isFailureFileEmpty=`cat $badFailureFile | wc -l ` |
---|
286 | if [ "x${isFailureFileEmpty}" != "x0" ] |
---|
287 | then |
---|
288 | sleep 2 # on attend que le fichier soit correctement rempli |
---|
289 | cat $badFailureFile |
---|
290 | exit 0 |
---|
291 | fi |
---|
292 | done |
---|
293 | |
---|
294 | if [ ${elapsedTime} -ge 500 ] |
---|
295 | then |
---|
296 | echo "Les 500 sec sont ecoulees, les traitements continuent..." |
---|
297 | fi |
---|
298 | |
---|
299 | |
---|
300 | |
---|
301 | |
---|