source: tags/libIGCM_v2.8.4/libIGCM_sys/libIGCM_sys_curie.ksh @ 1456

Last change on this file since 1456 was 1455, checked in by sdipsl, 6 years ago
  • Changes due to unaccessibility of p86ipsl. Things moved to the igcmg shared space.
  • 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: 63.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Curie
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=curie
71# add default project on curie
72typeset PROJECT=$(echo ${BRIDGE_MSUB_PROJECT:=gen0826} | cut -d@ -f1 )
73# jobWarningDelay in seconds
74typeset jobWarningDelay=${BRIDGE_MSUB_MAXTIME}
75
76#D-
77#D-#==================================================
78#D-Program used in libIGCM
79#D-#==================================================
80
81# Submit command
82typeset SUBMIT=${SUBMIT:=ccc_msub}
83# rsync with path
84typeset -r RSYNC=/usr/bin/rsync
85# RSYNC_opt args to rsync
86typeset -r RSYNC_opt="-va"
87# ie storage filesystem
88typeset -r STOREHOST=${MASTER}
89typeset -r REMOTE_RSYNC=/usr/bin/rsync
90
91#====================================================
92# Set environment tools (ferret, nco, cdo, rebuild, ...)
93#====================================================
94if [ X${TaskType} = Xcomputing ] ; then
95  IGCM_debug_Print 1 "Module will be loaded once we know the compiler version"
96else
97  module purge > /dev/null 2>&1
98  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/curie/env_intel17.0.2_curie   > /dev/null 2>&1
99  . $( ccc_home -u igcmg)/MachineEnvironment/curie/env_intel17.0.2_curie   > /dev/null 2>&1
100  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/curie/env_netcdf4.3.3.1_curie > /dev/null 2>&1
101  . $( ccc_home -u igcmg)/MachineEnvironment/curie/env_netcdf4.3.3.1_curie > /dev/null 2>&1
102  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/curie/env_atlas_curie         > /dev/null 2>&1
103  . $( ccc_home -u igcmg)/MachineEnvironment/curie/env_atlas_curie         > /dev/null 2>&1
104  export PCMDI_MP=/ccc/work/cont003/igcmg/igcmg/PCMDI-MP
105  export UVCDAT_ANONYMOUS_LOG=FALSE
106fi
107
108# Use CMIP6 storage space when using CMIP6 cpu ressources
109[[ X"$( echo ${PROJECT} | grep cmip6 )" != "X" && ! $(module list --terse 2>&1 | grep dfldatadir/gencmip6) ]] && module switch dfldatadir dfldatadir/gencmip6
110
111# FYI
112[ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
113[ ! X${TaskType} = Xchecking ] && module list
114
115# for rebuild, AddNoise and AddPertu3DOCE
116export PATH=${PATH}:$(ccc_home -u igcmg)/Tools/curie/bin
117##export PATH=${PATH}:/ccc/cont003/home/igcmg/igcmg/Tools/curie/bin
118
119#====================================================
120# Specific for ocean additionnal diagnostic
121export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
122export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
123
124#====================================================
125# Host specific DIRECTORIES
126#====================================================
127
128# ============ CESIUM START ============ #
129
130#====================================================
131#- Mirror libIGCM from titane to cesium if needed
132#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
133#if [ ! ${ROOTSYS} = "home" ] ; then
134#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
135#else
136#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
137#fi
138
139#====================================================
140#- libIGCM_POST
141#if ( ${MirrorlibIGCM} ) ; then
142#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
143#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
144#else
145#  typeset -r libIGCM_POST=${libIGCM}
146#fi
147
148# ============ CESIUM  END  ============ #
149
150#====================================================
151#- MirrorlibIGCM for frontend
152typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
153
154#====================================================
155#- libIGCM_POST for frontend
156typeset -r libIGCM_POST=${libIGCM}
157
158#====================================================
159#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
160typeset -r R_EXE="${MODIPSL}/bin"
161
162#====================================================
163#- SUBMIT_DIR : submission dir
164typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${BRIDGE_MSUB_PWD}}
165
166#====================================================
167#- IN
168typeset -r R_IN=${R_IN:=/ccc/work/cont003/igcmg/igcmg/IGCM}
169typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
170
171#====================================================
172#- RUN_DIR_PATH : Temporary working directory (=> TMP)
173typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${BRIDGE_MSUB_JOBID}_${$}}
174
175#====================================================
176#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
177typeset -r OUTCOMMAND_PATH=/tmp
178
179#====================================================
180#- HOST_MPIRUN_COMMAND
181typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time ccc_mprun -E-K1 "}
182
183#====================================================
184#- Max number of arguments passed to nco operator or demigration command
185UNIX_MAX_LIMIT=360
186
187#====================================================
188#- set PackDefault to true on curie
189PackDefault=true
190
191#====================================================
192#- Default number of MPI task for IPSL coupled model
193#- required for backward compatibility
194#-
195DEFAULT_NUM_PROC_OCE=5
196DEFAULT_NUM_PROC_CPL=1
197(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
198
199#====================================================
200#- Number of computing cores per node
201#-
202NB_CORE_PER_NODE=16
203
204#D-#==================================================
205#D-function IGCM_sys_defineArchives
206#D-* Purpose:
207#D-* Define ARCHIVE : Dedicated to large files
208#D-* Define STORAGE : Dedicated to small/medium files
209#D-* Define R_OUT   : Output tree located on ARCHIVE
210#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
211#D-* Define R_BUF   : Output tree located on SCRATCHDIR hosting files waiting for rebuild or pack processes
212#D-* if SpaceName=TEST everything is stored on SCRATCHDIR
213#D-* Examples:
214#D-
215function IGCM_sys_defineArchives {
216  IGCM_debug_PushStack "IGCM_sys_defineArchives"
217
218  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
219    #====================================================
220    #- ARCHIVE (dedicated to large files)
221    ARCHIVE=${config_UserChoices_ARCHIVE}
222  else
223    #====================================================
224    #- ARCHIVE (dedicated to large files)
225    ARCHIVE=${CCCSTOREDIR}
226  fi
227
228  if [ ! X${config_UserChoices_STORAGE} = X ]; then
229    #====================================================
230    #- STORAGE (dedicated to small/medium files)
231    STORAGE=${config_UserChoices_STORAGE}
232  else
233    #====================================================
234    #- STORAGE (dedicated to small/medium files)
235    STORAGE=${CCCWORKDIR}
236  fi
237
238  if [ X${config_UserChoices_SpaceName} = XTEST ]; then
239    #====================================================
240    #- R_OUT
241    R_OUT=${SCRATCHDIR}/IGCM_OUT
242
243    #====================================================
244    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
245    R_FIG=${SCRATCHDIR}/IGCM_OUT
246
247    IGCM_debug_Print 1 "SpaceName=TEST ==> OVERRULE destination path directories"
248
249  else
250    #====================================================
251    #- R_OUT
252    R_OUT=${ARCHIVE}/IGCM_OUT
253
254    #====================================================
255    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
256    R_FIG=${STORAGE}/IGCM_OUT
257  fi
258
259  #====================================================
260  #- CMIP6 (hosting CMIP6 files produced by XIOS2 and configured by dr2xml)
261  CMIP6_BUF=${STORAGE}/IGCM_OUT
262
263  #====================================================
264  #- R_BUF (ONLY FOR double copy an scratch)
265  R_BUF=${SCRATCHDIR}/IGCM_OUT
266
267  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
268  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
269  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
270
271  IGCM_debug_PopStack "IGCM_sys_defineArchives"
272}
273
274#D-#==================================================
275#D-function IGCM_sys_RshArchive
276#D-* Purpose: Archive rsh command
277#D-* Examples:
278#D-
279function IGCM_sys_RshArchive {
280  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
281  /bin/ksh <<-EOF
282    ${@}
283EOF
284  status=$?
285  if [ ${status} -gt 0 ] ; then
286    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
287    IGCM_debug_Exit "IGCM_sys_RshArchive"
288  fi
289  IGCM_debug_PopStack "IGCM_sys_RshArchive"
290}
291
292#D-#==================================================
293#D-function IGCM_sys_RshArchive_NoError
294#D-* Purpose: Archive rsh command, without error
295#D-*          used only in monitoring.job
296#D-* Examples:
297#D-
298function IGCM_sys_RshArchive_NoError {
299  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
300  /bin/ksh <<-EOF
301    ${@} 2> /dev/null
302EOF
303  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
304}
305
306#D-#==================================================
307#D-function IGCM_sys_MkdirArchive
308#D-* Purpose: Mkdir on Archive
309#D-* Examples:
310#D-
311function IGCM_sys_MkdirArchive {
312  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
313  if ( $DEBUG_sys ) ; then
314    echo "IGCM_sys_MkdirArchive :" $@
315  fi
316  #- creation de repertoire sur le serveur fichier
317  if [ ! -d ${1} ]; then
318    \mkdir -p $1
319    status=$?
320
321    if [ ${status} -gt 0 ] ; then
322      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
323      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
324    fi
325  fi
326  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
327}
328
329#D-#==================================================
330#D-function IGCM_sys_TestDirArchive
331#D-* Purpose: Test Directory that must exists on Archive
332#D-* Examples:
333#D-
334function IGCM_sys_TestDirArchive {
335  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
336  if ( $DEBUG_sys ) ; then
337    echo "IGCM_sys_TestDirArchive :" $@
338  fi
339  typeset ExistFlag
340  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
341  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
342  return ${ExistFlag}
343}
344
345#D-#==================================================
346#D-function IGCM_sys_IsFileArchived
347#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
348#D-* Examples:
349#D-
350function IGCM_sys_IsFileArchived {
351  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
352  if ( $DEBUG_sys ) ; then
353    echo "IGCM_sys_IsFileArchived :" $@
354  fi
355  typeset IsArchivedFlag
356  IsArchivedFlag=$( [ X$( echo $@ | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
357  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
358
359  return ${IsArchivedFlag}
360}
361
362#D-#==================================================
363#D-function IGCM_sys_TestFileArchive
364#D-* Purpose: Test file that must NOT EXISTS on Archive
365#D-* Examples:
366#D-
367function IGCM_sys_TestFileArchive {
368  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
369  typeset ExistFlag
370  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
371  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
372
373  return ${ExistFlag}
374}
375
376#D-#==================================================
377#D-function IGCM_sys_CountFileArchive
378#D-* Purpose: Count files on Archive filesystem
379#D-* Examples:
380#D-
381function IGCM_sys_CountFileArchive {
382  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
383  ls ${@} 2>/dev/null | wc -l
384  if [ $? -gt 0 ] ; then
385    echo "IGCM_sys_CountFileArchive : erreur."
386  fi
387  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
388}
389
390#D-#==================================================
391#D-function IGCM_sys_Tree
392#D-* Purpose: Tree directories with files on ${ARCHIVE}
393#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
394#D-
395function IGCM_sys_Tree {
396  IGCM_debug_PushStack "IGCM_sys_Tree" $@
397  if ( $DEBUG_sys ) ; then
398    echo "IGCM_sys_Tree :" $@
399  fi
400
401  \ls -lR ${@}
402
403  IGCM_debug_PopStack "IGCM_sys_Tree"
404}
405
406#D-#==================================================
407#D-function IGCM_sys_Qsub
408#D-* Purpose: Qsub new job
409#D-* Examples:
410#D-
411function IGCM_sys_Qsub {
412  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
413  if ( $DEBUG_sys ) ; then
414    echo "IGCM_sys_Qsub :" $@
415  fi
416  typeset options status
417  options="-o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output}"
418
419  /usr/bin/ccc_msub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
420  status=$?
421
422  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
423  if [ ${status} -gt 0 ] ; then
424    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
425    IGCM_debug_Exit "IGCM_sys_Qsub"
426  else
427    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
428  fi
429  IGCM_debug_PopStack "IGCM_sys_Qsub"
430}
431
432#D-#==================================================
433#D-function IGCM_sys_QsubPost
434#D-* Purpose: Qsub new job on scalaire
435#D-* Examples:
436#D-
437function IGCM_sys_QsubPost {
438  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
439  if ( $DEBUG_sys ) ; then
440    echo "IGCM_sys_QsubPost :" $@
441  fi
442  typeset options status
443
444  # EASIER TO DO THIS INSTEAD OF DUPLICATING libIGCM_sys_curie.ksh
445  case $( hostname -s ) in
446  curie*)
447    options="-Q normal -A ${PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out";;
448  airain*)
449    options="-q ivybridge -A dsm -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out"
450  esac
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_home -u igcmg)/Tools/curie/bin/thredds_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
936      ## /ccc/cont003/home/igcmg/igcmg/Tools/curie/bin/thredds_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
937      status=$?
938    else
939      $(ccc_home -u igcmg)/Tools/curie/bin/thredds_rm public/${LOGIN}/${R_DODS} # > out_dods_rm 2>&1
940      ## /ccc/cont003/home/igcmg/igcmg/Tools/curie/bin/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_home -u igcmg)/Tools/curie/bin/thredds_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
975    ## /ccc/cont003/home/igcmg/igcmg/Tools/curie/bin/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      . $(ccc_home -u igcmg)/MachineEnvironment/curie/env_intel17.0.2_curie   > /dev/null 2>&1
1075      ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/curie/env_intel17.0.2_curie   > /dev/null 2>&1
1076  elif [ X${compilerVersion} = XV14 ] ; then
1077      . $(ccc_home -u igcmg)/MachineEnvironment/curie/env_intel14.0.3_curie   > /dev/null 2>&1
1078      ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/curie/env_intel14.0.3_curie   > /dev/null 2>&1
1079  else
1080    IGCM_debug_Exit "This compiler version is not yet supported : ${compilerVersion}"
1081  fi
1082  . $(ccc_home -u igcmg)/MachineEnvironment/curie/env_netcdf4.3.3.1_curie > /dev/null 2>&1
1083  ##. /ccc/cont003/home/igcmg/igcmg/MachineEnvironment/curie/env_netcdf4.3.3.1_curie > /dev/null 2>&1
1084
1085  # Keep track of this
1086  [ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
1087  [ ! X${TaskType} = Xchecking ] && module list
1088
1089# --------------------------------------------------------------------
1090#D- MPI specifications
1091# --------------------------------------------------------------------
1092
1093# --------------------------------------------------------------------
1094#D- Other specifications
1095# --------------------------------------------------------------------
1096
1097  ulimit -s unlimited
1098
1099  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1100}
1101
1102############################################################
1103# Desactivate Running Environnment Variables
1104
1105#D-#==================================================
1106#D-function IGCM_sys_desactiv_variables
1107#D-* Purpose: unset environement variables after execution
1108#D-* Examples:
1109#D-
1110function IGCM_sys_desactiv_variables {
1111  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1112  if ( $DEBUG_sys ) ; then
1113    echo "IGCM_sys_desactiv_variables"
1114  fi
1115# --------------------------------------------------------------------
1116#D- MPI specifications
1117# --------------------------------------------------------------------
1118
1119# --------------------------------------------------------------------
1120#D- Other specifications
1121# --------------------------------------------------------------------
1122
1123  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1124}
1125
1126############################################################
1127# Update job headers to be used by the scheduler
1128
1129#D-#==================================================
1130#D-function IGCM_sys_updateHeaders
1131#D-* Purpose: Update job headers to be used by the scheduler
1132#D-* Examples: IGCM_sys_updateHeaders /path/to/Job_MYEXP
1133#D-
1134function IGCM_sys_updateHeaders {
1135  IGCM_debug_PushStack "IGCM_sys_updateHeaders"
1136  if ( $DEBUG_sys ) ; then
1137    echo "IGCM_sys_updateHeaders"
1138  fi
1139  typeset file
1140  file=$1
1141
1142  if [ ${executionType} -eq 1 ] ; then
1143    # MPMD + MPI
1144    sed -e "/::openMPthreads::/d"                  \
1145        -e "s/::JobNumProcTot::/${coreNumber}/"    \
1146        -e "/#MSUB -x/d"                           \
1147        -e "/--cpu_bind=none/d"                    \
1148      ${file} > ${file}.tmp
1149
1150  elif [ ${executionType} -eq 2 ] ; then
1151    # MPMD + MPI + OMP : mpirun/ccc_mprun/error
1152    if ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "X" ] || [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xmpirun" ] ) ; then
1153      sed -e "/::openMPthreads::/d"                  \
1154          -e "s/::JobNumProcTot::/${coreNumber}/"    \
1155        ${file} > ${file}.tmp
1156    elif ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xccc_mprun" ] ) ; then
1157      sed -e "/::openMPthreads::/d"                  \
1158          -e "s/::JobNumProcTot::/${coreNumber}/"    \
1159          -e "/--cpu_bind=none/d"                    \
1160        ${file} > ${file}.tmp
1161    else
1162     IGCM_debug_Print 1 "You have to set ExecutionModeOnCurie=ccc_mprun or mpirun in config.card"
1163     IGCM_debug_Exit "IGCM_sys_updateHeaders"
1164    fi
1165  elif [ ${executionType} -eq 3 ] ; then
1166    # SPMD + MPI/OMP
1167    sed -e "s/::openMPthreads::/${openMPthreads}/" \
1168        -e "s/::JobNumProcTot::/${mpiTasks}/"      \
1169        -e "/#MSUB -x/d"                           \
1170        -e "/--cpu_bind=none/d"                    \
1171      ${file} > ${file}.tmp
1172
1173  elif [ ${executionType} -eq 4 ] ; then
1174    # SPMD + MPI only
1175    sed -e "s/::JobNumProcTot::/${mpiTasks}/"      \
1176        -e "/::openMPthreads::/d"                  \
1177        -e "/#MSUB -x/d"                           \
1178        -e "/--cpu_bind=none/d"                    \
1179      ${file} > ${file}.tmp
1180
1181  elif [ ${executionType} -eq 5 ] ; then
1182    # SPMD + OMP only
1183    sed -e "s/::openMPthreads::/${openMPthreads}/" \
1184        -e "/::JobNumProcTot::/d"                  \
1185        -e "/#MSUB -x/d"                           \
1186        -e "/--cpu_bind=none/d"                    \
1187      ${file} > ${file}.tmp
1188
1189  elif [ ${executionType} -eq 6 ] ; then
1190    # SEQUENTIAL THEN
1191    sed -e "s/::JobNumProcTot::/1/"                \
1192        -e "/::openMPthreads::/d"                  \
1193        -e "/#MSUB -x/d"                           \
1194        -e "/--cpu_bind=none/d"                    \
1195      ${file} > ${file}.tmp
1196
1197  fi
1198
1199  IGCM_sys_Mv ${file}.tmp ${file}
1200
1201  IGCM_debug_PopStack "IGCM_sys_updateHeaders"
1202}
1203
1204############################################################
1205# Build MPI/OMP scripts run file (dummy function)
1206
1207#D-#==================================================
1208#D-function IGCM_sys_build_run_file
1209#D-* Purpose: build run file (deprecated)
1210#D-* Examples:
1211#D-
1212function IGCM_sys_build_run_file {
1213  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1214}
1215
1216############################################################
1217# Build MPI/OMP scripts
1218
1219#D-#==================================================
1220#D-function IGCM_sys_build_execution_scripts
1221#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1222#D-* Examples:
1223#D-
1224function IGCM_sys_build_execution_scripts
1225{
1226  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1227  if ( $DEBUG_sys ) ; then
1228    echo "IGCM_sys_build_execution_scripts " $@
1229  fi
1230
1231  EXECUTION=${HOST_MPIRUN_COMMAND}
1232
1233  if ( ${OK_PARA_MPMD} ) ; then
1234
1235    # MPMD mode
1236    # 1 MPI only
1237    # 2 MPI/OpenMP mpirun method
1238    # 3 MPI/OpenMP ccc_mprun method
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
1248      # Build run_file
1249
1250      # First loop on the components for the coupler ie oasis (only if oasis3)
1251      # the coupler ie oasis3 must be the first one
1252      for comp in ${config_ListOfComponents[*]} ; do
1253
1254        eval ExeNameIn=\${config_Executable_${comp}[0]}
1255        eval ExeNameOut=\${config_Executable_${comp}[1]}
1256
1257        # for CPL component only
1258        if [ "X${comp}" = "XCPL" ] && [ "X${ExeNameOut}" != X\"\" ] ; then
1259
1260          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1261          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1262          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1263        fi
1264      done
1265
1266      # Then second loop on the components
1267      for comp in ${config_ListOfComponents[*]} ; do
1268
1269        eval ExeNameIn=\${config_Executable_${comp}[0]}
1270        eval ExeNameOut=\${config_Executable_${comp}[1]}
1271
1272        # Only if we really have an executable for the component and not the coupler ie oasis:
1273        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1274
1275          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1276          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1277          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1278        fi
1279      done
1280
1281      EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1282
1283      IGCM_sys_Chmod u+x run_file
1284      if ( $DEBUG_sys ) ; then
1285        echo "run_file contains : "
1286        cat run_file
1287      fi
1288
1289    elif ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "X" ] || [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xmpirun" ] ) ; then
1290
1291    # 2 MPI/OpenMP mpirun method
1292
1293      # Use of mpirun instead of ccc_mprun
1294      EXECUTION="time mpirun"
1295
1296      #  Hosts treatment
1297      ${EXECUTION} hostname | sort | uniq > hosts.tmp
1298
1299      i=0
1300      rm -f hosts rankfile
1301      IGCM_debug_Print 1 "sys Curie, Hosts available :"
1302      for nodes in `cat hosts.tmp`
1303      do
1304        host[$i]=$nodes
1305        echo "${host[$i]}" >> hosts
1306        IGCM_debug_Print 1 ${host[$i]}
1307        i=$((i+1))
1308      done
1309      rm -f hosts.tmp
1310
1311      listnodes=${host[*]}
1312
1313      EXECUTION="${EXECUTION} -hostfile hosts -rankfile rankfile"
1314
1315      # Initialisation
1316      rank=0
1317      current_core=0
1318      init_exec=n
1319
1320      # Loop on the components
1321      for comp in ${config_ListOfComponents[*]} ; do
1322
1323        eval ExeNameIn=\${config_Executable_${comp}[0]}
1324        eval ExeNameOut=\${config_Executable_${comp}[1]}
1325
1326        # Not possible if oasis has an executable (i.e old version of oasis3)
1327        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
1328          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
1329          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
1330          IGCM_debug_Verif_Exit
1331        fi
1332
1333        # Only if we really have an executable for the component :
1334        if [ "X${ExeNameOut}" != X\"\" ] ; then
1335
1336          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1337          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1338          eval comp_proc_nod_loc=\${${comp}_PROC_NOD}
1339
1340          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1341          echo ""  >> script_${ExeNameOut}.ksh
1342          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
1343
1344            # Check if the number of threads is correct
1345            case ${comp_proc_omp_loc} in
1346            2|4|8|16)
1347              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1348              ;;
1349            *)
1350              IGCM_debug_Exit "ERROR with OMP parameters !"
1351              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1352              IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
1353              IGCM_debug_Verif_Exit
1354              ;;
1355            esac
1356            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1357            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1358            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1359            echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1360          fi
1361
1362          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1363          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK )) " >> script_${ExeNameOut}.ksh
1364          echo "MYMPIRANK=\$(printf '%3.3d\n' \${MYMPIRANK})" >> script_${ExeNameOut}.ksh
1365          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}" >> script_${ExeNameOut}.ksh
1366          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1367
1368          if [ ${init_exec} = y ] ; then
1369            EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1370          else
1371            EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1372            init_exec=y
1373          fi
1374
1375          # Build rankfile : method used to assign cores and nodes for the MPI process
1376          # Ex :
1377          #rank 0=curie5296 slot=0,1,2,3
1378          #rank 1=curie5296 slot=4,5,6,7
1379          # Example of final command :
1380          # mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
1381          # with script_lmdz.x.ksh :
1382          # #!/bin/ksh
1383          #export KMP_STACKSIZE=3g
1384          #export KMP_LIBRARY=turnaround
1385          #export MKL_SERIAL=YES
1386          #OMP_NUM_THREADS=4
1387          #./lmdz.x
1388          if [ ${comp_proc_nod_loc} -gt 1 ] ; then
1389              (( offset_comp_proc_loc =  NB_CORE_PER_NODE / (comp_proc_mpi_loc / comp_proc_nod_loc) ))
1390          else
1391              (( offset_comp_proc_loc =  comp_proc_omp_loc ))
1392          fi
1393          for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
1394             (( index_host = current_core / NB_CORE_PER_NODE ))
1395             host_value=${host[${index_host}]}
1396             (( slot =  current_core % NB_CORE_PER_NODE ))
1397             virg=","
1398             string_final=""
1399             for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
1400                 string=$index$virg
1401                 string_final=$string_final$string
1402             done
1403             string_final=$( echo $string_final | sed "s/.$//" )
1404             echo "rank $rank=$host_value slot=$string_final" >> rankfile
1405             (( rank = rank + 1 ))
1406             (( current_core = current_core + offset_comp_proc_loc ))
1407          done
1408        fi
1409      done
1410
1411    elif ( [ "X${config_UserChoices_ExecutionModeOnCurie}" = "Xccc_mprun" ] ) ; then
1412
1413    # 3 MPI/OpenMP ccc_mprun method
1414
1415    # MPI-OpenMP (MPMD)
1416    # example of run_file
1417    # 71-8 env OMP_NUM_THREADS=8 ./script_lmdz.x.ksh
1418    # 480-1 env OMP_NUM_THREADS=1 ./script_opa.xx.ksh
1419    # 1-1 env OMP_NUM_THREADS=1 ./script_xios.x.ksh
1420
1421      # Loop on the components
1422      for comp in ${config_ListOfComponents[*]} ; do
1423
1424        eval ExeNameIn=\${config_Executable_${comp}[0]}
1425        eval ExeNameOut=\${config_Executable_${comp}[1]}
1426
1427        # Not possible if oasis has an executable (i.e old version of oasis3)
1428        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
1429          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
1430          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
1431          IGCM_debug_Verif_Exit
1432        fi
1433
1434        # Only if we really have an executable for the component :
1435        if [ "X${ExeNameOut}" != X\"\" ] ; then
1436
1437          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1438          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1439
1440          # Build script files
1441
1442          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1443          echo ""  >> script_${ExeNameOut}.ksh
1444          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
1445
1446            # Check if the number of threads is correct
1447            case ${comp_proc_omp_loc} in
1448            2|4|8|16)
1449              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1450              ;;
1451            *)
1452              IGCM_debug_Exit "ERROR with OMP parameters !"
1453              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1454              IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
1455              IGCM_debug_Verif_Exit
1456              ;;
1457            esac
1458            ### only for LMDZ?
1459            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1460            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1461            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1462            echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1463
1464          fi
1465
1466          # to have out/err per process on different files
1467          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}" >> script_${ExeNameOut}.ksh
1468          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1469
1470          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1471
1472          # Complete run_file
1473
1474          echo "${comp_proc_mpi_loc}-${comp_proc_omp_loc} env OMP_NUM_THREADS=${comp_proc_omp_loc} ./script_${ExeNameOut}.ksh " >>run_file
1475
1476        fi
1477      done
1478
1479      ## variable added to stop after 60s instead of 600s by default.
1480      ## This is used when no error comes from executables and when something stopped an executable without notice.
1481      export SLURM_WAIT=60
1482
1483      ## module advised by TGCC (instead of 2 variables)
1484      module load feature/bridge/heterogenous_mpmd
1485
1486      # set EXECUTION for ccc_mprun case (similar to #1 : MPI only MPMD method)
1487
1488      EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1489
1490      IGCM_sys_Chmod u+x run_file
1491      if ( $DEBUG_sys ) ; then
1492        echo "run_file contains : "
1493        cat run_file
1494      fi
1495
1496    else
1497
1498      IGCM_debug_Print 1 "sys Curie :  choose mpirun or ccc_mprun in config.card for ExecutionModeOnCurie"
1499
1500    fi # 1 2 or 3 if ${OK_PARA_MPMD}
1501
1502  else
1503  # Only one executable (SPMD mode).
1504
1505    for comp in ${config_ListOfComponents[*]} ; do
1506
1507      # Only if we really have an executable for the component :
1508      eval ExeNameOut=\${config_Executable_${comp}[1]}
1509      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1510
1511        # Build script files
1512
1513        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1514        echo ""  >> script_${ExeNameOut}.ksh
1515        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1516
1517        if ( ${OK_PARA_OMP} ) ; then
1518          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1519          echo ""  >> script_${ExeNameOut}.ksh
1520          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1521          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1522          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1523          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1524        fi
1525
1526        if  ( ${OK_PARA_MPI} ) ; then
1527          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1528          # Default : ccc_mprun used if nb_proc gt 1
1529          # to have out/err per process on different files
1530          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
1531          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1532          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1533        else
1534          # Default : ccc_mprun is NOT used if nb_proc eq 1
1535          # to have out/err per process on different files
1536          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1537          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1538          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
1539        fi
1540
1541        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
1542        cat script_${ExeNameOut}.ksh
1543
1544      fi
1545
1546    done
1547
1548  fi # ${OK_PARA_MPMD}
1549
1550  IGCM_debug_Print 1 "sys Curie : execution command is "
1551  IGCM_debug_Print 1 "$EXECUTION"
1552
1553  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1554}
1555
1556#D-#==================================================
1557#D-function IGCM_sys_check_path
1558#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1559#D-* do not point to an important use directory. Stop immediately in that case.
1560#D-* Examples:
1561#D-
1562function IGCM_sys_check_path {
1563  IGCM_debug_PushStack "IGCM_sys_check_path"
1564  if ( $DEBUG_sys ) ; then
1565    echo "IGCM_sys_check_path"
1566  fi
1567
1568  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${WORKDIR} ] || [ X${RUN_DIR_PATH} = X${SCRATCHDIR} ] || [ X${RUN_DIR_PATH} = X${CCCWORKDIR} ] || [ X${RUN_DIR_PATH} = X${CCCSTOREDIR} ] ) ; then
1569    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1570    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1571    IGCM_debug_Exit "This will stop the job"
1572  fi
1573  IGCM_debug_PopStack "IGCM_sys_check_path"
1574}
1575
1576#D-#==================================================
1577#D-function IGCM_sys_check_quota
1578#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1579#D-* Examples:
1580#D-
1581function IGCM_sys_check_quota {
1582  IGCM_debug_PushStack "IGCM_sys_check_quota"
1583  if ( $DEBUG_sys ) ; then
1584    echo "IGCM_sys_check_quota"
1585  fi
1586  # Limit of quota (in %)
1587  limit_quota=90
1588
1589  # Check of the volume
1590  volume_quota=$(ccc_quota | grep ' scratch' | gawk '{print $2}')
1591  volume_avail=$(ccc_quota | grep ' scratch' | gawk '{print $3}')
1592
1593  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1594
1595    unit_avail=${volume_avail: -1}
1596    unit_quota=${volume_quota: -1}
1597
1598    if [ "${unit_quota}" = "*" ] ; then
1599      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1600      IGCM_debug_Print 1 "More than 100% of your quota is used"
1601      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1602      IGCM_debug_Print 1 "You must have more than 10% available to run"
1603      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1604      IGCM_debug_Verif_Exit
1605    fi
1606
1607    temp_avail=${volume_avail%%${volume_avail: -1}*}
1608    temp_quota=${volume_quota%%${volume_quota: -1}*}
1609
1610    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1611
1612    # Convertion
1613      if [ ${volume_avail: -1} = "T" ] ; then
1614        (( temp_avail = temp_avail * 1000000000000 ))
1615      elif [ ${volume_avail: -1} = "G" ] ; then
1616        (( temp_avail = temp_avail * 1000000000 ))
1617      elif [ ${volume_avail: -1} = "M" ] ; then
1618        (( temp_avail = temp_avail * 1000000 ))
1619      elif [ ${volume_avail: -1} = "k" ] ; then
1620        (( temp_avail = temp_avail * 1000 ))
1621      else
1622        (( temp_avail = volume_avail ))
1623      fi
1624      if [ ${volume_quota: -1} = "T" ] ; then
1625        (( temp_quota = temp_quota * 1000000000000 ))
1626      elif [ ${volume_quota: -1} = "G" ] ; then
1627        (( temp_quota = temp_quota * 1000000000 ))
1628      elif [ ${volume_quota: -1} = "M" ] ; then
1629        (( temp_quota = temp_quota * 1000000 ))
1630      elif [ ${volume_quota: -1} = "k" ] ; then
1631        (( temp_quota = temp_quota * 1000 ))
1632      else
1633        (( temp_quota = volume_quota ))
1634      fi
1635    fi
1636
1637    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1638#    echo "volume ratio is " $quota_volume
1639
1640    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1641      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1642      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1643      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1644      IGCM_debug_Print 1 "You must have more than 10% available to run"
1645      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1646      IGCM_debug_Verif_Exit
1647    fi
1648
1649  fi
1650
1651# Check of the number of inodes
1652
1653  inode_quota=$(ccc_quota | grep ' scratch' | gawk '{print $6}')
1654  inode_avail=$(ccc_quota | grep ' scratch' | gawk '{print $7}')
1655
1656  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
1657
1658    unit_avail=${inode_avail: -1}
1659    unit_quota=${inode_quota: -1}
1660
1661    if [ "${unit_quota}" = "*" ] ; then
1662      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1663      IGCM_debug_Print 1 "More than 100% of your quota is used"
1664      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1665      IGCM_debug_Print 1 "You must have more than 10% available to run"
1666      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1667      IGCM_debug_Verif_Exit
1668    fi
1669
1670    temp_avail=${inode_avail%%${inode_avail: -1}*}
1671    temp_quota=${inode_quota%%${inode_quota: -1}*}
1672
1673    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1674
1675    # Convertion
1676      if [ ${inode_avail: -1} = "T" ] ; then
1677        (( temp_avail = temp_avail * 1000000000000 ))
1678      elif [ ${inode_avail: -1} = "G" ] ; then
1679        (( temp_avail = temp_avail * 1000000000 ))
1680      elif [ ${inode_avail: -1} = "M" ] ; then
1681        (( temp_avail = temp_avail * 1000000 ))
1682      elif [ ${inode_avail: -1} = "k" ] ; then
1683        (( temp_avail = temp_avail * 1000 ))
1684      else
1685        (( temp_avail = inode_avail ))
1686      fi
1687
1688      if [ ${inode_quota: -1} = "T" ] ; then
1689        (( temp_quota = temp_quota * 1000000000000 ))
1690      elif [ ${inode_quota: -1} = "G" ] ; then
1691        (( temp_quota = temp_quota * 1000000000 ))
1692      elif [ ${inode_quota: -1} = "M" ] ; then
1693        (( temp_quota = temp_quota * 1000000 ))
1694      elif [ ${inode_quota: -1} = "k" ] ; then
1695        (( temp_quota = temp_quota * 1000 ))
1696      else
1697        (( temp_quota = inode_quota ))
1698      fi
1699    fi
1700    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1701#    echo "inode ratio is " $quota_inode
1702
1703    if [ ${quota_inode} -ge ${limit_quota} ] ; then
1704      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1705      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
1706      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1707      IGCM_debug_Print 1 "You must have more than 10% available to run"
1708      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1709      IGCM_debug_Verif_Exit
1710    fi
1711  fi
1712  IGCM_debug_PopStack "IGCM_sys_check_quota"
1713}
1714
1715#D-#==================================================
1716#D-function IGCM_sys_projectAccounting
1717#D-* Purpose: store project accounting information in a file
1718#D-* Examples:
1719#D-
1720function IGCM_sys_projectAccounting {
1721  IGCM_debug_PushStack "IGCM_sys_projectAccounting"
1722  if ( $DEBUG_sys ) ; then
1723    echo "IGCM_sys_check_quota"
1724  fi
1725
1726  ssh curie91 /usr/bin/ccc_myproject > $1
1727
1728  IGCM_debug_PopStack "IGCM_sys_projectAccounting"
1729}
1730
1731#D-#==================================================
1732#D-function IGCM_sys_getJobSchedulerID
1733#D-* Purpose: Get the job ID during execution
1734#D-* Examples: IGCM_sys_getJobSchedulerID jobSchedulerID
1735#D-
1736function IGCM_sys_getJobSchedulerID {
1737  IGCM_debug_PushStack "IGCM_sys_getJobSchedulerID"
1738  if ( $DEBUG_sys ) ; then
1739    echo "IGCM_sys_getJobSchedulerID"
1740  fi
1741
1742  eval ${1}=${BRIDGE_MSUB_JOBID}
1743
1744  IGCM_debug_PopStack "IGCM_sys_getJobSchedulerID"
1745}
1746
1747#D-#==================================================
1748#D-function IGCM_sys_GetJobID
1749#D-* Purpose: Get the job ID from the JobName
1750#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1751#D-
1752function IGCM_sys_GetJobID {
1753  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1754  if ( $DEBUG_sys ) ; then
1755    echo "IGCM_sys_GetJobID"
1756  fi
1757
1758  # With -f option, the full job name is given in the last column
1759  ID=$( ccc_mstat -f -u $2 | \
1760        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
1761
1762  eval ${3}=${ID}
1763  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1764}
1765
1766#D-#==================================================
1767#D-function IGCM_sys_CountJobInQueue
1768#D-* Purpose: Count number of users job
1769#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1770#D-
1771function IGCM_sys_CountJobInQueue {
1772  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1773  if ( $DEBUG_sys ) ; then
1774    echo "IGCM_sys_CountJobInQueue"
1775  fi
1776
1777  # With -f option, the full job name is given in the last column
1778  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ( $NF ~ JobName ) { x=x+1 } END { print x }' )
1779
1780  eval ${2}=${NbRun}
1781
1782  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1783}
1784
1785#D-#==================================================
1786#D-function IGCM_sys_ListJobInQueue
1787#D-* Purpose: Produce a list of users computing jobs (excluding post-processing)
1788#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
1789#D-
1790function IGCM_sys_ListJobInQueue {
1791  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
1792  if ( $DEBUG_sys ) ; then
1793    echo "IGCM_sys_ListJobInQueue"
1794  fi
1795
1796  # With -f option, the full job name is given in the last column
1797  set -A JobList $( ccc_mstat -f | gawk -v User=$1             \
1798                                        '( $2  == User      && \
1799                                           $NF != /TS/      && \
1800                                           $NF !~ /PACK/    && \
1801                                           $NF !~ /REBUILD/ && \
1802                                           $NF !~ /pack/ )     \
1803                                         { print $NF }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
1804
1805  eval set -A ${2} ${JobList[*]}
1806
1807  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
1808}
1809
1810#D-#==================================================
1811#D-function IGCM_sys_atlas
1812#D-* Purpose: encapsulate atlas call so as to manage error code and curie specificity
1813#D-* Examples:
1814#D-
1815function IGCM_sys_atlas {
1816  IGCM_debug_PushStack "IGCM_sys_atlas" $@
1817  if ( $DEBUG_sys ) ; then
1818    echo "IGCM_sys_atlas :" $@
1819  fi
1820
1821  typeset status
1822
1823  \ccc_mprun atlas $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1824  status=$?
1825  if [ ${status} -gt 0 ] ; then
1826    echo "IGCM_sys_atlas : error code ${status}"
1827    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1828    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1829    IGCM_debug_PopStack "IGCM_sys_atlas"
1830    return 1
1831  else
1832    IGCM_debug_PopStack "IGCM_sys_atlas"
1833    return 0
1834  fi
1835
1836  IGCM_debug_PopStack "IGCM_sys_atlas"
1837}
1838
1839#D-#==================================================
1840#D-function IGCM_sys_rebuild_nemo
1841#D-* Purpose: rebuild nemo parallel files with nemo specific rebuild on curie
1842#D-* Examples:
1843#D-
1844
1845function IGCM_sys_rebuild_nemo {
1846  IGCM_debug_PushStack "IGCM_sys_rebuild_nemo" $@
1847  if ( $DEBUG_sys ) ; then
1848    echo "IGCM_sys_rebuild_nemo :" $@
1849  fi
1850
1851  $( ccc_home -u igcmg)/Tools/curie/bin/rebuild_nemo ${1} ${2}
1852
1853  IGCM_debug_PopStack "IGCM_sys_rebuild_nemo"
1854}
1855
Note: See TracBrowser for help on using the repository browser.