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

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

On mercure SX9 and titane, add R_BUFR information in mailed information message.

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