source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh @ 1308

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