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

Last change on this file since 1473 was 1473, checked in by mafoipsl, 6 years ago

Consolidation of last commit to use a default project for irene.

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