source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_titane.ksh @ 623

Last change on this file since 623 was 623, checked in by sdipsl, 12 years ago
  • adapt curie system for the pack
  • homogenize curie and titane system. Easier to maintain
  • Property svn:keywords set to Revision Author Date
File size: 60.9 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  Files to be rebuild are temporarily available in ${REBUILD_DIR}
352  Pre-packed files are temporarily available in ${R_BUFR}
353  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
354END_MAIL
355
356    if [ ! -z ${config_UserChoices_MailName} ] ; then
357        mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
358    elif [ -f ~/.forward ] ; then
359        mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
360    fi
361    sleep 10
362    rm -f job_end.mail
363
364  if [ $? -gt 0 ] ; then
365    echo "IGCM_sys_SendMail : erreur."
366    IGCM_debug_Exit "IGCM_sys_SendMail"
367  fi
368  IGCM_debug_PopStack "IGCM_sys_SendMail"
369}
370
371#D-#==================================================
372#D-function IGCM_sys_Mkdir
373#D-* Purpose: Master locale mkdir command
374#D-* Examples:
375#D-
376function IGCM_sys_Mkdir {
377  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
378  if ( $DEBUG_sys ) ; then
379    echo "IGCM_sys_Mkdir :" $@
380  fi
381  if [ ! -d ${1} ]; then
382    \mkdir -p $1
383    if [ $? -gt 0 ] ; then
384      echo "IGCM_sys_Mkdir : erreur."
385      IGCM_debug_Exit "IGCM_sys_Mkdir"
386    fi
387  fi
388  # vérification :
389  if [ ! -d ${1} ] ; then
390    echo "IGCM_sys_Mkdir : erreur."
391    IGCM_debug_Exit "IGCM_sys_Mkdir"
392  fi
393  IGCM_debug_PopStack "IGCM_sys_Mkdir"
394}
395
396#D-#==================================================
397#D-function IGCM_sys_MkdirArchive
398#D-* Purpose: Mkdir on Archive
399#D-* Examples:
400#D-
401function IGCM_sys_MkdirArchive {
402  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
403  if ( $DEBUG_sys ) ; then
404    echo "IGCM_sys_MkdirArchive :" $@
405  fi
406  #- creation de repertoire sur le serveur fichier
407  if [ ! -d ${1} ]; then
408    \mkdir -p $1
409    if [ $? -gt 0 ] ; then
410      echo "IGCM_sys_MkdirArchive : erreur."
411      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
412    fi
413  fi
414  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
415}
416
417#D-#==================================================
418#D-function IGCM_sys_MkdirWork
419#D-* Purpose: Mkdir on Work
420#D-* Examples:
421#D-
422function IGCM_sys_MkdirWork {
423  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
424  if ( $DEBUG_sys ) ; then
425    echo "IGCM_sys_MkdirWork :" $@
426  fi
427  #- creation de repertoire sur le serveur fichier
428  if [ ! -d ${1} ]; then
429    \mkdir -p $1
430    if [ $? -gt 0 ] ; then
431      echo "IGCM_sys_MkdirWork : erreur."
432      IGCM_debug_Exit "IGCM_sys_MkdirWork"
433    fi
434  fi
435  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
436}
437
438#D-#==================================================
439#D-function IGCM_sys_Cd
440#D-* Purpose: master cd command
441#D-* Examples:
442#D-
443function IGCM_sys_Cd {
444  IGCM_debug_PushStack "IGCM_sys_Cd" $@
445  if ( $DEBUG_sys ) ; then
446    echo "IGCM_sys_Cd :" $@
447  fi
448  \cd $1
449  if [ $? -gt 0 ] ; then
450    echo "IGCM_sys_Cd : erreur."
451    IGCM_debug_Exit "IGCM_sys_Cd"
452  fi
453  IGCM_debug_PopStack "IGCM_sys_Cd"
454}
455
456#D-#==================================================
457#D-function IGCM_sys_Chmod
458#D-* Purpose: Chmod
459#D-* Examples:
460#D-
461function IGCM_sys_Chmod {
462  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
463  if ( $DEBUG_sys ) ; then
464    echo "IGCM_sys_Chmod :" $@
465  fi
466  if [ $DRYRUN -le 1 ]; then
467    \chmod $@
468    if [ $? -gt 0 ] ; then
469      echo "IGCM_sys_Chmod : erreur."
470      IGCM_debug_Exit "IGCM_sys_Chmod"
471    fi
472  else
473    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
474  fi
475  IGCM_debug_PopStack "IGCM_sys_Chmod"
476}
477
478#D-#==================================================
479#D-function IGCM_sys_FileSize
480#D-* Purpose: Filesize
481#D-* Examples:
482#D-
483function IGCM_sys_FileSize {
484  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
485
486  typeset sizeF
487  set +A sizeF -- $( ls -la ${1} )
488  if [ $? -gt 0 ] ; then
489    IGCM_debug_Exit "IGCM_sys_FileSize"
490  fi
491  eval ${2}=${sizeF[4]}
492
493  IGCM_debug_PopStack "IGCM_sys_FileSize"
494}
495
496#D-#==================================================
497#D-function IGCM_sys_TestDir
498#D-* Purpose: Test Directory that must exists
499#D-* Examples:
500#D-
501function IGCM_sys_TestDir {
502  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
503  if ( $DEBUG_sys ) ; then
504    echo "IGCM_sys_TestDir :" $@
505  fi
506  typeset ExistFlag
507  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
508  IGCM_debug_PopStack "IGCM_sys_TestDir"
509
510  return ${ExistFlag}
511}
512
513#D-#==================================================
514#D-function IGCM_sys_TestDirArchive
515#D-* Purpose: Test Directory that must exists on Archive
516#D-* Examples:
517#D-
518function IGCM_sys_TestDirArchive {
519  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
520  if ( $DEBUG_sys ) ; then
521    echo "IGCM_sys_TestDirArchive :" $@
522  fi
523  typeset ExistFlag
524  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
525  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
526
527  return ${ExistFlag}
528}
529
530#D-#==================================================
531#D-function IGCM_sys_IsFileArchived
532#D-* Purpose: Test file that must NOT EXISTS on Archive
533#D-* Examples:
534#D-
535function IGCM_sys_IsFileArchived {
536  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
537  if ( $DEBUG_sys ) ; then
538    echo "IGCM_sys_IsFileArchived :" $@
539  fi
540  typeset IsArchivedFlag
541  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
542  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
543
544  return ${IsArchivedFlag}
545}
546
547#D-#==================================================
548#D-function IGCM_sys_TestFileArchive
549#D-* Purpose: Test file that must NOT EXISTS on Archive
550#D-* Examples:
551#D-
552function IGCM_sys_TestFileArchive {
553  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
554  if ( $DEBUG_sys ) ; then
555    echo "IGCM_sys_TestFileArchive :" $@
556  fi
557  typeset ExistFlag
558  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
559  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
560
561  return ${ExistFlag}
562}
563
564#D-#==================================================
565#D-function IGCM_sys_TestFileBuffer
566#D-* Purpose: Test file that must NOT EXISTS on Buffer
567#D-* Examples:
568#D-
569function IGCM_sys_TestFileBuffer {
570  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
571  typeset ExistFlag
572  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
573  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
574
575  return ${ExistFlag}
576}
577
578#D-#==================================================
579#D-function IGCM_sys_CountFileArchive
580#D-* Purpose: Count files on Archive filesystem
581#D-* Examples:
582#D-
583function IGCM_sys_CountFileArchive {
584  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
585  ls ${@} 2>/dev/null | wc -l
586  if [ $? -gt 0 ] ; then
587    echo "IGCM_sys_CountFileArchive : erreur."
588  fi
589  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
590}
591
592#D-#==================================================
593#D-function IGCM_sys_CountFileBuffer
594#D-* Purpose: Count files on Scratch filesystem
595#D-* Examples:
596#D-
597function IGCM_sys_CountFileBuffer {
598  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
599  ls ${@} 2>/dev/null | wc -l
600  if [ $? -gt 0 ] ; then
601    echo "IGCM_sys_CountFileBuffer : erreur."
602  fi
603  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
604}
605
606#D-#==================================================
607#D-function IGCM_sys_Tree
608#D-* Purpose: Tree directories with files on ${ARCHIVE}
609#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
610#D-
611function IGCM_sys_Tree {
612  IGCM_debug_PushStack "IGCM_sys_Tree" $@
613  if ( $DEBUG_sys ) ; then
614    echo "IGCM_sys_Tree :" $@
615  fi
616
617  \ls -lR ${@}
618
619  IGCM_debug_PopStack "IGCM_sys_Tree"
620}
621
622#D-#==================================================
623#D-function IGCM_sys_Tar
624#D-* Purpose: master tar command
625#D-* Examples:
626#D-
627function IGCM_sys_Tar {
628  IGCM_debug_PushStack "IGCM_sys_Tar" $@
629  if ( $DEBUG_sys ) ; then
630    echo "IGCM_sys_Tar :" $@
631  fi
632  \tar cf $@
633  if [ $? -gt 0 ] ; then
634    echo "IGCM_sys_Tar : erreur."
635    IGCM_debug_Exit "IGCM_sys_Tar"
636  fi
637  IGCM_debug_PopStack "IGCM_sys_Tar"
638}
639
640#D-#==================================================
641#D-function IGCM_sys_UnTar
642#D-* Purpose: master un-tar command
643#D-* Examples:
644#D-
645function IGCM_sys_UnTar {
646  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
647  if ( $DEBUG_sys ) ; then
648    echo "IGCM_sys_UnTar :" $@
649  fi
650  \tar xvf $1
651  if [ $? -gt 0 ] ; then
652    echo "IGCM_sys_UnTar : erreur."
653    IGCM_debug_Exit "IGCM_sys_UnTar"
654  fi
655  IGCM_debug_PopStack "IGCM_sys_UnTar"
656}
657
658#D-#==================================================
659#D-function IGCM_sys_Qsub
660#D-* Purpose: Qsub new job
661#D-* Examples:
662#D-
663function IGCM_sys_Qsub {
664  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
665  if ( $DEBUG_sys ) ; then
666    echo "IGCM_sys_Qsub :" $@
667  fi
668  typeset options
669  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
670    options=" -o ${Script_Output} -e ${Script_Output}"
671  else
672    options=" -o ${Script_Output} -e ${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
673  fi
674
675  /usr/local/bin/ccc_msub ${options} < $1
676  if [ $? -gt 0 ] ; then
677    echo "IGCM_sys_Qsub : erreur ${options} $1"
678    IGCM_debug_Exit "IGCM_sys_Qsub"
679  fi
680  IGCM_debug_PopStack "IGCM_sys_Qsub"
681}
682
683#D-#==================================================
684#D-function IGCM_sys_QsubPost
685#D-* Purpose: Qsub new job on scalaire
686#D-* Examples:
687#D-
688function IGCM_sys_QsubPost {
689  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
690  if ( $DEBUG_sys ) ; then
691    echo "IGCM_sys_QsubPost :" $@
692  fi
693
694  # Need to export listVarEnv for cesium
695  # NO Need to export listVarEnv for titane
696# ============ FRONTEND START ============ #
697
698  /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
699
700# ============ FRONTEND  END  ============ #
701
702# ============ CESIUM START ============ #
703#  typeset NB_ESSAI DELAI status i
704#  # number of tentative
705#  NB_ESSAI=10
706#  # time delay between tentative
707#  DELAI=10
708#  (( i = 0 ))
709#  while [ $i -lt $NB_ESSAI ] ; do
710#    /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
711#    status=$?
712#    if [ ${status} -gt 0 ]; then
713#      sleep $DELAI
714#    else
715#      break
716#    fi
717#    (( i = i + 1 ))
718#  done
719# ============ CESIUM  END  ============ #
720
721  if [ $? -gt 0 ] ; then
722    echo "IGCM_sys_QsubPost : erreur " $@
723    IGCM_debug_Exit "IGCM_sys_QsubPost"
724  fi
725  IGCM_debug_PopStack "IGCM_sys_QsubPost"
726}
727
728#D-*************************
729#D- File transfer functions
730#D-*************************
731#D-
732
733#D-#==================================================
734#D-function IGCM_sys_Rsync_out
735#D-* Purpose: treat return val of rsync
736#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
737#D-  Error values and explanations can depend on your system version.
738function IGCM_sys_Rsync_out {
739  RET=$1
740  if [ ! $RET ] ; then
741    echo "rsync error !"
742  fi
743
744  if [ $MYLANG = "fr" ]; then
745    case $RET in
746    0)  return ;;
747    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
748      echo "Erreur de syntaxe ou d'utilisation."
749      return;;
750    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
751      echo "Incompatibilité de protocole."
752      return;;
753    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
754      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
755      echo "répertoires"
756      return;;
757    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
758      echo "Action demandée non supportée : une tentative de manipulation de"
759      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
760      echo "été faite ; ou une option qui est supportée par le  client  mais"
761      echo "pas par le serveur a été spécifiée."
762      return;;
763    10) echo "Erreur de rsync ; RERR_SOCKETIO"
764      echo "Erreur dans le socket d'entrée sortie"
765      return;;
766    11) echo "Erreur de rsync ; RERR_FILEIO"
767      echo "Erreur d'entrée sortie fichier"
768      return;;
769    12) echo "Erreur de rsync ; RERR_STREAMIO"
770      echo "Erreur dans flux de donnée du protocole rsync"
771      return;;
772    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
773      echo "Erreur avec les diagnostics du programme"
774      return;;
775    14) echo "Erreur de rsync ; RERR_IPC"
776      echo "Erreur dans le code IPC"
777      return;;
778    20) echo "Erreur de rsync ; RERR_SIGNAL"
779      echo "SIGUSR1 ou SIGINT reçu"
780      return;;
781    21) echo "Erreur de rsync ; RERR_WAITCHILD"
782      echo "Une erreur retournée par waitpid()"
783      return;;
784    22) echo "Erreur de rsync ; RERR_MALLOC"
785      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
786      return;;
787    23) echo ""
788      echo "Erreur fichier inexistant"
789      return;;
790    30) echo "Erreur de rsync ; RERR_TIMEOUT"
791      echo "Temps d'attente écoulé dans l'envoi/réception de données"
792      return;;
793    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
794      return;;
795    esac
796  elif [ $MYLANG = "en" ] ; then
797    case $RET in
798    0)  return;;
799    1)  echo "rsync error : Syntax or usage error "
800      return;;
801    2)  echo "rsync error : Protocol incompatibility "
802      return;;
803    3)  echo "rsync error : Errors selecting input/output files, dirs"
804      return;;
805    4)  echo "rsync error : Requested action not supported: an attempt"
806      echo "was made to manipulate 64-bit files on a platform that cannot support"
807      echo "them; or an option was specified that is supported by the client and"
808      echo "not by the server."
809      return;;
810    5)  echo "rsync error : Error starting client-server protocol"
811      return;;
812    10) echo "rsync error : Error in socket I/O "
813      return;;
814    11) echo "rsync error : Error in file I/O "
815      return;;
816    12) echo "rsync error : Error in rsync protocol data stream "
817      return;;
818    13) echo "rsync error : Errors with program diagnostics "
819      return;;
820    14) echo "rsync error : Error in IPC code "
821      return;;
822    20) echo "rsync error : Received SIGUSR1 or SIGINT "
823      return;;
824    21) echo "rsync error : Some error returned by waitpid() "
825      return;;
826    22) echo "rsync error : Error allocating core memory buffers "
827      return;;
828    23) echo "rsync error : Partial transfer due to error"
829      return;;
830    24) echo "rsync error : Partial transfer due to vanished source files"
831      return;;
832    30) echo "rsync error : Timeout in data send/receive "
833      return;;
834    *)  echo "rsync error : return code of rsync unknown :" $RET
835      return;;
836    esac
837  else
838    echo "unknown language $MYLANG."
839    return
840  fi
841}
842
843#D-#==================================================
844#D-function IGCM_sys_Miror_libIGCM
845#D-* Purpose: Mirror libIGCM PATH and lib to cesium
846#D-* Examples:
847#D-
848function IGCM_sys_Mirror_libIGCM {
849  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
850  if ( $DEBUG_sys ) ; then
851    echo "IGCM_sys_Mirror_libIGCM"
852  fi
853
854  typeset RET DEST
855
856  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
857
858  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
859  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
860  RET=$?
861
862  if [ ${RET} -gt 0 ] ; then
863    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
864    cat out_rsync
865  fi
866  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
867}
868
869#====================================================
870#- Call IGCM_sys_Mirror_libIGCM now !
871if ( $MirrorlibIGCM ) ; then
872  IGCM_sys_Mirror_libIGCM
873fi
874
875#D-#==================================================
876#D-function IGCM_sys_Cp
877#D-* Purpose: generic cp
878#D-* Examples:
879#D-
880function IGCM_sys_Cp {
881  IGCM_debug_PushStack "IGCM_sys_Cp" $@
882  if ( $DEBUG_sys ) ; then
883    echo "IGCM_sys_Cp :" $@
884  fi
885
886  typeset RET
887
888  echo cp $@ > out_rsync 2>&1
889  \cp $@ >> out_rsync 2>&1
890  RET=$?
891
892  if [ ${RET} -gt 0 ] ; then
893    echo "IGCM_sys_Cp : error."
894    cat out_rsync
895    IGCM_debug_Exit "IGCM_sys_Cp"
896  else
897    \rm out_rsync
898  fi
899  IGCM_debug_PopStack "IGCM_sys_Cp"
900}
901
902#D-#==================================================
903#D-function IGCM_sys_Rm
904#D-* Purpose: generic rm
905#D-* Examples:
906#D-
907function IGCM_sys_Rm {
908  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
909  if ( $DEBUG_sys ) ; then
910    echo "IGCM_sys_Rm :" $@
911  fi
912
913  typeset RET
914
915  echo rm $@ > out_rsync 2>&1
916  \rm $@ >> out_rsync 2>&1
917  RET=$?
918
919  if [ ${RET} -gt 0 ] ; then
920    echo "IGCM_sys_Rm : error."
921    cat out_rsync
922    IGCM_debug_Exit "IGCM_sys_Rm"
923  else
924    \rm out_rsync
925  fi
926  IGCM_debug_PopStack "IGCM_sys_Rm"
927}
928
929#D-#==================================================
930#D-function IGCM_sys_RmRunDir
931#D-* Purpose: rm tmpdir (dummy function most of the time batch
932#D-                      scheduler will do the job)
933#D-* Examples:
934#D-
935function IGCM_sys_RmRunDir {
936  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
937  if ( $DEBUG_sys ) ; then
938    echo "IGCM_sys_RmRunDir :" $@
939  fi
940
941  typeset RET
942
943  echo rm $@ > out_rsync 2>&1
944  \rm $@ >> out_rsync 2>&1
945  RET=$?
946
947  if [ ${RET} -gt 0 ] ; then
948    echo "IGCM_sys_RmRunDir : error."
949    cat out_rsync
950    IGCM_debug_Exit "IGCM_sys_RmRunDir"
951  else
952    \rm out_rsync
953  fi
954  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
955}
956
957#D-#==================================================
958#D-function IGCM_sys_Mv
959#D-* Purpose: generic move
960#D-* Examples:
961#D-
962function IGCM_sys_Mv {
963  IGCM_debug_PushStack "IGCM_sys_Mv" $@
964  if ( $DEBUG_sys ) ; then
965    echo "IGCM_sys_Mv :" $@
966  fi
967
968  if [ $DRYRUN = 0 ]; then
969
970    typeset RET
971
972    echo mv $@ > out_rsync 2>&1
973    \mv $@ >> out_rsync 2>&1
974    RET=$?
975
976    if [ ${RET} -gt 0 ] ; then
977      echo "IGCM_sys_Mv : error in mv."
978      cat out_rsync
979      IGCM_debug_Exit "IGCM_sys_Mv"
980    else
981      \rm out_rsync
982    fi
983  else
984    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
985  fi
986
987  IGCM_debug_PopStack "IGCM_sys_Mv"
988}
989
990#D-#==================================================
991#D-function IGCM_sys_Put_Dir
992#D-* Purpose: Copy a complete directory on $(ARCHIVE)
993#D-* Examples:
994#D-
995function IGCM_sys_Put_Dir {
996  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
997  if ( $DEBUG_sys ) ; then
998    echo "IGCM_sys_Put_Dir :" $@
999  fi
1000  if [ $DRYRUN = 0 ]; then
1001    if [ ! -d ${1} ] ; then
1002      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
1003      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1004      return
1005    fi
1006
1007    typeset RET
1008
1009    # Only if we use rsync
1010    #IGCM_sys_TestDirArchive $( dirname $2 )
1011    #
1012    #USUAL WAY
1013    \cp -r $1 $2 > out_rsync 2>&1
1014    RET=$?
1015
1016    if [ ${RET} -gt 0 ] ; then
1017      echo "IGCM_sys_Put_Dir : error."
1018      cat out_rsync
1019      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1020    else
1021      \rm out_rsync
1022    fi
1023  else
1024    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1025  fi
1026  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1027}
1028
1029#D-#==================================================
1030#D-function IGCM_sys_Get_Dir
1031#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1032#D-* Examples:
1033#D-
1034function IGCM_sys_Get_Dir {
1035  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1036  if ( $DEBUG_sys ) ; then
1037    echo "IGCM_sys_Get_Dir :" $@
1038  fi
1039  if [ $DRYRUN = 0 ]; then
1040#    if [ ! -d ${1} ] ; then
1041#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1042#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1043#      return
1044#    fi
1045
1046    typeset RET
1047
1048    # Only if we use rsync
1049    #IGCM_sys_TestDirArchive $( dirname $2 )
1050    #
1051    # USUAL WAY
1052    # add dmfind/dmget (to demigrate all offline files) :
1053    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
1054    \cp -r $1 $2 > out_rsync 2>&1
1055    RET=$?
1056
1057    if [ ${RET} -gt 0 ] ; then
1058      echo "IGCM_sys_Get_Dir : error."
1059      cat out_rsync
1060      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1061    else
1062      \rm out_rsync
1063    fi
1064  else
1065    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1066  fi
1067  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1068}
1069
1070#D-#==================================================
1071#D-function IGCM_sys_Get_Master
1072#D-* Purpose: Copy a complete directory from MASTER filesystem
1073#D-* Examples:
1074#D-
1075function IGCM_sys_Get_Master {
1076  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1077  if ( $DEBUG_sys ) ; then
1078    echo "IGCM_sys_Get_Master :" $@
1079  fi
1080  if [ $DRYRUN = 0 ]; then
1081    if [ ! -d ${1} ] ; then
1082      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1083      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1084      return
1085    fi
1086
1087    typeset RET
1088
1089    #USUAL WAY
1090    \cp -r $1 $2 > out_rsync 2>&1
1091    RET=$?
1092
1093    if [ ${RET} -gt 0 ] ; then
1094      echo "IGCM_sys_Get_Master : error."
1095      cat out_rsync
1096      IGCM_debug_Exit "IGCM_sys_Get_Master"
1097    else
1098      \rm out_rsync
1099    fi
1100  else
1101    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1102  fi
1103  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1104}
1105
1106#D-#==================================================
1107#D-function IGCM_sys_Put_Rest
1108#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1109#D-           File and target directory must exist.
1110#D-* Examples:
1111#D-
1112function IGCM_sys_Put_Rest {
1113  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1114  if ( $DEBUG_sys ) ; then
1115    echo "IGCM_sys_Put_Rest :" $@
1116  fi
1117  if [ $DRYRUN = 0 ]; then
1118    if [ ! -f ${1} ] ; then
1119      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1120      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1121    fi
1122
1123    typeset RET
1124    #
1125    if [ X${JobType} = XRUN ] ; then
1126      IGCM_sys_Chmod 444 ${1}
1127    fi
1128
1129    #
1130    # USUAL WAY
1131    \cp $1 $2 > out_rsync 2>&1
1132    RET=$?
1133
1134#       #RSYNC WITH NETWORK SSH CALL
1135#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1136#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1137
1138#       #RSYNC WITH NFS USE
1139#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1140#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1141
1142#       RET=$?
1143#       IGCM_sys_Rsync_out $RET
1144
1145#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1146#       (( RET=RET+$? ))
1147
1148    if [ ${RET} -gt 0 ] ; then
1149      echo "IGCM_sys_Put_Rest : error."
1150      cat out_rsync
1151      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1152    else
1153      \rm out_rsync
1154    fi
1155  else
1156    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1157  fi
1158  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1159}
1160
1161#D-#==================================================
1162#D-function IGCM_sys_PutBuffer_Rest
1163#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1164#D-           File and target directory must exist.
1165#D-* Examples:
1166#D-
1167function IGCM_sys_PutBuffer_Rest {
1168  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1169  if ( $DEBUG_sys ) ; then
1170    echo "IGCM_sys_PutBuffer_Rest :" $@
1171  fi
1172  if [ $DRYRUN = 0 ]; then
1173    if [ ! -f ${1} ] ; then
1174      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1175      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1176    fi
1177
1178    typeset RET
1179    #
1180    if [ X${JobType} = XRUN ] ; then
1181      IGCM_sys_Chmod 444 ${1}
1182    fi
1183
1184    #
1185    # USUAL WAY
1186    \cp $1 $2 > out_rsync 2>&1
1187    RET=$?
1188
1189    if [ ${RET} -gt 0 ] ; then
1190      echo "IGCM_sys_PutBuffer_Rest : error."
1191      cat out_rsync
1192      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1193    else
1194      \rm out_rsync
1195    fi
1196  else
1197    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1198  fi
1199  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1200}
1201
1202#D-#==================================================
1203#D-function IGCM_sys_Put_Out
1204#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1205#D-* Examples:
1206#D-
1207function IGCM_sys_Put_Out {
1208  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1209  if ( $DEBUG_sys ) ; then
1210    echo "IGCM_sys_Put_Out :" $@
1211  fi
1212  if [ $DRYRUN = 0 ]; then
1213    if [ ! -f ${1} ] ; then
1214      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1215      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1216      return 1
1217    fi
1218    #
1219    IGCM_sys_MkdirArchive $( dirname $2 )
1220    #
1221    typeset RET
1222
1223    #=====================================================
1224    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1225    #=====================================================
1226
1227    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1228    #if [ $? -eq 0 ] ; then
1229    #    typeset WORKPATH FILEPATH
1230    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1231    #    IGCM_sys_MkdirWork ${WORKPATH}
1232    #    FILEPATH=${WORKPATH}/$( basename $2 )
1233    #    #
1234    #    IGCM_sys_Cp ${1} ${FILEPATH}
1235    #fi
1236
1237    if [ X${JobType} = XRUN ] ; then
1238      if [ X${3} = X ] ; then
1239        IGCM_sys_Chmod 444 ${1}
1240      fi
1241    fi
1242    #
1243    # USUAL WAY
1244    \cp $1 $2 > out_rsync 2>&1
1245    RET=$?
1246
1247#       #RSYNC WITH NETWORK SSH CALL
1248#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1249#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1250
1251#       #RSYNC WITH NFS USE
1252#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1253#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1254
1255#       RET=$?
1256#       IGCM_sys_Rsync_out $RET
1257
1258#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1259#       (( RET=RET+$? ))
1260
1261    if [ ${RET} -gt 0 ] ; then
1262      echo "IGCM_sys_Put_Out : error."
1263      cat out_rsync
1264      IGCM_debug_Exit "IGCM_sys_Put_Out"
1265    else
1266      \rm out_rsync
1267    fi
1268  else
1269    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1270  fi
1271  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1272  return 0
1273}
1274
1275#D-#==================================================
1276#D-function IGCM_sys_PutBuffer_Out
1277#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1278#D-* Examples:
1279#D-
1280function IGCM_sys_PutBuffer_Out {
1281  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1282  if ( $DEBUG_sys ) ; then
1283    echo "IGCM_sys_PutBuffer_Out :" $@
1284  fi
1285  if [ $DRYRUN = 0 ]; then
1286    if [ ! -f ${1} ] ; then
1287      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1288      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1289      return 1
1290    fi
1291    #
1292    IGCM_sys_Mkdir $( dirname $2 )
1293    #
1294    typeset RET
1295
1296    if [ X${JobType} = XRUN ] ; then
1297      if [ X${3} = X ] ; then
1298        IGCM_sys_Chmod 444 ${1}
1299      fi
1300    fi
1301    #
1302    # USUAL WAY
1303    \cp $1 $2 > out_rsync 2>&1
1304    RET=$?
1305
1306    if [ ${RET} -gt 0 ] ; then
1307      echo "IGCM_sys_PutBuffer_Out : error."
1308      cat out_rsync
1309      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1310    else
1311      \rm out_rsync
1312    fi
1313  else
1314    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1315  fi
1316  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1317  return 0
1318}
1319
1320#D-#==================================================
1321#D-function IGCM_sys_Get
1322#D-* Purpose: Get a file from ${ARCHIVE}
1323#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1324#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1325function IGCM_sys_Get {
1326  IGCM_debug_PushStack "IGCM_sys_Get" $@
1327
1328  typeset DEST RET dm_liste ifile target file_work
1329
1330  if ( $DEBUG_sys ) ; then
1331    echo "IGCM_sys_Get :" $@
1332  fi
1333  if [ $DRYRUN -le 2 ]; then
1334    if [ X${1} = X'/l' ] ; then
1335      # test if the first file is present in the old computation :
1336      eval set +A dm_liste \${${2}}
1337    else
1338      eval set +A dm_liste ${1}
1339    fi
1340    eval DEST=\${${#}}
1341
1342    #=====================================================
1343    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1344    #=====================================================
1345
1346    # Is it an R_OUT file (not R_IN) ?
1347    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1348    #if [ $? -eq 0 ] ; then
1349    #    # Yes  ? then we try to get it in SCRATCHDIR
1350    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1351    #    if [ -f ${file_work[0]} ] ; then
1352    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1353    #   IGCM_debug_PopStack "IGCM_sys_Get"
1354    #   return
1355    #    fi
1356    #fi
1357
1358    # test if the (first) file is present in the old computation :
1359    IGCM_sys_TestFileArchive ${dm_liste[0]}
1360    RET=$?
1361    if [ ${RET} -gt 0 ] ; then
1362      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1363      IGCM_debug_Exit "IGCM_sys_Get"
1364    fi
1365
1366    #dmget ${dm_liste[*]} > out_rsync 2>&1
1367    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1368    RET=$?
1369    if [ ${RET} -gt 0 ] ; then
1370      echo "WARNING IGCM_sys_Get : demigration error."
1371      cat out_rsync
1372      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1373    fi
1374
1375    #if [ ${RET} -gt 0 ] ; then
1376    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1377    #   cat out_rsync
1378    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1379    #   sleep 30
1380    #   echo "We try another time"
1381    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1382    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1383    #   RET=$?
1384    #   if [ ${RET} -gt 0 ] ; then
1385    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1386    #       cat out_rsync
1387    #       IGCM_debug_Exit "IGCM_sys_Get"
1388    #   fi
1389    #    else
1390    #   echo "ERROR IGCM_sys_Get : demigration error :"
1391    #   cat out_rsync
1392    #   IGCM_debug_Exit "IGCM_sys_Get"
1393    #    fi
1394    #fi
1395
1396    #USUAL WAY
1397    if [ X${1} = X'/l' ] ; then
1398      (( RET=0 ))
1399      for target in ${dm_liste[*]} ; do
1400        local_file=$( basename ${target} )
1401        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1402        (( RET = RET + $? ))
1403      done
1404    else
1405      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1406      RET=$?
1407    fi
1408
1409#       #RSYNC WITH NETWORK SSH CALL
1410#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1411#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1412
1413#       #RSYNC WITH NFS USE
1414#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1415#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1416
1417#       RET=$?
1418#       IGCM_sys_Rsync_out $RET
1419
1420#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1421#       (( RET=RET+$? ))
1422
1423    if [ ${RET} -gt 0 ] ; then
1424      echo "IGCM_sys_Get : copy error."
1425      cat out_rsync
1426      IGCM_debug_Exit "IGCM_sys_Get"
1427    else
1428      \rm out_rsync
1429    fi
1430  else
1431    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1432  fi
1433  IGCM_debug_PopStack "IGCM_sys_Get"
1434}
1435
1436#D-#==================================================
1437#D-function IGCM_sys_GetBuffer
1438#D-* Purpose: Get a file from ${SCRATCHDIR}
1439#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1440#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1441function IGCM_sys_GetBuffer {
1442  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1443
1444  typeset DEST RET buf_liste ifile target file_work
1445
1446  if ( $DEBUG_sys ) ; then
1447    echo "IGCM_sys_GetBuffer :" $@
1448  fi
1449  if [ $DRYRUN -le 2 ]; then
1450    if [ X${1} = X'/l' ] ; then
1451      # test if the first file is present in the old computation :
1452      eval set +A buf_liste \${${2}}
1453    else
1454      eval set +A buf_liste ${1}
1455    fi
1456    eval DEST=\${${#}}
1457
1458    #USUAL WAY
1459    if [ X${1} = X'/l' ] ; then
1460      (( RET=0 ))
1461      for target in ${buf_liste[*]} ; do
1462        local_file=$( basename ${target} )
1463        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1464        (( RET = RET + $? ))
1465      done
1466    else
1467      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1468      RET=$?
1469    fi
1470
1471    if [ ${RET} -gt 0 ] ; then
1472      echo "IGCM_sys_GetBuffer : copy error."
1473      cat out_rsync
1474      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1475    else
1476      \rm out_rsync
1477    fi
1478  else
1479    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1480  fi
1481  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1482}
1483
1484#D-#==================================================
1485#D-function IGCM_sys_GetDate_FichWork
1486#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1487#D-* Examples:
1488#D-
1489function IGCM_sys_GetDate_FichWork {
1490  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1491  if ( $DEBUG_sys ) ; then
1492    echo "IGCM_sys_GetDate_FichWork :" $@
1493  fi
1494  typeset dateF
1495  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1496  eval ${2}=${dateF[5]}
1497
1498    # donne la date filesys d'un fichier sur la machine work
1499  IGCM_debug_PopStack "IGCM_sys_FichWork"
1500}
1501
1502#D-#==================================================
1503#D-function IGCM_sys_GetDate_FichArchive
1504#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1505#D-* Examples:
1506#D-
1507function IGCM_sys_GetDate_FichArchive {
1508  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1509  if ( $DEBUG_sys ) ; then
1510    echo "IGCM_sys_GetDate_FichArchive :" $@
1511  fi
1512  typeset dateF
1513  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1514  eval ${2}=${dateF[5]}
1515
1516  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1517}
1518
1519#D-#==================================================
1520#D-function IGCM_sys_Dods_Rm
1521#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1522#D-* Examples:
1523#D-
1524function IGCM_sys_Dods_Rm {
1525  if ( $DEBUG_sys ) ; then
1526    echo "IGCM_sys_Dods_Rm :" $@
1527  fi
1528  typeset RET
1529  RET=0
1530  if [ $DRYRUN = 0 ]; then
1531
1532#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1533#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1534#      echo "Nothing has been done."
1535#      return
1536#    fi
1537
1538    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1539    RET=$?
1540
1541#       if [ ${RET} -gt 0 ] ; then
1542#           echo "IGCM_sys_Dods_Rm : error."
1543#           cat out_dods_rm
1544#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1545#       else
1546#           rm out_dods_rm
1547#       fi
1548
1549  else
1550    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1551  fi
1552  return $RET
1553}
1554
1555#D-#==================================================
1556#D-function IGCM_sys_Dods_Cp
1557#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1558#D-* Examples:
1559#D-
1560function IGCM_sys_Dods_Cp {
1561  if ( $DEBUG_sys ) ; then
1562    echo "IGCM_sys_Dods_Cp :" $@
1563  fi
1564  typeset RET
1565  RET=0
1566  if [ $DRYRUN = 0 ]; then
1567
1568#    if [ ! -d ${R_SAVE}/${1} ] ; then
1569#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1570#      echo "Nothing has been done."
1571#      return
1572#    fi
1573
1574    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1575    RET=$?
1576
1577#       if [ ${RET} -gt 0 ] ; then
1578#           echo "IGCM_sys_Dods_Cp : error."
1579#           cat out_dods_cp
1580#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1581#       else
1582#           rm out_dods_cp
1583#       fi
1584
1585  else
1586    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1587  fi
1588  return $RET
1589}
1590
1591#D-#==================================================
1592#D-function IGCM_sys_Put_Dods
1593#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1594#D-* Examples:
1595#D-
1596function IGCM_sys_Put_Dods {
1597  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1598  if ( $DEBUG_sys ) ; then
1599    echo "IGCM_sys_Put_Dods :" $@
1600  fi
1601  set -vx
1602  typeset RET
1603  if [ $DRYRUN = 0 ]; then
1604    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1605      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1606      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1607      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1608      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1609      return
1610    fi
1611
1612    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1613      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1614      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1615      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1616      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1617      return
1618    fi
1619    #
1620    if [ -d ${R_SAVE}/${1} ] ; then
1621      cd ${R_SAVE}
1622    elif [ -d ${R_FIGR}/${1} ] ; then
1623      cd ${R_FIGR}
1624    fi
1625
1626    IGCM_sys_Dods_Rm ${1}
1627    IGCM_sys_Dods_Cp ${1}
1628    RET=0
1629
1630    if [ ${RET} -gt 0 ] ; then
1631      echo "IGCM_sys_Put_Dods : error."
1632      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1633    fi
1634  else
1635    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1636  fi
1637  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1638}
1639
1640##############################################################
1641# REBUILD OPERATOR
1642
1643function IGCM_sys_rebuild {
1644  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1645  if ( $DEBUG_sys ) ; then
1646    echo "IGCM_sys_rebuild :" $@
1647  fi
1648  /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1649  if [ $? -gt 0 ] ; then
1650    echo "IGCM_sys_rebuild : erreur ${@}."
1651    IGCM_debug_Exit "rebuild"
1652  fi
1653
1654  IGCM_debug_PopStack "IGCM_sys_rebuild"
1655}
1656
1657############################################################
1658# Activate Running Environnment Variables
1659
1660function IGCM_sys_activ_variables {
1661  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1662  if ( $DEBUG_sys ) ; then
1663    echo "IGCM_sys_activ_variables"
1664  fi
1665
1666  typeset max_omp
1667
1668  ulimit -s unlimited
1669
1670  (( max_omp = 0 ))
1671  for comp in ${config_ListOfComponents[*]} ; do
1672
1673    eval ExeNameIn=\${config_Executable_${comp}[0]}
1674    eval ExeNameOut=\${config_Executable_${comp}[1]}
1675
1676    # Only if we really have an executable for the component :
1677    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1678      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1679      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1680        (( max_omp = comp_proc_omp_loc ))
1681      fi
1682    fi
1683  done
1684  if [ ${max_omp} -gt 1 ] ; then
1685    module load openmp/${max_omp}thds
1686  fi
1687
1688  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1689}
1690
1691############################################################
1692# Desactivate Running Environnment Variables
1693
1694function IGCM_sys_desactiv_variables {
1695  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1696  if ( $DEBUG_sys ) ; then
1697    echo "IGCM_sys_desactiv_variables"
1698  fi
1699  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1700}
1701
1702############################################################
1703# Build MPI/OMP scripts run file (dummy function)
1704
1705function IGCM_sys_build_run_file {
1706
1707IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1708
1709}
1710
1711############################################################
1712# Build MPI/OMP scripts
1713function IGCM_sys_build_execution_scripts
1714{
1715  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1716  if ( $DEBUG_sys ) ; then
1717    echo "IGCM_sys_build_execution_scripts " $@
1718  fi
1719  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1720  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1721  typeset num_corempi nombre_restant_node nombre_restant_comp
1722
1723  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1724    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1725  fi
1726
1727  if ( ${OK_PARA_MPMD} ) ; then
1728
1729    if [ -f run_file ] ; then
1730      IGCM_sys_Rm -f run_file
1731    fi
1732    touch run_file
1733
1734    if ( ${OK_PARA_OMP} ) ; then
1735
1736      #  Hosts treatment
1737
1738      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1739
1740      i=0
1741      rm -f hosts
1742      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1743      for nodes in `cat hosts.tmp` ; do
1744        host[$i]=$nodes
1745        echo "${host[$i]} slots=8 max_slots=8" >> hosts
1746        IGCM_debug_Print 1 ${host[$i]}
1747        i=$((i+1))
1748      done
1749      rm -f hosts.tmp
1750
1751      listnodes=${host[*]}
1752
1753      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1754
1755      # Initialisation
1756
1757      init_node=y
1758      node_num_current=0
1759      start_num=0
1760      init_exec=n
1761
1762      # Test : if oasis is there, we put it at the first position
1763
1764      for comp in ${config_ListOfComponents[*]} ; do
1765
1766        if [ "X${comp}" = "XCPL" ]  ; then
1767
1768          eval ExeNameIn=\${config_Executable_${comp}[0]}
1769          eval ExeNameOut=\${config_Executable_${comp}[1]}
1770
1771          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1772          echo ""  >> script_${ExeNameOut}.ksh
1773          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1774          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1775          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1776          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1777          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1778
1779          init_node=n
1780
1781          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1782          node_num_current=0
1783          node_current=${host[${node_num_current}]}
1784
1785          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1786
1787          init_exec=y
1788          start_num=1
1789
1790        fi
1791
1792      done
1793
1794      # Then loop on the components (except for oasis)
1795
1796      for comp in ${config_ListOfComponents[*]} ; do
1797
1798        eval ExeNameIn=\${config_Executable_${comp}[0]}
1799        eval ExeNameOut=\${config_Executable_${comp}[1]}
1800
1801        # Only if we really have an executable for the component :
1802        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1803
1804          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1805          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1806
1807          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1808          # echo "set -vx" >> script_${ExeNameOut}.ksh
1809          echo ""  >> script_${ExeNameOut}.ksh
1810          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1811          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1812          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1813          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1814          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1815          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1816          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1817
1818          node_num=0
1819
1820          # We define the number of MPI process to be assigned for the component
1821
1822          nombre_restant_comp=${comp_proc_mpi_loc}
1823
1824          # Loop on the allocated nodes
1825
1826          for node in ${listnodes} ; do
1827
1828            # We go to the current node
1829            if [ ${node_num} = ${node_num_current} ] ; then
1830
1831              node_current=${host[${node_num_current}]}
1832
1833              # If first time on the node : initialisation
1834
1835              if [ ${init_node} = y ] ; then
1836                nombre_restant_node=${NUM_COREPERNODE}
1837              fi
1838
1839              # Test on the number of OMP threads
1840
1841              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1842                (( node_num = node_num + 1 ))
1843                node_num_current=${node_num}
1844                init_node=y
1845                continue
1846              fi
1847
1848              # Number of MPI process to assign
1849
1850              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1851
1852              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1853                num_corempi=${nombre_restant_comp}
1854              fi
1855
1856              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1857              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1858
1859              if [ ${init_exec} = y ] ; then
1860                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1861              else
1862                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1863                init_exec=y
1864              fi
1865
1866              ((  start_num = num_corempi + start_num ))
1867
1868            else
1869
1870              (( node_num = node_num + 1 ))
1871              continue
1872            fi
1873
1874            # Test on the number of core/process remaining on the node/component
1875
1876            if [ ${nombre_restant_node} = 0 ] ; then
1877              (( node_num = node_num + 1 ))
1878              node_num_current=${node_num}
1879              init_node=y
1880
1881              if [ ${nombre_restant_comp} = 0 ] ; then
1882                break 1
1883              fi
1884            else
1885
1886              node_num_current=${node_num}
1887              init_node=n
1888
1889              if [ ${nombre_restant_comp} = 0 ] ; then
1890                break 1
1891              fi
1892            fi
1893          done
1894        fi
1895      done
1896
1897    else
1898
1899        # Then first loop on the components for the coupler ie oasis
1900
1901        ## the coupler ie oasis must be the first one
1902        for comp in ${config_ListOfComponents[*]} ; do
1903
1904            eval ExeNameOut=\${config_Executable_${comp}[1]}
1905
1906        # for CPL component only
1907            if [ "X${comp}" = "XCPL" ] ; then
1908                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1909                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1910            fi
1911        done
1912
1913        # Then second loop on the components
1914
1915        for comp in ${config_ListOfComponents[*]} ; do
1916
1917            eval ExeNameOut=\${config_Executable_${comp}[1]}
1918
1919            # Only if we really have an executable for the component and not the coupler ie oasis:
1920            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1921                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1922                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1923            fi
1924        done
1925        IGCM_sys_Chmod u+x run_file
1926
1927        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1928
1929    fi
1930
1931  else # Only one executable. launch it.
1932
1933      for comp in ${config_ListOfComponents[*]} ; do
1934
1935          # Only if we really have an executable for the component :
1936          eval ExeNameOut=\${config_Executable_${comp}[1]}
1937          if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then
1938
1939              echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1940              echo ""  >> script_${ExeNameOut}.ksh
1941              if ( ${OK_PARA_OMP} ) ; then
1942                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1943                  echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1944              fi
1945              if  ( ${OK_PARA_MPI} ) ; then
1946                  # Default : mpirun used if nb_proc gt 1
1947                  # pour sortie out/err par process
1948                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1949                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1950                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1951                  EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1952              else
1953                  # Default : mpirun is NOT used if nb_proc eq 1
1954                  # pour sortie out/err par process
1955                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1956                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1957                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1958                  EXECUTION="time ./script_${ExeNameOut}.ksh"
1959              fi
1960          fi
1961      done
1962
1963  fi
1964
1965  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
1966  IGCM_debug_Print 1 $EXECUTION
1967
1968  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
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.