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

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