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

Last change on this file since 651 was 651, checked in by aclsce, 12 years ago

Added check to be sure there is enough space on temporary filesystems (only on vargas, titane and mercure sx9).
If there is not enough space, we stop.

  • Property svn:keywords set to Revision Author Date
File size: 47.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
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 Mercure SX9
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# gawk specific location on SX9
35export PATH=/applications/gawk-3.0.4/bin:${PATH}
36
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#=====================================================
67# Host and user names
68# $hostname ou hostname
69typeset  HOST=${HOST:=$( hostname )}
70# $username ou whoami
71typeset  LOGIN=${LOGIN:=$( whoami )}
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
83typeset -r RSYNC_opt="-va"
84# ie storage filesystem
85typeset -r STOREHOST=${MASTER}
86
87#====================================================
88# Host specific DIRECTORIES
89#====================================================
90
91# ============ CESIUM START ============ #
92
93#====================================================
94#- Mirror libIGCM from mercure to cesium if needed
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
101
102#====================================================
103#- libIGCM_POST
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
110
111# ============ CESIUM  END  ============ #
112
113#====================================================
114#- MirrorlibIGCM uncomment for frontend
115typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
116
117#====================================================
118#- libIGCM_POST uncomment for frontend
119typeset -r libIGCM_POST=${libIGCM}
120
121#====================================================
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#====================================================
137#- IN
138typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
139typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
140
141#====================================================
142#- R_OUT
143typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
144
145#====================================================
146#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
147typeset -r R_FIG=${STORAGE}/IGCM_OUT
148
149#====================================================
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#====================================================
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
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
186#D-#==================================================
187#D-function IGCM_sys_RshMaster
188#D-* Purpose: Connection to frontend machine.
189#D-* Examples:
190#D-
191function IGCM_sys_RshMaster {
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  ${@}
199EOF
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"
205}
206
207#D-#==================================================
208#D-function IGCM_sys_RshArchive
209#D-* Purpose: Archive rsh command
210#D-* Examples:
211#D-
212function IGCM_sys_RshArchive {
213  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
214  /bin/ksh <<-EOF
215    ${@}
216EOF
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"
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 {
230  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
231  if ( $DEBUG_sys ) ; then
232    echo "IGCM_sys_RshPost :" $@
233  fi
234
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
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_$$
248
249# ============ FRONTEND  END  ============ #
250
251# ============ CESIUM START ============ #
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_$$
272# ============ CESIUM  END  ============ #
273
274  IGCM_debug_PopStack "IGCM_sys_RshPost"
275}
276
277#D-#==================================================
278#D-function IGCM_sys_SendMail
279#D-* Purpose: Send mail when simulation is over
280#D-* Examples:
281#D-
282function IGCM_sys_SendMail {
283  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
284  if ( $DEBUG_sys ) ; then
285    echo "IGCM_sys_SendMail :" $@
286  fi
287
288  if ( ${ExitFlag} ) ; then
289    status=failed
290  else
291    status=completed
292  fi
293  cat  << END_MAIL > job_end.mail
294  Dear ${LOGIN},
295
296  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
297  Job started : ${DateBegin}
298  Job ended   : ${DateEnd}
299  Output files are available in ${R_SAVE}
300  Files to be rebuild are temporarily available in ${REBUILD_DIR}
301  Pre-packed files are temporarily available in ${R_BUFR}
302  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
303END_MAIL
304
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
312
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"
318}
319
320#D-#==================================================
321#D-function IGCM_sys_Mkdir
322#D-* Purpose: Master locale mkdir command
323#D-* Examples:
324#D-
325function IGCM_sys_Mkdir {
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"
335    fi
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"
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 {
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"
361    fi
362  fi
363  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
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 {
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"
382    fi
383  fi
384  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
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 {
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"
403}
404
405#D-#==================================================
406#D-function IGCM_sys_Chmod
407#D-* Purpose: Chmod
408#D-* Examples:
409#D-
410function IGCM_sys_Chmod {
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"
420    fi
421  else
422    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
423  fi
424  IGCM_debug_PopStack "IGCM_sys_Chmod"
425}
426
427#D-#==================================================
428#D-function IGCM_sys_FileSize
429#D-* Purpose: Filesize
430#D-* Examples:
431#D-
432function IGCM_sys_FileSize {
433  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
434
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]}
441
442  IGCM_debug_PopStack "IGCM_sys_FileSize"
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 {
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"
458
459  return ${ExistFlag}
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 {
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"
475
476  return ${ExistFlag}
477}
478
479#D-#==================================================
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
490  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
491  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
492
493  return ${IsArchivedFlag}
494}
495
496#D-#==================================================
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 {
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"
506
507  return ${ExistFlag}
508}
509
510#D-#==================================================
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-#==================================================
525#D-function IGCM_sys_CountFileArchive
526#D-* Purpose: Count files on Archive filesystem
527#D-* Examples:
528#D-
529function IGCM_sys_CountFileArchive {
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"
536}
537
538#D-#==================================================
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-#==================================================
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 {
558  IGCM_debug_PushStack "IGCM_sys_Tree" $@
559  if ( $DEBUG_sys ) ; then
560    echo "IGCM_sys_Tree :" $@
561  fi
562
563  \ls -lR ${@}
564
565  IGCM_debug_PopStack "IGCM_sys_Tree"
566}
567
568#D-#==================================================
569#D-function IGCM_sys_Tar
570#D-* Purpose: master tar command
571#D-* Examples:
572#D-
573function IGCM_sys_Tar {
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"
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 {
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"
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 {
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"
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 {
628  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
629  if ( $DEBUG_sys ) ; then
630    echo "IGCM_sys_QsubPost :" $@
631  fi
632
633# ============ FRONTEND START ============ #
634
635  /usr/bin/nqsII/qsub -q scalaire -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
636
637# ============ FRONTEND  END  ============ #
638
639# ============ CESIUM START ============ #
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
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"
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 {
676  RET=$1
677  if [ ! $RET ] ; then
678    echo "rsync error !"
679  fi
680
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
778}
779
780#D-#==================================================
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 {
786  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
787  if ( $DEBUG_sys ) ; then
788    echo "IGCM_sys_Mirror_libIGCM"
789  fi
790
791  typeset RET DEST
792
793  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
794
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=$?
798
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"
804}
805
806#====================================================
807#- Call IGCM_sys_Mirror_libIGCM now !
808if ( $MirrorlibIGCM ) ; then
809  IGCM_sys_Mirror_libIGCM
810fi
811
812#D-#==================================================
813#D-function IGCM_sys_Cp
814#D-* Purpose: generic cp
815#D-* Examples:
816#D-
817function IGCM_sys_Cp {
818  IGCM_debug_PushStack "IGCM_sys_Cp" $@
819  if ( $DEBUG_sys ) ; then
820    echo "IGCM_sys_Cp :" $@
821  fi
822
823  typeset RET
824
825  echo cp $@ > out_rsync 2>&1
826  \cp $@ >> out_rsync 2>&1
827  RET=$?
828
829  if [ ${RET} -gt 0 ] ; then
830    echo "IGCM_sys_Cp : error."
831    cat out_rsync
832    IGCM_debug_Exit "IGCM_sys_Cp"
833  else
834    \rm out_rsync
835  fi
836  IGCM_debug_PopStack "IGCM_sys_Cp"
837}
838
839#D-#==================================================
840#D-function IGCM_sys_Rm
841#D-* Purpose: generic rm
842#D-* Examples:
843#D-
844function IGCM_sys_Rm {
845  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
846  if ( $DEBUG_sys ) ; then
847    echo "IGCM_sys_Rm :" $@
848  fi
849
850  typeset RET
851
852  echo rm $@ > out_rsync 2>&1
853  \rm $@ >> out_rsync 2>&1
854  RET=$?
855
856  if [ ${RET} -gt 0 ] ; then
857    echo "IGCM_sys_Rm : error."
858    cat out_rsync
859    IGCM_debug_Exit "IGCM_sys_Rm"
860  else
861    \rm out_rsync
862  fi
863  IGCM_debug_PopStack "IGCM_sys_Rm"
864}
865
866#D-#==================================================
867#D-function IGCM_sys_Mv
868#D-* Purpose: generic move
869#D-* Examples:
870#D-
871function IGCM_sys_Mv {
872  IGCM_debug_PushStack "IGCM_sys_Mv" $@
873  if ( $DEBUG_sys ) ; then
874    echo "IGCM_sys_Mv :" $@
875  fi
876
877  if [ $DRYRUN = 0 ]; then
878
879    typeset RET
880   
881    echo mv $@ > out_rsync 2>&1
882    \mv $@ >> out_rsync 2>&1
883    RET=$?
884   
885    if [ ${RET} -gt 0 ] ; then
886      echo "IGCM_sys_Mv : error in mv."
887      cat out_rsync
888      IGCM_debug_Exit "IGCM_sys_Mv"
889    else
890      \rm out_rsync
891    fi
892  else
893    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
894  fi
895
896  IGCM_debug_PopStack "IGCM_sys_Mv"
897}
898
899#D-#==================================================
900#D-function IGCM_sys_Put_Dir
901#D-* Purpose: Copy a complete directory on $(ARCHIVE)
902#D-* Examples:
903#D-
904function IGCM_sys_Put_Dir {
905  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
906  if ( $DEBUG_sys ) ; then
907    echo "IGCM_sys_Put_Dir :" $@
908  fi
909  if [ $DRYRUN = 0 ]; then
910    if [ ! -d ${1} ] ; then
911      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
912      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
913      return
914    fi
915
916    typeset RET
917
918    # Only if we use rsync
919    #IGCM_sys_TestDirArchive $( dirname $2 )
920    #
921    #USUAL WAY
922    \cp -r $1 $2 > out_rsync 2>&1
923    RET=$?
924
925    if [ ${RET} -gt 0 ] ; then
926      echo "IGCM_sys_Put_Dir : error."
927      cat out_rsync
928      IGCM_debug_Exit "IGCM_sys_Put_Dir"
929    else
930      \rm out_rsync
931    fi
932  else
933    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
934  fi
935  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
936}
937
938#D-#==================================================
939#D-function IGCM_sys_Get_Dir
940#D-* Purpose: Copy a complete directory from ${ARCHIVE}
941#D-* Examples:
942#D-
943function IGCM_sys_Get_Dir {
944  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
945  if ( $DEBUG_sys ) ; then
946    echo "IGCM_sys_Get_Dir :" $@
947  fi
948  if [ $DRYRUN = 0 ]; then
949#    if [ ! -d ${1} ] ; then
950#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
951#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
952#      return
953#    fi
954
955    typeset RET
956
957    # Only if we use rsync
958    #IGCM_sys_TestDirArchive $( dirname $2 )
959    #
960    # USUAL WAY
961    # add dmfind/dmget (to demigrate all offline files) :
962    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
963    \cp -r $1 $2 > out_rsync 2>&1
964    RET=$?
965
966    if [ ${RET} -gt 0 ] ; then
967      echo "IGCM_sys_Get_Dir : error."
968      cat out_rsync
969      IGCM_debug_Exit "IGCM_sys_Get_Dir"
970    else
971      \rm out_rsync
972    fi
973  else
974    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
975  fi
976  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
977}
978
979#D-#==================================================
980#D-function IGCM_sys_Put_Rest
981#D-* Purpose: Put computied restarts on ${ARCHIVE}.
982#D-           File and target directory must exist.
983#D-* Examples:
984#D-
985function IGCM_sys_Put_Rest {
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"
994    fi
995
996    typeset RET
997    #
998    if [ X${JobType} = XRUN ] ; then
999      IGCM_sys_Chmod 444 ${1}
1000    fi
1001
1002    #
1003    # USUAL WAY
1004    \cp $1 $2 > out_rsync 2>&1
1005    RET=$?
1006
1007#       #RSYNC WITH NETWORK SSH CALL
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
1010
1011#       #RSYNC WITH NFS USE
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
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
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"
1025    else
1026      \rm out_rsync
1027    fi
1028  else
1029    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1030  fi
1031  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1032}
1033
1034#D-#==================================================
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-#==================================================
1076#D-function IGCM_sys_Put_Out
1077#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1078#D-* Examples:
1079#D-
1080function IGCM_sys_Put_Out {
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
1090    fi
1091    #
1092    IGCM_sys_MkdirArchive $( dirname $2 )
1093    #
1094    typeset RET
1095
1096    #=====================================================
1097    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1098    #=====================================================
1099
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
1109
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=$?
1119
1120#       #RSYNC WITH NETWORK SSH CALL
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
1123
1124#       #RSYNC WITH NFS USE
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
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
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"
1138    else
1139      \rm out_rsync
1140    fi
1141  else
1142    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1143  fi
1144  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1145  return 0
1146}
1147
1148#D-#==================================================
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-#==================================================
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 {
1199  IGCM_debug_PushStack "IGCM_sys_Get" $@
1200
1201  typeset DEST RET dm_liste ifile target file_work
1202
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}
1212    fi
1213    eval DEST=\${${#}}
1214
1215    #=====================================================
1216    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1217    #=====================================================
1218
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
1230
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
1238
1239    #dmget ${dm_liste[*]} > out_rsync 2>&1
1240    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
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
1247
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"
1254    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1255    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
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
1268
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
1282#       #RSYNC WITH NETWORK SSH CALL
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
1285
1286#       #RSYNC WITH NFS USE
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
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
1296    if [ ${RET} -gt 0 ] ; then
1297      echo "IGCM_sys_Get : copy error."
1298      cat out_rsync
1299      IGCM_debug_Exit "IGCM_sys_Get"
1300    else
1301      \rm out_rsync
1302    fi
1303  else
1304    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1305  fi
1306  IGCM_debug_PopStack "IGCM_sys_Get"
1307}
1308
1309#D-#==================================================
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-#==================================================
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 {
1363  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1364  if ( $DEBUG_sys ) ; then
1365    echo "IGCM_sys_GetDate_FichWork :" $@
1366  fi
1367  typeset dateF
1368  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1369  eval ${2}=${dateF[5]}
1370
1371    # donne la date filesys d'un fichier sur la machine work
1372  IGCM_debug_PopStack "IGCM_sys_FichWork"
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 {
1381  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1382  if ( $DEBUG_sys ) ; then
1383    echo "IGCM_sys_GetDate_FichArchive :" $@
1384  fi
1385  typeset dateF
1386  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1387  eval ${2}=${dateF[5]}
1388
1389  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1390}
1391
1392##############################################################
1393# REBUILD OPERATOR
1394
1395function IGCM_sys_rebuild {
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
1405
1406  IGCM_debug_PopStack "IGCM_sys_rebuild"
1407}
1408
1409############################################################
1410# Activate Running Environnment Variables
1411
1412function IGCM_sys_activ_variables {
1413  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1414  if ( $DEBUG_sys ) ; then
1415    echo "IGCM_sys_activ_variables"
1416  fi
1417
1418# --------------------------------------------------------------------
1419#D- MPI specifications
1420# --------------------------------------------------------------------
1421
1422#D-- MPISUSPEND
1423  export MPISUSPEND=${MPISUSPEND:=OFF}
1424
1425#D-- MPIPROGINF #other choices : ALL_DETAIL2
1426  export MPIPROGINF=ALL
1427#D- activate ftrace (with -ftrace)
1428  export F_FTRACE=YES
1429#D- communication information (with -ftrace)
1430  export MPICOMMINF=DETAIL
1431
1432# --------------------------------------------------------------------
1433#D- Other specifications
1434# --------------------------------------------------------------------
1435
1436#D- max number of character/line in output job
1437  export F_SYSLEN=5000
1438#D- number of error that can be admitted on the NEC
1439  export F_ERRCNT=0
1440#D- global performance
1441  export F_PROGINF=DETAIL
1442
1443#D- I/O performance (FORTRAN I/O only not netCDF)
1444  export F_FILEINF=${F_FILEINF:=NO}
1445#D- netCDF I/O performance
1446  export NC_FILEINF=${NC_FILEINF:=NO}
1447
1448  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1449}
1450
1451############################################################
1452# Desactivate Running Environnment Variables
1453
1454function IGCM_sys_desactiv_variables {
1455  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1456  if ( $DEBUG_sys ) ; then
1457    echo "IGCM_sys_desactiv_variables"
1458  fi
1459# --------------------------------------------------------------------
1460#D- MPI specifications
1461# --------------------------------------------------------------------
1462
1463#D-- MPIPROGINF
1464  export MPIPROGINF=NO
1465
1466# --------------------------------------------------------------------
1467#D- Other specifications
1468# --------------------------------------------------------------------
1469
1470#D- global performance
1471  export F_PROGINF=NO 
1472
1473  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1474}
1475
1476############################################################
1477# Build MPI/OMP scripts
1478function IGCM_sys_build_execution_scripts
1479{
1480    IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1481    if ( $DEBUG_sys ) ; then
1482        echo "IGCM_sys_build_execution_scripts " $@
1483    fi
1484
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
1490
1491    if ( ${OK_PARA_MPMD} ) ; then
1492
1493        if [ -f run_file ] ; then
1494            IGCM_sys_Rm -f run_file
1495        fi
1496        touch run_file
1497
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
1502# OLD :
1503#PBS -v BATCH_NUM_PROC_TOT=4
1504#PBS -l cpunum_job=${BATCH_NUM_PROC_TOT}
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
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
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}
1530           
1531            if ( ${OK_PARA_MPI} ) ; then
1532                echo "-p ${comp_proc_mpi_loc} -e ./${ExeNameOut}" >> run_file
1533            fi
1534        fi
1535    done
1536
1537# Then second loop on the components
1538
1539    for comp in ${config_ListOfComponents[*]} ; do
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}
1549           
1550            if ( ${OK_PARA_MPI} ) ; then
1551                    echo "-p ${comp_proc_mpi_loc} -e ./${ExeNameOut}" >> run_file
1552            fi
1553        fi
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
1564else # Only one executable. launch it.
1565
1566    for comp in ${config_ListOfComponents[*]} ; do
1567
1568        eval ExeNameIn=\${config_Executable_${comp}[0]}
1569        eval ExeNameOut=\${config_Executable_${comp}[1]}
1570
1571        [ "X${ExeNameOut}" != X\"\" ] &&  EXECUTION="time mpirun -np ${BATCH_NUM_PROC_TOT} ./${ExeNameOut}"
1572
1573    done
1574
1575fi
1576
1577    IGCM_debug_Print 1 "sys mercurex9 : execution command is "
1578    IGCM_debug_Print 1 "$EXECUTION"
1579
1580    IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1581
1582}
1583
1584function IGCM_sys_build_run_file {
1585
1586IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1587
1588}
1589
1590############################################################
1591# Check of space available on temporary filesytems
1592function IGCM_sys_check_quota {
1593  IGCM_debug_PushStack "IGCM_sys_check_quota" 
1594  if ( $DEBUG_sys ) ; then
1595    echo "IGCM_sys_check_quota "
1596  fi
1597  # Limit of quota (in %)
1598  limit_quota=90
1599
1600  # Check of the volume
1601  volume_quota=$(ccc_quota | grep ' scratch' | awk '{print $2}')
1602  volume_avail=$(ccc_quota | grep ' scratch' | awk '{print $3}')
1603
1604  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1605
1606    unit_avail=${volume_avail: -1}
1607    unit_quota=${volume_quota: -1}
1608
1609    temp_avail=${volume_avail%%${volume_avail: -1}*}
1610    temp_quota=${volume_quota%%${volume_quota: -1}*}
1611
1612    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1613
1614    # Convertion
1615      if [ ${volume_avail: -1} = "T" ] ; then
1616          (( temp_avail = temp_avail * 1000000000000 ))
1617      elif [ ${volume_avail: -1} = "G" ] ; then
1618          (( temp_avail = temp_avail * 1000000000 ))
1619      elif [ ${volume_avail: -1} = "M" ] ; then
1620          (( temp_avail = temp_avail * 1000000 ))
1621      elif [ ${volume_avail: -1} = "k" ] ; then
1622          (( temp_avail = temp_avail * 1000 ))
1623      else
1624          (( temp_avail = volume_avail ))
1625      fi
1626      if [ ${volume_quota: -1} = "T" ] ; then
1627          (( temp_quota = temp_quota * 1000000000000 ))
1628      elif [ ${volume_quota: -1} = "G" ] ; then
1629          (( temp_quota = temp_quota * 1000000000 ))
1630      elif [ ${volume_quota: -1} = "M" ] ; then
1631          (( temp_quota = temp_quota * 1000000 ))
1632      elif [ ${volume_quota: -1} = "k" ] ; then
1633          (( temp_quota = temp_quota * 1000 ))
1634      else
1635          (( temp_quota = volume_quota ))
1636      fi
1637    fi
1638
1639    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1640#    echo "volume ratio is " $quota_volume
1641
1642    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1643      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1644      IGCM_debug_Print 1 "Use the ccc_quota command"
1645      IGCM_debug_Print 1 "You must have more than 10% available to run"
1646      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1647      IGCM_debug_Verif_Exit
1648    fi
1649
1650  fi
1651  IGCM_debug_PopStack "IGCM_sys_check_quota"
1652}
Note: See TracBrowser for help on using the repository browser.