source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 437

Last change on this file since 437 was 437, checked in by sdipsl, 13 years ago

Send mail notification when computing job stops
It could be that we send a notification if a post-processing job stops in PROD mode ---> need some refactoring and caution...

File size: 31.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sébastien Denvil
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision:: 423                                      $ Revision of last commit
7# $Author:: sdipsl                                     $ Author of last commit
8# $Date:: 2011-02-18 16:49:14 +0100 (ven. 18 févr. 20#$ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for IITM IBM machine
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset -r MASTER=iitm01
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81
82#====================================================
83# Host specific DIRECTORIES
84#====================================================
85
86#====================================================
87#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
88typeset -r R_EXE="${MODIPSL}/bin"
89
90#====================================================
91#- SUBMIT_DIR : submission dir
92typeset SUBMIT_DIR=${SUBMIT_DIR:=${LOADL_STEP_INITDIR}}
93
94#====================================================
95#- ARCHIVE
96typeset -r ARCHIVE=$( echo ${HOME} | sed -e "s/gpfs1/gpfs3/" )
97
98#====================================================
99#- Mirror libIGCM from iitm to a post-processing machine
100typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
101
102#====================================================
103#- libIGCM_POST
104typeset -r HOME_POST=${HOME}
105typeset -r libIGCM_POST=${libIGCM}
106
107#====================================================
108#- IN
109typeset -r R_IN=${R_IN:=/gpfs1/home/sabin}
110typeset -r R_IN_ECMWF=${R_IN:=/gpfs1/home/sabin}
111
112#====================================================
113#- OUT
114typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
115
116#====================================================
117#- OUT_POST
118typeset -r R_OUT_POST=${ARCHIVE}/IGCM_OUT_SCRIPT
119
120#====================================================
121#- RUN_DIR_PATH : Temporary working directory (=> TMP)
122typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${ARCHIVE}/RUN/${LOADL_STEP_ID}}
123
124#====================================================
125#- BIG_DIR : BIG_DIR to store files waiting for rebuild
126typeset -r BIG_DIR=${BIG_DIR:=${ARCHIVE}/REBUILD}
127
128#====================================================
129#- HOST_MPIRUN_COMMAND
130typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time poe"}
131
132#====================================================
133#- Max number of arguments passed to nco operator or demigration command
134UNIX_MAX_LIMIT=360
135
136#D-#==================================================
137#D-function IGCM_sys_RshMaster
138#D-* Purpose: Just a fake command to wrapp
139#D-           IGCM_card call in post-treatment
140#D-           Ulam do not see brodie filesystem
141#D-           Cesium do not see all mercure filesystem
142#D-           That's why we need this hack.
143#D-* Examples:
144#D-
145function IGCM_sys_RshMaster {
146    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
147    /bin/ksh <<-EOF
148    ${@}
149EOF
150    if [ $? -gt 0 ] ; then
151        echo "IGCM_sys_RshArchive : erreur."
152        IGCM_debug_Exit "IGCM_sys_RshArchive"
153    fi
154    IGCM_debug_PopStack "IGCM_sys_RshMaster"
155}
156
157#D-#==================================================
158#D-function IGCM_sys_RshArchive
159#D-* Purpose: Archive rsh command
160#D-* Examples:
161#D-
162function IGCM_sys_RshArchive {
163    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
164    /bin/ksh <<-EOF
165    ${@}
166EOF
167    if [ $? -gt 0 ] ; then
168        echo "IGCM_sys_RshArchive : erreur."
169        IGCM_debug_Exit "IGCM_sys_RshArchive"
170    fi
171    IGCM_debug_PopStack "IGCM_sys_RshArchive"
172}
173
174#D-#==================================================
175#D-function IGCM_sys_RshPost
176#D-* Purpose: Post-process rsh command
177#D-* Examples:
178#D-
179function IGCM_sys_RshPost {
180    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
181    if ( $DEBUG_sys ) ; then
182        echo "IGCM_sys_RshPost :" $@
183    fi
184    /bin/ksh ${@}
185    #rsh ulam exec /bin/ksh ${@}
186    if [ $? -gt 0 ] ; then
187        echo "IGCM_sys_RshPost : erreur."
188        IGCM_debug_Exit "IGCM_sys_RshPost"
189    fi
190    IGCM_debug_PopStack "IGCM_sys_RshPost"
191}
192
193#D-#==================================================
194#D-function IGCM_sys_SendMail
195#D-* Purpose: Send mail when simulation is over
196#D-* Examples:
197#D-
198function IGCM_sys_SendMail {
199    IGCM_debug_PushStack "IGCM_sys_SendMail" $@
200    if ( $DEBUG_sys ) ; then
201        echo "IGCM_sys_SendMail :" $@
202    fi
203
204    if ( ${ExitFlag} ) ; then
205        status=FAILED
206        cat  << END_MAIL > job_end.mail
207Dear ${LOGIN},
208
209  Simulation ${config_UserChoices_JobName} failed on supercomputer `hostname`.
210  Job started : ${PeriodDateBegin}
211  Job ended   : ${PeriodDateEnd}
212  Output files are available in ${R_SAVE}
213  Script files, Script Outputs and Debug files are available in ${SUBMIT_DIR}
214END_MAIL
215    else
216        status=COMPLETED
217        cat  << END_MAIL > job_end.mail
218Dear ${LOGIN},
219
220  Simulation ${config_UserChoices_JobName} is finished on supercomputer `hostname`.
221  Job started : ${DateBegin}
222  Job ended   : ${DateEnd}
223  Ouput files are available in ${R_SAVE}
224  Script files and Script Outputs are available in ${SUBMIT_DIR}
225END_MAIL
226    fi
227
228    if [ ! -z ${config_UserChoices_MailName} ] ; then
229        mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
230    elif [ -f ~/.forward ] ; then
231        mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
232    else
233        mailx -s "${config_UserChoices_JobName} ${status}" ${USER} < job_end.mail
234    fi
235
236    if [ $? -gt 0 ] ; then
237        echo "IGCM_sys_SendMail : erreur."
238        IGCM_debug_Exit "IGCM_sys_SendMail"
239    fi
240    IGCM_debug_PopStack "IGCM_sys_SendMail"
241}
242
243#D-#==================================================
244#D-function IGCM_sys_Mkdir
245#D-* Purpose: Master locale mkdir command
246#D-* Examples:
247#D-
248function IGCM_sys_Mkdir {
249    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
250    if ( $DEBUG_sys ) ; then
251        echo "IGCM_sys_Mkdir :" $@
252    fi
253    if [ ! -d ${1} ]; then
254        \mkdir -p $1
255        if [ $? -gt 0 ] ; then
256            echo "IGCM_sys_Mkdir : erreur."
257            IGCM_debug_Exit "IGCM_sys_Mkdir"
258        fi
259    fi
260    # vérification :
261    if [ ! -d ${1} ] ; then
262        echo "IGCM_sys_Mkdir : erreur."
263        IGCM_debug_Exit "IGCM_sys_Mkdir"
264    fi
265    IGCM_debug_PopStack "IGCM_sys_Mkdir"
266}
267
268#D-#==================================================
269#D-function IGCM_sys_MkdirArchive
270#D-* Purpose: Mkdir on Archive
271#D-* Examples:
272#D-
273function IGCM_sys_MkdirArchive {
274    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
275    if ( $DEBUG_sys ) ; then
276        echo "IGCM_sys_MkdirArchive :" $@
277    fi
278    #- creation de repertoire sur le serveur fichier
279    mkdir -p $1
280
281    if [ $? -gt 0 ] ; then
282        echo "IGCM_sys_MkdirArchive : erreur."
283        IGCM_debug_Exit "IGCM_sys_MkdirArchive"
284    fi
285    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
286}
287
288#D-#==================================================
289#D-function IGCM_sys_MkdirWork
290#D-* Purpose: Mkdir on Work
291#D-* Examples:
292#D-
293function IGCM_sys_MkdirWork {
294    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
295    if ( $DEBUG_sys ) ; then
296        echo "IGCM_sys_MkdirWork :" $@
297    fi
298    #- creation de repertoire sur le serveur fichier
299    if [ ! -d ${1} ]; then 
300        \mkdir -p $1
301        if [ $? -gt 0 ] ; then
302            echo "IGCM_sys_MkdirWork : erreur."
303            IGCM_debug_Exit "IGCM_sys_MkdirWork"
304        fi
305    fi
306    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
307}
308
309#D-#==================================================
310#D-function IGCM_sys_Cd
311#D-* Purpose: master cd command
312#D-* Examples:
313#D-
314function IGCM_sys_Cd {
315    IGCM_debug_PushStack "IGCM_sys_Cd" $@
316    if ( $DEBUG_sys ) ; then
317        echo "IGCM_sys_Cd :" $@
318    fi
319    \cd $1
320    if [ $? -gt 0 ] ; then
321        echo "IGCM_sys_Cd : erreur."
322        IGCM_debug_Exit "IGCM_sys_Cd"
323    fi
324    IGCM_debug_PopStack "IGCM_sys_Cd"
325}
326
327#D-#==================================================
328#D-function IGCM_sys_Chmod
329#D-* Purpose: Chmod
330#D-* Examples:
331#D-
332function IGCM_sys_Chmod {
333    IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
334    if ( $DEBUG_sys ) ; then
335        echo "IGCM_sys_Chmod :" $@
336    fi
337    if [ $DRYRUN -le 1 ]; then
338        \chmod $@
339        if [ $? -gt 0 ] ; then
340            echo "IGCM_sys_Chmod : erreur."
341            IGCM_debug_Exit "IGCM_sys_Chmod"
342        fi
343    else
344        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
345    fi
346    IGCM_debug_PopStack "IGCM_sys_Chmod"
347}
348
349#D-#==================================================
350#D-function IGCM_sys_FileSize
351#D-* Purpose: Filesize
352#D-* Examples:
353#D-
354function IGCM_sys_FileSize {
355    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
356
357    typeset sizeF
358    set +A sizeF -- $( ls -la ${1} )
359    if [ $? -gt 0 ] ; then
360        IGCM_debug_Exit "IGCM_sys_FileSize"
361    fi
362    eval ${2}=${sizeF[4]}
363
364    IGCM_debug_PopStack "IGCM_sys_FileSize"
365}
366
367#D-#==================================================
368#D-function IGCM_sys_TestDir
369#D-* Purpose: Test Directory that must exists
370#D-* Examples:
371#D-
372function IGCM_sys_TestDir {
373    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
374    if ( $DEBUG_sys ) ; then
375        echo "IGCM_sys_TestDir :" $@
376    fi
377    typeset ExistFlag
378    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
379    IGCM_debug_PopStack "IGCM_sys_TestDir"
380
381    return ${ExistFlag}
382}
383
384#D-#==================================================
385#D-function IGCM_sys_TestDirArchive
386#D-* Purpose: Test Directory that must exists on Archive
387#D-* Examples:
388#D-
389function IGCM_sys_TestDirArchive {
390    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
391    if ( $DEBUG_sys ) ; then
392        echo "IGCM_sys_TestDirArchive :" $@
393    fi
394    typeset ExistFlag
395    ExistFlag=$( IGCM_sys_RshArchive "[ -d $1 ] && echo 0 || echo 1" )
396    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
397
398    return ${ExistFlag}
399}
400
401#D-#==================================================
402#D-function IGCM_sys_TestFileArchive
403#D-* Purpose: Test file that must NOT EXISTS on Archive
404#D-* Examples:
405#D-
406function IGCM_sys_TestFileArchive {
407    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
408    typeset ExistFlag
409    ExistFlag=$( IGCM_sys_RshArchive "[ -f $1 ] && echo 0 || echo 1" )
410    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
411
412    return ${ExistFlag}
413}
414
415#D-#==================================================
416#D-function IGCM_sys_CountFileArchive
417#D-* Purpose: Count files on Archive filesystem
418#D-* Examples:
419#D-
420function IGCM_sys_CountFileArchive {
421    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
422    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
423    if [ $? -gt 0 ] ; then
424        echo "IGCM_sys_CountFileArchive : erreur."
425    fi
426    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
427}
428
429#D-#==================================================
430#D-function IGCM_sys_Tree
431#D-* Purpose: Tree directories with files on ${ARCHIVE}
432#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
433#D-
434function IGCM_sys_Tree {
435    IGCM_debug_PushStack "IGCM_sys_Tree" $@
436    if ( $DEBUG_sys ) ; then
437        echo "IGCM_sys_Tree :" $@
438    fi
439
440    \ls -r $@
441
442    IGCM_debug_PopStack "IGCM_sys_Tree"
443}
444
445#D-#==================================================
446#D-function IGCM_sys_Tar
447#D-* Purpose: master un-tar command
448#D-* Examples:
449#D-
450function IGCM_sys_Tar {
451    IGCM_debug_PushStack "IGCM_sys_Tar" $@
452    if ( $DEBUG_sys ) ; then
453        echo "IGCM_sys_Tar :" $@
454    fi
455    \tar cvf $@
456    if [ $? -gt 0 ] ; then
457        echo "IGCM_sys_Tar : erreur."
458        IGCM_debug_Exit "IGCM_sys_Tar"
459    fi
460    \tar tvf $1
461
462    IGCM_debug_PopStack "IGCM_sys_Tar"
463}
464
465#D-#==================================================
466#D-function IGCM_sys_UnTar
467#D-* Purpose: master un-tar command
468#D-* Examples:
469#D-
470function IGCM_sys_UnTar {
471    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
472    if ( $DEBUG_sys ) ; then
473        echo "IGCM_sys_UnTar :" $@
474    fi
475    \tar xvf $1
476    if [ $? -gt 0 ] ; then
477        echo "IGCM_sys_UnTar : erreur."
478        IGCM_debug_Exit "IGCM_sys_UnTar"
479    fi
480    IGCM_debug_PopStack "IGCM_sys_UnTar"
481}
482
483#D-#==================================================
484#D-function IGCM_sys_Qsub
485#D-* Purpose: Qsub new job
486#D-* Examples:
487#D-
488function IGCM_sys_Qsub {
489    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
490    if ( $DEBUG_sys ) ; then
491        echo "IGCM_sys_Qsub :" $@
492    fi
493    {
494      [ ${#@} = 1 ] &&  { cd $LOADL_STEP_INITDIR ; /usr/lpp/LoadL/full/bin/llsubmit $1 ; ERROR=$? ; cd - ; }
495      [ ${#@} = 2 ] &&  { cd $2 ; /usr/lpp/LoadL/full/bin/llsubmit $1 ; ERROR=$? ; cd - ; }
496    }
497    if [ ${ERROR} -gt 0 ] ; then
498        echo "IGCM_sys_Qsub : erreur $@."
499        IGCM_debug_Exit "IGCM_sys_Qsub"
500    fi
501    IGCM_debug_PopStack "IGCM_sys_Qsub"
502}
503
504#D-#==================================================
505#D-function IGCM_sys_QsubPost
506#D-* Purpose: Qsub new job on scalaire
507#D-* Examples:
508#D-
509function IGCM_sys_QsubPost {
510    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
511    if ( $DEBUG_sys ) ; then
512        echo "IGCM_sys_QsubPost :" $@
513    fi
514    cd ${POST_DIR}
515    /usr/lpp/LoadL/full/bin/llsubmit ${libIGCM_POST}/$1.job
516    cd -
517    if [ $? -gt 0 ] ; then
518        echo "IGCM_sys_QsubPost : erreur " $@
519        IGCM_debug_Exit "IGCM_sys_QsubPost"
520    fi
521    IGCM_debug_PopStack "IGCM_sys_QsubPost"
522}
523
524#D-*************************
525#D- File transfer functions
526#D-*************************
527#D-
528
529#D-#==================================================
530#D-function IGCM_sys_Rsync_out
531#D-* Purpose: treat return val of rsync
532#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
533#D-  Error values and explanations can depend on your system version.
534function IGCM_sys_Rsync_out {
535    RET=$1
536    if [ ! $RET ] ; then
537        echo "rsync error !"
538    fi
539
540    if [ $MYLANG = "fr" ]; then
541        case $RET in
542            0)  return ;;
543            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
544                echo "Erreur de syntaxe ou d'utilisation."
545                return;;
546            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
547                echo "Incompatibilité de protocole."
548                return;;
549            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
550                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
551                echo "répertoires"
552                return;;
553            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
554                echo "Action demandée non supportée : une tentative de manipulation de"
555                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
556                echo "été faite ; ou une option qui est supportée par le  client  mais"
557                echo "pas par le serveur a été spécifiée."
558                return;;
559            10) echo "Erreur de rsync ; RERR_SOCKETIO"
560                echo "Erreur dans le socket d'entrée sortie"
561                return;;
562            11) echo "Erreur de rsync ; RERR_FILEIO"
563                echo "Erreur d'entrée sortie fichier"
564                return;;
565            12) echo "Erreur de rsync ; RERR_STREAMIO"
566                echo "Erreur dans flux de donnée du protocole rsync"
567                return;;
568            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
569                echo "Erreur avec les diagnostics du programme"
570                return;;
571            14) echo "Erreur de rsync ; RERR_IPC"
572                echo "Erreur dans le code IPC"
573                return;;
574            20) echo "Erreur de rsync ; RERR_SIGNAL"
575                echo "SIGUSR1 ou SIGINT reçu"
576                return;;
577            21) echo "Erreur de rsync ; RERR_WAITCHILD"
578                echo "Une erreur retournée par waitpid()"
579                return;;
580            22) echo "Erreur de rsync ; RERR_MALLOC"
581                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
582                return;;
583            23) echo ""
584                echo "Erreur fichier inexistant"
585                return;;
586            30) echo "Erreur de rsync ; RERR_TIMEOUT"
587                echo "Temps d'attente écoulé dans l'envoi/réception de données"
588                return;;
589            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
590                return;;
591        esac
592    elif [ $MYLANG = "en" ] ; then
593        case $RET in
594            0)  return;;               
595            1)  echo "rsync error : Syntax or usage error "
596                return;;
597            2)  echo "rsync error : Protocol incompatibility "
598                return;;
599            3)  echo "rsync error : Errors selecting input/output files, dirs"
600                return;;
601            4)  echo "rsync error : Requested action not supported: an attempt"
602                echo "was made to manipulate 64-bit files on a platform that cannot support"
603                echo "them; or an option was specified that is supported by the client and"
604                echo "not by the server."
605                return;;
606            5)  echo "rsync error : Error starting client-server protocol"
607                return;;
608            10) echo "rsync error : Error in socket I/O "
609                return;;
610            11) echo "rsync error : Error in file I/O "
611                return;;
612            12) echo "rsync error : Error in rsync protocol data stream "
613                return;;
614            13) echo "rsync error : Errors with program diagnostics "
615                return;;
616            14) echo "rsync error : Error in IPC code "
617                return;;
618            20) echo "rsync error : Received SIGUSR1 or SIGINT "
619                return;;
620            21) echo "rsync error : Some error returned by waitpid() "
621                return;;
622            22) echo "rsync error : Error allocating core memory buffers "
623                return;;
624            23) echo "rsync error : Partial transfer due to error"
625                return;;
626            24) echo "rsync error : Partial transfer due to vanished source files"
627                return;;
628            30) echo "rsync error : Timeout in data send/receive "
629                return;;
630            *)  echo "rsync error : return code of rsync unknown :" $RET
631                return;;
632        esac
633    else
634        echo "unknown language $MYLANG."
635        return
636    fi
637}
638
639#D-#==================================================
640#D-function IGCM_sys_Cp
641#D-* Purpose: generic cp
642#D-* Examples:
643#D-
644function IGCM_sys_Cp {
645    IGCM_debug_PushStack "IGCM_sys_Cp" $@
646    if ( $DEBUG_sys ) ; then
647        echo "IGCM_sys_Cp :" $@
648    fi
649
650    typeset RET
651
652    echo cp $@ > out_rsync 2>&1
653    \cp $@ >> out_rsync 2>&1
654    RET=$?
655
656    if [ ${RET} -gt 0 ] ; then
657        echo "IGCM_sys_Cp : error."
658        cat out_rsync
659        IGCM_debug_Exit "IGCM_sys_Cp"
660    fi
661    IGCM_debug_PopStack "IGCM_sys_Cp"
662}
663
664#D-#==================================================
665#D-function IGCM_sys_Rm
666#D-* Purpose: generic rm
667#D-* Examples:
668#D-
669function IGCM_sys_Rm {
670    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
671    if ( $DEBUG_sys ) ; then
672        echo "IGCM_sys_Rm :" $@
673    fi
674
675    typeset RET
676
677    echo rm $@ > out_rsync 2>&1
678    \rm $@ >> out_rsync 2>&1
679    RET=$?
680
681    if [ ${RET} -gt 0 ] ; then
682        echo "IGCM_sys_Rm : error."
683        cat out_rsync
684        IGCM_debug_Exit "IGCM_sys_Rm"
685    fi
686    IGCM_debug_PopStack "IGCM_sys_Rm"
687}
688
689#D-#==================================================
690#D-function IGCM_sys_RmRunDir
691#D-* Purpose: rm tmpdir (dummy function most of the time batch
692#D-                      scheduler will do the job)
693#D-* Examples:
694#D-
695function IGCM_sys_RmRunDir {
696    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
697    if ( $DEBUG_sys ) ; then
698        echo "IGCM_sys_RmRunDir :" $@
699    fi
700
701    typeset RET
702
703    echo rm $@ > out_rsync 2>&1
704    \rm $@ >> out_rsync 2>&1
705    RET=$?
706
707    if [ ${RET} -gt 0 ] ; then
708        echo "IGCM_sys_RmRunDir : error."
709        cat out_rsync
710        IGCM_debug_Exit "IGCM_sys_RmRunDir"
711    else
712        \rm out_rsync
713    fi
714
715    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
716}
717
718#D-#==================================================
719#D-function IGCM_sys_Mv
720#D-* Purpose: generic move
721#D-* Examples:
722#D-
723function IGCM_sys_Mv {
724    IGCM_debug_PushStack "IGCM_sys_Mv" $@
725    if ( $DEBUG_sys ) ; then
726        echo "IGCM_sys_Mv :" $@
727    fi
728
729    if [ $DRYRUN = 0 ]; then
730
731        typeset RET
732           
733        echo mv $@ > out_rsync 2>&1
734        \mv $@ >> out_rsync 2>&1
735        RET=$?
736   
737        if [ ${RET} -gt 0 ] ; then
738            echo "IGCM_sys_Mv : error in mv."
739            cat out_rsync
740            IGCM_debug_Exit "IGCM_sys_Mv"
741        fi
742    else
743        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
744    fi
745
746    IGCM_debug_PopStack "IGCM_sys_Mv"
747}
748
749#D-#==================================================
750#D-function IGCM_sys_Put_Dir
751#D-* Purpose: Copy a complete directory on $(ARCHIVE)
752#D-* Examples:
753#D-
754function IGCM_sys_Put_Dir {
755    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
756    if ( $DEBUG_sys ) ; then
757        echo "IGCM_sys_Put_Dir :" $@
758    fi
759    if [ $DRYRUN = 0 ]; then
760        if [ ! -d ${1} ] ; then
761            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
762            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
763            return
764        fi
765
766        typeset RET
767
768        # Only if we use rsync
769        #IGCM_sys_TestDirArchive $( dirname $2 )
770        #
771        #USUAL WAY
772        \cp -r $1 $2 > out_rsync 2>&1
773        RET=$?
774
775        if [ ${RET} -gt 0 ] ; then
776            echo "IGCM_sys_Put_Dir : error."
777            cat out_rsync
778            IGCM_debug_Exit "IGCM_sys_Put_Dir"
779        fi
780    else
781        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
782    fi
783    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
784}
785
786#D-#==================================================
787#D-function IGCM_sys_Get_Dir
788#D-* Purpose: Copy a complete directory from $(ARCHIVE)
789#D-* Examples:
790#D-
791function IGCM_sys_Get_Dir {
792    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
793    if ( $DEBUG_sys ) ; then
794        echo "IGCM_sys_Get_Dir :" $@
795    fi
796    if [ $DRYRUN = 0 ]; then
797        if [ ! -d ${1} ] ; then
798            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
799            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
800            return
801        fi
802
803        typeset RET
804
805        #USUAL WAY
806        \cp -rp $1 $2 > out_rsync 2>&1
807        RET=$?
808
809        if [ ${RET} -gt 0 ] ; then
810            echo "IGCM_sys_Get_Dir : error."
811            cat out_rsync
812            IGCM_debug_Exit "IGCM_sys_Get_Dir"
813        fi
814    else
815        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
816    fi
817    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
818}
819
820#D-#==================================================
821#D-function IGCM_sys_Get_Master
822#D-* Purpose: Copy a complete directory from MASTER filesystem
823#D-* Examples:
824#D-
825function IGCM_sys_Get_Master {
826    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
827    if ( $DEBUG_sys ) ; then
828        echo "IGCM_sys_Get_Master :" $@
829    fi
830    if [ $DRYRUN = 0 ]; then
831        if [ ! -d ${1} ] ; then
832            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
833            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
834            return
835        fi
836
837        typeset RET
838
839        #USUAL WAY
840        \cp -rp $1 $2 > out_rsync 2>&1
841        RET=$?
842
843        if [ ${RET} -gt 0 ] ; then
844            echo "IGCM_sys_Get_Dir : error."
845            cat out_rsync
846            IGCM_debug_Exit "IGCM_sys_Get_Dir"
847        fi
848    else
849        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
850    fi
851    IGCM_debug_PopStack "IGCM_sys_Get_Master"
852}
853
854#D-#==================================================
855#D-function IGCM_sys_Put_Rest
856#D-* Purpose: Put computied restarts on $(ARCHIVE).
857#D-           File and target directory must exist.
858#D-* Examples:
859#D-
860function IGCM_sys_Put_Rest {
861    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
862    if ( $DEBUG_sys ) ; then
863        echo "IGCM_sys_Put_Rest :" $@
864    fi
865    if [ $DRYRUN = 0 ]; then
866        if [ ! -f ${1} ] ; then
867            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
868            IGCM_debug_Exit "IGCM_sys_Put_Rest"
869        fi
870
871        typeset RET
872        #
873        if [ X${JobType} = XRUN ] ; then
874            IGCM_sys_Chmod 444 ${1}
875        fi
876        #
877        # Only if we use rsync
878        #IGCM_sys_MkdirArchive $( dirname $2 )
879        #
880        #USUAL WAY
881        \cp $1 $2 > out_rsync 2>&1
882        RET=$?
883
884        if [ ${RET} -gt 0 ] ; then
885            echo "IGCM_sys_Put_Rest : error."
886            cat out_rsync
887            IGCM_debug_Exit "IGCM_sys_Put_Rest"
888        fi
889    else
890        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
891    fi
892    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
893}
894
895#D-#==================================================
896#D-function IGCM_sys_Put_Out
897#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
898#D-* Examples:
899#D-
900function IGCM_sys_Put_Out {
901    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
902    if ( $DEBUG_sys ) ; then
903        echo "IGCM_sys_Put_Out :" $@
904    fi
905    if [ $DRYRUN = 0 ]; then
906        if [ ! -f ${1} ] ; then
907            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
908            IGCM_debug_PopStack "IGCM_sys_Put_Out"
909            return 1
910        fi
911        #
912        IGCM_sys_MkdirArchive $( dirname $2 )
913        #
914        typeset RET
915        #
916        if [ X${JobType} = XRUN ] ; then
917            if [ X${3} = X ] ; then
918                IGCM_sys_Chmod 444 ${1}
919            fi
920        fi
921        #
922        #USUAL WAY
923        \cp $1 $2 > out_rsync 2>&1
924        RET=$?
925
926        if [ ${RET} -gt 0 ] ; then
927            echo "IGCM_sys_Put_Out : error."
928            cat out_rsync
929            IGCM_debug_Exit "IGCM_sys_Put_Out"
930        fi
931    else
932        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
933    fi
934    IGCM_debug_PopStack "IGCM_sys_Put_Out"
935    return 0
936}
937
938#D-#==================================================
939#D-function IGCM_sys_Get
940#D-* Purpose: Get a file from ${ARCHIVE}
941#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
942#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
943function IGCM_sys_Get {
944    IGCM_debug_PushStack "IGCM_sys_Get" $@
945
946    typeset DEST RET dm_liste ifile target
947
948    if ( $DEBUG_sys ) ; then
949        echo "IGCM_sys_Get :" $@
950    fi
951    if [ $DRYRUN -le 2 ]; then
952        if [ X${1} = X'/l' ] ; then
953            # test if the first file is present in the old computation :
954            eval set +A dm_liste \${${2}}
955        else
956            dm_liste=${1}
957        fi
958        eval DEST=\${${#}}
959
960        # test if the (first) file is present in the old computation :
961        IGCM_sys_TestFileArchive ${dm_liste[0]}
962        RET=$?
963        if [ ${RET} -gt 0 ] ; then
964            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
965            IGCM_debug_Exit "IGCM_sys_Get"
966            return
967        fi
968
969        # SD : dm_liste is not suited for computing job
970        #      because we change filename during transfert
971        #      dm_liste is better suited for post-treatment
972        #dm_liste=" "
973        #(( ifile=1 ))
974        #while [ $ifile -lt $# ] ; do
975        #    dm_liste=$( eval echo ${dm_liste} " "\${${ifile}} )
976        #    (( ifile = ifile + 1 ))
977        #done
978        #DEST=$( eval echo \${${#}} )
979
980        #USUAL WAY
981        \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
982        RET=$?
983
984        if [ ${RET} -gt 0 ] ; then
985            echo "IGCM_sys_Get : copy error."
986            cat out_rsync
987            IGCM_debug_Exit "IGCM_sys_Get"
988        fi
989    else
990        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
991    fi
992    IGCM_debug_PopStack "IGCM_sys_Get"
993}
994
995############################################################## A FINIR !!
996
997#D-#==================================================
998#D-function IGCM_sys_GetDate_FichWork
999#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1000#D-* Examples:
1001#D-
1002function IGCM_sys_GetDate_FichWork {
1003    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1004    if ( $DEBUG_sys ) ; then
1005        echo "IGCM_sys_GetDate_FichWork :" $@
1006    fi
1007    # donne la date filesys d'un fichier sur la machine work
1008    IGCM_debug_PopStack "IGCM_sys_FichWork"
1009}
1010
1011#D-#==================================================
1012#D-function IGCM_sys_GetDate_FichArchive
1013#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1014#D-* Examples:
1015#D-
1016function IGCM_sys_GetDate_FichArchive {
1017    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1018    if ( $DEBUG_sys ) ; then
1019        echo "IGCM_sys_GetDate_FichArchive :" $@
1020    fi
1021    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1022}
1023
1024##############################################################
1025# REBUILD OPERATOR
1026
1027function IGCM_sys_rebuild {
1028    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1029    if ( $DEBUG_sys ) ; then
1030        echo "IGCM_sys_rebuild :" $@
1031    fi
1032    /gpfs1/home/sebastien/REBUILD/rebuild -f -o $@
1033    if [ $? -gt 0 ] ; then
1034       echo "IGCM_sys_rebuild : erreur ${@}."
1035       IGCM_debug_Exit "rebuild"
1036    fi
1037
1038    IGCM_debug_PopStack "IGCM_sys_rebuild"
1039}
1040
1041############################################################
1042# Activate Running Environnment Variables
1043
1044function IGCM_sys_activ_variables {
1045    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1046    if ( $DEBUG_sys ) ; then
1047        echo "IGCM_sys_activ_variables "
1048    fi
1049
1050# --------------------------------------------------------------------
1051#D- MPI specifications
1052# --------------------------------------------------------------------
1053
1054# --------------------------------------------------------------------
1055#D- Other specifications
1056# --------------------------------------------------------------------
1057
1058    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1059
1060}
1061
1062############################################################
1063# Desactivate Running Environnment Variables
1064
1065function IGCM_sys_desactiv_variables {
1066    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1067    if ( $DEBUG_sys ) ; then
1068        echo "IGCM_sys_desactiv_variables "
1069    fi
1070# --------------------------------------------------------------------
1071#D- MPI specifications
1072# --------------------------------------------------------------------
1073
1074# --------------------------------------------------------------------
1075#D- Other specifications
1076# --------------------------------------------------------------------
1077
1078    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1079 
1080}
1081
1082############################################################
1083# Build run file
1084
1085function IGCM_sys_build_run_file {
1086    IGCM_debug_PushStack "IGCM_sys_build_run_file" $@
1087set -x
1088    if ( $DEBUG_sys ) ; then
1089        echo "IGCM_sys_build_run_file " $@
1090    fi
1091
1092    NUM_PROC_OASIS=1
1093
1094    # Set the number of processors for OCE here
1095    NUM_PROC_OCE=5
1096
1097    (( NUM_PROC_ATM = BATCH_NUM_PROC_TOT - NUM_PROC_OASIS - NUM_PROC_OCE ))
1098   
1099    if [ $1 = MPI2 ]; then
1100       echo "IGCM_sys_build_run_file : error - MPI2 not available on iitm. "
1101       IGCM_debug_Exit "IGCM_sys_build_run_file"
1102    elif [ $1 = MPI1 ]; then
1103        cat <<EOF > run_file
1104./oasis
1105EOF
1106
1107        typeset i
1108        (( i = 0 ))
1109        while [ ${i} -lt ${NUM_PROC_ATM} ] ; do
1110            (( i = i + 1 ))
1111            cat <<EOF >> run_file
1112./lmdz.x
1113EOF
1114        done
1115
1116        (( i = 0 ))
1117        while [ ${i} -lt ${NUM_PROC_OCE} ] ; do
1118            (( i = i + 1 ))
1119            cat <<EOF >> run_file
1120./opa.xx
1121EOF
1122        done
1123
1124        wc -l run_file
1125    fi
1126set +x
1127    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1128}
Note: See TracBrowser for help on using the repository browser.