source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 689

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