source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_vargas.ksh @ 479

Last change on this file since 479 was 479, checked in by mafoipsl, 13 years ago

Modification for vargas :

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