source: tags/libIGCM_v2.0_rc1/libIGCM_sys/libIGCM_sys_vargas.ksh @ 1137

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