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

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

Add more information about directories used in simulation information message on SX9 and titane.

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