source: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 595

Last change on this file since 595 was 595, checked in by mafoipsl, 12 years ago

Add PackDefault=false as default.
Set PackDefault=true on SX9 and titane.
Add out_execution and out_* into PackDebug

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