source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_irene.ksh @ 1459

Last change on this file since 1459 was 1459, checked in by jgipsl, 6 years ago

Removed variable R_IN_ECMWF (never used in reference experiment setups)

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 62.0 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 Irene
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 |            |         |                           |
46# |          |  Chmod 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 user names project maxCpuTime
65# $hostname ou hostname
66typeset HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=irene
71# add default project on irene
72typeset PROJECT=$(echo ${BRIDGE_MSUB_PROJECT:=gen0826} | cut -d@ -f1 )
73# jobWarningDelay in seconds
74typeset jobWarningDelay=${BRIDGE_MSUB_MAXTIME}
75
76#D-
77#D-#==================================================
78#D-Program used in libIGCM
79#D-#==================================================
80
81# Submit command
82typeset SUBMIT=${SUBMIT:=ccc_msub}
83# rsync with path
84typeset -r RSYNC=/usr/bin/rsync
85# RSYNC_opt args to rsync
86typeset -r RSYNC_opt="-va"
87# ie storage filesystem
88typeset -r STOREHOST=${MASTER}
89typeset -r REMOTE_RSYNC=/usr/bin/rsync
90
91#====================================================
92# Set environment tools (ferret, nco, cdo, rebuild, ...)
93#====================================================
94if [ X${TaskType} = Xcomputing ] ; then
95  IGCM_debug_Print 1 "Module will be loaded once we know the compiler version"
96else
97  module purge > /dev/null 2>&1
98  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/irene/env_irene > /dev/null 2>&1
99  . $( ccc_home -u igcmg)/MachineEnvironment/irene/env_irene > /dev/null 2>&1
100  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/irene/env_atlas_irene > /dev/null 2>&1
101  . $( ccc_home -u igcmg)/MachineEnvironment/irene/env_atlas_irene > /dev/null 2>&1
102
103  export PCMDI_MP=/ccc/work/cont003/igcmg/igcmg/PCMDI-MP
104  export UVCDAT_ANONYMOUS_LOG=FALSE
105fi
106
107# Use CMIP6 storage space when using project id gch0316
108[[ "X${PROJECT}" = "Xgch0316" && ! $(module list --terse 2>&1 | grep dfldatadir/gencmip6) ]] && module switch dfldatadir dfldatadir/gencmip6
109
110# FYI
111[ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
112[ ! X${TaskType} = Xchecking ] && module list
113
114# For AddNoise and AddPertu3DOCE
115##export PATH=${PATH}:/ccc/cont003/home/igcmg/igcmg/Tools/curie/bin
116export PATH=${PATH}:$(ccc_home -u igcmg)/Tools/curie/bin
117
118# For rebuild
119##export PATH=${PATH}:/ccc/cont003/home/igcmg/igcmg/Tools/irene/rebuild/modipsl_IOIPSL_PLUS_v2_2_4/bin
120export PATH=${PATH}:$(ccc_home -u igcmg)/Tools/irene/rebuild/modipsl_IOIPSL_PLUS_v2_2_4/bin
121
122#====================================================
123# Host specific DIRECTORIES
124#====================================================
125
126# ============ CESIUM START ============ #
127
128#====================================================
129#- Mirror libIGCM from titane to cesium if needed
130#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
131#if [ ! ${ROOTSYS} = "home" ] ; then
132#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
133#else
134#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
135#fi
136
137#====================================================
138#- libIGCM_POST
139#if ( ${MirrorlibIGCM} ) ; then
140#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
141#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
142#else
143#  typeset -r libIGCM_POST=${libIGCM}
144#fi
145
146# ============ CESIUM  END  ============ #
147
148#====================================================
149#- MirrorlibIGCM for frontend
150typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
151
152#====================================================
153#- libIGCM_POST for frontend
154typeset -r libIGCM_POST=${libIGCM}
155
156#====================================================
157#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
158typeset -r R_EXE="${MODIPSL}/bin"
159
160#====================================================
161#- SUBMIT_DIR : submission dir
162typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${BRIDGE_MSUB_PWD}}
163
164#====================================================
165#- IN
166typeset -r R_IN=${R_IN:=/ccc/work/cont003/igcmg/igcmg/IGCM}
167
168#====================================================
169#- RUN_DIR_PATH : Temporary working directory (=> TMP)
170typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${CCCSCRATCHDIR}/RUN_DIR/${BRIDGE_MSUB_JOBID}_${$}}
171
172#====================================================
173#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
174typeset -r OUTCOMMAND_PATH=/tmp
175
176#====================================================
177#- HOST_MPIRUN_COMMAND
178typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time ccc_mprun -E-K1 "}
179
180#====================================================
181#- Max number of arguments passed to nco operator or demigration command
182UNIX_MAX_LIMIT=360
183
184#====================================================
185#- set PackDefault to true on irene
186PackDefault=true
187
188#====================================================
189#- Default number of MPI task for IPSL coupled model
190#- required for backward compatibility
191#-
192DEFAULT_NUM_PROC_OCE=5
193DEFAULT_NUM_PROC_CPL=1
194(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
195
196#====================================================
197#- Number of computing cores per node
198#-
199NB_CORE_PER_NODE=16
200
201#D-#==================================================
202#D-function IGCM_sys_defineArchives
203#D-* Purpose:
204#D-* Define ARCHIVE : Dedicated to large files
205#D-* Define STORAGE : Dedicated to small/medium files
206#D-* Define R_OUT   : Output tree located on ARCHIVE
207#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
208#D-* Define R_BUF   : Output tree located on CCCSCRATCHDIR hosting files waiting for rebuild or pack processes
209#D-* if SpaceName=TEST everything is stored on CCCSCRATCHDIR
210#D-* Examples:
211#D-
212function IGCM_sys_defineArchives {
213  IGCM_debug_PushStack "IGCM_sys_defineArchives"
214
215  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
216    #====================================================
217    #- ARCHIVE (dedicated to large files)
218    ARCHIVE=${config_UserChoices_ARCHIVE}
219  else
220    #====================================================
221    #- ARCHIVE (dedicated to large files)
222    ARCHIVE=${CCCSTOREDIR}
223  fi
224
225  if [ ! X${config_UserChoices_STORAGE} = X ]; then
226    #====================================================
227    #- STORAGE (dedicated to small/medium files)
228    STORAGE=${config_UserChoices_STORAGE}
229  else
230    #====================================================
231    #- STORAGE (dedicated to small/medium files)
232    STORAGE=${CCCWORKDIR}
233  fi
234
235  if [ X${config_UserChoices_SpaceName} = XTEST ]; then
236    #====================================================
237    #- R_OUT
238    R_OUT=${CCCSCRATCHDIR}/IGCM_OUT
239
240    #====================================================
241    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
242    R_FIG=${CCCSCRATCHDIR}/IGCM_OUT
243
244    IGCM_debug_Print 1 "SpaceName=TEST ==> OVERRULE destination path directories"
245
246  else
247    #====================================================
248    #- R_OUT
249    R_OUT=${ARCHIVE}/IGCM_OUT
250
251    #====================================================
252    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
253    R_FIG=${STORAGE}/IGCM_OUT
254  fi
255
256  #====================================================
257  #- CMIP6 (hosting CMIP6 files produced by XIOS2 and configured by dr2xml)
258  CMIP6_BUF=${STORAGE}/IGCM_OUT
259
260  #====================================================
261  #- R_BUF (ONLY FOR double copy an scratch)
262  R_BUF=${CCCSCRATCHDIR}/IGCM_OUT
263
264  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
265  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
266  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
267
268  IGCM_debug_PopStack "IGCM_sys_defineArchives"
269}
270
271#D-#==================================================
272#D-function IGCM_sys_RshArchive
273#D-* Purpose: Archive rsh command
274#D-* Examples:
275#D-
276function IGCM_sys_RshArchive {
277  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
278  /bin/ksh <<-EOF
279    ${@}
280EOF
281  status=$?
282  if [ ${status} -gt 0 ] ; then
283    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
284    IGCM_debug_Exit "IGCM_sys_RshArchive"
285  fi
286  IGCM_debug_PopStack "IGCM_sys_RshArchive"
287}
288
289#D-#==================================================
290#D-function IGCM_sys_RshArchive_NoError
291#D-* Purpose: Archive rsh command, without error
292#D-*          used only in monitoring.job
293#D-* Examples:
294#D-
295function IGCM_sys_RshArchive_NoError {
296  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
297  /bin/ksh <<-EOF
298    ${@} 2> /dev/null
299EOF
300  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
301}
302
303#D-#==================================================
304#D-function IGCM_sys_MkdirArchive
305#D-* Purpose: Mkdir on Archive
306#D-* Examples:
307#D-
308function IGCM_sys_MkdirArchive {
309  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
310  if ( $DEBUG_sys ) ; then
311    echo "IGCM_sys_MkdirArchive :" $@
312  fi
313  #- creation de repertoire sur le serveur fichier
314  if [ ! -d ${1} ]; then
315    \mkdir -p $1
316    status=$?
317
318    if [ ${status} -gt 0 ] ; then
319      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
320      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
321    fi
322  fi
323  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
324}
325
326#D-#==================================================
327#D-function IGCM_sys_TestDirArchive
328#D-* Purpose: Test Directory that must exists on Archive
329#D-* Examples:
330#D-
331function IGCM_sys_TestDirArchive {
332  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
333  if ( $DEBUG_sys ) ; then
334    echo "IGCM_sys_TestDirArchive :" $@
335  fi
336  typeset ExistFlag
337  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
338  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
339  return ${ExistFlag}
340}
341
342#D-#==================================================
343#D-function IGCM_sys_IsFileArchived
344#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
345#D-* Examples:
346#D-
347function IGCM_sys_IsFileArchived {
348  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
349  if ( $DEBUG_sys ) ; then
350    echo "IGCM_sys_IsFileArchived :" $@
351  fi
352  typeset IsArchivedFlag
353  IsArchivedFlag=$( [ X$( echo $@ | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
354  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
355
356  return ${IsArchivedFlag}
357}
358
359#D-#==================================================
360#D-function IGCM_sys_TestFileArchive
361#D-* Purpose: Test file that must NOT EXISTS on Archive
362#D-* Examples:
363#D-
364function IGCM_sys_TestFileArchive {
365  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
366  typeset ExistFlag
367  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
368  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
369
370  return ${ExistFlag}
371}
372
373#D-#==================================================
374#D-function IGCM_sys_CountFileArchive
375#D-* Purpose: Count files on Archive filesystem
376#D-* Examples:
377#D-
378function IGCM_sys_CountFileArchive {
379  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
380  ls ${@} 2>/dev/null | wc -l
381  if [ $? -gt 0 ] ; then
382    echo "IGCM_sys_CountFileArchive : erreur."
383  fi
384  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
385}
386
387#D-#==================================================
388#D-function IGCM_sys_Tree
389#D-* Purpose: Tree directories with files on ${ARCHIVE}
390#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
391#D-
392function IGCM_sys_Tree {
393  IGCM_debug_PushStack "IGCM_sys_Tree" $@
394  if ( $DEBUG_sys ) ; then
395    echo "IGCM_sys_Tree :" $@
396  fi
397
398  \ls -lR ${@}
399
400  IGCM_debug_PopStack "IGCM_sys_Tree"
401}
402
403#D-#==================================================
404#D-function IGCM_sys_Qsub
405#D-* Purpose: Qsub new job
406#D-* Examples:
407#D-
408function IGCM_sys_Qsub {
409  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
410  if ( $DEBUG_sys ) ; then
411    echo "IGCM_sys_Qsub :" $@
412  fi
413  typeset options status
414  options="-o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output}"
415
416  /usr/bin/ccc_msub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
417  status=$?
418
419  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
420  if [ ${status} -gt 0 ] ; then
421    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
422    IGCM_debug_Exit "IGCM_sys_Qsub"
423  else
424    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
425  fi
426  IGCM_debug_PopStack "IGCM_sys_Qsub"
427}
428
429#D-#==================================================
430#D-function IGCM_sys_QsubPost
431#D-* Purpose: Qsub new job on scalaire
432#D-* Examples:
433#D-
434function IGCM_sys_QsubPost {
435  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
436  if ( $DEBUG_sys ) ; then
437    echo "IGCM_sys_QsubPost :" $@
438  fi
439  typeset options status
440  options="-Q normal -A ${PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out"
441
442  /usr/bin/ccc_msub ${options} ${libIGCM_POST}/$1.job > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
443  status=$?
444
445  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
446  if [ ${status} -gt 0 ] ; then
447    IGCM_debug_Print 2 "IGCM_sys_QsubPost ${options} ${libIGCM_POST}/$1.job : error code ${status}"
448    IGCM_debug_Exit "IGCM_sys_QsubPost"
449  else
450    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
451  fi
452  IGCM_debug_PopStack "IGCM_sys_QsubPost"
453}
454
455#D-*************************
456#D- File transfer functions
457#D-*************************
458#D-
459
460#D-#==================================================
461#D-function IGCM_sys_RmRunDir
462#D-* Purpose: rm tmpdir (dummy function most of the time batch
463#D-                      scheduler will do the job)
464#D-* Examples:
465#D-
466function IGCM_sys_RmRunDir {
467  IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@
468  if ( $DEBUG_sys ) ; then
469    echo "IGCM_sys_RmRunDir :" $@
470  fi
471
472  typeset status
473
474  echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
475  \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
476  status=$?
477
478  if [ ${status} -gt 0 ] ; then
479    IGCM_debug_Print 1 "IGCM_sys_RmRunDir : rm error code is ${status}."
480    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
481    IGCM_debug_Exit "IGCM_sys_RmRunDir"
482  else
483    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
484  fi
485  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
486}
487
488#D-#==================================================
489#D-function IGCM_sys_Put_Dir
490#D-* Purpose: Copy a complete directory on $(ARCHIVE)
491#D-* Examples:
492#D-
493function IGCM_sys_Put_Dir {
494  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
495  if ( $DEBUG_sys ) ; then
496    echo "IGCM_sys_Put_Dir :" $@
497  fi
498  if [ $DRYRUN = 0 ]; then
499    if [ ! -d ${1} ] ; then
500      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
501      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
502      return
503    fi
504
505    typeset status
506
507    # Only if we use rsync
508    #IGCM_sys_TestDirArchive $( dirname $2 )
509    #
510    #USUAL WAY
511    \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
512    status=$?
513
514    if [ ${status} -gt 0 ] ; then
515      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
516      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
517      IGCM_debug_Exit "IGCM_sys_Put_Dir"
518    else
519      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
520    fi
521  fi
522  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
523}
524
525#D-#==================================================
526#D-function IGCM_sys_Get_Dir
527#D-* Purpose: Copy a complete directory from ${ARCHIVE}
528#D-* Examples:
529#D-
530function IGCM_sys_Get_Dir {
531  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
532  if ( $DEBUG_sys ) ; then
533    echo "IGCM_sys_Get_Dir :" $@
534  fi
535  if [ $DRYRUN = 0 ]; then
536    typeset NB_ESSAI DELAI status i
537    # number of tentative
538    NB_ESSAI=3
539    # time delay between tentative
540    DELAI=2
541
542    #
543    # USUAL WAY
544    # add 'ccc_hsm get' (to demigrate all offline files) to reduce time of this command :
545    ccc_hsm get -r $1
546
547    i=0
548    while [ $i -lt $NB_ESSAI ] ; do
549      \cp -ur $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
550      status=$?
551      if [ ${status} -gt 0 ] ; then
552        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
553        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
554        sleep $DELAI
555      else
556        break
557      fi
558      (( i = i + 1 ))
559    done
560
561    if [ ${status} -gt 0 ] ; then
562      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
563      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
564      IGCM_debug_Exit "IGCM_sys_Get_Dir"
565    else
566      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
567    fi
568  fi
569  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
570}
571
572#D-#==================================================
573#D-function IGCM_sys_Put_Rest
574#D-* Purpose: Put computied restarts on ${ARCHIVE}.
575#D-           File and target directory must exist.
576#D-* Examples:
577#D-
578function IGCM_sys_Put_Rest {
579  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
580  if ( $DEBUG_sys ) ; then
581    echo "IGCM_sys_Put_Rest :" $@
582  fi
583  if [ $DRYRUN = 0 ]; then
584    if [ ! -f ${1} ] ; then
585      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
586      IGCM_debug_Exit "IGCM_sys_Put_Rest"
587    fi
588
589    typeset status
590    #
591    # USUAL WAY
592    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
593    status=$?
594
595#       #RSYNC WITH NETWORK SSH CALL
596#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
597#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
598
599#       #RSYNC WITH NFS USE
600#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
601#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
602
603#       status=$?
604#       IGCM_sys_Rsync_out $status
605
606#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
607#       (( status=status+$? ))
608
609    if [ ${status} -gt 0 ] ; then
610      IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}"
611      [ -f ${1} ] && ls -l ${1}
612      [ -f ${2} ] && ls -l ${2}
613      [ -f ${2}/${1} ] && ls -l ${2}/${1}
614      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
615      IGCM_debug_Exit "IGCM_sys_Put_Rest"
616    else
617
618      if [ X${JobType} = XRUN ] ; then
619        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
620        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
621      fi
622
623      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
624    fi
625  fi
626  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
627}
628
629#D-#==================================================
630#D-function IGCM_sys_Put_Out
631#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
632#D-* Examples:
633#D-
634function IGCM_sys_Put_Out {
635  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
636  if ( $DEBUG_sys ) ; then
637    echo "IGCM_sys_Put_Out :" $@
638  fi
639
640  typeset NB_ESSAI DELAI status i exist skip
641  typeset fileDeviceNumberInHex directoryDeviceNumberInHex
642
643  # number of tentative
644  NB_ESSAI=3
645  # time delay between tentative
646  DELAI=2
647
648  if [ $DRYRUN = 0 ]; then
649    if [ ! -f ${1} ] ; then
650      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
651      IGCM_debug_PopStack "IGCM_sys_Put_Out"
652      return 1
653    fi
654    #
655    IGCM_sys_MkdirArchive $( dirname $2 )
656    #
657    exist=false
658    skip=false
659    if [ -f $2 ] ; then
660      IGCM_debug_Print 1 "$2 already exist"
661      ccc_hsm get $2
662      exist=true
663      if [ "X$( diff $1 $2 )" = X ] ; then
664        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
665        skip=true
666      else
667        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
668        skip=false
669      fi
670    fi
671    #
672    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
673      IGCM_sys_Chmod u+w $2
674    fi
675
676    if [ X${skip} = Xfalse ] ; then
677      i=0
678      while [ $i -lt $NB_ESSAI ] ; do
679        # Identify file system
680        fileDeviceNumberInHex=$( stat -c %d $1 )
681        status=$?
682        if [ ${status} -gt 0 ] ; then
683          IGCM_debug_Exit "IGCM_sys_Put_Out"
684        fi
685        # Identify file system
686        directoryDeviceNumberInHex=$( stat -c %d $( dirname $2 ) )
687        status=$?
688        if [ ${status} -gt 0 ] ; then
689          IGCM_debug_Exit "IGCM_sys_Put_Out"
690        fi
691
692        if ( [ ${fileDeviceNumberInHex} -ne ${directoryDeviceNumberInHex} ] || [ X$3 = XNOMOVE ] ) ; then
693          # They are not on the same device. USUAL WAY
694          \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
695          status=$?
696        else
697          # They are on the same device. NOT SO USUAL WAY
698          \mv $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
699          status=$?
700        fi
701        if [ ${status} -gt 0 ]; then
702          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
703          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
704          [ -f ${1} ] && ls -l ${1}
705          [ -f ${2} ] && ls -l ${2}
706          [ -f ${2}/${1} ] && ls -l ${2}/${1}
707          sleep $DELAI
708        else
709          break
710        fi
711        (( i = i + 1 ))
712      done
713    fi
714
715#       #RSYNC WITH NETWORK SSH CALL
716#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
717#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
718
719#       #RSYNC WITH NFS USE
720#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
721#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
722
723#       status=$?
724#       IGCM_sys_Rsync_out $status
725
726#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
727#       (( status=status+$? ))
728
729    if [ ${status} -gt 0 ] ; then
730      IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status}"
731      [ -f ${1} ] && ls -l ${1}
732      [ -f ${2} ] && ls -l ${2}
733      [ -f ${2}/${1} ] && ls -l ${2}/${1}
734      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
735      IGCM_debug_Exit "IGCM_sys_Put_Out"
736    else
737
738      if [ X${JobType} = XRUN ] ; then
739        if [ X${3} = X ] ; then
740          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
741          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
742        fi
743      fi
744
745      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
746    fi
747  fi
748  IGCM_debug_PopStack "IGCM_sys_Put_Out"
749  return 0
750}
751
752#D-#==================================================
753#D-function IGCM_sys_Get
754#D-* Purpose: Get a file from ${ARCHIVE}
755#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
756#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
757function IGCM_sys_Get {
758  IGCM_debug_PushStack "IGCM_sys_Get" $@
759
760  typeset DEST dm_liste target file_work
761  typeset NB_ESSAI DELAI status i
762
763  if ( $DEBUG_sys ) ; then
764    echo "IGCM_sys_Get :" $@
765  fi
766
767  # number of tentative
768  NB_ESSAI=3
769  # time delay between tentative
770  DELAI=2
771
772  if [ $DRYRUN -le 2 ]; then
773    if [ X${1} = X'/l' ] ; then
774      eval set +A dm_liste \${${2}}
775    else
776      eval set +A dm_liste ${1}
777    fi
778    eval DEST=\${${#}}
779    ccc_hsm get ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
780    status=$?
781    if [ ${status} -gt 0 ] ; then
782      echo "WARNING IGCM_sys_Get : error code ${status}"
783      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
784      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
785    fi
786
787    #if [ ${status} -gt 0 ] ; then
788    #  if [ ! "X$( grep "Lost dmusrcmd connection" ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )" = "X" ] ; then
789    #    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
790    #    echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
791    #    sleep 30
792    #    echo "We try another time"
793    ##    dmget ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
794    #    ccc_hsm get ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
795    #    status=$?
796    #    if [ ${status} -gt 0 ] ; then
797    #      echo "ERROR IGCM_sys_Get : again demigration error :"
798    #      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
799    #      IGCM_debug_Exit "IGCM_sys_Get"
800    #    fi
801    #  else
802    #    echo "ERROR IGCM_sys_Get : demigration error :"
803    #    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
804    #    IGCM_debug_Exit "IGCM_sys_Get"
805    #  fi
806    #fi
807
808    #   #RSYNC WITH NETWORK SSH CALL
809    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
810    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
811
812    #   #RSYNC WITH NFS USE
813    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
814    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
815
816    #   status=$?
817    #   IGCM_sys_Rsync_out $status
818
819    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
820    #   (( status=status+$? ))
821
822    #USUAL WAY
823    if [ X${1} = X'/l' ] ; then
824      for target in ${dm_liste[*]} ; do
825        local_file=$( basename ${target} )
826        # test if the target file is present before the loop
827        IGCM_sys_TestFileArchive ${target}
828        status=$?
829        if [ ${status} -gt 0 ] ; then
830          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
831          IGCM_debug_Exit "IGCM_sys_Get"
832        else
833          i=0
834          while [ $i -lt $NB_ESSAI ] ; do
835            #if [ X${DoLink} = Xtrue ] ; then
836            #  \ln -s ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
837            #  status=$?
838            #  else
839            #  \cp ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
840            #  status=$?
841            #fi
842            \ln -s ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
843            status=$?
844            if [ ${status} -gt 0 ]; then
845              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
846              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
847              sleep $DELAI
848            else
849              break
850            fi
851            (( i = i + 1 ))
852          done
853          if [ ${status} -gt 0 ] ; then
854            echo "IGCM_sys_Get : error"
855            cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
856            \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
857            IGCM_debug_Exit "IGCM_sys_Get"
858          else
859            \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
860          fi
861        fi
862      done
863    else
864      i=0
865      while [ $i -lt $NB_ESSAI ] ; do
866        \cp ${dm_liste} ${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
867        status=$?
868        if [ ${status} -gt 0 ]; then
869          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
870          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
871          sleep $DELAI
872        else
873          break
874        fi
875        (( i = i + 1 ))
876      done
877      if [ ${status} -gt 0 ] ; then
878        echo "IGCM_sys_Get : error"
879        cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
880        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
881        IGCM_debug_Exit "IGCM_sys_Get"
882      else
883        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
884      fi
885    fi
886  fi
887  IGCM_debug_PopStack "IGCM_sys_Get"
888}
889
890#D-#==================================================
891#D-function IGCM_sys_GetDate_Monitoring
892#D-* Purpose: get the last year for which the monitoring has been computed
893#D-* Examples:
894#D-
895function IGCM_sys_GetDate_Monitoring {
896  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
897  if ( $DEBUG_sys ) ; then
898    echo "IGCM_sys_GetDate_Monitoring :" $@
899  fi
900
901  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
902
903  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
904}
905
906#D-#==================================================
907#D-function IGCM_sys_Dods_Rm
908#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
909#D-* Examples:
910#D-
911function IGCM_sys_Dods_Rm {
912  if ( $DEBUG_sys ) ; then
913    echo "IGCM_sys_Dods_Rm :" $@
914  fi
915  typeset status
916  if [ $DRYRUN = 0 ]; then
917
918#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
919#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
920#      echo "Nothing has been done."
921#      return
922#    fi
923
924    if [ "$#" -eq 1 ]; then
925      ## /ccc/cont003/home/igcmg/igcmg/Tools/irene/thredds_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
926      $(ccc_home -u igcmg)/Tools/irene/thredds_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
927      status=$?
928    else
929      ## /ccc/cont003/home/igcmg/igcmg/Tools/irene/thredds_rm public/${LOGIN}/${R_DODS} # > out_dods_rm 2>&1
930      $(ccc_home -u igcmg)/Tools/irene/thredds_rm public/${LOGIN}/${R_DODS} # > out_dods_rm 2>&1
931      status=$?
932    fi
933
934#    if [ ${status} -gt 0 ] ; then
935#      echo "IGCM_sys_Dods_Rm : error."
936#      cat out_dods_rm
937#      IGCM_debug_Exit "IGCM_sys_Dods_Rm"
938#    else
939#      rm out_dods_rm
940#    fi
941
942  fi
943  return $status
944}
945
946#D-#==================================================
947#D-function IGCM_sys_Dods_Cp
948#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
949#D-* Examples:
950#D-
951function IGCM_sys_Dods_Cp {
952  if ( $DEBUG_sys ) ; then
953    echo "IGCM_sys_Dods_Cp :" $@
954  fi
955  typeset status
956  if [ $DRYRUN = 0 ]; then
957
958#    if [ ! -d ${R_SAVE}/${1} ] ; then
959#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
960#      echo "Nothing has been done."
961#      return
962#    fi
963
964    ## /ccc/cont003/home/igcmg/igcmg/Tools/irene/bin/thredds_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
965    $(ccc_home -u igcmg)/Tools/irene/thredds_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
966    status=$?
967
968#       if [ ${status} -gt 0 ] ; then
969#           echo "IGCM_sys_Dods_Cp : error."
970#           cat out_dods_cp
971#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
972#       else
973#           rm out_dods_cp
974#       fi
975
976  fi
977  return $status
978}
979
980#D-#==================================================
981#D-function IGCM_sys_Put_Dods
982#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole.
983#D-* Examples:
984#D-
985function IGCM_sys_Put_Dods {
986  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
987  if ( $DEBUG_sys ) ; then
988    echo "IGCM_sys_Put_Dods :" $@
989  fi
990  typeset status
991  if [ $DRYRUN = 0 ]; then
992    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
993      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
994      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
995      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
996      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
997      return
998    fi
999
1000    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1001      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1002      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1003      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1004      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1005      return
1006    fi
1007    #
1008    if [ -d ${R_SAVE}/${1} ] ; then
1009      cd ${R_SAVE}
1010    elif [ -d ${R_FIGR}/${1} ] ; then
1011      cd ${R_FIGR}
1012    fi
1013
1014    IGCM_sys_Dods_Rm ${1}
1015    IGCM_sys_Dods_Cp ${1}
1016    status=0
1017
1018    if [ ${status} -gt 0 ] ; then
1019      echo "IGCM_sys_Put_Dods : error."
1020      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1021    fi
1022  fi
1023  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1024}
1025
1026##############################################################
1027# REBUILD OPERATOR
1028
1029#D-#==================================================
1030#D-function IGCM_sys_sync
1031#D-* Purpose: flush buffer on disk
1032#D-* Examples:
1033#D-
1034function IGCM_sys_sync {
1035  IGCM_debug_PushStack "IGCM_sys_sync" $@
1036  if ( $DEBUG_sys ) ; then
1037    echo "IGCM_sys_sync :" $@
1038  fi
1039
1040  /bin/sync
1041
1042  IGCM_debug_PopStack "IGCM_sys_sync"
1043}
1044
1045############################################################
1046# Activate Running Environnment Variables
1047
1048#D-#==================================================
1049#D-function IGCM_sys_activ_variables
1050#D-* Purpose: set environement variables prior to execution
1051#D-* Examples:
1052#D-
1053function IGCM_sys_activ_variables {
1054  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1055  if ( $DEBUG_sys ) ; then
1056    echo "IGCM_sys_activ_variables"
1057  fi
1058
1059# --------------------------------------------------------------------
1060#D- MODULE specifications
1061# --------------------------------------------------------------------
1062  module purge > /dev/null 2>&1
1063  if [ X${compilerVersion} = XV17 ] ; then
1064    IGCM_debug_Print 1 "IGCM_sys_active_variables : Using compiler version V17"
1065  else
1066    IGCM_debug_Exit "This compiler version is not yet supported : ${compilerVersion}"
1067  fi
1068  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/irene/env_irene > /dev/null 2>&1
1069  . $( ccc_home -u igcmg)/MachineEnvironment/irene/env_irene > /dev/null 2>&1
1070  IGCM_debug_Print 1 "IGCM_sys_active_variables : Now loaded modules for Irene. "
1071  module list
1072
1073  # Keep track of this
1074  [ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
1075  [ ! X${TaskType} = Xchecking ] && module list
1076
1077# --------------------------------------------------------------------
1078#D- MPI specifications
1079# --------------------------------------------------------------------
1080
1081# --------------------------------------------------------------------
1082#D- Other specifications
1083# --------------------------------------------------------------------
1084
1085  ulimit -s unlimited
1086
1087  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1088}
1089
1090############################################################
1091# Desactivate Running Environnment Variables
1092
1093#D-#==================================================
1094#D-function IGCM_sys_desactiv_variables
1095#D-* Purpose: unset environement variables after execution
1096#D-* Examples:
1097#D-
1098function IGCM_sys_desactiv_variables {
1099  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1100  if ( $DEBUG_sys ) ; then
1101    echo "IGCM_sys_desactiv_variables"
1102  fi
1103# --------------------------------------------------------------------
1104#D- MPI specifications
1105# --------------------------------------------------------------------
1106
1107# --------------------------------------------------------------------
1108#D- Other specifications
1109# --------------------------------------------------------------------
1110
1111  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1112}
1113
1114############################################################
1115# Update job headers to be used by the scheduler
1116
1117#D-#==================================================
1118#D-function IGCM_sys_updateHeaders
1119#D-* Purpose: Update job headers to be used by the scheduler
1120#D-* Examples: IGCM_sys_updateHeaders /path/to/Job_MYEXP
1121#D-
1122function IGCM_sys_updateHeaders {
1123  IGCM_debug_PushStack "IGCM_sys_updateHeaders"
1124  if ( $DEBUG_sys ) ; then
1125    echo "IGCM_sys_updateHeaders"
1126  fi
1127  typeset file
1128  file=$1
1129
1130  if [ ${executionType} -eq 1 ] ; then
1131    # MPMD + MPI
1132    sed -e "/::openMPthreads::/d"                  \
1133        -e "s/::JobNumProcTot::/${coreNumber}/"    \
1134        -e "/#MSUB -x/d"                           \
1135        -e "/--cpu_bind=none/d"                    \
1136      ${file} > ${file}.tmp
1137
1138  elif [ ${executionType} -eq 2 ] ; then
1139    # MPMD + MPI + OMP : mpirun/ccc_mprun/error
1140    if ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xmpirun" ] ) ; then
1141      sed -e "/::openMPthreads::/d"                  \
1142          -e "s/::JobNumProcTot::/${coreNumber}/"    \
1143        ${file} > ${file}.tmp
1144    elif ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "X" ] || [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xccc_mprun" ] ) ; then
1145      sed -e "/::openMPthreads::/d"                  \
1146          -e "s/::JobNumProcTot::/${coreNumber}/"    \
1147          -e "/--cpu_bind=none/d"                    \
1148        ${file} > ${file}.tmp
1149    else
1150     IGCM_debug_Print 1 "You have to set ExecutionModeOnCurie=ccc_mprun or mpirun in config.card"
1151     IGCM_debug_Exit "IGCM_sys_updateHeaders"
1152    fi
1153  elif [ ${executionType} -eq 3 ] ; then
1154    # SPMD + MPI/OMP
1155    sed -e "s/::openMPthreads::/${openMPthreads}/" \
1156        -e "s/::JobNumProcTot::/${mpiTasks}/"      \
1157        -e "/#MSUB -x/d"                           \
1158        -e "/--cpu_bind=none/d"                    \
1159      ${file} > ${file}.tmp
1160
1161  elif [ ${executionType} -eq 4 ] ; then
1162    # SPMD + MPI only
1163    sed -e "s/::JobNumProcTot::/${mpiTasks}/"      \
1164        -e "/::openMPthreads::/d"                  \
1165        -e "/#MSUB -x/d"                           \
1166        -e "/--cpu_bind=none/d"                    \
1167      ${file} > ${file}.tmp
1168
1169  elif [ ${executionType} -eq 5 ] ; then
1170    # SPMD + OMP only
1171    sed -e "s/::openMPthreads::/${openMPthreads}/" \
1172        -e "/::JobNumProcTot::/d"                  \
1173        -e "/#MSUB -x/d"                           \
1174        -e "/--cpu_bind=none/d"                    \
1175      ${file} > ${file}.tmp
1176
1177  elif [ ${executionType} -eq 6 ] ; then
1178    # SEQUENTIAL THEN
1179    sed -e "s/::JobNumProcTot::/1/"                \
1180        -e "/::openMPthreads::/d"                  \
1181        -e "/#MSUB -x/d"                           \
1182        -e "/--cpu_bind=none/d"                    \
1183      ${file} > ${file}.tmp
1184
1185  fi
1186
1187  IGCM_sys_Mv ${file}.tmp ${file}
1188
1189  IGCM_debug_PopStack "IGCM_sys_updateHeaders"
1190}
1191
1192############################################################
1193# Build MPI/OMP scripts run file (dummy function)
1194
1195#D-#==================================================
1196#D-function IGCM_sys_build_run_file
1197#D-* Purpose: build run file (deprecated)
1198#D-* Examples:
1199#D-
1200function IGCM_sys_build_run_file {
1201  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1202}
1203
1204############################################################
1205# Build MPI/OMP scripts
1206
1207#D-#==================================================
1208#D-function IGCM_sys_build_execution_scripts
1209#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1210#D-* Examples:
1211#D-
1212function IGCM_sys_build_execution_scripts
1213{
1214  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1215  if ( $DEBUG_sys ) ; then
1216    echo "IGCM_sys_build_execution_scripts " $@
1217  fi
1218
1219  EXECUTION=${HOST_MPIRUN_COMMAND}
1220
1221  if ( ${OK_PARA_MPMD} ) ; then
1222
1223    # MPMD mode
1224    # 1 MPI only
1225    # 2 MPI/OpenMP mpirun method
1226    # 3 MPI/OpenMP ccc_mprun method
1227
1228    if [ -f run_file ] ; then
1229      IGCM_sys_Rm -f run_file
1230    fi
1231    touch run_file
1232
1233    # case 1 : Only MPI (MPMD)
1234    if  ( ! ${OK_PARA_OMP} ) ; then
1235
1236      # Build run_file
1237
1238      # First loop on the components for the coupler ie oasis (only if oasis3)
1239      # the coupler ie oasis3 must be the first one
1240      for comp in ${config_ListOfComponents[*]} ; do
1241
1242        eval ExeNameIn=\${config_Executable_${comp}[0]}
1243        eval ExeNameOut=\${config_Executable_${comp}[1]}
1244
1245        # for CPL component only
1246        if [ "X${comp}" = "XCPL" ] && [ "X${ExeNameOut}" != X\"\" ] ; then
1247
1248          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1249          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1250          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1251        fi
1252      done
1253
1254      # Then second loop on the components
1255      for comp in ${config_ListOfComponents[*]} ; do
1256
1257        eval ExeNameIn=\${config_Executable_${comp}[0]}
1258        eval ExeNameOut=\${config_Executable_${comp}[1]}
1259
1260        # Only if we really have an executable for the component and not the coupler ie oasis:
1261        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1262
1263          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1264          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1265          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1266        fi
1267      done
1268
1269      EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1270
1271      IGCM_sys_Chmod u+x run_file
1272      if ( $DEBUG_sys ) ; then
1273        echo "run_file contains : "
1274        cat run_file
1275      fi
1276
1277    elif ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xmpirun" ] ) ; then
1278
1279    # 2 MPI/OpenMP mpirun method
1280
1281      # Use of mpirun instead of ccc_mprun
1282      EXECUTION="time mpirun"
1283
1284      #  Hosts treatment
1285      ${EXECUTION} hostname | sort | uniq > hosts.tmp
1286
1287      i=0
1288      rm -f hosts rankfile
1289      IGCM_debug_Print 1 "sys Curie, Hosts available :"
1290      for nodes in `cat hosts.tmp`
1291      do
1292        host[$i]=$nodes
1293        echo "${host[$i]}" >> hosts
1294        IGCM_debug_Print 1 ${host[$i]}
1295        i=$((i+1))
1296      done
1297      rm -f hosts.tmp
1298
1299      listnodes=${host[*]}
1300
1301      EXECUTION="${EXECUTION} -hostfile hosts -rankfile rankfile"
1302
1303      # Initialisation
1304      rank=0
1305      current_core=0
1306      init_exec=n
1307
1308      # Loop on the components
1309      for comp in ${config_ListOfComponents[*]} ; do
1310
1311        eval ExeNameIn=\${config_Executable_${comp}[0]}
1312        eval ExeNameOut=\${config_Executable_${comp}[1]}
1313
1314        # Not possible if oasis has an executable (i.e old version of oasis3)
1315        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
1316          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
1317          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
1318          IGCM_debug_Verif_Exit
1319        fi
1320
1321        # Only if we really have an executable for the component :
1322        if [ "X${ExeNameOut}" != X\"\" ] ; then
1323
1324          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1325          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1326          eval comp_proc_nod_loc=\${${comp}_PROC_NOD}
1327
1328          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1329          echo ""  >> script_${ExeNameOut}.ksh
1330          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
1331
1332            # Check if the number of threads is correct
1333            case ${comp_proc_omp_loc} in
1334            2|4|8|16)
1335              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1336              ;;
1337            *)
1338              IGCM_debug_Exit "ERROR with OMP parameters !"
1339              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1340              IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
1341              IGCM_debug_Verif_Exit
1342              ;;
1343            esac
1344            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1345            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1346            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1347            echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1348          fi
1349
1350          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1351          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK )) " >> script_${ExeNameOut}.ksh
1352          echo "MYMPIRANK=\$(printf '%3.3d\n' \${MYMPIRANK})" >> script_${ExeNameOut}.ksh
1353          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}" >> script_${ExeNameOut}.ksh
1354          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1355
1356          if [ ${init_exec} = y ] ; then
1357            EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1358          else
1359            EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1360            init_exec=y
1361          fi
1362
1363          # Build rankfile : method used to assign cores and nodes for the MPI process
1364          # Ex :
1365          #rank 0=curie5296 slot=0,1,2,3
1366          #rank 1=curie5296 slot=4,5,6,7
1367          # Example of final command :
1368          # mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
1369          # with script_lmdz.x.ksh :
1370          # #!/bin/ksh
1371          #export KMP_STACKSIZE=3g
1372          #export KMP_LIBRARY=turnaround
1373          #export MKL_SERIAL=YES
1374          #OMP_NUM_THREADS=4
1375          #./lmdz.x
1376          if [ ${comp_proc_nod_loc} -gt 1 ] ; then
1377              (( offset_comp_proc_loc =  NB_CORE_PER_NODE / (comp_proc_mpi_loc / comp_proc_nod_loc) ))
1378          else
1379              (( offset_comp_proc_loc =  comp_proc_omp_loc ))
1380          fi
1381          for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
1382             (( index_host = current_core / NB_CORE_PER_NODE ))
1383             host_value=${host[${index_host}]}
1384             (( slot =  current_core % NB_CORE_PER_NODE ))
1385             virg=","
1386             string_final=""
1387             for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
1388                 string=$index$virg
1389                 string_final=$string_final$string
1390             done
1391             string_final=$( echo $string_final | sed "s/.$//" )
1392             echo "rank $rank=$host_value slot=$string_final" >> rankfile
1393             (( rank = rank + 1 ))
1394             (( current_core = current_core + offset_comp_proc_loc ))
1395          done
1396        fi
1397      done
1398
1399    elif ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "X" ] || [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xccc_mprun" ] ) ; then
1400
1401    # 3 MPI/OpenMP ccc_mprun method
1402
1403    # MPI-OpenMP (MPMD)
1404    # example of run_file
1405    # 71-8 env OMP_NUM_THREADS=8 ./script_lmdz.x.ksh
1406    # 480-1 env OMP_NUM_THREADS=1 ./script_opa.xx.ksh
1407    # 1-1 env OMP_NUM_THREADS=1 ./script_xios.x.ksh
1408
1409      # Loop on the components
1410      for comp in ${config_ListOfComponents[*]} ; do
1411
1412        eval ExeNameIn=\${config_Executable_${comp}[0]}
1413        eval ExeNameOut=\${config_Executable_${comp}[1]}
1414
1415        # Not possible if oasis has an executable (i.e old version of oasis3)
1416        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
1417          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
1418          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
1419          IGCM_debug_Verif_Exit
1420        fi
1421
1422        # Only if we really have an executable for the component :
1423        if [ "X${ExeNameOut}" != X\"\" ] ; then
1424
1425          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1426          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1427
1428          # Build script files
1429
1430          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1431          echo ""  >> script_${ExeNameOut}.ksh
1432          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
1433
1434            # Check if the number of threads is correct
1435            case ${comp_proc_omp_loc} in
1436            2|4|8|12|16|24)
1437              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1438              ;;
1439            *)
1440              IGCM_debug_Exit "ERROR with OMP parameters !"
1441              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1442              IGCM_debug_Print 2 "Only 2,4,8,12,16,24 as number of OMP threads are possible "
1443              IGCM_debug_Verif_Exit
1444              ;;
1445            esac
1446            ### only for LMDZ?
1447            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1448            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1449            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1450            echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1451
1452          fi
1453
1454          # to have out/err per process on different files
1455          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}" >> script_${ExeNameOut}.ksh
1456          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1457
1458          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1459
1460          # Complete run_file
1461
1462          echo "${comp_proc_mpi_loc}-${comp_proc_omp_loc} env OMP_NUM_THREADS=${comp_proc_omp_loc} ./script_${ExeNameOut}.ksh " >>run_file
1463
1464        fi
1465      done
1466
1467      ## variable added to stop after 60s instead of 600s by default.
1468      ## This is used when no error comes from executables and when something stopped an executable without notice.
1469      export SLURM_WAIT=60
1470
1471      ## module advised by TGCC (instead of 2 variables)
1472      module load feature/bridge/heterogenous_mpmd
1473
1474      # set EXECUTION for ccc_mprun case (similar to #1 : MPI only MPMD method)
1475
1476      EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1477
1478      IGCM_sys_Chmod u+x run_file
1479      if ( $DEBUG_sys ) ; then
1480        echo "run_file contains : "
1481        cat run_file
1482      fi
1483
1484    else
1485
1486      IGCM_debug_Print 1 "sys Curie :  choose mpirun or ccc_mprun in config.card for ExecutionModeOnCurie"
1487
1488    fi # 1 2 or 3 if ${OK_PARA_MPMD}
1489
1490  else
1491  # Only one executable (SPMD mode).
1492
1493    for comp in ${config_ListOfComponents[*]} ; do
1494
1495      # Only if we really have an executable for the component :
1496      eval ExeNameOut=\${config_Executable_${comp}[1]}
1497      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1498
1499        # Build script files
1500
1501        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1502        echo ""  >> script_${ExeNameOut}.ksh
1503        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1504
1505        if ( ${OK_PARA_OMP} ) ; then
1506          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1507          echo ""  >> script_${ExeNameOut}.ksh
1508          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1509          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1510          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1511          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1512        fi
1513
1514        if  ( ${OK_PARA_MPI} ) ; then
1515          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1516          # Default : ccc_mprun used if nb_proc gt 1
1517          # to have out/err per process on different files
1518          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
1519          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1520          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1521        else
1522          # Default : ccc_mprun is NOT used if nb_proc eq 1
1523          # to have out/err per process on different files
1524          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1525          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1526          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
1527        fi
1528
1529        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
1530        cat script_${ExeNameOut}.ksh
1531
1532      fi
1533
1534    done
1535
1536  fi # ${OK_PARA_MPMD}
1537
1538  IGCM_debug_Print 1 "sys Curie : execution command is "
1539  IGCM_debug_Print 1 "$EXECUTION"
1540
1541  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1542}
1543
1544#D-#==================================================
1545#D-function IGCM_sys_check_path
1546#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1547#D-* do not point to an important use directory. Stop immediately in that case.
1548#D-* Examples:
1549#D-
1550function IGCM_sys_check_path {
1551  IGCM_debug_PushStack "IGCM_sys_check_path"
1552  if ( $DEBUG_sys ) ; then
1553    echo "IGCM_sys_check_path"
1554  fi
1555
1556  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${CCCWORKDIR} ] || [ X${RUN_DIR_PATH} = X${CCCSCRATCHDIR} ] || [ X${RUN_DIR_PATH} = X${CCCSTOREDIR} ] ) ; then
1557    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1558    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1559    IGCM_debug_Exit "This will stop the job"
1560  fi
1561  IGCM_debug_PopStack "IGCM_sys_check_path"
1562}
1563
1564#D-#==================================================
1565#D-function IGCM_sys_check_quota
1566#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1567#D-* Examples:
1568#D-
1569function IGCM_sys_check_quota {
1570  IGCM_debug_PushStack "IGCM_sys_check_quota"
1571  if ( $DEBUG_sys ) ; then
1572    echo "IGCM_sys_check_quota"
1573  fi
1574  # Limit of quota (in %)
1575  limit_quota=90
1576
1577  # Check of the volume
1578  volume_quota=$(ccc_quota | grep ' scratch' | gawk '{print $2}')
1579  volume_avail=$(ccc_quota | grep ' scratch' | gawk '{print $3}')
1580
1581  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1582
1583    unit_avail=${volume_avail: -1}
1584    unit_quota=${volume_quota: -1}
1585
1586    if [ "${unit_quota}" = "*" ] ; then
1587      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1588      IGCM_debug_Print 1 "More than 100% of your quota is used"
1589      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1590      IGCM_debug_Print 1 "You must have more than 10% available to run"
1591      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1592      IGCM_debug_Verif_Exit
1593    fi
1594
1595    temp_avail=${volume_avail%%${volume_avail: -1}*}
1596    temp_quota=${volume_quota%%${volume_quota: -1}*}
1597
1598    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1599
1600    # Convertion
1601      if [ ${volume_avail: -1} = "T" ] ; then
1602        (( temp_avail = temp_avail * 1000000000000 ))
1603      elif [ ${volume_avail: -1} = "G" ] ; then
1604        (( temp_avail = temp_avail * 1000000000 ))
1605      elif [ ${volume_avail: -1} = "M" ] ; then
1606        (( temp_avail = temp_avail * 1000000 ))
1607      elif [ ${volume_avail: -1} = "k" ] ; then
1608        (( temp_avail = temp_avail * 1000 ))
1609      else
1610        (( temp_avail = volume_avail ))
1611      fi
1612      if [ ${volume_quota: -1} = "T" ] ; then
1613        (( temp_quota = temp_quota * 1000000000000 ))
1614      elif [ ${volume_quota: -1} = "G" ] ; then
1615        (( temp_quota = temp_quota * 1000000000 ))
1616      elif [ ${volume_quota: -1} = "M" ] ; then
1617        (( temp_quota = temp_quota * 1000000 ))
1618      elif [ ${volume_quota: -1} = "k" ] ; then
1619        (( temp_quota = temp_quota * 1000 ))
1620      else
1621        (( temp_quota = volume_quota ))
1622      fi
1623    fi
1624
1625    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1626#    echo "volume ratio is " $quota_volume
1627
1628    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1629      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1630      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1631      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1632      IGCM_debug_Print 1 "You must have more than 10% available to run"
1633      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1634      IGCM_debug_Verif_Exit
1635    fi
1636
1637  fi
1638
1639# Check of the number of inodes
1640
1641  inode_quota=$(ccc_quota | grep ' scratch' | gawk '{print $6}')
1642  inode_avail=$(ccc_quota | grep ' scratch' | gawk '{print $7}')
1643
1644  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
1645
1646    unit_avail=${inode_avail: -1}
1647    unit_quota=${inode_quota: -1}
1648
1649    if [ "${unit_quota}" = "*" ] ; then
1650      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1651      IGCM_debug_Print 1 "More than 100% of your quota is used"
1652      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1653      IGCM_debug_Print 1 "You must have more than 10% available to run"
1654      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1655      IGCM_debug_Verif_Exit
1656    fi
1657
1658    temp_avail=${inode_avail%%${inode_avail: -1}*}
1659    temp_quota=${inode_quota%%${inode_quota: -1}*}
1660
1661    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1662
1663    # Convertion
1664      if [ ${inode_avail: -1} = "T" ] ; then
1665        (( temp_avail = temp_avail * 1000000000000 ))
1666      elif [ ${inode_avail: -1} = "G" ] ; then
1667        (( temp_avail = temp_avail * 1000000000 ))
1668      elif [ ${inode_avail: -1} = "M" ] ; then
1669        (( temp_avail = temp_avail * 1000000 ))
1670      elif [ ${inode_avail: -1} = "k" ] ; then
1671        (( temp_avail = temp_avail * 1000 ))
1672      else
1673        (( temp_avail = inode_avail ))
1674      fi
1675
1676      if [ ${inode_quota: -1} = "T" ] ; then
1677        (( temp_quota = temp_quota * 1000000000000 ))
1678      elif [ ${inode_quota: -1} = "G" ] ; then
1679        (( temp_quota = temp_quota * 1000000000 ))
1680      elif [ ${inode_quota: -1} = "M" ] ; then
1681        (( temp_quota = temp_quota * 1000000 ))
1682      elif [ ${inode_quota: -1} = "k" ] ; then
1683        (( temp_quota = temp_quota * 1000 ))
1684      else
1685        (( temp_quota = inode_quota ))
1686      fi
1687    fi
1688    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1689#    echo "inode ratio is " $quota_inode
1690
1691    if [ ${quota_inode} -ge ${limit_quota} ] ; then
1692      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1693      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
1694      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1695      IGCM_debug_Print 1 "You must have more than 10% available to run"
1696      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1697      IGCM_debug_Verif_Exit
1698    fi
1699  fi
1700  IGCM_debug_PopStack "IGCM_sys_check_quota"
1701}
1702
1703#D-#==================================================
1704#D-function IGCM_sys_projectAccounting
1705#D-* Purpose: store project accounting information in a file
1706#D-* Examples:
1707#D-
1708function IGCM_sys_projectAccounting {
1709  IGCM_debug_PushStack "IGCM_sys_projectAccounting"
1710  if ( $DEBUG_sys ) ; then
1711    echo "IGCM_sys_check_quota"
1712  fi
1713
1714  ssh curie91 /usr/bin/ccc_myproject > $1
1715
1716  IGCM_debug_PopStack "IGCM_sys_projectAccounting"
1717}
1718
1719#D-#==================================================
1720#D-function IGCM_sys_getJobSchedulerID
1721#D-* Purpose: Get the job ID during execution
1722#D-* Examples: IGCM_sys_getJobSchedulerID jobSchedulerID
1723#D-
1724function IGCM_sys_getJobSchedulerID {
1725  IGCM_debug_PushStack "IGCM_sys_getJobSchedulerID"
1726  if ( $DEBUG_sys ) ; then
1727    echo "IGCM_sys_getJobSchedulerID"
1728  fi
1729
1730  eval ${1}=${BRIDGE_MSUB_JOBID}
1731
1732  IGCM_debug_PopStack "IGCM_sys_getJobSchedulerID"
1733}
1734
1735#D-#==================================================
1736#D-function IGCM_sys_GetJobID
1737#D-* Purpose: Get the job ID from the JobName
1738#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1739#D-
1740function IGCM_sys_GetJobID {
1741  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1742  if ( $DEBUG_sys ) ; then
1743    echo "IGCM_sys_GetJobID"
1744  fi
1745
1746  # With -f option, the full job name is given in the last column
1747  ID=$( ccc_mstat -f -u $2 | \
1748        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
1749
1750  eval ${3}=${ID}
1751  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1752}
1753
1754#D-#==================================================
1755#D-function IGCM_sys_CountJobInQueue
1756#D-* Purpose: Count number of users job
1757#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1758#D-
1759function IGCM_sys_CountJobInQueue {
1760  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1761  if ( $DEBUG_sys ) ; then
1762    echo "IGCM_sys_CountJobInQueue"
1763  fi
1764
1765  # With -f option, the full job name is given in the last column
1766  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ( $NF ~ JobName ) { x=x+1 } END { print x }' )
1767
1768  eval ${2}=${NbRun}
1769
1770  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1771}
1772
1773#D-#==================================================
1774#D-function IGCM_sys_ListJobInQueue
1775#D-* Purpose: Produce a list of users computing jobs (excluding post-processing)
1776#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
1777#D-
1778function IGCM_sys_ListJobInQueue {
1779  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
1780  if ( $DEBUG_sys ) ; then
1781    echo "IGCM_sys_ListJobInQueue"
1782  fi
1783
1784  # With -f option, the full job name is given in the last column
1785  set -A JobList $( ccc_mstat -f | gawk -v User=$1             \
1786                                        '( $2  == User      && \
1787                                           $NF != /TS/      && \
1788                                           $NF !~ /PACK/    && \
1789                                           $NF !~ /REBUILD/ && \
1790                                           $NF !~ /pack/ )     \
1791                                         { print $NF }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
1792
1793  eval set -A ${2} ${JobList[*]}
1794
1795  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
1796}
1797
1798#D-#==================================================
1799#D-function IGCM_sys_atlas
1800#D-* Purpose: encapsulate atlas call so as to manage error code and curie specificity
1801#D-* Examples:
1802#D-
1803function IGCM_sys_atlas {
1804  IGCM_debug_PushStack "IGCM_sys_atlas" $@
1805  if ( $DEBUG_sys ) ; then
1806    echo "IGCM_sys_atlas :" $@
1807  fi
1808
1809  typeset status
1810
1811  \ccc_mprun atlas $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1812  status=$?
1813  if [ ${status} -gt 0 ] ; then
1814    echo "IGCM_sys_atlas : error code ${status}"
1815    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1816    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1817    IGCM_debug_PopStack "IGCM_sys_atlas"
1818    return 1
1819  else
1820    IGCM_debug_PopStack "IGCM_sys_atlas"
1821    return 0
1822  fi
1823
1824  IGCM_debug_PopStack "IGCM_sys_atlas"
1825}
1826
1827#D-#==================================================
1828#D-function IGCM_sys_rebuild_nemo
1829#D-* Purpose: rebuild nemo parallel files with nemo specific rebuild on curie
1830#D-* Examples:
1831#D-
1832
1833function IGCM_sys_rebuild_nemo {
1834  IGCM_debug_PushStack "IGCM_sys_rebuild_nemo" $@
1835  if ( $DEBUG_sys ) ; then
1836    echo "IGCM_sys_rebuild_nemo :" $@
1837  fi
1838
1839  $( ccc_home -u igcmg)/Tools/curie/bin/rebuild_nemo ${1} ${2}
1840
1841  IGCM_debug_PopStack "IGCM_sys_rebuild_nemo"
1842}
1843
Note: See TracBrowser for help on using the repository browser.