source: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_vargas.ksh @ 571

Last change on this file since 571 was 571, checked in by mafoipsl, 12 years ago

First try to merge libIGCM_MPI_OpenMP branch with libIGCM trunk revision 569. Tested on vargas with PackFrequency?=NONE included into config.card.

  • Property svn:keywords set to Revision Author Date
File size: 44.9 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
66  # $hostname ou hostname
67typeset  HOST=${HOST:=$( hostname )}
68# $username ou whoami
69typeset  LOGIN=${LOGIN:=$( whoami )}
70# $hostname of the MASTER job
71typeset -r MASTER=vargas
72
73#D-
74#D-#==================================================
75#D-Program used in libIGCM
76#D-#==================================================
77
78# rsync with path
79typeset -r RSYNC=/usr/local/bin/rsync
80# RSYNC_opt args to rsync
81typeset -r RSYNC_opt="-va"
82# ie storage filesystem
83typeset -r STOREHOST=gaya.idris.fr
84typeset -r REMOTE_RSYNC=/u/rech/ces/rces452/RSYNC/bin/rsync
85
86#====================================================
87# Host specific DIRECTORIES
88#====================================================
89
90#====================================================
91#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
92typeset -r R_EXE="${MODIPSL}/bin"
93
94#====================================================
95#- SUBMIT_DIR : submission dir
96typeset SUBMIT_DIR=${SUBMIT_DIR:=${LOADL_STEP_INITDIR}}
97
98#====================================================
99#- ARCHIVE
100typeset -r ARCHIVE=$( echo ${HOME} | sed -e "s/homegpfs/u/" )
101
102#====================================================
103#- Mirror libIGCM from vargas to ulam
104typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
105
106#====================================================
107#- libIGCM_POST
108PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
109typeset -r HOME_POST=$( echo ${HOME} | sed -e "s/homegpfs/home/" )
110typeset -r libIGCM_POST=${HOME_POST}/MIRROR/${PATHlibIGCM}/libIGCM
111
112#====================================================
113#- IN
114typeset -r R_IN=${R_IN:=/u/rech/psl/rpsl035/IGCM}
115typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/u/rech/psl/rpsl376}
116
117#====================================================
118#- OUT
119typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
120
121#====================================================
122#- R_BUF  Buffer to pack files
123typeset -r R_BUF=${WORKDIR}/BUFFER_IGCM
124
125#====================================================
126#- OUT_POST
127typeset -r R_OUT_POST=$( echo ${HOME} | sed -e "s/homegpfs/workdir/" )/IGCM_OUT
128
129#====================================================
130#- RUN_DIR_PATH : Temporary working directory (=> TMP)
131typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${TMPDIR}}
132
133#====================================================
134#- BIG_DIR : BIG_DIR to store files waiting for rebuild
135typeset -r BIG_DIR=${BIG_DIR:=${WORKDIR}/REBUILD}
136
137#====================================================
138#- HOST_MPIRUN_COMMAND
139typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time poe"}
140
141#====================================================
142#- Max number of arguments passed to nco operator or demigration command
143UNIX_MAX_LIMIT=120
144
145#====================================================
146#- Default number of MPI task for IPSL coupled model
147#- required for backward compatibility
148#-
149DEFAULT_NUM_PROC_OCE=5
150DEFAULT_NUM_PROC_CPL=1
151DEFAULT_NUM_PROC_ATM=26
152DEFAULT_NUM_PROC_TOTAL=32
153
154#D-#==================================================
155#D-function IGCM_sys_RshMaster
156#D-* Purpose: Connection to frontend machine.
157#D-* Examples:
158#D-
159(( RshMNum = 0 ))
160function IGCM_sys_RshMaster {
161    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
162
163    typeset THEFILE OUTFILE ERR
164
165    RshDIR=${WORKDIR}/RUN_DIR/${config_UserChoices_TagName}/${config_UserChoices_JobName}.${$}
166    if [ ! -d ${RshDIR} ] ; then
167        IGCM_sys_Mkdir ${RshDIR}
168    fi
169    THEFILE=${RshDIR}/file_sys_RshMaster_$$_${RshMNum}
170    echo '#!/bin/ksh' > ${THEFILE}
171    echo "export libIGCM=${libIGCM} > /dev/null 2>&1" >> ${THEFILE}
172    echo "export DEBUG_debug=${DEBUG_debug} > /dev/null 2>&1" >> ${THEFILE}
173    echo ". ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh > /dev/null 2>&1" >> ${THEFILE}
174    echo ". ${libIGCM}/libIGCM_card/libIGCM_card.ksh > /dev/null 2>&1" >> ${THEFILE}
175    echo "${@} " >> ${THEFILE}
176
177    # No frontend queue on brodie : just rsh the job on the frontend with submission.
178    sed -e "s@IGCM_sys_Qsub\(.*\)@\1@" ${THEFILE} > ${THEFILE}_
179
180    chmod u+x  ${THEFILE}_
181
182    OUTFILE=${RshDIR}/out_RshMaster.$$.${RshMNum}
183    (( RshMNum = RshMNum + 1 ))
184
185    rsh ${MASTER} 'bash -c "nohup '${THEFILE}'_ > '${OUTFILE}' 2>&1 &"'
186    if [ $? -gt 0 ] ; then
187        echo "IGCM_sys_RshMaster : erreur."
188        IGCM_debug_Exit "IGCM_sys_RshMaster"
189    fi
190    IGCM_debug_PopStack "IGCM_sys_RshMaster"
191}
192
193#D-#==================================================
194#D-function IGCM_sys_RshArchive
195#D-* Purpose: Archive rsh command
196#D-* Examples:
197#D-
198function IGCM_sys_RshArchive {
199    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
200    rsh ${STOREHOST} exec /bin/ksh <<-EOF
201    ${@}
202EOF
203    if [ $? -gt 0 ] ; then
204        echo "IGCM_sys_RshArchive : erreur."
205        IGCM_debug_Exit "IGCM_sys_RshArchive"
206    fi
207    IGCM_debug_PopStack "IGCM_sys_RshArchive"
208}
209
210#D-#==================================================
211#D-function IGCM_sys_RshPost
212#D-* Purpose: Post-process rsh command
213#D-* Examples:
214#D-
215function IGCM_sys_RshPost {
216    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
217    if ( $DEBUG_sys ) ; then
218        echo "IGCM_sys_RshPost :" $@
219    fi
220
221    # keep standard input to keep it for postpone if ulam don't answer
222    cat >/tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
223
224    ## Add submission for old postponed files only if command is a Qsub
225    ##
226    ISITQSUB=0
227    grep Qsub /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME} >/dev/null 2>&1 && ISITQSUB=1
228    if  ( [ ${ISITQSUB} -gt 0 ] ) ; then
229      if [ -d ${SUBMIT_DIR}/POSTPONE ] ; then
230            for postponed_file in ${SUBMIT_DIR}/POSTPONE/* ; do
231              if [ -f ${postponed_file} ] ; then
232                IGCM_debug_Print 2 " submit postponed file : " ${postponed_file}
233                rsh ulam exec /bin/ksh <${postponed_file}
234                if [ $? -eq 0 ] ; then
235                     IGCM_sys_Rm ${postponed_file}
236                else
237                     IGCM_debug_Print 2 "keep postponed file for an other submission :" ${postponed_file}
238                fi
239              fi
240          done
241      fi
242    fi
243
244    RETURN=0
245    # rsh ulam command
246    rsh ulam exec /bin/ksh </tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
247    RETURN=$?
248
249    # keep standard input for postpone if ulam don't answer
250    if ( [ ${RETURN} -gt 0 ] ) ; then
251        IGCM_debug_Print 2 "Postpone tmp_IGCM_sys_RshPost_$$_${LOGNAME}"
252        [ -d ${SUBMIT_DIR}/POSTPONE ] || mkdir ${SUBMIT_DIR}/POSTPONE
253        mv /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME} ${SUBMIT_DIR}/POSTPONE
254    else
255        IGCM_sys_Rm /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
256    fi
257    IGCM_debug_PopStack "IGCM_sys_RshPost"
258}
259
260#D-#==================================================
261#D-function IGCM_sys_SendMail
262#D-* Purpose: Send mail when simulation is over
263#D-* Examples:
264#D-
265function IGCM_sys_SendMail {
266    IGCM_debug_PushStack "IGCM_sys_SendMail" $@
267    if ( $DEBUG_sys ) ; then
268        echo "IGCM_sys_SendMail :" $@
269    fi
270
271    if ( ${ExitFlag} ) ; then
272        status=failed
273    else
274        status=completed
275    fi
276    cat  << END_MAIL > job_end.mail
277Dear ${LOGIN},
278
279  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
280  Job started : ${DateBegin}
281  Job ended   : ${DateEnd}
282  Output files are available in ${R_SAVE}
283  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
284END_MAIL
285
286    if [ ! -z ${config_UserChoices_MailName} ] ; then
287        mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
288    elif [ -f ~/.forward ] ; then
289        mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
290    else
291        mailx -s "${config_UserChoices_JobName} ${status}" ${USER} < job_end.mail
292    fi
293
294    if [ $? -gt 0 ] ; then
295        echo "IGCM_sys_SendMail : erreur."
296        IGCM_debug_Exit "IGCM_sys_SendMail"
297    fi
298    IGCM_debug_PopStack "IGCM_sys_SendMail"
299}
300
301#D-#==================================================
302#D-function IGCM_sys_Mkdir
303#D-* Purpose: Master locale mkdir command
304#D-* Examples:
305#D-
306function IGCM_sys_Mkdir {
307    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
308    if ( $DEBUG_sys ) ; then
309        echo "IGCM_sys_Mkdir :" $@
310    fi
311    if [ ! -d ${1} ]; then
312        \mkdir -p $1
313        if [ $? -gt 0 ] ; then
314            echo "IGCM_sys_Mkdir : erreur."
315            IGCM_debug_Exit "IGCM_sys_Mkdir"
316        fi
317    fi
318    # vérification :
319    if [ ! -d ${1} ] ; then
320        echo "IGCM_sys_Mkdir : erreur."
321        IGCM_debug_Exit "IGCM_sys_Mkdir"
322    fi
323    IGCM_debug_PopStack "IGCM_sys_Mkdir"
324}
325
326#D-#==================================================
327#D-function IGCM_sys_MkdirArchive
328#D-* Purpose: Mkdir on Archive
329#D-* Examples:
330#D-
331function IGCM_sys_MkdirArchive {
332    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
333    if ( $DEBUG_sys ) ; then
334        echo "IGCM_sys_MkdirArchive :" $@
335    fi
336    #- creation de repertoire sur le serveur fichier
337    rsh ${STOREHOST} -n mkdir -p $1
338
339    if [ $? -gt 0 ] ; then
340        echo "IGCM_sys_MkdirArchive : erreur."
341        IGCM_debug_Exit "IGCM_sys_MkdirArchive"
342    fi
343    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
344}
345
346#D-#==================================================
347#D-function IGCM_sys_MkdirWork
348#D-* Purpose: Mkdir on Work
349#D-* Examples:
350#D-
351function IGCM_sys_MkdirWork {
352    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
353    if ( $DEBUG_sys ) ; then
354        echo "IGCM_sys_MkdirWork :" $@
355    fi
356    #- creation de repertoire sur le serveur fichier
357    if [ ! -d ${1} ]; then 
358        \mkdir -p $1
359        if [ $? -gt 0 ] ; then
360            echo "IGCM_sys_MkdirWork : erreur."
361            IGCM_debug_Exit "IGCM_sys_MkdirWork"
362        fi
363    fi
364    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
365}
366
367#D-#==================================================
368#D-function IGCM_sys_Cd
369#D-* Purpose: master cd command
370#D-* Examples:
371#D-
372function IGCM_sys_Cd {
373    IGCM_debug_PushStack "IGCM_sys_Cd" $@
374    if ( $DEBUG_sys ) ; then
375        echo "IGCM_sys_Cd :" $@
376    fi
377    \cd $1
378    if [ $? -gt 0 ] ; then
379        echo "IGCM_sys_Cd : erreur."
380        IGCM_debug_Exit "IGCM_sys_Cd"
381    fi
382    IGCM_debug_PopStack "IGCM_sys_Cd"
383}
384
385#D-#==================================================
386#D-function IGCM_sys_Chmod
387#D-* Purpose: Chmod
388#D-* Examples:
389#D-
390function IGCM_sys_Chmod {
391    IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
392    if ( $DEBUG_sys ) ; then
393        echo "IGCM_sys_Chmod :" $@
394    fi
395    if [ $DRYRUN -le 1 ]; then
396        \chmod $@
397        if [ $? -gt 0 ] ; then
398            echo "IGCM_sys_Chmod : erreur."
399            IGCM_debug_Exit "IGCM_sys_Chmod"
400        fi
401    else
402        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
403    fi
404    IGCM_debug_PopStack "IGCM_sys_Chmod"
405}
406
407#D-#==================================================
408#D-function IGCM_sys_FileSize
409#D-* Purpose: Filesize
410#D-* Examples:
411#D-
412function IGCM_sys_FileSize {
413    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
414
415    typeset sizeF
416    set +A sizeF -- $( ls -la ${1} )
417    if [ $? -gt 0 ] ; then
418        IGCM_debug_Exit "IGCM_sys_FileSize"
419    fi
420    eval ${2}=${sizeF[4]}
421
422    IGCM_debug_PopStack "IGCM_sys_FileSize"
423}
424
425#D-#==================================================
426#D-function IGCM_sys_TestDir
427#D-* Purpose: Test Directory that must exists
428#D-* Examples:
429#D-
430function IGCM_sys_TestDir {
431    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
432    if ( $DEBUG_sys ) ; then
433        echo "IGCM_sys_TestDir :" $@
434    fi
435    typeset ExistFlag
436    ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
437    IGCM_debug_PopStack "IGCM_sys_TestDir"
438
439    return ${ExistFlag}
440}
441
442#D-#==================================================
443#D-function IGCM_sys_TestDirArchive
444#D-* Purpose: Test Directory that must exists on Archive
445#D-* Examples:
446#D-
447function IGCM_sys_TestDirArchive {
448    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
449    if ( $DEBUG_sys ) ; then
450        echo "IGCM_sys_TestDirArchive :" $@
451    fi
452    typeset ExistFlag
453    ExistFlag=$( IGCM_sys_RshArchive "[ -d $1 ] && echo 0 || echo 1" )
454    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
455
456    return ${ExistFlag}
457}
458
459#D-#==================================================
460#D-function IGCM_sys_IsFileArchived
461#D-* Purpose: Test file that must NOT EXISTS on Archive
462#D-* always true on vargas.
463#D-* Examples:
464#D-
465function IGCM_sys_IsFileArchived {
466  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
467  if ( $DEBUG_sys ) ; then
468    echo "IGCM_sys_IsFileArchived :" $@
469  fi
470  typeset IsArchivedFlag
471  IsArchivedFlag=$( echo 0 )
472  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
473
474  return ${IsArchivedFlag}
475}
476
477#D-#==================================================
478#D-function IGCM_sys_TestFileArchive
479#D-* Purpose: Test file that must NOT EXISTS on Archive
480#D-* Examples:
481#D-
482function IGCM_sys_TestFileArchive {
483    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
484    typeset ExistFlag
485    ExistFlag=$( IGCM_sys_RshArchive "[ -f $1 ] && echo 0 || echo 1" )
486    IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
487
488    return ${ExistFlag}
489}
490
491#D-#==================================================
492#D-function IGCM_sys_TestFileBuffer
493#D-* Purpose: Test file that must NOT EXISTS on Buffer
494#D-* Examples:
495#D-
496function IGCM_sys_TestFileBuffer {
497  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
498  typeset ExistFlag
499  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
500  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
501
502  return ${ExistFlag}
503}
504
505#D-#==================================================
506#D-function IGCM_sys_CountFileArchive
507#D-* Purpose: Count files on Archive filesystem
508#D-* Examples:
509#D-
510function IGCM_sys_CountFileArchive {
511    IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
512    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
513    if [ $? -gt 0 ] ; then
514        echo "IGCM_sys_CountFileArchive : erreur."
515    fi
516    IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
517}
518
519#D-#==================================================
520#D-function IGCM_sys_CountFileBuffer
521#D-* Purpose: Count files on Scratch filesystem
522#D-* Examples:
523#D-
524function IGCM_sys_CountFileBuffer {
525  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
526  ls ${@} 2>/dev/null | wc -l
527  if [ $? -gt 0 ] ; then
528    echo "IGCM_sys_CountFileBuffer : erreur."
529  fi
530  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
531}
532
533#D-#==================================================
534#D-function IGCM_sys_Tree
535#D-* Purpose: Tree directories with files on ${ARCHIVE}
536#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
537#D-
538function IGCM_sys_Tree {
539    IGCM_debug_PushStack "IGCM_sys_Tree" $@
540    if ( $DEBUG_sys ) ; then
541        echo "IGCM_sys_Tree :" $@
542    fi
543
544    \mfls -r $@
545
546    IGCM_debug_PopStack "IGCM_sys_Tree"
547}
548
549#D-#==================================================
550#D-function IGCM_sys_Tar
551#D-* Purpose: master un-tar command
552#D-* Examples:
553#D-
554function IGCM_sys_Tar {
555    IGCM_debug_PushStack "IGCM_sys_Tar" $@
556    if ( $DEBUG_sys ) ; then
557        echo "IGCM_sys_Tar :" $@
558    fi
559    \tar cf $@
560    if [ $? -gt 0 ] ; then
561        echo "IGCM_sys_Tar : erreur."
562        IGCM_debug_Exit "IGCM_sys_Tar"
563    fi
564    IGCM_debug_PopStack "IGCM_sys_Tar"
565}
566
567#D-#==================================================
568#D-function IGCM_sys_UnTar
569#D-* Purpose: master un-tar command
570#D-* Examples:
571#D-
572function IGCM_sys_UnTar {
573    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
574    if ( $DEBUG_sys ) ; then
575        echo "IGCM_sys_UnTar :" $@
576    fi
577    \tar xvf $1
578    if [ $? -gt 0 ] ; then
579        echo "IGCM_sys_UnTar : erreur."
580        IGCM_debug_Exit "IGCM_sys_UnTar"
581    fi
582    IGCM_debug_PopStack "IGCM_sys_UnTar"
583}
584
585#D-#==================================================
586#D-function IGCM_sys_Qsub
587#D-* Purpose: Qsub new job
588#D-* Examples:
589#D-
590function IGCM_sys_Qsub {
591    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
592    if ( $DEBUG_sys ) ; then
593        echo "IGCM_sys_Qsub :" $@
594    fi
595    # We have to change output/error file
596    [ ${#@} = 1 ] &&  REP_FOR_JOB=$LOADL_STEP_INITDIR
597    [ ${#@} = 2 ] &&  REP_FOR_JOB=$2
598    sed -e "s/\# \@ output *= .*/\# \@ output = ${Script_Output}/" -e "s/\# \@ error *= .*/\# \@ error = ${Script_Output}/" <$1 >${REP_FOR_JOB}/JOB_FOR_IGCM
599    {
600       [ ${#@} = 1 ] &&  ( cd $LOADL_STEP_INITDIR ; /usr/local/bin/llsubmit JOB_FOR_IGCM ; ERROR=$? ; cd - ; )
601       [ ${#@} = 2 ] &&  ( cd $2 ; /usr/local/bin/llsubmit JOB_FOR_IGCM ; ERROR=$? ; cd - ; )
602    }
603    if [ ${ERROR} -gt 0 ] ; then
604       echo "IGCM_sys_Qsub : erreur $@."
605       IGCM_debug_Exit "IGCM_sys_Qsub"
606    fi
607    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM
608    IGCM_debug_PopStack "IGCM_sys_Qsub"
609
610}
611
612#D-#==================================================
613#D-function IGCM_sys_QsubPost
614#D-* Purpose: Qsub new job on scalaire
615#D-* Examples:
616#D-
617function IGCM_sys_QsubPost {
618    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
619    if ( $DEBUG_sys ) ; then
620        echo "IGCM_sys_QsubPost :" $@
621    fi
622    cd ${POST_DIR}
623    echo MAF QsubPost vargas
624    /opt/ibmll/LoadL/full/bin/llsubmit ${libIGCM_POST}/$1.job
625    cd -
626    if [ $? -gt 0 ] ; then
627        echo "IGCM_sys_QsubPost : erreur " $@
628        IGCM_debug_Exit "IGCM_sys_QsubPost"
629    fi
630    IGCM_debug_PopStack "IGCM_sys_QsubPost"
631}
632
633#D-*************************
634#D- File transfer functions
635#D-*************************
636#D-
637
638#D-#==================================================
639#D-function IGCM_sys_Rsync_out
640#D-* Purpose: treat return val of rsync
641#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
642#D-  Error values and explanations can depend on your system version.
643function IGCM_sys_Rsync_out {
644    RET=$1
645    if [ ! $RET ] ; then
646        echo "rsync error !"
647    fi
648
649    if [ $MYLANG = "fr" ]; then
650        case $RET in
651            0)  return ;;
652            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
653                echo "Erreur de syntaxe ou d'utilisation."
654                return;;
655            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
656                echo "Incompatibilité de protocole."
657                return;;
658            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
659                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
660                echo "répertoires"
661                return;;
662            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
663                echo "Action demandée non supportée : une tentative de manipulation de"
664                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
665                echo "été faite ; ou une option qui est supportée par le  client  mais"
666                echo "pas par le serveur a été spécifiée."
667                return;;
668            10) echo "Erreur de rsync ; RERR_SOCKETIO"
669                echo "Erreur dans le socket d'entrée sortie"
670                return;;
671            11) echo "Erreur de rsync ; RERR_FILEIO"
672                echo "Erreur d'entrée sortie fichier"
673                return;;
674            12) echo "Erreur de rsync ; RERR_STREAMIO"
675                echo "Erreur dans flux de donnée du protocole rsync"
676                return;;
677            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
678                echo "Erreur avec les diagnostics du programme"
679                return;;
680            14) echo "Erreur de rsync ; RERR_IPC"
681                echo "Erreur dans le code IPC"
682                return;;
683            20) echo "Erreur de rsync ; RERR_SIGNAL"
684                echo "SIGUSR1 ou SIGINT reçu"
685                return;;
686            21) echo "Erreur de rsync ; RERR_WAITCHILD"
687                echo "Une erreur retournée par waitpid()"
688                return;;
689            22) echo "Erreur de rsync ; RERR_MALLOC"
690                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
691                return;;
692            23) echo ""
693                echo "Erreur fichier inexistant"
694                return;;
695            30) echo "Erreur de rsync ; RERR_TIMEOUT"
696                echo "Temps d'attente écoulé dans l'envoi/réception de données"
697                return;;
698            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
699                return;;
700        esac
701    elif [ $MYLANG = "en" ] ; then
702        case $RET in
703            0)  return;;               
704            1)  echo "rsync error : Syntax or usage error "
705                return;;
706            2)  echo "rsync error : Protocol incompatibility "
707                return;;
708            3)  echo "rsync error : Errors selecting input/output files, dirs"
709                return;;
710            4)  echo "rsync error : Requested action not supported: an attempt"
711                echo "was made to manipulate 64-bit files on a platform that cannot support"
712                echo "them; or an option was specified that is supported by the client and"
713                echo "not by the server."
714                return;;
715            5)  echo "rsync error : Error starting client-server protocol"
716                return;;
717            10) echo "rsync error : Error in socket I/O "
718                return;;
719            11) echo "rsync error : Error in file I/O "
720                return;;
721            12) echo "rsync error : Error in rsync protocol data stream "
722                return;;
723            13) echo "rsync error : Errors with program diagnostics "
724                return;;
725            14) echo "rsync error : Error in IPC code "
726                return;;
727            20) echo "rsync error : Received SIGUSR1 or SIGINT "
728                return;;
729            21) echo "rsync error : Some error returned by waitpid() "
730                return;;
731            22) echo "rsync error : Error allocating core memory buffers "
732                return;;
733            23) echo "rsync error : Partial transfer due to error"
734                return;;
735            24) echo "rsync error : Partial transfer due to vanished source files"
736                return;;
737            30) echo "rsync error : Timeout in data send/receive "
738                return;;
739            *)  echo "rsync error : return code of rsync unknown :" $RET
740                return;;
741        esac
742    else
743        echo "unknown language $MYLANG."
744        return
745    fi
746}
747   
748#D-#==================================================
749#D-function IGCM_sys_Rm
750#D-* Purpose: generic rm
751#D-* Examples:
752#D-
753function IGCM_sys_Rm {
754    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
755    if ( $DEBUG_sys ) ; then
756        echo "IGCM_sys_Rm :" $@
757    fi
758
759    typeset RET
760
761    echo rm $@ > out_rsync 2>&1
762    \rm $@ >> out_rsync 2>&1
763    RET=$?
764
765    if [ ${RET} -gt 0 ] ; then
766        echo "IGCM_sys_Rm : error."
767        cat out_rsync
768        IGCM_debug_Exit "IGCM_sys_Rm"
769    fi
770    IGCM_debug_PopStack "IGCM_sys_Rm"
771}
772
773#D-#==================================================
774#D-function IGCM_sys_Miror_libIGCM
775#D-* Purpose: Mirror libIGCM PATH and lib to ulam
776#D-* Examples:
777#D-
778function IGCM_sys_Mirror_libIGCM {
779    IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
780    if ( $DEBUG_sys ) ; then
781        echo "IGCM_sys_Mirror_libIGCM"
782    fi
783
784    typeset RET
785
786    IGCM_sys_RshPost <<-EOF
787    mkdir -p ${HOME_POST}/MIRROR/${PATHlibIGCM}
788EOF
789    rsh ulam -n hostname > /dev/null 2>&1
790    RET=$?
791    if [ $RET -eq 0 ] ; then
792        echo ${RSYNC} ${RSYNC_opt} -e "rsh " ${libIGCM} ulam:${HOME_POST}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
793        ${RSYNC} ${RSYNC_opt} -e "rsh " ${libIGCM} ulam:${HOME_POST}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
794        RET=$?
795
796        if [ ${RET} -gt 0 ] ; then
797            echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on ulam."
798            cat out_rsync
799        fi
800        IGCM_sys_Rm out_rsync
801    else
802        echo "No POST-TREATMENT avaible because ulam is down."
803    fi
804    IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
805}
806
807#====================================================
808#- Call IGCM_sys_Mirror_libIGCM now !
809if ( $MirrorlibIGCM ) ; then
810    IGCM_sys_Mirror_libIGCM
811fi
812
813#D-#==================================================
814#D-function IGCM_sys_Cp
815#D-* Purpose: generic cp
816#D-* Examples:
817#D-
818function IGCM_sys_Cp {
819    IGCM_debug_PushStack "IGCM_sys_Cp" $@
820    if ( $DEBUG_sys ) ; then
821        echo "IGCM_sys_Cp :" $@
822    fi
823
824    typeset RET
825
826    echo cp $@ > out_rsync 2>&1
827    \cp $@ >> out_rsync 2>&1
828    RET=$?
829
830    if [ ${RET} -gt 0 ] ; then
831        echo "IGCM_sys_Cp : error."
832        cat out_rsync
833        IGCM_debug_Exit "IGCM_sys_Cp"
834     else
835         \rm out_rsync
836    fi
837    IGCM_debug_PopStack "IGCM_sys_Cp"
838}
839
840#D-#==================================================
841#D-function IGCM_sys_RmRunDir
842#D-* Purpose: rm tmpdir (dummy function most of the time batch
843#D-                      scheduler will do the job)
844#D-* Examples:
845#D-
846function IGCM_sys_RmRunDir {
847    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
848    if ( $DEBUG_sys ) ; then
849        echo "IGCM_sys_RmRunDir :" $@
850        echo "Dummy call, let the scheduler do that."
851    fi
852    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
853}
854
855#D-#==================================================
856#D-function IGCM_sys_Mv
857#D-* Purpose: generic move
858#D-* Examples:
859#D-
860function IGCM_sys_Mv {
861    IGCM_debug_PushStack "IGCM_sys_Mv" $@
862    if ( $DEBUG_sys ) ; then
863        echo "IGCM_sys_Mv :" $@
864    fi
865
866    if [ $DRYRUN = 0 ]; then
867
868        typeset RET
869           
870        echo mv $@ > out_rsync 2>&1
871        \mv $@ >> out_rsync 2>&1
872        RET=$?
873   
874        if [ ${RET} -gt 0 ] ; then
875            echo "IGCM_sys_Mv : error in mv."
876            cat out_rsync
877            IGCM_debug_Exit "IGCM_sys_Mv"
878        else
879            \rm out_rsync
880        fi
881    else
882        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
883    fi
884
885    IGCM_debug_PopStack "IGCM_sys_Mv"
886}
887
888#D-#==================================================
889#D-function IGCM_sys_Put_Dir
890#D-* Purpose: Copy a complete directory on $(ARCHIVE)
891#D-* Examples:
892#D-
893function IGCM_sys_Put_Dir {
894    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
895    if ( $DEBUG_sys ) ; then
896        echo "IGCM_sys_Put_Dir :" $@
897    fi
898    if [ $DRYRUN = 0 ]; then
899        if [ ! -d ${1} ] ; then
900            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
901            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
902            return
903        fi
904
905        typeset RET
906
907        # Only if we use rsync
908        #IGCM_sys_TestDirArchive $( dirname $2 )
909        #
910        #USUAL WAY
911        rcp -r $1 ${STOREHOST}:$2 > out_rsync 2>&1
912        RET=$?
913
914        if [ ${RET} -gt 0 ] ; then
915            echo "IGCM_sys_Put_Dir : error."
916            cat out_rsync
917            IGCM_debug_Exit "IGCM_sys_Put_Dir"
918        else
919            \rm out_rsync
920        fi
921    else
922        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
923    fi
924    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
925}
926
927#D-#==================================================
928#D-function IGCM_sys_Get_Dir
929#D-* Purpose: Copy a complete directory from $(ARCHIVE)
930#D-* Examples:
931#D-
932function IGCM_sys_Get_Dir {
933    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
934    if ( $DEBUG_sys ) ; then
935        echo "IGCM_sys_Get_Dir :" $@
936    fi
937    if [ $DRYRUN = 0 ]; then
938        if [ ! -d ${1} ] ; then
939            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
940            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
941            return
942        fi
943
944        typeset RET
945
946        #USUAL WAY
947        rcp -rp ${STOREHOST}:$1 $2 > out_rsync 2>&1
948        RET=$?
949
950        if [ ${RET} -gt 0 ] ; then
951            echo "IGCM_sys_Get_Dir : error."
952            cat out_rsync
953            IGCM_debug_Exit "IGCM_sys_Get_Dir"
954        fi
955    else
956        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
957    fi
958    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
959}
960
961#D-#==================================================
962#D-function IGCM_sys_Put_Rest
963#D-* Purpose: Put computied restarts on $(ARCHIVE).
964#D-           File and target directory must exist.
965#D-* Examples:
966#D-
967function IGCM_sys_Put_Rest {
968    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
969    if ( $DEBUG_sys ) ; then
970        echo "IGCM_sys_Put_Rest :" $@
971    fi
972    if [ $DRYRUN = 0 ]; then
973        if [ ! -f ${1} ] ; then
974            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
975            IGCM_debug_Exit "IGCM_sys_Put_Rest"
976        fi
977
978        typeset RET
979        #
980        if [ X${JobType} = XRUN ] ; then
981            IGCM_sys_Chmod 444 ${1}
982        fi
983        #
984        # Only if we use rsync
985        #IGCM_sys_MkdirArchive $( dirname $2 )
986        #
987        #USUAL WAY
988        mfput $1 $2 > out_rsync 2>&1
989        RET=$?
990
991#       #RSYNC WITH NETWORK RSH CALL
992#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
993#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
994
995#       #RSYNC WITH NFS USE
996#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
997#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
998       
999#       RET=$?
1000#       IGCM_sys_Rsync_out $RET
1001
1002#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1003#       (( RET=RET+$? ))
1004
1005        if [ ${RET} -gt 0 ] ; then
1006            echo "IGCM_sys_Put_Rest : error."
1007            cat out_rsync
1008            IGCM_debug_Exit "IGCM_sys_Put_Rest"
1009        else
1010            \rm out_rsync
1011        fi
1012    else
1013        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1014    fi
1015    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1016}
1017
1018#D-#==================================================
1019#D-function IGCM_sys_PutBuffer_Rest
1020#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1021#D-           File and target directory must exist.
1022#D-* Examples:
1023#D-
1024function IGCM_sys_PutBuffer_Rest {
1025  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1026  if ( $DEBUG_sys ) ; then
1027    echo "IGCM_sys_PutBuffer_Rest :" $@
1028  fi
1029  if [ $DRYRUN = 0 ]; then
1030    if [ ! -f ${1} ] ; then
1031      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1032      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1033    fi
1034
1035    typeset RET
1036    #
1037    if [ X${JobType} = XRUN ] ; then
1038      IGCM_sys_Chmod 444 ${1}
1039    fi
1040
1041    #
1042    # USUAL WAY
1043    \cp $1 $2 > out_rsync 2>&1
1044    RET=$?
1045
1046    if [ ${RET} -gt 0 ] ; then
1047      echo "IGCM_sys_PutBuffer_Rest : error."
1048      cat out_rsync
1049      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1050    else
1051      \rm out_rsync
1052    fi
1053  else
1054    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1055  fi
1056  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1057}
1058
1059#D-#==================================================
1060#D-function IGCM_sys_Put_Out
1061#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
1062#D-* Examples:
1063#D-
1064function IGCM_sys_Put_Out {
1065    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1066    if ( $DEBUG_sys ) ; then
1067        echo "IGCM_sys_Put_Out :" $@
1068    fi
1069    if [ $DRYRUN = 0 ]; then
1070        if [ ! -f ${1} ] ; then
1071            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1072            IGCM_debug_PopStack "IGCM_sys_Put_Out"
1073            return 1
1074        fi
1075
1076        typeset RET
1077        #
1078        if [ X${JobType} = XRUN ] ; then
1079            if [ X${3} = X ] ; then
1080                IGCM_sys_Chmod 444 ${1}
1081            fi
1082        fi
1083        #
1084        # Only if we use rsync
1085        #IGCM_sys_MkdirArchive $( dirname $2 )
1086        #
1087        #USUAL WAY
1088        mfput $1 $2 > out_rsync 2>&1
1089        RET=$?
1090
1091#       #RSYNC WITH NETWORK RSH CALL
1092#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1093#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1094
1095#       #RSYNC WITH NFS USE
1096#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1097#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1098
1099#       RET=$?
1100#       IGCM_sys_Rsync_out $RET
1101
1102#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1103#       (( RET=RET+$? ))
1104
1105        if [ ${RET} -gt 0 ] ; then
1106            echo "IGCM_sys_Put_Out : error."
1107            cat out_rsync
1108            IGCM_debug_Exit "IGCM_sys_Put_Out"
1109        else
1110            \rm out_rsync
1111        fi
1112        IGCM_sys_Rm out_rsync
1113    else
1114        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1115    fi
1116    IGCM_debug_PopStack "IGCM_sys_Put_Out"
1117    return 0
1118}
1119
1120#D-#==================================================
1121#D-function IGCM_sys_PutBuffer_Out
1122#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1123#D-* Examples:
1124#D-
1125function IGCM_sys_PutBuffer_Out {
1126  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1127  if ( $DEBUG_sys ) ; then
1128    echo "IGCM_sys_PutBuffer_Out :" $@
1129  fi
1130  if [ $DRYRUN = 0 ]; then
1131    if [ ! -f ${1} ] ; then
1132      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1133      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1134      return 1
1135    fi
1136    #
1137    IGCM_sys_Mkdir $( dirname $2 )
1138    #
1139    typeset RET
1140
1141    if [ X${JobType} = XRUN ] ; then
1142      if [ X${3} = X ] ; then
1143        IGCM_sys_Chmod 444 ${1}
1144      fi
1145    fi
1146    #
1147    # USUAL WAY
1148    \cp $1 $2 > out_rsync 2>&1
1149    RET=$?
1150
1151    if [ ${RET} -gt 0 ] ; then
1152      echo "IGCM_sys_PutBuffer_Out : error."
1153      cat out_rsync
1154      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1155    else
1156      \rm out_rsync
1157    fi
1158  else
1159    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1160  fi
1161  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1162  return 0
1163}
1164
1165#D-#==================================================
1166#D-function IGCM_sys_Get
1167#D-* Purpose: Get a file from ${ARCHIVE}
1168#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1169#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1170function IGCM_sys_Get {
1171    IGCM_debug_PushStack "IGCM_sys_Get" $@
1172
1173    typeset DEST RET dm_liste ifile target
1174
1175    if ( $DEBUG_sys ) ; then
1176        echo "IGCM_sys_Get :" $@
1177    fi
1178    if [ $DRYRUN -le 2 ]; then
1179        if [ X${1} = X'/l' ] ; then
1180            # test if the first file is present in the old computation :
1181            eval set +A dm_liste \${${2}}
1182        else
1183            dm_liste=${1}
1184        fi
1185        eval DEST=\${${#}}
1186
1187        # test if the (first) file is present in the old computation :
1188        IGCM_sys_TestFileArchive ${dm_liste[0]}
1189        RET=$?
1190        if [ ${RET} -gt 0 ] ; then
1191            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1192            IGCM_debug_Exit "IGCM_sys_Get"
1193            return
1194        fi
1195
1196        # SD : dm_liste is not suited for computing job
1197        #      because we change filename during transfert
1198        #      dm_liste is better suited for post-treatment
1199        #dm_liste=" "
1200        #(( ifile=1 ))
1201        #while [ $ifile -lt $# ] ; do
1202        #    dm_liste=$( eval echo ${dm_liste} " "\${${ifile}} )
1203        #    (( ifile = ifile + 1 ))
1204        #done
1205        #DEST=$( eval echo \${${#}} )
1206
1207        #USUAL WAY
1208        mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1209        #mfget $1 $2 > out_rsync 2>&1
1210        RET=$?
1211
1212#       #RSYNC WITH NETWORK RSH CALL
1213#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1214#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1215
1216#       #RSYNC WITH NFS USE
1217#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1218#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1219
1220#       RET=$?
1221#       IGCM_sys_Rsync_out $RET
1222
1223#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1224#       (( RET=RET+$? ))
1225
1226        if [ ${RET} -gt 0 ] ; then
1227            echo "IGCM_sys_Get : copy error."
1228            cat out_rsync
1229            IGCM_debug_Exit "IGCM_sys_Get"
1230        else
1231            \rm out_rsync
1232        fi
1233    else
1234        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1235    fi
1236    IGCM_debug_PopStack "IGCM_sys_Get"
1237}
1238
1239#D-#==================================================
1240#D-function IGCM_sys_GetBuffer
1241#D-* Purpose: Get a file from ${SCRATCHDIR}
1242#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1243#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1244function IGCM_sys_GetBuffer {
1245  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1246
1247  typeset DEST RET buf_liste ifile target file_work
1248
1249  if ( $DEBUG_sys ) ; then
1250    echo "IGCM_sys_GetBuffer :" $@
1251  fi
1252  if [ $DRYRUN -le 2 ]; then
1253    if [ X${1} = X'/l' ] ; then
1254      # test if the first file is present in the old computation :
1255      eval set +A buf_liste \${${2}}
1256    else
1257      eval set +A buf_liste ${1}
1258    fi
1259    eval DEST=\${${#}}
1260
1261    #USUAL WAY
1262    if [ X${1} = X'/l' ] ; then
1263      (( RET=0 ))
1264      for target in ${buf_liste[*]} ; do
1265        local_file=$( basename ${target} )
1266        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1267        (( RET = RET + $? ))
1268      done
1269    else
1270      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1271      RET=$?
1272    fi
1273
1274    if [ ${RET} -gt 0 ] ; then
1275      echo "IGCM_sys_GetBuffer : copy error."
1276      cat out_rsync
1277      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1278    else
1279      \rm out_rsync
1280    fi
1281  else
1282    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1283  fi
1284  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1285}
1286
1287############################################################## A FINIR !!
1288
1289#D-#==================================================
1290#D-function IGCM_sys_GetDate_FichWork
1291#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1292#D-* Examples:
1293#D-
1294function IGCM_sys_GetDate_FichWork {
1295    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1296    if ( $DEBUG_sys ) ; then
1297        echo "IGCM_sys_GetDate_FichWork :" $@
1298    fi
1299    typeset dateF
1300    set +A dateF -- $( rsh ${MASTER} -n /opt/freeware/bin/ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1301    eval ${2}=${dateF[5]}
1302
1303    # donne la date filesys d'un fichier sur la machine work
1304    IGCM_debug_PopStack "IGCM_sys_FichWork"
1305}
1306
1307#D-#==================================================
1308#D-function IGCM_sys_GetDate_FichArchive
1309#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1310#D-* Examples:
1311#D-
1312function IGCM_sys_GetDate_FichArchive {
1313    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1314    if ( $DEBUG_sys ) ; then
1315        echo "IGCM_sys_GetDate_FichArchive :" $@
1316    fi
1317    typeset dateF
1318    set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1319    eval ${2}=${dateF[5]}
1320
1321    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1322}
1323
1324##############################################################
1325# REBUILD OPERATOR
1326
1327function IGCM_sys_rebuild {
1328    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1329    if ( $DEBUG_sys ) ; then
1330        echo "IGCM_sys_rebuild :" $@
1331    fi
1332    /homegpfs/rech/psl/rpsl035/bin/rebuild -f -o $@
1333    if [ $? -gt 0 ] ; then
1334       echo "IGCM_sys_rebuild : erreur ${@}."
1335       IGCM_debug_Exit "rebuild"
1336    fi
1337
1338    IGCM_debug_PopStack "IGCM_sys_rebuild"
1339}
1340
1341############################################################
1342# Activate Running Environnment Variables
1343
1344function IGCM_sys_activ_variables {
1345    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1346    if ( $DEBUG_sys ) ; then
1347        echo "IGCM_sys_activ_variables "
1348    fi
1349
1350# --------------------------------------------------------------------
1351#D- MPI specifications
1352# --------------------------------------------------------------------
1353
1354# --------------------------------------------------------------------
1355#D- Other specifications
1356# --------------------------------------------------------------------
1357
1358    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1359
1360}
1361
1362############################################################
1363# Desactivate Running Environnment Variables
1364
1365function IGCM_sys_desactiv_variables {
1366    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1367    if ( $DEBUG_sys ) ; then
1368        echo "IGCM_sys_desactiv_variables "
1369    fi
1370# --------------------------------------------------------------------
1371#D- MPI specifications
1372# --------------------------------------------------------------------
1373
1374# --------------------------------------------------------------------
1375#D- Other specifications
1376# --------------------------------------------------------------------
1377
1378    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1379 
1380}
1381
1382############################################################
1383# Build MPI/OMP scripts
1384function IGCM_sys_build_execution_scripts
1385{
1386    IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1387    if ( $DEBUG_sys ) ; then
1388        echo "IGCM_sys_build_execution_scripts " $@
1389    fi
1390
1391    typeset NbNodes_Job NbProc_Job comp_proc_mpi_loc comp_proc_omp_loc mpi_count
1392   
1393    if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1394        IGCM_debug_Exit "IGCM_sys_vargas build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1395    fi
1396
1397    if ( ${OK_PARA_MPMD} ) ; then
1398
1399        if [ -f run_file ] ; then
1400            IGCM_sys_Rm -f run_file
1401        fi
1402        touch run_file
1403
1404        if ( ${OK_PARA_OMP} ) ; then
1405# NEW : 2 Noeuds
1406# @ task_geometry={(0)(1,2,3)}
1407# Nombre de processus demandes
1408            echo "Job_${config_UserChoices_JobName} includes task_geometry = \c"
1409            cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" 
1410            echo "Job_${config_UserChoices_JobName} includes task_geometry  with NbNodes = \c"
1411            cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" | wc -c
1412            NbNodes_Job=$(( $( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" | wc -c ) - 1 ))
1413
1414            if [ ${NbNodes_Job} -eq 0 ] ; then
1415                IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no task_geometry defined with OpenMP run."
1416                exit 1
1417            fi
1418        else
1419# OLD :
1420# @ total_tasks = 3
1421# @ environment = "BATCH_NUM_PROC_TOT=3"
1422# Pas d OpenMP
1423# @ resources = ConsumableCpus(1)
1424            echo "Job_${config_UserChoices_JobName} includes total_tasks = \c"
1425            cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "total_tasks" | sed -e "s/.*total_tasks = //" 
1426            NbProc_Job=$( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "total_tasks" | sed -e "s/.*total_tasks = //" )
1427            NbProc_Job=${NbProc_Job:=0}
1428            if [ ${NbProc_Job} -eq 0 ] ; then
1429                IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no total_tasks defined with MPI only run."
1430                exit 1
1431            fi
1432            if ( $( egrep '^# *@ *resources *= *ConsumableCpus\(1\)' ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} >/dev/null 2>&1 ) ) ; then
1433                IGCM_debug_Print 2 "ressources =  ConsumableCpus(1) line found into Job_${config_UserChoices_JobName}"
1434            else
1435                IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources = line not found. Job should include resources = ConsumableCpus(1) "
1436                exit 1
1437            fi           
1438        fi
1439
1440# run_file construction
1441
1442# Then first loop on the components for the coupler ie oasis
1443
1444### the coupler ie oasis must be the first one
1445    for comp in ${config_ListOfComponents[*]} ; do
1446       
1447        eval ExeNameIn=\${config_Executable_${comp}[0]}
1448        eval ExeNameOut=\${config_Executable_${comp}[1]}
1449           
1450        # for CPL component only
1451        if [ "X${comp}" = "XCPL" ] ; then
1452
1453            eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1454            eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1455           
1456            if ( ${OK_PARA_MPI} ) ; then 
1457
1458                (( mpi_count = 1 ))
1459                until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1460                    if ( ${OK_PARA_OMP} ) ; then
1461                        echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1462                    else
1463                        echo "./${ExeNameOut}" >> run_file
1464                    fi
1465                    (( mpi_count = mpi_count + 1 ))
1466                done
1467            else
1468                if ( ${OK_PARA_OMP} ) ; then
1469                    echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1470                else
1471                    echo "./${ExeNameOut} " >> run_file
1472                fi
1473            fi
1474        fi
1475    done
1476
1477# Then second loop on the components
1478
1479    for comp in ${config_ListOfComponents[*]} ; do
1480       
1481        eval ExeNameIn=\${config_Executable_${comp}[0]}
1482        eval ExeNameOut=\${config_Executable_${comp}[1]}
1483           
1484        # Only if we really have an executable for the component and not the coupler ie oasis:
1485        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1486
1487            eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1488            eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1489           
1490            if ( ${OK_PARA_MPI} ) ; then 
1491
1492                (( mpi_count = 1 ))
1493                until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1494                    if ( ${OK_PARA_OMP} ) ; then
1495                        echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1496                    else
1497                        echo "./${ExeNameOut}" >> run_file
1498                    fi
1499                    (( mpi_count = mpi_count + 1 ))
1500                done
1501            else
1502                if ( ${OK_PARA_OMP} ) ; then
1503                    echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1504                else
1505                    # to be tested : no MPI only OpenMP into MPMD mode
1506                    echo "./${ExeNameOut} " >> run_file
1507                fi
1508            fi
1509        fi
1510    done
1511
1512    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1513
1514    IGCM_sys_Chmod u+x run_file
1515    if ( $DEBUG_sys ) ; then
1516      echo "run_file contains : "
1517      cat run_file
1518    fi
1519
1520else # Only one executable. launch it.
1521
1522    for comp in ${config_ListOfComponents[*]} ; do
1523
1524        eval ExeNameIn=\${config_Executable_${comp}[0]}
1525        eval ExeNameOut=\${config_Executable_${comp}[1]}
1526
1527        [ "X${ExeNameOut}" != X\"\" ] &&  EXECUTION="time ./${ExeNameOut}"
1528
1529    done
1530
1531fi
1532
1533    IGCM_debug_Print 1 "sys vargas : execution command is "
1534    IGCM_debug_Print 1 "$EXECUTION"
1535
1536    IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1537}
1538
1539function IGCM_sys_build_run_file {
1540
1541IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1542
1543}
1544
Note: See TracBrowser for help on using the repository browser.