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

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