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