source: tags/libIGCM_v1_12/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 1456

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