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

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

On vargas: set and initialize ERROR variable into IGCM_sys_Qsub function.

  • 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
593    typeset ERROR
594    ERROR=0
595
596    if ( $DEBUG_sys ) ; then
597        echo "IGCM_sys_Qsub :" $@
598    fi
599    # We have to change output/error file
600    [ ${#@} = 1 ] &&  REP_FOR_JOB=$LOADL_STEP_INITDIR
601    [ ${#@} = 2 ] &&  REP_FOR_JOB=$2
602    sed -e "s/\# \@ output *= .*/\# \@ output = ${Script_Output}/" -e "s/\# \@ error *= .*/\# \@ error = ${Script_Output}/" <$1 >${REP_FOR_JOB}/JOB_FOR_IGCM
603    {
604       [ ${#@} = 1 ] &&  ( cd $LOADL_STEP_INITDIR ; /usr/local/bin/llsubmit JOB_FOR_IGCM ; ERROR=$? ; cd - ; )
605       [ ${#@} = 2 ] &&  ( cd $2 ; /usr/local/bin/llsubmit JOB_FOR_IGCM ; ERROR=$? ; cd - ; )
606    }
607    if [ ${ERROR} -gt 0 ] ; then
608       echo "IGCM_sys_Qsub : erreur $@."
609       IGCM_debug_Exit "IGCM_sys_Qsub"
610    fi
611    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM
612    IGCM_debug_PopStack "IGCM_sys_Qsub"
613
614}
615
616#D-#==================================================
617#D-function IGCM_sys_QsubPost
618#D-* Purpose: Qsub new job on scalaire
619#D-* Examples:
620#D-
621function IGCM_sys_QsubPost {
622    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
623    if ( $DEBUG_sys ) ; then
624        echo "IGCM_sys_QsubPost :" $@
625    fi
626    cd ${POST_DIR}
627    echo MAF QsubPost vargas
628    /opt/ibmll/LoadL/full/bin/llsubmit ${libIGCM_POST}/$1.job
629    cd -
630    if [ $? -gt 0 ] ; then
631        echo "IGCM_sys_QsubPost : erreur " $@
632        IGCM_debug_Exit "IGCM_sys_QsubPost"
633    fi
634    IGCM_debug_PopStack "IGCM_sys_QsubPost"
635}
636
637#D-*************************
638#D- File transfer functions
639#D-*************************
640#D-
641
642#D-#==================================================
643#D-function IGCM_sys_Rsync_out
644#D-* Purpose: treat return val of rsync
645#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
646#D-  Error values and explanations can depend on your system version.
647function IGCM_sys_Rsync_out {
648    RET=$1
649    if [ ! $RET ] ; then
650        echo "rsync error !"
651    fi
652
653    if [ $MYLANG = "fr" ]; then
654        case $RET in
655            0)  return ;;
656            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
657                echo "Erreur de syntaxe ou d'utilisation."
658                return;;
659            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
660                echo "Incompatibilité de protocole."
661                return;;
662            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
663                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
664                echo "répertoires"
665                return;;
666            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
667                echo "Action demandée non supportée : une tentative de manipulation de"
668                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
669                echo "été faite ; ou une option qui est supportée par le  client  mais"
670                echo "pas par le serveur a été spécifiée."
671                return;;
672            10) echo "Erreur de rsync ; RERR_SOCKETIO"
673                echo "Erreur dans le socket d'entrée sortie"
674                return;;
675            11) echo "Erreur de rsync ; RERR_FILEIO"
676                echo "Erreur d'entrée sortie fichier"
677                return;;
678            12) echo "Erreur de rsync ; RERR_STREAMIO"
679                echo "Erreur dans flux de donnée du protocole rsync"
680                return;;
681            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
682                echo "Erreur avec les diagnostics du programme"
683                return;;
684            14) echo "Erreur de rsync ; RERR_IPC"
685                echo "Erreur dans le code IPC"
686                return;;
687            20) echo "Erreur de rsync ; RERR_SIGNAL"
688                echo "SIGUSR1 ou SIGINT reçu"
689                return;;
690            21) echo "Erreur de rsync ; RERR_WAITCHILD"
691                echo "Une erreur retournée par waitpid()"
692                return;;
693            22) echo "Erreur de rsync ; RERR_MALLOC"
694                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
695                return;;
696            23) echo ""
697                echo "Erreur fichier inexistant"
698                return;;
699            30) echo "Erreur de rsync ; RERR_TIMEOUT"
700                echo "Temps d'attente écoulé dans l'envoi/réception de données"
701                return;;
702            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
703                return;;
704        esac
705    elif [ $MYLANG = "en" ] ; then
706        case $RET in
707            0)  return;;               
708            1)  echo "rsync error : Syntax or usage error "
709                return;;
710            2)  echo "rsync error : Protocol incompatibility "
711                return;;
712            3)  echo "rsync error : Errors selecting input/output files, dirs"
713                return;;
714            4)  echo "rsync error : Requested action not supported: an attempt"
715                echo "was made to manipulate 64-bit files on a platform that cannot support"
716                echo "them; or an option was specified that is supported by the client and"
717                echo "not by the server."
718                return;;
719            5)  echo "rsync error : Error starting client-server protocol"
720                return;;
721            10) echo "rsync error : Error in socket I/O "
722                return;;
723            11) echo "rsync error : Error in file I/O "
724                return;;
725            12) echo "rsync error : Error in rsync protocol data stream "
726                return;;
727            13) echo "rsync error : Errors with program diagnostics "
728                return;;
729            14) echo "rsync error : Error in IPC code "
730                return;;
731            20) echo "rsync error : Received SIGUSR1 or SIGINT "
732                return;;
733            21) echo "rsync error : Some error returned by waitpid() "
734                return;;
735            22) echo "rsync error : Error allocating core memory buffers "
736                return;;
737            23) echo "rsync error : Partial transfer due to error"
738                return;;
739            24) echo "rsync error : Partial transfer due to vanished source files"
740                return;;
741            30) echo "rsync error : Timeout in data send/receive "
742                return;;
743            *)  echo "rsync error : return code of rsync unknown :" $RET
744                return;;
745        esac
746    else
747        echo "unknown language $MYLANG."
748        return
749    fi
750}
751   
752#D-#==================================================
753#D-function IGCM_sys_Rm
754#D-* Purpose: generic rm
755#D-* Examples:
756#D-
757function IGCM_sys_Rm {
758    IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
759    if ( $DEBUG_sys ) ; then
760        echo "IGCM_sys_Rm :" $@
761    fi
762
763    typeset RET
764
765    echo rm $@ > out_rsync 2>&1
766    \rm $@ >> out_rsync 2>&1
767    RET=$?
768
769    if [ ${RET} -gt 0 ] ; then
770        echo "IGCM_sys_Rm : error."
771        cat out_rsync
772        IGCM_debug_Exit "IGCM_sys_Rm"
773    fi
774    IGCM_debug_PopStack "IGCM_sys_Rm"
775}
776
777#D-#==================================================
778#D-function IGCM_sys_Miror_libIGCM
779#D-* Purpose: Mirror libIGCM PATH and lib to ulam
780#D-* Examples:
781#D-
782function IGCM_sys_Mirror_libIGCM {
783    IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
784    if ( $DEBUG_sys ) ; then
785        echo "IGCM_sys_Mirror_libIGCM"
786    fi
787
788    typeset RET
789
790    IGCM_sys_RshPost <<-EOF
791    mkdir -p ${HOME_POST}/MIRROR/${PATHlibIGCM}
792EOF
793    rsh ulam -n hostname > /dev/null 2>&1
794    RET=$?
795    if [ $RET -eq 0 ] ; then
796        echo ${RSYNC} ${RSYNC_opt} -e "rsh " ${libIGCM} ulam:${HOME_POST}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
797        ${RSYNC} ${RSYNC_opt} -e "rsh " ${libIGCM} ulam:${HOME_POST}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
798        RET=$?
799
800        if [ ${RET} -gt 0 ] ; then
801            echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on ulam."
802            cat out_rsync
803        fi
804        IGCM_sys_Rm out_rsync
805    else
806        echo "No POST-TREATMENT avaible because ulam is down."
807    fi
808    IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
809}
810
811#====================================================
812#- Call IGCM_sys_Mirror_libIGCM now !
813if ( $MirrorlibIGCM ) ; then
814    IGCM_sys_Mirror_libIGCM
815fi
816
817#D-#==================================================
818#D-function IGCM_sys_Cp
819#D-* Purpose: generic cp
820#D-* Examples:
821#D-
822function IGCM_sys_Cp {
823    IGCM_debug_PushStack "IGCM_sys_Cp" $@
824    if ( $DEBUG_sys ) ; then
825        echo "IGCM_sys_Cp :" $@
826    fi
827
828    typeset RET
829
830    echo cp $@ > out_rsync 2>&1
831    \cp $@ >> out_rsync 2>&1
832    RET=$?
833
834    if [ ${RET} -gt 0 ] ; then
835        echo "IGCM_sys_Cp : error."
836        cat out_rsync
837        IGCM_debug_Exit "IGCM_sys_Cp"
838     else
839         \rm out_rsync
840    fi
841    IGCM_debug_PopStack "IGCM_sys_Cp"
842}
843
844#D-#==================================================
845#D-function IGCM_sys_RmRunDir
846#D-* Purpose: rm tmpdir (dummy function most of the time batch
847#D-                      scheduler will do the job)
848#D-* Examples:
849#D-
850function IGCM_sys_RmRunDir {
851    IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
852    if ( $DEBUG_sys ) ; then
853        echo "IGCM_sys_RmRunDir :" $@
854        echo "Dummy call, let the scheduler do that."
855    fi
856    IGCM_debug_PopStack "IGCM_sys_RmRunDir"
857}
858
859#D-#==================================================
860#D-function IGCM_sys_Mv
861#D-* Purpose: generic move
862#D-* Examples:
863#D-
864function IGCM_sys_Mv {
865    IGCM_debug_PushStack "IGCM_sys_Mv" $@
866    if ( $DEBUG_sys ) ; then
867        echo "IGCM_sys_Mv :" $@
868    fi
869
870    if [ $DRYRUN = 0 ]; then
871
872        typeset RET
873           
874        echo mv $@ > out_rsync 2>&1
875        \mv $@ >> out_rsync 2>&1
876        RET=$?
877   
878        if [ ${RET} -gt 0 ] ; then
879            echo "IGCM_sys_Mv : error in mv."
880            cat out_rsync
881            IGCM_debug_Exit "IGCM_sys_Mv"
882        else
883            \rm out_rsync
884        fi
885    else
886        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
887    fi
888
889    IGCM_debug_PopStack "IGCM_sys_Mv"
890}
891
892#D-#==================================================
893#D-function IGCM_sys_Put_Dir
894#D-* Purpose: Copy a complete directory on $(ARCHIVE)
895#D-* Examples:
896#D-
897function IGCM_sys_Put_Dir {
898    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
899    if ( $DEBUG_sys ) ; then
900        echo "IGCM_sys_Put_Dir :" $@
901    fi
902    if [ $DRYRUN = 0 ]; then
903        if [ ! -d ${1} ] ; then
904            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
905            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
906            return
907        fi
908
909        typeset RET
910
911        # Only if we use rsync
912        #IGCM_sys_TestDirArchive $( dirname $2 )
913        #
914        #USUAL WAY
915        rcp -r $1 ${STOREHOST}:$2 > out_rsync 2>&1
916        RET=$?
917
918        if [ ${RET} -gt 0 ] ; then
919            echo "IGCM_sys_Put_Dir : error."
920            cat out_rsync
921            IGCM_debug_Exit "IGCM_sys_Put_Dir"
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_Dir"
929}
930
931#D-#==================================================
932#D-function IGCM_sys_Get_Dir
933#D-* Purpose: Copy a complete directory from $(ARCHIVE)
934#D-* Examples:
935#D-
936function IGCM_sys_Get_Dir {
937    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
938    if ( $DEBUG_sys ) ; then
939        echo "IGCM_sys_Get_Dir :" $@
940    fi
941    if [ $DRYRUN = 0 ]; then
942        if [ ! -d ${1} ] ; then
943            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
944            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
945            return
946        fi
947
948        typeset RET
949
950        #USUAL WAY
951        rcp -rp ${STOREHOST}:$1 $2 > out_rsync 2>&1
952        RET=$?
953
954        if [ ${RET} -gt 0 ] ; then
955            echo "IGCM_sys_Get_Dir : error."
956            cat out_rsync
957            IGCM_debug_Exit "IGCM_sys_Get_Dir"
958        fi
959    else
960        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
961    fi
962    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
963}
964
965#D-#==================================================
966#D-function IGCM_sys_Put_Rest
967#D-* Purpose: Put computied restarts on $(ARCHIVE).
968#D-           File and target directory must exist.
969#D-* Examples:
970#D-
971function IGCM_sys_Put_Rest {
972    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
973    if ( $DEBUG_sys ) ; then
974        echo "IGCM_sys_Put_Rest :" $@
975    fi
976    if [ $DRYRUN = 0 ]; then
977        if [ ! -f ${1} ] ; then
978            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
979            IGCM_debug_Exit "IGCM_sys_Put_Rest"
980        fi
981
982        typeset RET
983        #
984        if [ X${JobType} = XRUN ] ; then
985            IGCM_sys_Chmod 444 ${1}
986        fi
987        #
988        # Only if we use rsync
989        #IGCM_sys_MkdirArchive $( dirname $2 )
990        #
991        #USUAL WAY
992        mfput $1 $2 > out_rsync 2>&1
993        RET=$?
994
995#       #RSYNC WITH NETWORK RSH CALL
996#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
997#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
998
999#       #RSYNC WITH NFS USE
1000#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1001#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1002       
1003#       RET=$?
1004#       IGCM_sys_Rsync_out $RET
1005
1006#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1007#       (( RET=RET+$? ))
1008
1009        if [ ${RET} -gt 0 ] ; then
1010            echo "IGCM_sys_Put_Rest : error."
1011            cat out_rsync
1012            IGCM_debug_Exit "IGCM_sys_Put_Rest"
1013        else
1014            \rm out_rsync
1015        fi
1016    else
1017        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1018    fi
1019    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1020}
1021
1022#D-#==================================================
1023#D-function IGCM_sys_PutBuffer_Rest
1024#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1025#D-           File and target directory must exist.
1026#D-* Examples:
1027#D-
1028function IGCM_sys_PutBuffer_Rest {
1029  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1030  if ( $DEBUG_sys ) ; then
1031    echo "IGCM_sys_PutBuffer_Rest :" $@
1032  fi
1033  if [ $DRYRUN = 0 ]; then
1034    if [ ! -f ${1} ] ; then
1035      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1036      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1037    fi
1038
1039    typeset RET
1040    #
1041    if [ X${JobType} = XRUN ] ; then
1042      IGCM_sys_Chmod 444 ${1}
1043    fi
1044
1045    #
1046    # USUAL WAY
1047    \cp $1 $2 > out_rsync 2>&1
1048    RET=$?
1049
1050    if [ ${RET} -gt 0 ] ; then
1051      echo "IGCM_sys_PutBuffer_Rest : error."
1052      cat out_rsync
1053      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1054    else
1055      \rm out_rsync
1056    fi
1057  else
1058    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1059  fi
1060  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1061}
1062
1063#D-#==================================================
1064#D-function IGCM_sys_Put_Out
1065#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
1066#D-* Examples:
1067#D-
1068function IGCM_sys_Put_Out {
1069    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1070    if ( $DEBUG_sys ) ; then
1071        echo "IGCM_sys_Put_Out :" $@
1072    fi
1073    if [ $DRYRUN = 0 ]; then
1074        if [ ! -f ${1} ] ; then
1075            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1076            IGCM_debug_PopStack "IGCM_sys_Put_Out"
1077            return 1
1078        fi
1079
1080        typeset RET
1081        #
1082        if [ X${JobType} = XRUN ] ; then
1083            if [ X${3} = X ] ; then
1084                IGCM_sys_Chmod 444 ${1}
1085            fi
1086        fi
1087        #
1088        # Only if we use rsync
1089        #IGCM_sys_MkdirArchive $( dirname $2 )
1090        #
1091        #USUAL WAY
1092        mfput $1 $2 > out_rsync 2>&1
1093        RET=$?
1094
1095#       #RSYNC WITH NETWORK RSH CALL
1096#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1097#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1098
1099#       #RSYNC WITH NFS USE
1100#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1101#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1102
1103#       RET=$?
1104#       IGCM_sys_Rsync_out $RET
1105
1106#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1107#       (( RET=RET+$? ))
1108
1109        if [ ${RET} -gt 0 ] ; then
1110            echo "IGCM_sys_Put_Out : error."
1111            cat out_rsync
1112            IGCM_debug_Exit "IGCM_sys_Put_Out"
1113        else
1114            \rm out_rsync
1115        fi
1116        IGCM_sys_Rm out_rsync
1117    else
1118        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1119    fi
1120    IGCM_debug_PopStack "IGCM_sys_Put_Out"
1121    return 0
1122}
1123
1124#D-#==================================================
1125#D-function IGCM_sys_PutBuffer_Out
1126#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1127#D-* Examples:
1128#D-
1129function IGCM_sys_PutBuffer_Out {
1130  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1131  if ( $DEBUG_sys ) ; then
1132    echo "IGCM_sys_PutBuffer_Out :" $@
1133  fi
1134  if [ $DRYRUN = 0 ]; then
1135    if [ ! -f ${1} ] ; then
1136      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1137      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1138      return 1
1139    fi
1140    #
1141    IGCM_sys_Mkdir $( dirname $2 )
1142    #
1143    typeset RET
1144
1145    if [ X${JobType} = XRUN ] ; then
1146      if [ X${3} = X ] ; then
1147        IGCM_sys_Chmod 444 ${1}
1148      fi
1149    fi
1150    #
1151    # USUAL WAY
1152    \cp $1 $2 > out_rsync 2>&1
1153    RET=$?
1154
1155    if [ ${RET} -gt 0 ] ; then
1156      echo "IGCM_sys_PutBuffer_Out : error."
1157      cat out_rsync
1158      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1159    else
1160      \rm out_rsync
1161    fi
1162  else
1163    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1164  fi
1165  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1166  return 0
1167}
1168
1169#D-#==================================================
1170#D-function IGCM_sys_Get
1171#D-* Purpose: Get a file from ${ARCHIVE}
1172#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1173#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1174function IGCM_sys_Get {
1175    IGCM_debug_PushStack "IGCM_sys_Get" $@
1176
1177    typeset DEST RET dm_liste ifile target
1178
1179    if ( $DEBUG_sys ) ; then
1180        echo "IGCM_sys_Get :" $@
1181    fi
1182    if [ $DRYRUN -le 2 ]; then
1183        if [ X${1} = X'/l' ] ; then
1184            # test if the first file is present in the old computation :
1185            eval set +A dm_liste \${${2}}
1186        else
1187            dm_liste=${1}
1188        fi
1189        eval DEST=\${${#}}
1190
1191        # test if the (first) file is present in the old computation :
1192        IGCM_sys_TestFileArchive ${dm_liste[0]}
1193        RET=$?
1194        if [ ${RET} -gt 0 ] ; then
1195            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1196            IGCM_debug_Exit "IGCM_sys_Get"
1197            return
1198        fi
1199
1200        # SD : dm_liste is not suited for computing job
1201        #      because we change filename during transfert
1202        #      dm_liste is better suited for post-treatment
1203        #dm_liste=" "
1204        #(( ifile=1 ))
1205        #while [ $ifile -lt $# ] ; do
1206        #    dm_liste=$( eval echo ${dm_liste} " "\${${ifile}} )
1207        #    (( ifile = ifile + 1 ))
1208        #done
1209        #DEST=$( eval echo \${${#}} )
1210
1211        #USUAL WAY
1212        mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1213        #mfget $1 $2 > out_rsync 2>&1
1214        RET=$?
1215
1216#       #RSYNC WITH NETWORK RSH CALL
1217#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1218#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1219
1220#       #RSYNC WITH NFS USE
1221#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1222#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1223
1224#       RET=$?
1225#       IGCM_sys_Rsync_out $RET
1226
1227#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1228#       (( RET=RET+$? ))
1229
1230        if [ ${RET} -gt 0 ] ; then
1231            echo "IGCM_sys_Get : copy error."
1232            cat out_rsync
1233            IGCM_debug_Exit "IGCM_sys_Get"
1234        else
1235            \rm out_rsync
1236        fi
1237    else
1238        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1239    fi
1240    IGCM_debug_PopStack "IGCM_sys_Get"
1241}
1242
1243#D-#==================================================
1244#D-function IGCM_sys_GetBuffer
1245#D-* Purpose: Get a file from ${SCRATCHDIR}
1246#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1247#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1248function IGCM_sys_GetBuffer {
1249  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1250
1251  typeset DEST RET buf_liste ifile target file_work
1252
1253  if ( $DEBUG_sys ) ; then
1254    echo "IGCM_sys_GetBuffer :" $@
1255  fi
1256  if [ $DRYRUN -le 2 ]; then
1257    if [ X${1} = X'/l' ] ; then
1258      # test if the first file is present in the old computation :
1259      eval set +A buf_liste \${${2}}
1260    else
1261      eval set +A buf_liste ${1}
1262    fi
1263    eval DEST=\${${#}}
1264
1265    #USUAL WAY
1266    if [ X${1} = X'/l' ] ; then
1267      (( RET=0 ))
1268      for target in ${buf_liste[*]} ; do
1269        local_file=$( basename ${target} )
1270        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1271        (( RET = RET + $? ))
1272      done
1273    else
1274      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1275      RET=$?
1276    fi
1277
1278    if [ ${RET} -gt 0 ] ; then
1279      echo "IGCM_sys_GetBuffer : copy error."
1280      cat out_rsync
1281      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1282    else
1283      \rm out_rsync
1284    fi
1285  else
1286    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1287  fi
1288  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1289}
1290
1291############################################################## A FINIR !!
1292
1293#D-#==================================================
1294#D-function IGCM_sys_GetDate_FichWork
1295#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1296#D-* Examples:
1297#D-
1298function IGCM_sys_GetDate_FichWork {
1299    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1300    if ( $DEBUG_sys ) ; then
1301        echo "IGCM_sys_GetDate_FichWork :" $@
1302    fi
1303    typeset dateF
1304    set +A dateF -- $( rsh ${MASTER} -n /opt/freeware/bin/ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1305    eval ${2}=${dateF[5]}
1306
1307    # donne la date filesys d'un fichier sur la machine work
1308    IGCM_debug_PopStack "IGCM_sys_FichWork"
1309}
1310
1311#D-#==================================================
1312#D-function IGCM_sys_GetDate_FichArchive
1313#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1314#D-* Examples:
1315#D-
1316function IGCM_sys_GetDate_FichArchive {
1317    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1318    if ( $DEBUG_sys ) ; then
1319        echo "IGCM_sys_GetDate_FichArchive :" $@
1320    fi
1321    typeset dateF
1322    set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1323    eval ${2}=${dateF[5]}
1324
1325    IGCM_debug_PopStack "IGCM_sys_FichArchive"
1326}
1327
1328##############################################################
1329# REBUILD OPERATOR
1330
1331function IGCM_sys_rebuild {
1332    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1333    if ( $DEBUG_sys ) ; then
1334        echo "IGCM_sys_rebuild :" $@
1335    fi
1336    /homegpfs/rech/psl/rpsl035/bin/rebuild -f -o $@
1337    if [ $? -gt 0 ] ; then
1338       echo "IGCM_sys_rebuild : erreur ${@}."
1339       IGCM_debug_Exit "rebuild"
1340    fi
1341
1342    IGCM_debug_PopStack "IGCM_sys_rebuild"
1343}
1344
1345############################################################
1346# Activate Running Environnment Variables
1347
1348function IGCM_sys_activ_variables {
1349    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1350    if ( $DEBUG_sys ) ; then
1351        echo "IGCM_sys_activ_variables "
1352    fi
1353
1354# --------------------------------------------------------------------
1355#D- MPI specifications
1356# --------------------------------------------------------------------
1357
1358# --------------------------------------------------------------------
1359#D- Other specifications
1360# --------------------------------------------------------------------
1361
1362    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1363
1364}
1365
1366############################################################
1367# Desactivate Running Environnment Variables
1368
1369function IGCM_sys_desactiv_variables {
1370    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1371    if ( $DEBUG_sys ) ; then
1372        echo "IGCM_sys_desactiv_variables "
1373    fi
1374# --------------------------------------------------------------------
1375#D- MPI specifications
1376# --------------------------------------------------------------------
1377
1378# --------------------------------------------------------------------
1379#D- Other specifications
1380# --------------------------------------------------------------------
1381
1382    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1383 
1384}
1385
1386############################################################
1387# Build MPI/OMP scripts
1388function IGCM_sys_build_execution_scripts
1389{
1390    IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1391    if ( $DEBUG_sys ) ; then
1392        echo "IGCM_sys_build_execution_scripts " $@
1393    fi
1394
1395    typeset NbNodes_Job NbProc_Job comp_proc_mpi_loc comp_proc_omp_loc mpi_count
1396   
1397    if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1398        IGCM_debug_Exit "IGCM_sys_vargas build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1399    fi
1400
1401    if ( ${OK_PARA_MPMD} ) ; then
1402
1403        if [ -f run_file ] ; then
1404            IGCM_sys_Rm -f run_file
1405        fi
1406        touch run_file
1407
1408        if ( ${OK_PARA_OMP} ) ; then
1409# NEW : 2 Noeuds
1410# @ task_geometry={(0)(1,2,3)}
1411# Nombre de processus demandes
1412            echo "Job_${config_UserChoices_JobName} includes task_geometry = \c"
1413            cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" 
1414            echo "Job_${config_UserChoices_JobName} includes task_geometry  with NbNodes = \c"
1415            cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" | wc -c
1416            NbNodes_Job=$(( $( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" | wc -c ) - 1 ))
1417
1418            if [ ${NbNodes_Job} -eq 0 ] ; then
1419                IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no task_geometry defined with OpenMP run."
1420                exit 1
1421            fi
1422        else
1423# OLD :
1424# @ total_tasks = 3
1425# @ environment = "BATCH_NUM_PROC_TOT=3"
1426# Pas d OpenMP
1427# @ resources = ConsumableCpus(1)
1428            echo "Job_${config_UserChoices_JobName} includes total_tasks = \c"
1429            cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "total_tasks" | sed -e "s/.*total_tasks = //" 
1430            NbProc_Job=$( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "total_tasks" | sed -e "s/.*total_tasks = //" )
1431            NbProc_Job=${NbProc_Job:=0}
1432            if [ ${NbProc_Job} -eq 0 ] ; then
1433                IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no total_tasks defined with MPI only run."
1434                exit 1
1435            fi
1436            if ( $( egrep '^# *@ *resources *= *ConsumableCpus\(1\)' ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} >/dev/null 2>&1 ) ) ; then
1437                IGCM_debug_Print 2 "ressources =  ConsumableCpus(1) line found into Job_${config_UserChoices_JobName}"
1438            else
1439                IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources = line not found. Job should include resources = ConsumableCpus(1) "
1440                exit 1
1441            fi           
1442        fi
1443
1444# run_file construction
1445
1446# Then first loop on the components for the coupler ie oasis
1447
1448### the coupler ie oasis must be the first one
1449    for comp in ${config_ListOfComponents[*]} ; do
1450       
1451        eval ExeNameIn=\${config_Executable_${comp}[0]}
1452        eval ExeNameOut=\${config_Executable_${comp}[1]}
1453           
1454        # for CPL component only
1455        if [ "X${comp}" = "XCPL" ] ; then
1456
1457            eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1458            eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1459           
1460            if ( ${OK_PARA_MPI} ) ; then 
1461
1462                (( mpi_count = 1 ))
1463                until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1464                    if ( ${OK_PARA_OMP} ) ; then
1465                        echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1466                    else
1467                        echo "./${ExeNameOut}" >> run_file
1468                    fi
1469                    (( mpi_count = mpi_count + 1 ))
1470                done
1471            else
1472                if ( ${OK_PARA_OMP} ) ; then
1473                    echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1474                else
1475                    echo "./${ExeNameOut} " >> run_file
1476                fi
1477            fi
1478        fi
1479    done
1480
1481# Then second loop on the components
1482
1483    for comp in ${config_ListOfComponents[*]} ; do
1484       
1485        eval ExeNameIn=\${config_Executable_${comp}[0]}
1486        eval ExeNameOut=\${config_Executable_${comp}[1]}
1487           
1488        # Only if we really have an executable for the component and not the coupler ie oasis:
1489        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1490
1491            eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1492            eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1493           
1494            if ( ${OK_PARA_MPI} ) ; then 
1495
1496                (( mpi_count = 1 ))
1497                until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1498                    if ( ${OK_PARA_OMP} ) ; then
1499                        echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1500                    else
1501                        echo "./${ExeNameOut}" >> run_file
1502                    fi
1503                    (( mpi_count = mpi_count + 1 ))
1504                done
1505            else
1506                if ( ${OK_PARA_OMP} ) ; then
1507                    echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
1508                else
1509                    # to be tested : no MPI only OpenMP into MPMD mode
1510                    echo "./${ExeNameOut} " >> run_file
1511                fi
1512            fi
1513        fi
1514    done
1515
1516    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1517
1518    IGCM_sys_Chmod u+x run_file
1519    if ( $DEBUG_sys ) ; then
1520      echo "run_file contains : "
1521      cat run_file
1522    fi
1523
1524else # Only one executable. launch it.
1525
1526    for comp in ${config_ListOfComponents[*]} ; do
1527
1528        eval ExeNameIn=\${config_Executable_${comp}[0]}
1529        eval ExeNameOut=\${config_Executable_${comp}[1]}
1530
1531        [ "X${ExeNameOut}" != X\"\" ] &&  EXECUTION="time ./${ExeNameOut}"
1532
1533    done
1534
1535fi
1536
1537    IGCM_debug_Print 1 "sys vargas : execution command is "
1538    IGCM_debug_Print 1 "$EXECUTION"
1539
1540    IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1541}
1542
1543function IGCM_sys_build_run_file {
1544
1545IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1546
1547}
1548
Note: See TracBrowser for help on using the repository browser.