source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_vargas.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...

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