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

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

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

  • Property svn:keywords set to Revision Author Date
File size: 60.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.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 Titane
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#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=titane
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81# ie storage filesystem
82typeset -r STOREHOST=${MASTER}
83
84#====================================================
85# Source default environment
86#====================================================
87. /etc/profile
88
89#====================================================
90# Set environment tools (ferret, nco, cdo)
91#====================================================
92. /home/cont003/p86ipsl/.atlas_env_titane_ksh
93
94module switch nco/3.9.4 nco/3.9.4_netcdf4
95
96#====================================================
97# Specific for ocean additionnal diagnostic
98export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
99export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
100
101#====================================================
102# Host specific DIRECTORIES
103#====================================================
104
105# ============ CESIUM START ============ #
106
107#====================================================
108#- Mirror libIGCM from titane to cesium if needed
109#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
110#if [ ! ${ROOTSYS} = "home" ] ; then
111#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
112#else
113#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
114#fi
115
116#====================================================
117#- libIGCM_POST
118#if ( ${MirrorlibIGCM} ) ; then
119#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
120#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
121#else
122#  typeset -r libIGCM_POST=${libIGCM}
123#fi
124
125# ============ CESIUM  END  ============ #
126
127#====================================================
128#- MirrorlibIGCM for frontend
129typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
130
131#====================================================
132#- libIGCM_POST for frontend
133typeset -r libIGCM_POST=${libIGCM}
134
135#====================================================
136#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
137typeset -r R_EXE="${MODIPSL}/bin"
138
139#====================================================
140#- SUBMIT_DIR : submission dir
141typeset SUBMIT_DIR=${SUBMIT_DIR:=${LS_SUBCWD}}
142
143#====================================================
144#- ARCHIVE (dedicated to large files)
145typeset -r ARCHIVE=${CCCSTOREDIR}
146
147#- ARCHIVE (dedicated to small/medium files)
148typeset -r STORAGE=${CCCWORKDIR}
149
150#====================================================
151#- IN
152typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
153typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
154
155#====================================================
156#- R_OUT
157typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
158
159#====================================================
160#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
161typeset -r R_FIG=${STORAGE}/IGCM_OUT
162
163#====================================================
164#- R_BUF (ONLY FOR double copy an scratch)
165typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
166
167#====================================================
168#- BIG_DIR : BIG_DIR to store files waiting for rebuild
169typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
170
171#====================================================
172#- OUT_POST
173typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
174
175#====================================================
176#- RUN_DIR_PATH : Temporary working directory (=> TMP)
177if [ ! X${LSB_QUEUE} = Xmono ] ; then
178  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${LSB_JOBID}}
179else
180  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/TMPDIR_IGCM/${LSB_JOBID}}
181fi
182
183#====================================================
184#- HOST_MPIRUN_COMMAND
185typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
186
187#====================================================
188#- Max number of arguments passed to nco operator or demigration command
189UNIX_MAX_LIMIT=360
190
191#====================================================
192#- set PackDefault true on titane
193PackDefault=true
194
195NUM_COREPERNODE=8
196       
197#====================================================
198#- Default number of MPI task for IPSL coupled model
199#- required for backward compatibility
200#-
201DEFAULT_NUM_PROC_OCE=5
202DEFAULT_NUM_PROC_CPL=1
203DEFAULT_NUM_PROC_ATM=26
204DEFAULT_NUM_PROC_TOTAL=32
205
206#D-#==================================================
207#D-function IGCM_sys_RshMaster
208#D-* Purpose: Connection to frontend machine.
209#D-* Examples:
210#D-
211function IGCM_sys_RshMaster {
212  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
213  /bin/ksh <<-EOF
214    export libIGCM=${libIGCM}
215    export DEBUG_debug=${DEBUG_debug}
216    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
217    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
218    ${@}
219EOF
220  if [ $? -gt 0 ] ; then
221    echo "IGCM_sys_RshMaster : erreur."
222    IGCM_debug_Exit "IGCM_sys_RshMaster"
223  fi
224  IGCM_debug_PopStack "IGCM_sys_RshMaster"
225}
226
227#D-#==================================================
228#D-function IGCM_sys_RshArchive
229#D-* Purpose: Archive rsh command
230#D-* Examples:
231#D-
232function IGCM_sys_RshArchive {
233  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
234  /bin/ksh <<-EOF
235    ${@}
236EOF
237  if [ $? -gt 0 ] ; then
238    echo "IGCM_sys_RshArchive : erreur."
239    IGCM_debug_Exit "IGCM_sys_RshArchive"
240  fi
241  IGCM_debug_PopStack "IGCM_sys_RshArchive"
242}
243
244#D-#==================================================
245#D-function IGCM_sys_RshPost
246#D-* Purpose: Post-process rsh command
247#D-* Examples:
248#D-
249function IGCM_sys_RshPost {
250  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
251  if ( $DEBUG_sys ) ; then
252    echo "IGCM_sys_RshPost :" $@
253  fi
254
255  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
256  #cat tmp_IGCM_sys_RshPost_$$
257  # keep standard input (stdin) for the loop onto temporary file
258  cat >tmp_IGCM_sys_RshPost_$$
259
260# ============ FRONTEND START ============ #
261
262  /bin/ksh <tmp_IGCM_sys_RshPost_$$
263  if [ $? -gt 0 ] ; then
264    echo "IGCM_sys_RshPost : erreur."
265    IGCM_debug_Exit "IGCM_sys_RshPost"
266  fi
267  # delete temporary file
268  \rm tmp_IGCM_sys_RshPost_$$
269
270# ============ FRONTEND  END  ============ #
271
272# ============ CESIUM START ============ #
273#  typeset NB_ESSAI DELAI status i
274#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
275#    #little hack so that rebuild submission is done on titane not an cesium
276#   
277#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
278#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
279#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
280#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
281#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
282#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
283#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
284#   
285#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
286#    cat tmp_IGCM_sys_RshPost_$$
287#
288#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
289#    if [ $? -gt 0 ] ; then
290#      echo "IGCM_sys_RshPost : erreur."
291#      IGCM_debug_Exit "IGCM_sys_RshPost"
292#    fi
293#    # delete temporary file
294#    \rm tmp_IGCM_sys_RshPost_$$
295#
296#  else
297#    # number of tentative
298#    NB_ESSAI=10
299#    # time delay between tentative
300#    DELAI=10
301#    i=0
302#    while [ $i -ne $NB_ESSAI ] ; do
303#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
304#      status=$?
305#      if [ ${status} -ne 0 ];
306#      then
307#       sleep $DELAI
308#      else
309#       break
310#      fi
311#      let i=$i+1
312#    done
313#    # delete temporary file
314#    \rm tmp_IGCM_sys_RshPost_$$
315#
316#    if [ ${status} -gt 0 ] ; then
317#      echo "IGCM_sys_RshPost : erreur."
318#      IGCM_debug_Exit "IGCM_sys_RshPost"
319#    fi
320#  fi
321
322# ============ CESIUM  END  ============ #
323
324  IGCM_debug_PopStack "IGCM_sys_RshPost"
325}
326
327#D-#==================================================
328#D-function IGCM_sys_SendMail
329#D-* Purpose: Send mail when simulation is over
330#D-* Examples:
331#D-
332function IGCM_sys_SendMail {
333  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
334  if ( $DEBUG_sys ) ; then
335    echo "IGCM_sys_SendMail :" $@
336  fi
337
338  if ( ${ExitFlag} ) ; then
339    status=failed
340  else
341    status=completed
342  fi
343
344    cat  << END_MAIL > job_end.mail
345Dear ${LOGIN},
346
347  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
348  Job started : ${DateBegin}
349  Job ended   : ${DateEnd}
350  Output files are available in ${R_SAVE}
351  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
352END_MAIL
353
354    if [ ! -z ${config_UserChoices_MailName} ] ; then
355        mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
356    elif [ -f ~/.forward ] ; then
357        mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
358    fi
359    sleep 10
360    rm -f job_end.mail
361
362  if [ $? -gt 0 ] ; then
363    echo "IGCM_sys_SendMail : erreur."
364    IGCM_debug_Exit "IGCM_sys_SendMail"
365  fi
366  IGCM_debug_PopStack "IGCM_sys_SendMail"
367}
368
369#D-#==================================================
370#D-function IGCM_sys_Mkdir
371#D-* Purpose: Master locale mkdir command
372#D-* Examples:
373#D-
374function IGCM_sys_Mkdir {
375  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
376  if ( $DEBUG_sys ) ; then
377    echo "IGCM_sys_Mkdir :" $@
378  fi
379  if [ ! -d ${1} ]; then
380    \mkdir -p $1
381    if [ $? -gt 0 ] ; then
382      echo "IGCM_sys_Mkdir : erreur."
383      IGCM_debug_Exit "IGCM_sys_Mkdir"
384    fi
385  fi
386  # vérification :
387  if [ ! -d ${1} ] ; then
388    echo "IGCM_sys_Mkdir : erreur."
389    IGCM_debug_Exit "IGCM_sys_Mkdir"
390  fi
391  IGCM_debug_PopStack "IGCM_sys_Mkdir"
392}
393
394#D-#==================================================
395#D-function IGCM_sys_MkdirArchive
396#D-* Purpose: Mkdir on Archive
397#D-* Examples:
398#D-
399function IGCM_sys_MkdirArchive {
400  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
401  if ( $DEBUG_sys ) ; then
402    echo "IGCM_sys_MkdirArchive :" $@
403  fi
404  #- creation de repertoire sur le serveur fichier
405  if [ ! -d ${1} ]; then 
406    \mkdir -p $1
407    if [ $? -gt 0 ] ; then
408      echo "IGCM_sys_MkdirArchive : erreur."
409      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
410    fi
411  fi
412  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
413}
414
415#D-#==================================================
416#D-function IGCM_sys_MkdirWork
417#D-* Purpose: Mkdir on Work
418#D-* Examples:
419#D-
420function IGCM_sys_MkdirWork {
421  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
422  if ( $DEBUG_sys ) ; then
423    echo "IGCM_sys_MkdirWork :" $@
424  fi
425  #- creation de repertoire sur le serveur fichier
426  if [ ! -d ${1} ]; then 
427    \mkdir -p $1
428    if [ $? -gt 0 ] ; then
429      echo "IGCM_sys_MkdirWork : erreur."
430      IGCM_debug_Exit "IGCM_sys_MkdirWork"
431    fi
432  fi
433  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
434}
435
436#D-#==================================================
437#D-function IGCM_sys_Cd
438#D-* Purpose: master cd command
439#D-* Examples:
440#D-
441function IGCM_sys_Cd {
442  IGCM_debug_PushStack "IGCM_sys_Cd" $@
443  if ( $DEBUG_sys ) ; then
444    echo "IGCM_sys_Cd :" $@
445  fi
446  \cd $1
447  if [ $? -gt 0 ] ; then
448    echo "IGCM_sys_Cd : erreur."
449    IGCM_debug_Exit "IGCM_sys_Cd"
450  fi
451  IGCM_debug_PopStack "IGCM_sys_Cd"
452}
453
454#D-#==================================================
455#D-function IGCM_sys_Chmod
456#D-* Purpose: Chmod
457#D-* Examples:
458#D-
459function IGCM_sys_Chmod {
460  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
461  if ( $DEBUG_sys ) ; then
462    echo "IGCM_sys_Chmod :" $@
463  fi
464  if [ $DRYRUN -le 1 ]; then
465    \chmod $@
466    if [ $? -gt 0 ] ; then
467      echo "IGCM_sys_Chmod : erreur."
468      IGCM_debug_Exit "IGCM_sys_Chmod"
469    fi
470  else
471    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
472  fi
473  IGCM_debug_PopStack "IGCM_sys_Chmod"
474}
475
476#D-#==================================================
477#D-function IGCM_sys_FileSize
478#D-* Purpose: Filesize
479#D-* Examples:
480#D-
481function IGCM_sys_FileSize {
482  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
483
484  typeset sizeF
485  set +A sizeF -- $( ls -la ${1} )
486  if [ $? -gt 0 ] ; then
487    IGCM_debug_Exit "IGCM_sys_FileSize"
488  fi
489  eval ${2}=${sizeF[4]}
490
491  IGCM_debug_PopStack "IGCM_sys_FileSize"
492}
493
494#D-#==================================================
495#D-function IGCM_sys_TestDir
496#D-* Purpose: Test Directory that must exists
497#D-* Examples:
498#D-
499function IGCM_sys_TestDir {
500  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
501  if ( $DEBUG_sys ) ; then
502    echo "IGCM_sys_TestDir :" $@
503  fi
504  typeset ExistFlag
505  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
506  IGCM_debug_PopStack "IGCM_sys_TestDir"
507
508  return ${ExistFlag}
509}
510
511#D-#==================================================
512#D-function IGCM_sys_TestDirArchive
513#D-* Purpose: Test Directory that must exists on Archive
514#D-* Examples:
515#D-
516function IGCM_sys_TestDirArchive {
517  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
518  if ( $DEBUG_sys ) ; then
519    echo "IGCM_sys_TestDirArchive :" $@
520  fi
521  typeset ExistFlag
522  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
523  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
524
525  return ${ExistFlag}
526}
527
528#D-#==================================================
529#D-function IGCM_sys_IsFileArchived
530#D-* Purpose: Test file that must NOT EXISTS on Archive
531#D-* Examples:
532#D-
533function IGCM_sys_IsFileArchived {
534  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
535  if ( $DEBUG_sys ) ; then
536    echo "IGCM_sys_IsFileArchived :" $@
537  fi
538  typeset IsArchivedFlag
539  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/dmnfs ) != X ] && echo 0 || echo 1 )
540  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
541
542  return ${IsArchivedFlag}
543}
544
545#D-#==================================================
546#D-function IGCM_sys_TestFileArchive
547#D-* Purpose: Test file that must NOT EXISTS on Archive
548#D-* Examples:
549#D-
550function IGCM_sys_TestFileArchive {
551  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
552  if ( $DEBUG_sys ) ; then
553    echo "IGCM_sys_TestFileArchive :" $@
554  fi
555  typeset ExistFlag
556  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
557  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
558
559  return ${ExistFlag}
560}
561
562#D-#==================================================
563#D-function IGCM_sys_TestFileBuffer
564#D-* Purpose: Test file that must NOT EXISTS on Buffer
565#D-* Examples:
566#D-
567function IGCM_sys_TestFileBuffer {
568  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
569  typeset ExistFlag
570  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
571  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
572
573  return ${ExistFlag}
574}
575
576#D-#==================================================
577#D-function IGCM_sys_CountFileArchive
578#D-* Purpose: Count files on Archive filesystem
579#D-* Examples:
580#D-
581function IGCM_sys_CountFileArchive {
582  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
583  ls ${@} 2>/dev/null | wc -l
584  if [ $? -gt 0 ] ; then
585    echo "IGCM_sys_CountFileArchive : erreur."
586  fi
587  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
588}
589
590#D-#==================================================
591#D-function IGCM_sys_CountFileBuffer
592#D-* Purpose: Count files on Scratch filesystem
593#D-* Examples:
594#D-
595function IGCM_sys_CountFileBuffer {
596  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
597  ls ${@} 2>/dev/null | wc -l
598  if [ $? -gt 0 ] ; then
599    echo "IGCM_sys_CountFileBuffer : erreur."
600  fi
601  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
602}
603
604#D-#==================================================
605#D-function IGCM_sys_Tree
606#D-* Purpose: Tree directories with files on ${ARCHIVE}
607#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
608#D-
609function IGCM_sys_Tree {
610  IGCM_debug_PushStack "IGCM_sys_Tree" $@
611  if ( $DEBUG_sys ) ; then
612    echo "IGCM_sys_Tree :" $@
613  fi
614
615  \ls -lR ${@}
616
617  IGCM_debug_PopStack "IGCM_sys_Tree"
618}
619
620#D-#==================================================
621#D-function IGCM_sys_Tar
622#D-* Purpose: master tar command
623#D-* Examples:
624#D-
625function IGCM_sys_Tar {
626  IGCM_debug_PushStack "IGCM_sys_Tar" $@
627  if ( $DEBUG_sys ) ; then
628    echo "IGCM_sys_Tar :" $@
629  fi
630  \tar cf $@
631  if [ $? -gt 0 ] ; then
632    echo "IGCM_sys_Tar : erreur."
633    IGCM_debug_Exit "IGCM_sys_Tar"
634  fi
635  IGCM_debug_PopStack "IGCM_sys_Tar"
636}
637
638#D-#==================================================
639#D-function IGCM_sys_UnTar
640#D-* Purpose: master un-tar command
641#D-* Examples:
642#D-
643function IGCM_sys_UnTar {
644  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
645  if ( $DEBUG_sys ) ; then
646    echo "IGCM_sys_UnTar :" $@
647  fi
648  \tar xvf $1
649  if [ $? -gt 0 ] ; then
650    echo "IGCM_sys_UnTar : erreur."
651    IGCM_debug_Exit "IGCM_sys_UnTar"
652  fi
653  IGCM_debug_PopStack "IGCM_sys_UnTar"
654}
655
656#D-#==================================================
657#D-function IGCM_sys_Qsub
658#D-* Purpose: Qsub new job
659#D-* Examples:
660#D-
661function IGCM_sys_Qsub {
662  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
663  if ( $DEBUG_sys ) ; then
664    echo "IGCM_sys_Qsub :" $@
665  fi
666  typeset options
667  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
668    options=" -o ${Script_Output} -e ${Script_Output}"
669  else
670    options=" -o ${Script_Output} -e ${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
671  fi
672
673  /usr/local/bin/ccc_msub ${options} < $1
674  if [ $? -gt 0 ] ; then
675    echo "IGCM_sys_Qsub : erreur ${options} $1"
676    IGCM_debug_Exit "IGCM_sys_Qsub"
677  fi
678  IGCM_debug_PopStack "IGCM_sys_Qsub"
679}
680
681#D-#==================================================
682#D-function IGCM_sys_QsubPost
683#D-* Purpose: Qsub new job on scalaire
684#D-* Examples:
685#D-
686function IGCM_sys_QsubPost {
687  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
688  if ( $DEBUG_sys ) ; then
689    echo "IGCM_sys_QsubPost :" $@
690  fi
691
692  # Need to export listVarEnv for cesium
693  # NO Need to export listVarEnv for titane
694# ============ FRONTEND START ============ #
695
696  /usr/local/bin/ccc_msub -p ${BRIDGE_MSUB_PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job
697
698# ============ FRONTEND  END  ============ #
699
700# ============ CESIUM START ============ #
701#  typeset NB_ESSAI DELAI status i
702#  # number of tentative
703#  NB_ESSAI=10
704#  # time delay between tentative
705#  DELAI=10
706#  (( i = 0 ))
707#  while [ $i -lt $NB_ESSAI ] ; do
708#    /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
709#    status=$?
710#    if [ ${status} -gt 0 ]; then
711#      sleep $DELAI
712#    else
713#      break
714#    fi
715#    (( i = i + 1 ))
716#  done
717# ============ CESIUM  END  ============ #
718
719  if [ $? -gt 0 ] ; then
720    echo "IGCM_sys_QsubPost : erreur " $@
721    IGCM_debug_Exit "IGCM_sys_QsubPost"
722  fi
723  IGCM_debug_PopStack "IGCM_sys_QsubPost"
724}
725
726#D-*************************
727#D- File transfer functions
728#D-*************************
729#D-
730
731#D-#==================================================
732#D-function IGCM_sys_Rsync_out
733#D-* Purpose: treat return val of rsync
734#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
735#D-  Error values and explanations can depend on your system version.
736function IGCM_sys_Rsync_out {
737  RET=$1
738  if [ ! $RET ] ; then
739    echo "rsync error !"
740  fi
741
742  if [ $MYLANG = "fr" ]; then
743    case $RET in
744    0)  return ;;
745    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
746      echo "Erreur de syntaxe ou d'utilisation."
747      return;;
748    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
749      echo "Incompatibilité de protocole."
750      return;;
751    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
752      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
753      echo "répertoires"
754      return;;
755    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
756      echo "Action demandée non supportée : une tentative de manipulation de"
757      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
758      echo "été faite ; ou une option qui est supportée par le  client  mais"
759      echo "pas par le serveur a été spécifiée."
760      return;;
761    10) echo "Erreur de rsync ; RERR_SOCKETIO"
762      echo "Erreur dans le socket d'entrée sortie"
763      return;;
764    11) echo "Erreur de rsync ; RERR_FILEIO"
765      echo "Erreur d'entrée sortie fichier"
766      return;;
767    12) echo "Erreur de rsync ; RERR_STREAMIO"
768      echo "Erreur dans flux de donnée du protocole rsync"
769      return;;
770    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
771      echo "Erreur avec les diagnostics du programme"
772      return;;
773    14) echo "Erreur de rsync ; RERR_IPC"
774      echo "Erreur dans le code IPC"
775      return;;
776    20) echo "Erreur de rsync ; RERR_SIGNAL"
777      echo "SIGUSR1 ou SIGINT reçu"
778      return;;
779    21) echo "Erreur de rsync ; RERR_WAITCHILD"
780      echo "Une erreur retournée par waitpid()"
781      return;;
782    22) echo "Erreur de rsync ; RERR_MALLOC"
783      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
784      return;;
785    23) echo ""
786      echo "Erreur fichier inexistant"
787      return;;
788    30) echo "Erreur de rsync ; RERR_TIMEOUT"
789      echo "Temps d'attente écoulé dans l'envoi/réception de données"
790      return;;
791    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
792      return;;
793    esac
794  elif [ $MYLANG = "en" ] ; then
795    case $RET in
796    0)  return;;               
797    1)  echo "rsync error : Syntax or usage error "
798      return;;
799    2)  echo "rsync error : Protocol incompatibility "
800      return;;
801    3)  echo "rsync error : Errors selecting input/output files, dirs"
802      return;;
803    4)  echo "rsync error : Requested action not supported: an attempt"
804      echo "was made to manipulate 64-bit files on a platform that cannot support"
805      echo "them; or an option was specified that is supported by the client and"
806      echo "not by the server."
807      return;;
808    5)  echo "rsync error : Error starting client-server protocol"
809      return;;
810    10) echo "rsync error : Error in socket I/O "
811      return;;
812    11) echo "rsync error : Error in file I/O "
813      return;;
814    12) echo "rsync error : Error in rsync protocol data stream "
815      return;;
816    13) echo "rsync error : Errors with program diagnostics "
817      return;;
818    14) echo "rsync error : Error in IPC code "
819      return;;
820    20) echo "rsync error : Received SIGUSR1 or SIGINT "
821      return;;
822    21) echo "rsync error : Some error returned by waitpid() "
823      return;;
824    22) echo "rsync error : Error allocating core memory buffers "
825      return;;
826    23) echo "rsync error : Partial transfer due to error"
827      return;;
828    24) echo "rsync error : Partial transfer due to vanished source files"
829      return;;
830    30) echo "rsync error : Timeout in data send/receive "
831      return;;
832    *)  echo "rsync error : return code of rsync unknown :" $RET
833      return;;
834    esac
835  else
836    echo "unknown language $MYLANG."
837    return
838  fi
839}
840
841#D-#==================================================
842#D-function IGCM_sys_Miror_libIGCM
843#D-* Purpose: Mirror libIGCM PATH and lib to cesium
844#D-* Examples:
845#D-
846function IGCM_sys_Mirror_libIGCM {
847  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
848  if ( $DEBUG_sys ) ; then
849    echo "IGCM_sys_Mirror_libIGCM"
850  fi
851
852  typeset RET DEST
853
854  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
855
856  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
857  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
858  RET=$?
859
860  if [ ${RET} -gt 0 ] ; then
861    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
862    cat out_rsync
863  fi
864  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
865}
866
867#====================================================
868#- Call IGCM_sys_Mirror_libIGCM now !
869if ( $MirrorlibIGCM ) ; then
870  IGCM_sys_Mirror_libIGCM
871fi
872
873#D-#==================================================
874#D-function IGCM_sys_Cp
875#D-* Purpose: generic cp
876#D-* Examples:
877#D-
878function IGCM_sys_Cp {
879  IGCM_debug_PushStack "IGCM_sys_Cp" $@
880  if ( $DEBUG_sys ) ; then
881    echo "IGCM_sys_Cp :" $@
882  fi
883
884  typeset RET
885
886  echo cp $@ > out_rsync 2>&1
887  \cp $@ >> out_rsync 2>&1
888  RET=$?
889
890  if [ ${RET} -gt 0 ] ; then
891    echo "IGCM_sys_Cp : error."
892    cat out_rsync
893    IGCM_debug_Exit "IGCM_sys_Cp"
894  else
895    \rm out_rsync
896  fi
897  IGCM_debug_PopStack "IGCM_sys_Cp"
898}
899
900#D-#==================================================
901#D-function IGCM_sys_Rm
902#D-* Purpose: generic rm
903#D-* Examples:
904#D-
905function IGCM_sys_Rm {
906  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
907  if ( $DEBUG_sys ) ; then
908    echo "IGCM_sys_Rm :" $@
909  fi
910
911  typeset RET
912
913  echo rm $@ > out_rsync 2>&1
914  \rm $@ >> out_rsync 2>&1
915  RET=$?
916
917  if [ ${RET} -gt 0 ] ; then
918    echo "IGCM_sys_Rm : error."
919    cat out_rsync
920    IGCM_debug_Exit "IGCM_sys_Rm"
921  else
922    \rm out_rsync
923  fi
924  IGCM_debug_PopStack "IGCM_sys_Rm"
925}
926
927#D-#==================================================
928#D-function IGCM_sys_RmRunDir
929#D-* Purpose: rm tmpdir (dummy function most of the time batch
930#D-                      scheduler will do the job)
931#D-* Examples:
932#D-
933function IGCM_sys_RmRunDir {
934  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
935  if ( $DEBUG_sys ) ; then
936    echo "IGCM_sys_RmRunDir :" $@
937  fi
938
939  typeset RET
940
941  echo rm $@ > out_rsync 2>&1
942  \rm $@ >> out_rsync 2>&1
943  RET=$?
944
945  if [ ${RET} -gt 0 ] ; then
946    echo "IGCM_sys_RmRunDir : error."
947    cat out_rsync
948    IGCM_debug_Exit "IGCM_sys_RmRunDir"
949  else
950    \rm out_rsync
951  fi
952  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
953}
954
955#D-#==================================================
956#D-function IGCM_sys_Mv
957#D-* Purpose: generic move
958#D-* Examples:
959#D-
960function IGCM_sys_Mv {
961  IGCM_debug_PushStack "IGCM_sys_Mv" $@
962  if ( $DEBUG_sys ) ; then
963    echo "IGCM_sys_Mv :" $@
964  fi
965
966  if [ $DRYRUN = 0 ]; then
967
968    typeset RET
969   
970    echo mv $@ > out_rsync 2>&1
971    \mv $@ >> out_rsync 2>&1
972    RET=$?
973   
974    if [ ${RET} -gt 0 ] ; then
975      echo "IGCM_sys_Mv : error in mv."
976      cat out_rsync
977      IGCM_debug_Exit "IGCM_sys_Mv"
978    else
979      \rm out_rsync
980    fi
981  else
982    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
983  fi
984
985  IGCM_debug_PopStack "IGCM_sys_Mv"
986}
987
988#D-#==================================================
989#D-function IGCM_sys_Put_Dir
990#D-* Purpose: Copy a complete directory on $(ARCHIVE)
991#D-* Examples:
992#D-
993function IGCM_sys_Put_Dir {
994  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
995  if ( $DEBUG_sys ) ; then
996    echo "IGCM_sys_Put_Dir :" $@
997  fi
998  if [ $DRYRUN = 0 ]; then
999    if [ ! -d ${1} ] ; then
1000      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
1001      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1002      return
1003    fi
1004
1005    typeset RET
1006
1007    # Only if we use rsync
1008    #IGCM_sys_TestDirArchive $( dirname $2 )
1009    #
1010    #USUAL WAY
1011    \cp -r $1 $2 > out_rsync 2>&1
1012    RET=$?
1013
1014    if [ ${RET} -gt 0 ] ; then
1015      echo "IGCM_sys_Put_Dir : error."
1016      cat out_rsync
1017      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1018    else
1019      \rm out_rsync
1020    fi
1021  else
1022    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1023  fi
1024  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1025}
1026
1027#D-#==================================================
1028#D-function IGCM_sys_Get_Dir
1029#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1030#D-* Examples:
1031#D-
1032function IGCM_sys_Get_Dir {
1033  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1034  if ( $DEBUG_sys ) ; then
1035    echo "IGCM_sys_Get_Dir :" $@
1036  fi
1037  if [ $DRYRUN = 0 ]; then
1038#    if [ ! -d ${1} ] ; then
1039#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1040#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1041#      return
1042#    fi
1043
1044    typeset RET
1045
1046    # Only if we use rsync
1047    #IGCM_sys_TestDirArchive $( dirname $2 )
1048    #
1049    # USUAL WAY
1050    # add dmfind/dmget (to demigrate all offline files) :
1051    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
1052    \cp -r $1 $2 > out_rsync 2>&1
1053    RET=$?
1054
1055    if [ ${RET} -gt 0 ] ; then
1056      echo "IGCM_sys_Get_Dir : error."
1057      cat out_rsync
1058      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1059    else
1060      \rm out_rsync
1061    fi
1062  else
1063    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1064  fi
1065  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1066}
1067
1068#D-#==================================================
1069#D-function IGCM_sys_Get_Master
1070#D-* Purpose: Copy a complete directory from MASTER filesystem
1071#D-* Examples:
1072#D-
1073function IGCM_sys_Get_Master {
1074  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1075  if ( $DEBUG_sys ) ; then
1076    echo "IGCM_sys_Get_Master :" $@
1077  fi
1078  if [ $DRYRUN = 0 ]; then
1079    if [ ! -d ${1} ] ; then
1080      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1081      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1082      return
1083    fi
1084
1085    typeset RET
1086
1087    #USUAL WAY
1088    \cp -r $1 $2 > out_rsync 2>&1
1089    RET=$?
1090
1091    if [ ${RET} -gt 0 ] ; then
1092      echo "IGCM_sys_Get_Master : error."
1093      cat out_rsync
1094      IGCM_debug_Exit "IGCM_sys_Get_Master"
1095    else
1096      \rm out_rsync
1097    fi
1098  else
1099    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1100  fi
1101  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1102}
1103
1104#D-#==================================================
1105#D-function IGCM_sys_Put_Rest
1106#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1107#D-           File and target directory must exist.
1108#D-* Examples:
1109#D-
1110function IGCM_sys_Put_Rest {
1111  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1112  if ( $DEBUG_sys ) ; then
1113    echo "IGCM_sys_Put_Rest :" $@
1114  fi
1115  if [ $DRYRUN = 0 ]; then
1116    if [ ! -f ${1} ] ; then
1117      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1118      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1119    fi
1120
1121    typeset RET
1122    #
1123    if [ X${JobType} = XRUN ] ; then
1124      IGCM_sys_Chmod 444 ${1}
1125    fi
1126
1127    #
1128    # USUAL WAY
1129    \cp $1 $2 > out_rsync 2>&1
1130    RET=$?
1131
1132#       #RSYNC WITH NETWORK SSH CALL
1133#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1134#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1135
1136#       #RSYNC WITH NFS USE
1137#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1138#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1139
1140#       RET=$?
1141#       IGCM_sys_Rsync_out $RET
1142
1143#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1144#       (( RET=RET+$? ))
1145
1146    if [ ${RET} -gt 0 ] ; then
1147      echo "IGCM_sys_Put_Rest : error."
1148      cat out_rsync
1149      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1150    else
1151      \rm out_rsync
1152    fi
1153  else
1154    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1155  fi
1156  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1157}
1158
1159#D-#==================================================
1160#D-function IGCM_sys_PutBuffer_Rest
1161#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1162#D-           File and target directory must exist.
1163#D-* Examples:
1164#D-
1165function IGCM_sys_PutBuffer_Rest {
1166  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1167  if ( $DEBUG_sys ) ; then
1168    echo "IGCM_sys_PutBuffer_Rest :" $@
1169  fi
1170  if [ $DRYRUN = 0 ]; then
1171    if [ ! -f ${1} ] ; then
1172      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1173      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1174    fi
1175
1176    typeset RET
1177    #
1178    if [ X${JobType} = XRUN ] ; then
1179      IGCM_sys_Chmod 444 ${1}
1180    fi
1181
1182    #
1183    # USUAL WAY
1184    \cp $1 $2 > out_rsync 2>&1
1185    RET=$?
1186
1187    if [ ${RET} -gt 0 ] ; then
1188      echo "IGCM_sys_PutBuffer_Rest : error."
1189      cat out_rsync
1190      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1191    else
1192      \rm out_rsync
1193    fi
1194  else
1195    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1196  fi
1197  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1198}
1199
1200#D-#==================================================
1201#D-function IGCM_sys_Put_Out
1202#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1203#D-* Examples:
1204#D-
1205function IGCM_sys_Put_Out {
1206  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1207  if ( $DEBUG_sys ) ; then
1208    echo "IGCM_sys_Put_Out :" $@
1209  fi
1210  if [ $DRYRUN = 0 ]; then
1211    if [ ! -f ${1} ] ; then
1212      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1213      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1214      return 1
1215    fi
1216    #
1217    IGCM_sys_MkdirArchive $( dirname $2 )
1218    #
1219    typeset RET
1220
1221    #=====================================================
1222    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1223    #=====================================================
1224
1225    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1226    #if [ $? -eq 0 ] ; then
1227    #    typeset WORKPATH FILEPATH
1228    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1229    #    IGCM_sys_MkdirWork ${WORKPATH}
1230    #    FILEPATH=${WORKPATH}/$( basename $2 )
1231    #    #
1232    #    IGCM_sys_Cp ${1} ${FILEPATH}
1233    #fi
1234
1235    if [ X${JobType} = XRUN ] ; then
1236      if [ X${3} = X ] ; then
1237        IGCM_sys_Chmod 444 ${1}
1238      fi
1239    fi
1240    #
1241    # USUAL WAY
1242    \cp $1 $2 > out_rsync 2>&1
1243    RET=$?
1244
1245#       #RSYNC WITH NETWORK SSH CALL
1246#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1247#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1248
1249#       #RSYNC WITH NFS USE
1250#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1251#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1252
1253#       RET=$?
1254#       IGCM_sys_Rsync_out $RET
1255
1256#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1257#       (( RET=RET+$? ))
1258
1259    if [ ${RET} -gt 0 ] ; then
1260      echo "IGCM_sys_Put_Out : error."
1261      cat out_rsync
1262      IGCM_debug_Exit "IGCM_sys_Put_Out"
1263    else
1264      \rm out_rsync
1265    fi
1266  else
1267    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1268  fi
1269  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1270  return 0
1271}
1272
1273#D-#==================================================
1274#D-function IGCM_sys_PutBuffer_Out
1275#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1276#D-* Examples:
1277#D-
1278function IGCM_sys_PutBuffer_Out {
1279  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1280  if ( $DEBUG_sys ) ; then
1281    echo "IGCM_sys_PutBuffer_Out :" $@
1282  fi
1283  if [ $DRYRUN = 0 ]; then
1284    if [ ! -f ${1} ] ; then
1285      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1286      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1287      return 1
1288    fi
1289    #
1290    IGCM_sys_Mkdir $( dirname $2 )
1291    #
1292    typeset RET
1293
1294    if [ X${JobType} = XRUN ] ; then
1295      if [ X${3} = X ] ; then
1296        IGCM_sys_Chmod 444 ${1}
1297      fi
1298    fi
1299    #
1300    # USUAL WAY
1301    \cp $1 $2 > out_rsync 2>&1
1302    RET=$?
1303
1304    if [ ${RET} -gt 0 ] ; then
1305      echo "IGCM_sys_PutBuffer_Out : error."
1306      cat out_rsync
1307      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1308    else
1309      \rm out_rsync
1310    fi
1311  else
1312    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1313  fi
1314  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1315  return 0
1316}
1317
1318#D-#==================================================
1319#D-function IGCM_sys_Get
1320#D-* Purpose: Get a file from ${ARCHIVE}
1321#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1322#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1323function IGCM_sys_Get {
1324  IGCM_debug_PushStack "IGCM_sys_Get" $@
1325
1326  typeset DEST RET dm_liste ifile target file_work
1327
1328  if ( $DEBUG_sys ) ; then
1329    echo "IGCM_sys_Get :" $@
1330  fi
1331  if [ $DRYRUN -le 2 ]; then
1332    if [ X${1} = X'/l' ] ; then
1333      # test if the first file is present in the old computation :
1334      eval set +A dm_liste \${${2}}
1335    else
1336      eval set +A dm_liste ${1}
1337    fi
1338    eval DEST=\${${#}}
1339
1340    #=====================================================
1341    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1342    #=====================================================
1343
1344    # Is it an R_OUT file (not R_IN) ?
1345    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1346    #if [ $? -eq 0 ] ; then
1347    #    # Yes  ? then we try to get it in SCRATCHDIR
1348    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1349    #    if [ -f ${file_work[0]} ] ; then
1350    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1351    #   IGCM_debug_PopStack "IGCM_sys_Get"
1352    #   return
1353    #    fi
1354    #fi
1355
1356    # test if the (first) file is present in the old computation :
1357    IGCM_sys_TestFileArchive ${dm_liste[0]}
1358    RET=$?
1359    if [ ${RET} -gt 0 ] ; then
1360      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1361      IGCM_debug_Exit "IGCM_sys_Get"
1362    fi
1363
1364    #dmget ${dm_liste[*]} > out_rsync 2>&1
1365    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1366    RET=$?
1367    if [ ${RET} -gt 0 ] ; then
1368      echo "WARNING IGCM_sys_Get : demigration error."
1369      cat out_rsync
1370      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1371    fi
1372
1373    #if [ ${RET} -gt 0 ] ; then
1374    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1375    #   cat out_rsync
1376    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1377    #   sleep 30
1378    #   echo "We try another time"
1379    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1380    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1381    #   RET=$?
1382    #   if [ ${RET} -gt 0 ] ; then
1383    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1384    #       cat out_rsync
1385    #       IGCM_debug_Exit "IGCM_sys_Get"
1386    #   fi
1387    #    else
1388    #   echo "ERROR IGCM_sys_Get : demigration error :"
1389    #   cat out_rsync
1390    #   IGCM_debug_Exit "IGCM_sys_Get"
1391    #    fi
1392    #fi
1393
1394    #USUAL WAY
1395    if [ X${1} = X'/l' ] ; then
1396      (( RET=0 ))
1397      for target in ${dm_liste[*]} ; do
1398        local_file=$( basename ${target} )
1399        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1400        (( RET = RET + $? ))
1401      done
1402    else
1403      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1404      RET=$?
1405    fi
1406
1407#       #RSYNC WITH NETWORK SSH CALL
1408#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1409#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1410
1411#       #RSYNC WITH NFS USE
1412#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1413#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1414
1415#       RET=$?
1416#       IGCM_sys_Rsync_out $RET
1417
1418#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1419#       (( RET=RET+$? ))
1420
1421    if [ ${RET} -gt 0 ] ; then
1422      echo "IGCM_sys_Get : copy error."
1423      cat out_rsync
1424      IGCM_debug_Exit "IGCM_sys_Get"
1425    else
1426      \rm out_rsync
1427    fi
1428  else
1429    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1430  fi
1431  IGCM_debug_PopStack "IGCM_sys_Get"
1432}
1433
1434#D-#==================================================
1435#D-function IGCM_sys_GetBuffer
1436#D-* Purpose: Get a file from ${SCRATCHDIR}
1437#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1438#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1439function IGCM_sys_GetBuffer {
1440  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1441
1442  typeset DEST RET buf_liste ifile target file_work
1443
1444  if ( $DEBUG_sys ) ; then
1445    echo "IGCM_sys_GetBuffer :" $@
1446  fi
1447  if [ $DRYRUN -le 2 ]; then
1448    if [ X${1} = X'/l' ] ; then
1449      # test if the first file is present in the old computation :
1450      eval set +A buf_liste \${${2}}
1451    else
1452      eval set +A buf_liste ${1}
1453    fi
1454    eval DEST=\${${#}}
1455
1456    #USUAL WAY
1457    if [ X${1} = X'/l' ] ; then
1458      (( RET=0 ))
1459      for target in ${buf_liste[*]} ; do
1460        local_file=$( basename ${target} )
1461        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1462        (( RET = RET + $? ))
1463      done
1464    else
1465      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1466      RET=$?
1467    fi
1468
1469    if [ ${RET} -gt 0 ] ; then
1470      echo "IGCM_sys_GetBuffer : copy error."
1471      cat out_rsync
1472      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1473    else
1474      \rm out_rsync
1475    fi
1476  else
1477    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1478  fi
1479  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1480}
1481
1482#D-#==================================================
1483#D-function IGCM_sys_GetDate_FichWork
1484#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1485#D-* Examples:
1486#D-
1487function IGCM_sys_GetDate_FichWork {
1488  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1489  if ( $DEBUG_sys ) ; then
1490    echo "IGCM_sys_GetDate_FichWork :" $@
1491  fi
1492  typeset dateF
1493  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1494  eval ${2}=${dateF[5]}
1495
1496    # donne la date filesys d'un fichier sur la machine work
1497  IGCM_debug_PopStack "IGCM_sys_FichWork"
1498}
1499
1500#D-#==================================================
1501#D-function IGCM_sys_GetDate_FichArchive
1502#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1503#D-* Examples:
1504#D-
1505function IGCM_sys_GetDate_FichArchive {
1506  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1507  if ( $DEBUG_sys ) ; then
1508    echo "IGCM_sys_GetDate_FichArchive :" $@
1509  fi
1510  typeset dateF
1511  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1512  eval ${2}=${dateF[5]}
1513
1514  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1515}
1516
1517#D-#==================================================
1518#D-function IGCM_sys_Dods_Rm
1519#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1520#D-* Examples:
1521#D-
1522function IGCM_sys_Dods_Rm {
1523  if ( $DEBUG_sys ) ; then
1524    echo "IGCM_sys_Dods_Rm :" $@
1525  fi
1526  typeset RET
1527  RET=0
1528  if [ $DRYRUN = 0 ]; then
1529
1530#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1531#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1532#      echo "Nothing has been done."
1533#      return
1534#    fi
1535
1536    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1537    RET=$?
1538   
1539#       if [ ${RET} -gt 0 ] ; then
1540#           echo "IGCM_sys_Dods_Rm : error."
1541#           cat out_dods_rm
1542#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1543#       else
1544#           rm out_dods_rm
1545#       fi
1546
1547  else
1548    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1549  fi
1550  return $RET
1551}
1552
1553#D-#==================================================
1554#D-function IGCM_sys_Dods_Cp
1555#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1556#D-* Examples:
1557#D-
1558function IGCM_sys_Dods_Cp {
1559  if ( $DEBUG_sys ) ; then
1560    echo "IGCM_sys_Dods_Cp :" $@
1561  fi
1562  typeset RET
1563  RET=0
1564  if [ $DRYRUN = 0 ]; then
1565
1566#    if [ ! -d ${R_SAVE}/${1} ] ; then
1567#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1568#      echo "Nothing has been done."
1569#      return
1570#    fi
1571
1572    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1573    RET=$?
1574
1575#       if [ ${RET} -gt 0 ] ; then
1576#           echo "IGCM_sys_Dods_Cp : error."
1577#           cat out_dods_cp
1578#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1579#       else
1580#           rm out_dods_cp
1581#       fi
1582
1583  else
1584    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1585  fi
1586  return $RET
1587}
1588
1589#D-#==================================================
1590#D-function IGCM_sys_Put_Dods
1591#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1592#D-* Examples:
1593#D-
1594function IGCM_sys_Put_Dods {
1595  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1596  if ( $DEBUG_sys ) ; then
1597    echo "IGCM_sys_Put_Dods :" $@
1598  fi
1599  set -vx
1600  typeset RET
1601  if [ $DRYRUN = 0 ]; then
1602    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1603      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1604      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1605      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1606      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1607      return
1608    fi
1609
1610    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1611      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1612      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1613      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1614      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1615      return
1616    fi
1617    #
1618    if [ -d ${R_SAVE}/${1} ] ; then
1619      cd ${R_SAVE}
1620    elif [ -d ${R_FIGR}/${1} ] ; then
1621      cd ${R_FIGR}
1622    fi
1623
1624    IGCM_sys_Dods_Rm ${1}
1625    IGCM_sys_Dods_Cp ${1}
1626    RET=0
1627   
1628    if [ ${RET} -gt 0 ] ; then
1629      echo "IGCM_sys_Put_Dods : error."
1630      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1631    fi
1632  else
1633    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1634  fi
1635  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1636}
1637
1638##############################################################
1639# REBUILD OPERATOR
1640
1641function IGCM_sys_rebuild {
1642  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1643  if ( $DEBUG_sys ) ; then
1644    echo "IGCM_sys_rebuild :" $@
1645  fi
1646  /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1647  if [ $? -gt 0 ] ; then
1648    echo "IGCM_sys_rebuild : erreur ${@}."
1649    IGCM_debug_Exit "rebuild"
1650  fi
1651
1652  IGCM_debug_PopStack "IGCM_sys_rebuild"
1653}
1654
1655############################################################
1656# Activate Running Environnment Variables
1657
1658function IGCM_sys_activ_variables {
1659  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1660  if ( $DEBUG_sys ) ; then
1661    echo "IGCM_sys_activ_variables"
1662  fi
1663
1664  typeset max_omp
1665
1666  ulimit -s unlimited
1667
1668  (( max_omp = 0 ))
1669  for comp in ${config_ListOfComponents[*]} ; do
1670       
1671    eval ExeNameIn=\${config_Executable_${comp}[0]}
1672    eval ExeNameOut=\${config_Executable_${comp}[1]}
1673   
1674    # Only if we really have an executable for the component :
1675    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1676      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1677      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1678        (( max_omp = comp_proc_omp_loc ))
1679      fi
1680    fi
1681  done
1682  if [ ${max_omp} -gt 1 ] ; then
1683    module load openmp/${max_omp}thds
1684  fi
1685
1686  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1687}
1688
1689############################################################
1690# Desactivate Running Environnment Variables
1691
1692function IGCM_sys_desactiv_variables {
1693  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1694  if ( $DEBUG_sys ) ; then
1695    echo "IGCM_sys_desactiv_variables"
1696  fi
1697  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1698}
1699
1700############################################################
1701# Build MPI/OMP scripts run file (dummy function)
1702
1703function IGCM_sys_build_run_file {
1704
1705IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1706
1707}
1708
1709############################################################
1710# Build MPI/OMP scripts
1711function IGCM_sys_build_execution_scripts
1712{
1713  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1714  if ( $DEBUG_sys ) ; then
1715    echo "IGCM_sys_build_execution_scripts " $@
1716  fi
1717  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1718  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1719  typeset num_corempi nombre_restant_node nombre_restant_comp
1720
1721  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1722    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1723  fi
1724
1725  if ( ${OK_PARA_MPMD} ) ; then
1726
1727    if [ -f run_file ] ; then
1728      IGCM_sys_Rm -f run_file
1729    fi
1730    touch run_file
1731
1732    if ( ${OK_PARA_OMP} ) ; then
1733
1734      #  Hosts treatment
1735
1736      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1737       
1738      i=0
1739      rm -f hosts
1740      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1741      for nodes in `cat hosts.tmp` ; do
1742        host[$i]=$nodes
1743        echo "${host[$i]} slots=8 max_slots=8" >> hosts
1744        IGCM_debug_Print 1 ${host[$i]}
1745        i=$((i+1))
1746      done
1747      rm -f hosts.tmp
1748           
1749      listnodes=${host[*]}
1750           
1751      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts" 
1752       
1753      # Initialisation
1754
1755      init_node=y
1756      node_num_current=0
1757      start_num=0
1758      init_exec=n
1759
1760      # Test : if oasis is there, we put it at the first position
1761           
1762      for comp in ${config_ListOfComponents[*]} ; do
1763               
1764        if [ "X${comp}" = "XCPL" ]  ; then
1765                   
1766          eval ExeNameIn=\${config_Executable_${comp}[0]}
1767          eval ExeNameOut=\${config_Executable_${comp}[1]}
1768                   
1769          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1770          echo ""  >> script_${ExeNameOut}.ksh
1771          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1772          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1773          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1774          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1775          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1776                   
1777          init_node=n
1778                   
1779          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1780          node_num_current=0
1781          node_current=${host[${node_num_current}]}
1782                   
1783          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh" 
1784                   
1785          init_exec=y
1786          start_num=1
1787                   
1788        fi
1789               
1790      done
1791           
1792      # Then loop on the components (except for oasis)
1793
1794      for comp in ${config_ListOfComponents[*]} ; do
1795               
1796        eval ExeNameIn=\${config_Executable_${comp}[0]}
1797        eval ExeNameOut=\${config_Executable_${comp}[1]}
1798               
1799        # Only if we really have an executable for the component :
1800        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1801
1802          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1803          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1804                   
1805          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1806          # echo "set -vx" >> script_${ExeNameOut}.ksh
1807          echo ""  >> script_${ExeNameOut}.ksh
1808          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1809          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1810          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1811          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1812          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1813          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1814          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1815                   
1816          node_num=0
1817                   
1818          # We define the number of MPI process to be assigned for the component
1819
1820          nombre_restant_comp=${comp_proc_mpi_loc}
1821                   
1822          # Loop on the allocated nodes
1823
1824          for node in ${listnodes} ; do
1825
1826            # We go to the current node
1827            if [ ${node_num} = ${node_num_current} ] ; then
1828
1829              node_current=${host[${node_num_current}]}
1830
1831              # If first time on the node : initialisation
1832
1833              if [ ${init_node} = y ] ; then
1834                nombre_restant_node=${NUM_COREPERNODE}
1835              fi
1836                           
1837              # Test on the number of OMP threads
1838
1839              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1840                (( node_num = node_num + 1 ))
1841                node_num_current=${node_num}
1842                init_node=y
1843                continue
1844              fi
1845
1846              # Number of MPI process to assign
1847
1848              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1849                           
1850              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1851                num_corempi=${nombre_restant_comp}
1852              fi
1853
1854              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1855              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1856                           
1857              if [ ${init_exec} = y ] ; then
1858                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1859              else     
1860                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1861                init_exec=y
1862              fi
1863
1864              ((  start_num = num_corempi + start_num ))
1865                           
1866            else
1867                           
1868              (( node_num = node_num + 1 )) 
1869              continue
1870            fi
1871                       
1872            # Test on the number of core/process remaining on the node/component
1873                       
1874            if [ ${nombre_restant_node} = 0 ] ; then
1875              (( node_num = node_num + 1 ))
1876              node_num_current=${node_num}
1877              init_node=y
1878
1879              if [ ${nombre_restant_comp} = 0 ] ; then
1880                break 1
1881              fi
1882            else
1883
1884              node_num_current=${node_num}
1885              init_node=n
1886                           
1887              if [ ${nombre_restant_comp} = 0 ] ; then
1888                break 1
1889              fi
1890            fi
1891          done
1892        fi
1893      done
1894           
1895    else
1896
1897        # Then first loop on the components for the coupler ie oasis
1898
1899        ## the coupler ie oasis must be the first one
1900        for comp in ${config_ListOfComponents[*]} ; do
1901           
1902            eval ExeNameOut=\${config_Executable_${comp}[1]}
1903               
1904        # for CPL component only
1905            if [ "X${comp}" = "XCPL" ] ; then
1906                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1907                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1908            fi
1909        done
1910
1911        # Then second loop on the components
1912
1913        for comp in ${config_ListOfComponents[*]} ; do
1914               
1915            eval ExeNameOut=\${config_Executable_${comp}[1]}
1916               
1917            # Only if we really have an executable for the component and not the coupler ie oasis:
1918            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1919                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1920                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1921            fi
1922        done
1923        IGCM_sys_Chmod u+x run_file
1924
1925        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1926         
1927    fi
1928
1929  else # Only one executable. launch it.
1930
1931      for comp in ${config_ListOfComponents[*]} ; do
1932
1933          # Only if we really have an executable for the component :
1934          eval ExeNameOut=\${config_Executable_${comp}[1]}
1935          if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then   
1936               
1937              echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1938              echo ""  >> script_${ExeNameOut}.ksh
1939              if ( ${OK_PARA_OMP} ) ; then
1940                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1941                  echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh       
1942              fi
1943              if  ( ${OK_PARA_MPI} ) ; then 
1944                  # Default : mpirun used if nb_proc gt 1
1945                  # pour sortie out/err par process
1946                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1947                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1948                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1949                  EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1950              else
1951                  # Default : mpirun is NOT used if nb_proc eq 1
1952                  # pour sortie out/err par process
1953                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1954                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1955                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1956                  EXECUTION="time ./script_${ExeNameOut}.ksh"
1957              fi
1958          fi
1959      done
1960     
1961  fi
1962
1963  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
1964  IGCM_debug_Print 1 $EXECUTION
1965
1966  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1967}
1968
1969
1970
1971##############################################################
1972# NCO OPERATOR
1973
1974function IGCM_sys_ncap2 {
1975  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1976  if ( $DEBUG_sys ) ; then
1977    echo "IGCM_sys_ncap2 :" $@
1978  fi
1979  ncap2 "$@"
1980  if [ $? -gt 0 ] ; then
1981    echo "IGCM_sys_ncap2 : erreur ${@}."
1982    IGCM_debug_Exit "ncap2"
1983  fi
1984
1985  IGCM_debug_PopStack "IGCM_sys_ncap2"
1986}
1987
1988function IGCM_sys_ncatted {
1989  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1990  if ( $DEBUG_sys ) ; then
1991    echo "IGCM_sys_ncatted :" $@
1992  fi
1993  ncatted "$@"
1994  if [ $? -gt 0 ] ; then
1995    echo "IGCM_sys_ncatted : erreur ${@}."
1996    IGCM_debug_Exit "ncatted"
1997  fi
1998
1999  IGCM_debug_PopStack "IGCM_sys_ncatted"
2000}
2001
2002function IGCM_sys_ncbo {
2003  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2004  if ( $DEBUG_sys ) ; then
2005    echo "IGCM_sys_ncbo :" $@
2006  fi
2007  ncbo $@
2008  if [ $? -gt 0 ] ; then
2009    echo "IGCM_sys_ncbo : erreur ${@}."
2010    IGCM_debug_Exit "ncbo"
2011  fi
2012
2013  IGCM_debug_PopStack "IGCM_sys_ncbo"
2014}
2015
2016function IGCM_sys_ncdiff {
2017  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2018  if ( $DEBUG_sys ) ; then
2019    echo "IGCM_sys_ncdiff :" $@
2020  fi
2021  ncdiff $@
2022  if [ $? -gt 0 ] ; then
2023    echo "IGCM_sys_ncdiff : erreur ${@}."
2024    IGCM_debug_Exit "ncdiff"
2025  fi
2026
2027  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2028}
2029
2030function IGCM_sys_ncea {
2031  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2032  if ( $DEBUG_sys ) ; then
2033    echo "IGCM_sys_ncea :" $@
2034  fi
2035  ncea $@
2036  if [ $? -gt 0 ] ; then
2037    echo "IGCM_sys_ncea : erreur ${@}."
2038    IGCM_debug_Exit "ncea"
2039  fi
2040
2041  IGCM_debug_PopStack "IGCM_sys_ncea"
2042}
2043
2044function IGCM_sys_ncecat {
2045  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2046  if ( $DEBUG_sys ) ; then
2047    echo "IGCM_sys_ncecat :" $@
2048  fi
2049  ncecat $@
2050  if [ $? -gt 0 ] ; then
2051    echo "IGCM_sys_ncecat : erreur ${@}."
2052    IGCM_debug_Exit "ncecat"
2053  fi
2054
2055  IGCM_debug_PopStack "IGCM_sys_ncecat"
2056}
2057
2058function IGCM_sys_ncflint {
2059  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2060  if ( $DEBUG_sys ) ; then
2061    echo "IGCM_sys_ncflint :" $@
2062  fi
2063  ncflint $@
2064  if [ $? -gt 0 ] ; then
2065    echo "IGCM_sys_ncflint : erreur ${@}."
2066    IGCM_debug_Exit "ncflint"
2067  fi
2068
2069  IGCM_debug_PopStack "IGCM_sys_ncflint"
2070}
2071
2072function IGCM_sys_ncks {
2073  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2074  if ( $DEBUG_sys ) ; then
2075    echo "IGCM_sys_ncks :" $@
2076  fi
2077  ncks $@
2078  if [ $? -gt 0 ] ; then
2079    echo "IGCM_sys_ncks : erreur ${@}."
2080    IGCM_debug_Exit "ncks"
2081  fi
2082
2083  IGCM_debug_PopStack "IGCM_sys_ncks"
2084}
2085
2086function IGCM_sys_ncpdq {
2087  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2088  if ( $DEBUG_sys ) ; then
2089    echo "IGCM_sys_ncpdq :" $@
2090  fi
2091  ncpdq $@
2092  if [ $? -gt 0 ] ; then
2093    echo "IGCM_sys_ncpdq : erreur ${@}."
2094    IGCM_debug_Exit "ncpdq"
2095  fi
2096
2097  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2098}
2099
2100function IGCM_sys_ncra {
2101  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2102  if ( $DEBUG_sys ) ; then
2103    echo "IGCM_sys_ncra :" $@
2104  fi
2105  ncra $@
2106  if [ $? -gt 0 ] ; then
2107    echo "IGCM_sys_ncra : erreur ${@}."
2108    IGCM_debug_Exit "ncra"
2109  fi
2110
2111  IGCM_debug_PopStack "IGCM_sys_ncra"
2112}
2113
2114function IGCM_sys_ncrcat {
2115  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2116  if ( $DEBUG_sys ) ; then
2117    echo "IGCM_sys_ncrcat :" $@
2118  fi
2119  ncrcat --omp_num_threads 2 $@
2120  if [ $? -gt 0 ] ; then
2121    echo "IGCM_sys_ncrcat : erreur ${@}."
2122#       IGCM_debug_Exit "ncrcat"
2123  fi
2124
2125  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2126}
2127
2128function IGCM_sys_ncrename {
2129  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2130  if ( $DEBUG_sys ) ; then
2131    echo "IGCM_sys_ncrename :" $@
2132  fi
2133  ncrename $@
2134  if [ $? -gt 0 ] ; then
2135    echo "IGCM_sys_ncrename : erreur ${@}."
2136    IGCM_debug_Exit "ncrename"
2137  fi
2138
2139  IGCM_debug_PopStack "IGCM_sys_ncrename"
2140}
2141
2142function IGCM_sys_ncwa {
2143  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2144  if ( $DEBUG_sys ) ; then
2145    echo "IGCM_sys_ncwa :" $@
2146  fi
2147  ncwa $@
2148  if [ $? -gt 0 ] ; then
2149    echo "IGCM_sys_ncwa : erreur ${@}."
2150    IGCM_debug_Exit "ncwa"
2151  fi
2152
2153  IGCM_debug_PopStack "IGCM_sys_ncwa"
2154}
2155
2156##############################################################
2157# CDO OPERATOR
2158
2159function IGCM_sys_cdo {
2160  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2161  if ( $DEBUG_sys ) ; then
2162    echo "IGCM_sys_cdo :" $@
2163  fi
2164  \cdo $@
2165  if [ $? -gt 0 ] ; then
2166    echo "IGCM_sys_cdo : erreur ${@}."
2167    IGCM_debug_PopStack "IGCM_sys_cdo"
2168    return 1
2169  else
2170    IGCM_debug_PopStack "IGCM_sys_cdo"
2171    return 0
2172  fi
2173
2174  IGCM_debug_PopStack "IGCM_sys_cdo"
2175}
Note: See TracBrowser for help on using the repository browser.