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

Last change on this file since 1196 was 1196, checked in by sdipsl, 9 years ago
  • Fix a typo
  • 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: 51.1 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 and user names
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 DEFAULT_PROJECT=gen0826
73
74#D-
75#D-#==================================================
76#D-Program used in libIGCM
77#D-#==================================================
78
79# Submit command
80typeset SUBMIT=${SUBMIT:=ccc_msub}
81# rsync with path
82typeset -r RSYNC=/usr/bin/rsync
83# RSYNC_opt args to rsync
84typeset -r RSYNC_opt="-va"
85# ie storage filesystem
86typeset -r STOREHOST=${MASTER}
87typeset -r REMOTE_RSYNC=/usr/bin/rsync
88
89#====================================================
90# Set environment tools (ferret, nco, cdo, rebuild, ...)
91#====================================================
92if [ X${TaskType} = Xcomputing ] ; then
93  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_netcdf4.3.3.1_hdf5_parallel_curie_ksh > /dev/null 2>&1
94# to run with netcdf 3.6.3 ie compilation done before 17/2/2014
95# uncomment 2 lines :
96#  module unload netcdf
97#  module load netcdf/3.6.3
98else
99  . /ccc/cont003/home/dsm/p86ipsl/.atlas_env_netcdf4.3.3.1_hdf5_parallel_curie_ksh > /dev/null 2>&1
100  PCMDI_MP=/ccc/work/cont003/dsm/p86ipsl/PCMDI-MP
101fi
102export PATH=${PATH}:/ccc/cont003/home/dsm/p86ipsl/AddNoise/src_X64_CURIE/bin
103export PATH=${PATH}:/ccc/cont003/home/dsm/p86ipsl/AddPerturbation/src_X64_CURIE/bin
104export PATH=${PATH}:$( ccc_home -u p86ipsl )/rebuild/src_X64_CURIE/modipsl_v2_2_2_netcdf4.2/bin/
105
106#====================================================
107# Specific for ocean additionnal diagnostic
108export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
109export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
110
111#====================================================
112# Host specific DIRECTORIES
113#====================================================
114
115# ============ CESIUM START ============ #
116
117#====================================================
118#- Mirror libIGCM from titane to cesium if needed
119#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
120#if [ ! ${ROOTSYS} = "home" ] ; then
121#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
122#else
123#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
124#fi
125
126#====================================================
127#- libIGCM_POST
128#if ( ${MirrorlibIGCM} ) ; then
129#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
130#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
131#else
132#  typeset -r libIGCM_POST=${libIGCM}
133#fi
134
135# ============ CESIUM  END  ============ #
136
137#====================================================
138#- MirrorlibIGCM for frontend
139typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
140
141#====================================================
142#- libIGCM_POST for frontend
143typeset -r libIGCM_POST=${libIGCM}
144
145#====================================================
146#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
147typeset -r R_EXE="${MODIPSL}/bin"
148
149#====================================================
150#- SUBMIT_DIR : submission dir
151typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${BRIDGE_MSUB_PWD}}
152
153#====================================================
154#- IN
155typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
156typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
157
158#====================================================
159#- RUN_DIR_PATH : Temporary working directory (=> TMP)
160typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${BRIDGE_MSUB_JOBID}_${$}}
161
162#====================================================
163#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
164typeset -r OUTCOMMAND_PATH=/tmp
165
166#====================================================
167#- HOST_MPIRUN_COMMAND
168typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time ccc_mprun -E-K1"}
169
170#====================================================
171#- Max number of arguments passed to nco operator or demigration command
172UNIX_MAX_LIMIT=360
173
174#====================================================
175#- set PackDefault to true on curie
176PackDefault=true
177
178#====================================================
179#- Number of core per node (max number of OpenMP task)
180NUM_COREPERNODE=8
181
182#====================================================
183#- Default number of MPI task for IPSL coupled model
184#- required for backward compatibility
185#-
186DEFAULT_NUM_PROC_OCE=5
187DEFAULT_NUM_PROC_CPL=1
188(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
189DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
190
191#D-#==================================================
192#D-function IGCM_sys_defineArchives
193#D-* Purpose:
194#D-* Define ARCHIVE : Dedicated to large files
195#D-* Define STORAGE : Dedicated to small/medium files
196#D-* Define R_OUT   : Output tree located on ARCHIVE
197#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
198#D-* Define R_BUF   : Output tree located on SCRATCHDIR hosting files waiting for rebuild or pack processes
199#D-* if SpaceName=TEST everything is stored on SCRATCHDIR
200#D-* Examples:
201#D-
202function IGCM_sys_defineArchives {
203  IGCM_debug_PushStack "IGCM_sys_defineArchives"
204
205  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
206    #====================================================
207    #- ARCHIVE (dedicated to large files)
208    ARCHIVE=${config_UserChoices_ARCHIVE}
209  else
210    #====================================================
211    #- ARCHIVE (dedicated to large files)
212    ARCHIVE=${CCCSTOREDIR}
213  fi
214
215  if [ ! X${config_UserChoices_STORAGE} = X ]; then
216    #====================================================
217    #- STORAGE (dedicated to small/medium files)
218    STORAGE=${config_UserChoices_STORAGE}
219  else
220    #====================================================
221    #- STORAGE (dedicated to small/medium files)
222    STORAGE=${CCCWORKDIR}
223  fi
224
225  if [ X${config_UserChoices_SpaceName} = XTEST ]; then
226    #====================================================
227    #- R_OUT
228    R_OUT=${SCRATCHDIR}/IGCM_OUT
229
230    #====================================================
231    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
232    R_FIG=${SCRATCHDIR}/IGCM_OUT
233
234    IGCM_debug_Print 1 "SpaceName=TEST ==> OVERRULE destination path directories"
235
236  else
237    #====================================================
238    #- R_OUT
239    R_OUT=${ARCHIVE}/IGCM_OUT
240
241    #====================================================
242    #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
243    R_FIG=${STORAGE}/IGCM_OUT
244  fi
245
246  #====================================================
247  #- R_BUF (ONLY FOR double copy an scratch)
248  R_BUF=${SCRATCHDIR}/IGCM_OUT
249
250  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
251  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
252  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
253
254  IGCM_debug_PopStack "IGCM_sys_defineArchives"
255}
256
257#D-#==================================================
258#D-function IGCM_sys_RshArchive
259#D-* Purpose: Archive rsh command
260#D-* Examples:
261#D-
262function IGCM_sys_RshArchive {
263  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
264  /bin/ksh <<-EOF
265    ${@}
266EOF
267  status=$?
268  if [ ${status} -gt 0 ] ; then
269    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
270    IGCM_debug_Exit "IGCM_sys_RshArchive"
271  fi
272  IGCM_debug_PopStack "IGCM_sys_RshArchive"
273}
274
275#D-#==================================================
276#D-function IGCM_sys_RshArchive_NoError
277#D-* Purpose: Archive rsh command, without error
278#D-*          used only in monitoring.job
279#D-* Examples:
280#D-
281function IGCM_sys_RshArchive_NoError {
282  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
283  /bin/ksh <<-EOF
284    ${@} 2> /dev/null
285EOF
286  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
287}
288
289#D-#==================================================
290#D-function IGCM_sys_MkdirArchive
291#D-* Purpose: Mkdir on Archive
292#D-* Examples:
293#D-
294function IGCM_sys_MkdirArchive {
295  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
296  if ( $DEBUG_sys ) ; then
297    echo "IGCM_sys_MkdirArchive :" $@
298  fi
299  #- creation de repertoire sur le serveur fichier
300  if [ ! -d ${1} ]; then
301    \mkdir -p $1
302    status=$?
303
304    if [ ${status} -gt 0 ] ; then
305      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
306      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
307    fi
308  fi
309  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
310}
311
312#D-#==================================================
313#D-function IGCM_sys_TestDirArchive
314#D-* Purpose: Test Directory that must exists on Archive
315#D-* Examples:
316#D-
317function IGCM_sys_TestDirArchive {
318  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
319  if ( $DEBUG_sys ) ; then
320    echo "IGCM_sys_TestDirArchive :" $@
321  fi
322  typeset ExistFlag
323  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
324  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
325  return ${ExistFlag}
326}
327
328#D-#==================================================
329#D-function IGCM_sys_IsFileArchived
330#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
331#D-* Examples:
332#D-
333function IGCM_sys_IsFileArchived {
334  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
335  if ( $DEBUG_sys ) ; then
336    echo "IGCM_sys_IsFileArchived :" $@
337  fi
338  typeset IsArchivedFlag
339  IsArchivedFlag=$( [ X$( echo $@ | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
340  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
341
342  return ${IsArchivedFlag}
343}
344
345#D-#==================================================
346#D-function IGCM_sys_TestFileArchive
347#D-* Purpose: Test file that must NOT EXISTS on Archive
348#D-* Examples:
349#D-
350function IGCM_sys_TestFileArchive {
351  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
352  typeset ExistFlag
353  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
354  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
355
356  return ${ExistFlag}
357}
358
359#D-#==================================================
360#D-function IGCM_sys_CountFileArchive
361#D-* Purpose: Count files on Archive filesystem
362#D-* Examples:
363#D-
364function IGCM_sys_CountFileArchive {
365  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
366  ls ${@} 2>/dev/null | wc -l
367  if [ $? -gt 0 ] ; then
368    echo "IGCM_sys_CountFileArchive : erreur."
369  fi
370  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
371}
372
373#D-#==================================================
374#D-function IGCM_sys_Tree
375#D-* Purpose: Tree directories with files on ${ARCHIVE}
376#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
377#D-
378function IGCM_sys_Tree {
379  IGCM_debug_PushStack "IGCM_sys_Tree" $@
380  if ( $DEBUG_sys ) ; then
381    echo "IGCM_sys_Tree :" $@
382  fi
383
384  \ls -lR ${@}
385
386  IGCM_debug_PopStack "IGCM_sys_Tree"
387}
388
389#D-#==================================================
390#D-function IGCM_sys_Qsub
391#D-* Purpose: Qsub new job
392#D-* Examples:
393#D-
394function IGCM_sys_Qsub {
395  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
396  if ( $DEBUG_sys ) ; then
397    echo "IGCM_sys_Qsub :" $@
398  fi
399  typeset options status
400  options="-o ${SUBMIT_DIR}/${Script_Output} -e ${SUBMIT_DIR}/${Script_Output}"
401
402  /usr/bin/ccc_msub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
403  status=$?
404
405  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
406  if [ ${status} -gt 0 ] ; then
407    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
408    IGCM_debug_Exit "IGCM_sys_Qsub"
409  else
410    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
411  fi
412  IGCM_debug_PopStack "IGCM_sys_Qsub"
413}
414
415#D-#==================================================
416#D-function IGCM_sys_QsubPost
417#D-* Purpose: Qsub new job on scalaire
418#D-* Examples:
419#D-
420function IGCM_sys_QsubPost {
421  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
422  if ( $DEBUG_sys ) ; then
423    echo "IGCM_sys_QsubPost :" $@
424  fi
425  typeset options status
426  MY_PROJECT=$(echo ${BRIDGE_MSUB_PROJECT:=${DEFAULT_PROJECT}} | cut -d@ -f1 )
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 ${MY_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
636  # number of tentative
637  NB_ESSAI=3
638  # time delay between tentative
639  DELAI=2
640
641  if [ $DRYRUN = 0 ]; then
642    if [ ! -f ${1} ] ; then
643      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
644      IGCM_debug_PopStack "IGCM_sys_Put_Out"
645      return 1
646    fi
647    #
648    IGCM_sys_MkdirArchive $( dirname $2 )
649    #
650    exist=false
651    skip=false
652    if [ -f $2 ] ; then
653      IGCM_debug_Print 1 "$2 already exist"
654      ccc_hsm get $2
655      exist=true
656      if [ "X$( diff $1 $2 )" = X ] ; then
657        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
658        skip=true
659      else
660        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
661        skip=false
662      fi
663    fi
664    #
665    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
666      IGCM_sys_Chmod u+w $2
667    fi
668
669    if [ X${skip} = Xfalse ] ; then
670      i=0
671      while [ $i -lt $NB_ESSAI ] ; do
672        if [ $( stat -c %d $1 ) -ne $( stat -c %d $( dirname $2 ) ) ] ; then
673          # USUAL WAY
674          \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
675          status=$?
676        else
677          # NOT SO USUAL WAY
678          \mv $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
679          status=$?
680        fi
681        if [ ${status} -gt 0 ]; then
682          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
683          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
684          [ -f ${1} ] && ls -l ${1}
685          [ -f ${2} ] && ls -l ${2}
686          [ -f ${2}/${1} ] && ls -l ${2}/${1}
687          sleep $DELAI
688        else
689          break
690        fi
691        (( i = i + 1 ))
692      done
693    fi
694
695#       #RSYNC WITH NETWORK SSH CALL
696#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
697#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
698
699#       #RSYNC WITH NFS USE
700#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
701#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
702
703#       status=$?
704#       IGCM_sys_Rsync_out $status
705
706#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
707#       (( status=status+$? ))
708
709    if [ ${status} -gt 0 ] ; then
710      IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status}"
711      [ -f ${1} ] && ls -l ${1}
712      [ -f ${2} ] && ls -l ${2}
713      [ -f ${2}/${1} ] && ls -l ${2}/${1}
714      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
715      IGCM_debug_Exit "IGCM_sys_Put_Out"
716    else
717
718      if [ X${JobType} = XRUN ] ; then
719        if [ X${3} = X ] ; then
720          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
721          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
722        fi
723      fi
724
725      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
726    fi
727  fi
728  IGCM_debug_PopStack "IGCM_sys_Put_Out"
729  return 0
730}
731
732#D-#==================================================
733#D-function IGCM_sys_Get
734#D-* Purpose: Get a file from ${ARCHIVE}
735#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
736#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
737function IGCM_sys_Get {
738  IGCM_debug_PushStack "IGCM_sys_Get" $@
739
740  typeset DEST dm_liste target file_work
741  typeset NB_ESSAI DELAI status i
742
743  if ( $DEBUG_sys ) ; then
744    echo "IGCM_sys_Get :" $@
745  fi
746
747  # number of tentative
748  NB_ESSAI=3
749  # time delay between tentative
750  DELAI=2
751
752  if [ $DRYRUN -le 2 ]; then
753    if [ X${1} = X'/l' ] ; then
754      eval set +A dm_liste \${${2}}
755    else
756      eval set +A dm_liste ${1}
757    fi
758    eval DEST=\${${#}}
759    ccc_hsm get ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
760    status=$?
761    if [ ${status} -gt 0 ] ; then
762      echo "WARNING IGCM_sys_Get : error code ${status}"
763      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
764      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
765    fi
766
767    #if [ ${status} -gt 0 ] ; then
768    #  if [ ! "X$( grep "Lost dmusrcmd connection" ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )" = "X" ] ; then
769    #    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
770    #    echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
771    #    sleep 30
772    #    echo "We try another time"
773    ##    dmget ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
774    #    ccc_hsm get ${dm_liste[*]} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
775    #    status=$?
776    #    if [ ${status} -gt 0 ] ; then
777    #      echo "ERROR IGCM_sys_Get : again demigration error :"
778    #      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
779    #      IGCM_debug_Exit "IGCM_sys_Get"
780    #    fi
781    #  else
782    #    echo "ERROR IGCM_sys_Get : demigration error :"
783    #    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
784    #    IGCM_debug_Exit "IGCM_sys_Get"
785    #  fi
786    #fi
787
788    #   #RSYNC WITH NETWORK SSH CALL
789    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
790    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
791
792    #   #RSYNC WITH NFS USE
793    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
794    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
795
796    #   status=$?
797    #   IGCM_sys_Rsync_out $status
798
799    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
800    #   (( status=status+$? ))
801
802    #USUAL WAY
803    if [ X${1} = X'/l' ] ; then
804      for target in ${dm_liste[*]} ; do
805        local_file=$( basename ${target} )
806        # test if the target file is present before the loop
807        IGCM_sys_TestFileArchive ${target}
808        status=$?
809        if [ ${status} -gt 0 ] ; then
810          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
811          IGCM_debug_Exit "IGCM_sys_Get"
812        else
813          i=0
814          while [ $i -lt $NB_ESSAI ] ; do
815            #if [ X${DoLink} = Xtrue ] ; then
816            #  \ln -s ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
817            #  status=$?
818            #  else
819            #  \cp ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
820            #  status=$?
821            #fi
822            \ln -s ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
823            status=$?
824            if [ ${status} -gt 0 ]; then
825              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
826              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
827              sleep $DELAI
828            else
829              break
830            fi
831            (( i = i + 1 ))
832          done
833          if [ ${status} -gt 0 ] ; then
834            echo "IGCM_sys_Get : error"
835            cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
836            \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
837            IGCM_debug_Exit "IGCM_sys_Get"
838          else
839            \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
840          fi
841        fi
842      done
843    else
844      i=0
845      while [ $i -lt $NB_ESSAI ] ; do
846        \cp ${dm_liste} ${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
847        status=$?
848        if [ ${status} -gt 0 ]; then
849          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
850          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
851          sleep $DELAI
852        else
853          break
854        fi
855        (( i = i + 1 ))
856      done
857      if [ ${status} -gt 0 ] ; then
858        echo "IGCM_sys_Get : error"
859        cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
860        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
861        IGCM_debug_Exit "IGCM_sys_Get"
862      else
863        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
864      fi
865    fi
866  fi
867  IGCM_debug_PopStack "IGCM_sys_Get"
868}
869
870#D-#==================================================
871#D-function IGCM_sys_GetDate_Monitoring
872#D-* Purpose: get the last year for which the monitoring has been computed
873#D-* Examples:
874#D-
875function IGCM_sys_GetDate_Monitoring {
876  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
877  if ( $DEBUG_sys ) ; then
878    echo "IGCM_sys_GetDate_Monitoring :" $@
879  fi
880
881  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
882
883  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
884}
885
886#D-#==================================================
887#D-function IGCM_sys_Dods_Rm
888#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
889#D-* Examples:
890#D-
891function IGCM_sys_Dods_Rm {
892  if ( $DEBUG_sys ) ; then
893    echo "IGCM_sys_Dods_Rm :" $@
894  fi
895  typeset status
896  if [ $DRYRUN = 0 ]; then
897
898#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
899#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
900#      echo "Nothing has been done."
901#      return
902#    fi
903
904    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
905    status=$?
906
907#    if [ ${status} -gt 0 ] ; then
908#      echo "IGCM_sys_Dods_Rm : error."
909#      cat out_dods_rm
910#      IGCM_debug_Exit "IGCM_sys_Dods_Rm"
911#    else
912#      rm out_dods_rm
913#    fi
914
915  fi
916  return $status
917}
918
919#D-#==================================================
920#D-function IGCM_sys_Dods_Cp
921#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
922#D-* Examples:
923#D-
924function IGCM_sys_Dods_Cp {
925  if ( $DEBUG_sys ) ; then
926    echo "IGCM_sys_Dods_Cp :" $@
927  fi
928  typeset status
929  if [ $DRYRUN = 0 ]; then
930
931#    if [ ! -d ${R_SAVE}/${1} ] ; then
932#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
933#      echo "Nothing has been done."
934#      return
935#    fi
936
937    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
938    status=$?
939
940#       if [ ${status} -gt 0 ] ; then
941#           echo "IGCM_sys_Dods_Cp : error."
942#           cat out_dods_cp
943#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
944#       else
945#           rm out_dods_cp
946#       fi
947
948  fi
949  return $status
950}
951
952#D-#==================================================
953#D-function IGCM_sys_Put_Dods
954#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole.
955#D-* Examples:
956#D-
957function IGCM_sys_Put_Dods {
958  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
959  if ( $DEBUG_sys ) ; then
960    echo "IGCM_sys_Put_Dods :" $@
961  fi
962  typeset status
963  if [ $DRYRUN = 0 ]; then
964    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
965      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
966      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
967      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
968      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
969      return
970    fi
971
972    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
973      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
974      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
975      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
976      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
977      return
978    fi
979    #
980    if [ -d ${R_SAVE}/${1} ] ; then
981      cd ${R_SAVE}
982    elif [ -d ${R_FIGR}/${1} ] ; then
983      cd ${R_FIGR}
984    fi
985
986    IGCM_sys_Dods_Rm ${1}
987    IGCM_sys_Dods_Cp ${1}
988    status=0
989
990    if [ ${status} -gt 0 ] ; then
991      echo "IGCM_sys_Put_Dods : error."
992      IGCM_debug_Exit "IGCM_sys_Put_Dods"
993    fi
994  fi
995  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
996}
997
998##############################################################
999# REBUILD OPERATOR
1000
1001#D-#==================================================
1002#D-function IGCM_sys_sync
1003#D-* Purpose: flush buffer on disk
1004#D-* Examples:
1005#D-
1006function IGCM_sys_sync {
1007  IGCM_debug_PushStack "IGCM_sys_sync" $@
1008  if ( $DEBUG_sys ) ; then
1009    echo "IGCM_sys_sync :" $@
1010  fi
1011
1012  /bin/sync
1013
1014  IGCM_debug_PopStack "IGCM_sys_sync"
1015}
1016
1017############################################################
1018# Activate Running Environnment Variables
1019
1020#D-#==================================================
1021#D-function IGCM_sys_desactiv_variables
1022#D-* Purpose: set environement variables prior to execution
1023#D-* Examples:
1024#D-
1025function IGCM_sys_activ_variables {
1026  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1027  if ( $DEBUG_sys ) ; then
1028    echo "IGCM_sys_activ_variables"
1029  fi
1030
1031# --------------------------------------------------------------------
1032#D- MPI specifications
1033# --------------------------------------------------------------------
1034
1035# --------------------------------------------------------------------
1036#D- Other specifications
1037# --------------------------------------------------------------------
1038
1039  ulimit -s unlimited
1040
1041  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1042}
1043
1044############################################################
1045# Desactivate Running Environnment Variables
1046
1047#D-#==================================================
1048#D-function IGCM_sys_desactiv_variables
1049#D-* Purpose: unset environement variables after execution
1050#D-* Examples:
1051#D-
1052function IGCM_sys_desactiv_variables {
1053  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1054  if ( $DEBUG_sys ) ; then
1055    echo "IGCM_sys_desactiv_variables"
1056  fi
1057# --------------------------------------------------------------------
1058#D- MPI specifications
1059# --------------------------------------------------------------------
1060
1061# --------------------------------------------------------------------
1062#D- Other specifications
1063# --------------------------------------------------------------------
1064
1065  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1066}
1067
1068############################################################
1069# Build MPI/OMP scripts run file (dummy function)
1070
1071#D-#==================================================
1072#D-function IGCM_sys_build_run_file
1073#D-* Purpose: build run file (deprecated)
1074#D-* Examples:
1075#D-
1076function IGCM_sys_build_run_file {
1077
1078  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1079
1080}
1081
1082############################################################
1083# Build MPI/OMP scripts
1084
1085#D-#==================================================
1086#D-function IGCM_sys_build_execution_scripts
1087#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1088#D-* Examples:
1089#D-
1090function IGCM_sys_build_execution_scripts
1091{
1092  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1093  if ( $DEBUG_sys ) ; then
1094    echo "IGCM_sys_build_execution_scripts " $@
1095  fi
1096
1097  EXECUTION=${HOST_MPIRUN_COMMAND}
1098
1099  # MPMD mode
1100  if ( ${OK_PARA_MPMD} ) ; then
1101
1102    # Only MPI (MPMD)
1103    if  ( ! ${OK_PARA_OMP} ) ; then
1104
1105      if [ -f run_file ] ; then
1106        IGCM_sys_Rm -f run_file
1107      fi
1108      touch run_file
1109
1110      # Build run_file
1111
1112      # First loop on the components for the coupler ie oasis (only if oasis3)
1113      # the coupler ie oasis3 must be the first one
1114      for comp in ${config_ListOfComponents[*]} ; do
1115
1116        eval ExeNameIn=\${config_Executable_${comp}[0]}
1117        eval ExeNameOut=\${config_Executable_${comp}[1]}
1118
1119        # for CPL component only
1120        if [ "X${comp}" = "XCPL" ] && [ "X${ExeNameOut}" != X\"\" ] ; then
1121
1122          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1123          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1124          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1125        fi
1126      done
1127
1128      # Then second loop on the components
1129      for comp in ${config_ListOfComponents[*]} ; do
1130
1131        eval ExeNameIn=\${config_Executable_${comp}[0]}
1132        eval ExeNameOut=\${config_Executable_${comp}[1]}
1133
1134        # Only if we really have an executable for the component and not the coupler ie oasis:
1135        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1136
1137          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1138          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1139          echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1140        fi
1141      done
1142
1143      EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1144
1145      IGCM_sys_Chmod u+x run_file
1146      if ( $DEBUG_sys ) ; then
1147        echo "run_file contains : "
1148        cat run_file
1149      fi
1150
1151    # MPI-OpenMP (MPMD)
1152    else
1153
1154      # Use of mpirun instead of ccc_mprun
1155      EXECUTION="time mpirun"
1156
1157      #  Hosts treatment
1158      ${EXECUTION} hostname | sort | uniq > hosts.tmp
1159
1160      i=0
1161      rm -f hosts rankfile
1162      IGCM_debug_Print 1 "sys Curie, Hosts available :"
1163      for nodes in `cat hosts.tmp`
1164      do
1165        host[$i]=$nodes
1166        echo "${host[$i]}" >> hosts
1167        IGCM_debug_Print 1 ${host[$i]}
1168        i=$((i+1))
1169      done
1170      rm -f hosts.tmp
1171
1172      listnodes=${host[*]}
1173
1174      EXECUTION="${EXECUTION} -hostfile hosts -rankfile rankfile"
1175
1176      # Initialisation
1177      rank=0
1178      current_core=0
1179      core_per_node=16
1180      init_exec=n
1181
1182      # Loop on the components
1183      for comp in ${config_ListOfComponents[*]} ; do
1184
1185        eval ExeNameIn=\${config_Executable_${comp}[0]}
1186        eval ExeNameOut=\${config_Executable_${comp}[1]}
1187
1188        # Not possible if oasis has an executable (i.e old version of oasis3)
1189        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
1190          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
1191          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
1192          IGCM_debug_Verif_Exit
1193        fi
1194
1195        # Only if we really have an executable for the component :
1196        if [ "X${ExeNameOut}" != X\"\" ] ; then
1197
1198          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1199          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1200
1201          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1202          echo ""  >> script_${ExeNameOut}.ksh
1203          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
1204
1205            # Check if the number of threads is correct
1206            case ${comp_proc_omp_loc} in
1207            2|4|8|16)
1208              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1209              ;;
1210            *)
1211              IGCM_debug_Exit "ERROR with OMP parameters !"
1212              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1213              IGCM_debug_Print 2 "Only 2,4,8,16 as number of OMP threads are possible "
1214              IGCM_debug_Verif_Exit
1215              ;;
1216            esac
1217            echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1218            echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1219            echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1220            echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1221          fi
1222          #echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1223          #echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1224          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1225          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1226
1227          if [ ${init_exec} = y ] ; then
1228            EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1229          else
1230            EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1231            init_exec=y
1232          fi
1233
1234# Build rankfile : method used to assign cores and nodes for the MPI process
1235# Ex :
1236#rank 0=curie5296 slot=0,1,2,3
1237#rank 1=curie5296 slot=4,5,6,7
1238# Example of final command :
1239# mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
1240# with script_lmdz.x.ksh :
1241# #!/bin/ksh
1242#export KMP_STACKSIZE=3g
1243#export KMP_LIBRARY=turnaround
1244#export MKL_SERIAL=YES
1245#OMP_NUM_THREADS=4
1246#./lmdz.x
1247#
1248
1249          for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
1250            (( index_host = current_core / core_per_node ))
1251            host_value=${host[${index_host}]}
1252            (( slot =  current_core % core_per_node ))
1253            virg=","
1254            string_final=""
1255            for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
1256              string=$index$virg
1257              string_final=$string_final$string
1258            done
1259            string_final=$( echo $string_final | sed "s/.$//" )
1260            echo "rank $rank=$host_value slot=$string_final" >> rankfile
1261            (( rank = rank + 1 ))
1262            (( current_core = current_core + comp_proc_omp_loc ))
1263          done
1264        fi
1265
1266      done
1267    fi
1268
1269  # Only one executable (SPMD mode).
1270  else
1271
1272    for comp in ${config_ListOfComponents[*]} ; do
1273
1274      # Only if we really have an executable for the component :
1275      eval ExeNameOut=\${config_Executable_${comp}[1]}
1276      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1277
1278        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1279        echo ""  >> script_${ExeNameOut}.ksh
1280        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1281
1282        if ( ${OK_PARA_OMP} ) ; then
1283          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1284          echo ""  >> script_${ExeNameOut}.ksh
1285          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1286          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1287          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1288          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1289        fi
1290
1291        if  ( ${OK_PARA_MPI} ) ; then
1292          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1293          # Default : ccc_mprun used if nb_proc gt 1
1294          # to have out/err per process on different files
1295          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
1296          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1297          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1298        else
1299          # Default : ccc_mprun is NOT used if nb_proc eq 1
1300          # to have out/err per process on different files
1301          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1302          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1303          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
1304        fi
1305
1306        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
1307        cat script_${ExeNameOut}.ksh
1308
1309      fi
1310
1311    done
1312
1313  fi
1314
1315  IGCM_debug_Print 1 "sys Curie : execution command is "
1316  IGCM_debug_Print 1 "$EXECUTION"
1317
1318  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1319}
1320
1321#D-#==================================================
1322#D-function IGCM_sys_check_path
1323#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1324#D-* do not point to an important use directory. Stop immediately in that case.
1325#D-* Examples:
1326#D-
1327function IGCM_sys_check_path {
1328  IGCM_debug_PushStack "IGCM_sys_check_path"
1329  if ( $DEBUG_sys ) ; then
1330    echo "IGCM_sys_check_path"
1331  fi
1332
1333  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
1334    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1335    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1336    IGCM_debug_Exit "This will stop the job"
1337  fi
1338  IGCM_debug_PopStack "IGCM_sys_check_path"
1339}
1340
1341#D-#==================================================
1342#D-function IGCM_sys_check_quota
1343#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1344#D-* Examples:
1345#D-
1346function IGCM_sys_check_quota {
1347  IGCM_debug_PushStack "IGCM_sys_check_quota"
1348  if ( $DEBUG_sys ) ; then
1349    echo "IGCM_sys_check_quota"
1350  fi
1351  # Limit of quota (in %)
1352  limit_quota=90
1353
1354  # Check of the volume
1355  volume_quota=$(ccc_quota | grep ' scratch' | gawk '{print $2}')
1356  volume_avail=$(ccc_quota | grep ' scratch' | gawk '{print $3}')
1357
1358  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1359
1360    unit_avail=${volume_avail: -1}
1361    unit_quota=${volume_quota: -1}
1362
1363    if [ "${unit_quota}" = "*" ] ; then
1364      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1365      IGCM_debug_Print 1 "More than 100% of your quota is used"
1366      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1367      IGCM_debug_Print 1 "You must have more than 10% available to run"
1368      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1369      IGCM_debug_Verif_Exit
1370    fi
1371
1372    temp_avail=${volume_avail%%${volume_avail: -1}*}
1373    temp_quota=${volume_quota%%${volume_quota: -1}*}
1374
1375    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1376
1377    # Convertion
1378      if [ ${volume_avail: -1} = "T" ] ; then
1379        (( temp_avail = temp_avail * 1000000000000 ))
1380      elif [ ${volume_avail: -1} = "G" ] ; then
1381        (( temp_avail = temp_avail * 1000000000 ))
1382      elif [ ${volume_avail: -1} = "M" ] ; then
1383        (( temp_avail = temp_avail * 1000000 ))
1384      elif [ ${volume_avail: -1} = "k" ] ; then
1385        (( temp_avail = temp_avail * 1000 ))
1386      else
1387        (( temp_avail = volume_avail ))
1388      fi
1389      if [ ${volume_quota: -1} = "T" ] ; then
1390        (( temp_quota = temp_quota * 1000000000000 ))
1391      elif [ ${volume_quota: -1} = "G" ] ; then
1392        (( temp_quota = temp_quota * 1000000000 ))
1393      elif [ ${volume_quota: -1} = "M" ] ; then
1394        (( temp_quota = temp_quota * 1000000 ))
1395      elif [ ${volume_quota: -1} = "k" ] ; then
1396        (( temp_quota = temp_quota * 1000 ))
1397      else
1398        (( temp_quota = volume_quota ))
1399      fi
1400    fi
1401
1402    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1403#    echo "volume ratio is " $quota_volume
1404
1405    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1406      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1407      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1408      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1409      IGCM_debug_Print 1 "You must have more than 10% available to run"
1410      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1411      IGCM_debug_Verif_Exit
1412    fi
1413
1414  fi
1415
1416# Check of the number of inodes
1417
1418  inode_quota=$(ccc_quota | grep ' scratch' | gawk '{print $6}')
1419  inode_avail=$(ccc_quota | grep ' scratch' | gawk '{print $7}')
1420
1421  if ( [ ! X${inode_quota} = X ] && [ ! ${inode_quota} = "-" ] ) ; then
1422
1423    unit_avail=${inode_avail: -1}
1424    unit_quota=${inode_quota: -1}
1425
1426    if [ "${unit_quota}" = "*" ] ; then
1427      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1428      IGCM_debug_Print 1 "More than 100% of your quota is used"
1429      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1430      IGCM_debug_Print 1 "You must have more than 10% available to run"
1431      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1432      IGCM_debug_Verif_Exit
1433    fi
1434
1435    temp_avail=${inode_avail%%${inode_avail: -1}*}
1436    temp_quota=${inode_quota%%${inode_quota: -1}*}
1437
1438    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1439
1440    # Convertion
1441      if [ ${inode_avail: -1} = "T" ] ; then
1442        (( temp_avail = temp_avail * 1000000000000 ))
1443      elif [ ${inode_avail: -1} = "G" ] ; then
1444        (( temp_avail = temp_avail * 1000000000 ))
1445      elif [ ${inode_avail: -1} = "M" ] ; then
1446        (( temp_avail = temp_avail * 1000000 ))
1447      elif [ ${inode_avail: -1} = "k" ] ; then
1448        (( temp_avail = temp_avail * 1000 ))
1449      else
1450        (( temp_avail = inode_avail ))
1451      fi
1452
1453      if [ ${inode_quota: -1} = "T" ] ; then
1454        (( temp_quota = temp_quota * 1000000000000 ))
1455      elif [ ${inode_quota: -1} = "G" ] ; then
1456        (( temp_quota = temp_quota * 1000000000 ))
1457      elif [ ${inode_quota: -1} = "M" ] ; then
1458        (( temp_quota = temp_quota * 1000000 ))
1459      elif [ ${inode_quota: -1} = "k" ] ; then
1460        (( temp_quota = temp_quota * 1000 ))
1461      else
1462        (( temp_quota = inode_quota ))
1463      fi
1464    fi
1465    quota_inode=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1466#    echo "inode ratio is " $quota_inode
1467
1468    if [ ${quota_inode} -ge ${limit_quota} ] ; then
1469      IGCM_debug_Print 1 "Please, check your quota of inode on scratch"
1470      IGCM_debug_Print 1 "${quota_inode}% of your quota is used"
1471      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1472      IGCM_debug_Print 1 "You must have more than 10% available to run"
1473      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1474      IGCM_debug_Verif_Exit
1475    fi
1476  fi
1477  IGCM_debug_PopStack "IGCM_sys_check_quota"
1478}
1479
1480#D-#==================================================
1481#D-function IGCM_sys_GetJobID
1482#D-* Purpose: Check if job_name is currently
1483#D-  running or in queue
1484#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1485#D-
1486function IGCM_sys_GetJobID {
1487  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1488  if ( $DEBUG_sys ) ; then
1489    echo "IGCM_sys_GetJobID"
1490  fi
1491
1492  # With -f option, the full job name is given in the last column
1493  ID=$( ccc_mstat -f -u $2 | \
1494        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
1495
1496  eval ${3}=${ID}
1497  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1498}
1499
1500#D-#==================================================
1501#D-function IGCM_sys_CountJobInQueue
1502#D-* Purpose: Check if job_name is currently
1503#D-  running or in queue
1504#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1505#D-
1506function IGCM_sys_CountJobInQueue {
1507  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1508  if ( $DEBUG_sys ) ; then
1509    echo "IGCM_sys_CountJobInQueue"
1510  fi
1511
1512  # With -f option, the full job name is given in the last column
1513  NbRun=$( ccc_mstat -f | gawk -v JobName=$1 'BEGIN { x=0 } ( $NF ~ JobName ) { x=x+1 } END { print x }' )
1514
1515  eval ${2}=${NbRun}
1516
1517  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1518}
1519
1520#D-#==================================================
1521#D-function IGCM_sys_ListJobInQueue
1522#D-* Purpose: Check if job_name is currently
1523#D-  running or in queue
1524#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
1525#D-
1526function IGCM_sys_ListJobInQueue {
1527  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
1528  if ( $DEBUG_sys ) ; then
1529    echo "IGCM_sys_ListJobInQueue"
1530  fi
1531
1532  # With -f option, the full job name is given in the last column
1533  set -A JobList $( ccc_mstat -f | gawk -v User=$1             \
1534                                        '( $2  == User      && \
1535                                           $NF != /TS/      && \
1536                                           $NF !~ /PACK/    && \
1537                                           $NF !~ /REBUILD/ && \
1538                                           $NF !~ /pack/ )     \
1539                                         { print $NF }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
1540
1541  eval set -A ${2} ${JobList[*]}
1542
1543  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
1544}
Note: See TracBrowser for help on using the repository browser.