source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_jeanzay.ksh @ 1513

Last change on this file since 1513 was 1513, checked in by acosce, 4 years ago

add specific case for training account (dataproject = for) who are not stored in /rech/ partition - revert previous commit [1511]

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