source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_default.ksh @ 1188

Last change on this file since 1188 was 1186, checked in by sdipsl, 9 years ago

Ada bugfix. House keeping side effect when calling scipt interactively (clean_month, TimeSeriesChecker?, ...)

  • 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: 33.9 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Martial.Mancip__at__ipsl.jussieu.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 Default host
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=${MASTER:=$( hostname )}
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# Submit command
78typeset SUBMIT=${SUBMIT:=qsub}
79# rsync with path
80typeset -r RSYNC=/usr/bin/rsync
81# RSYNC_opt args to rsync
82typeset -r RSYNC_opt="-va"
83# ie storage filesystem
84typeset -r STOREHOST=${MASTER}
85
86#====================================================
87# Set environment tools (ferret, nco, cdo, rebuild, ...)
88#====================================================
89#. /home/${LOGIN}/.atlas_env_${HOST}_ksh
90#export PATH=${PATH}:/home/${LOGIN}/rebuild/bin/
91
92#====================================================
93# Host specific DIRECTORIES
94#====================================================
95
96#====================================================
97#- MirrorlibIGCM for frontend
98typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
99
100#====================================================
101#- libIGCM_POST for frontend
102typeset -r libIGCM_POST=${libIGCM}
103
104#====================================================
105#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
106typeset -r R_EXE="${MODIPSL}/bin"
107
108#====================================================
109#- SUBMIT_DIR : submission dir
110typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
111
112#====================================================
113#- IN
114typeset -r R_IN=${R_IN:=/home/${LOGIN}/IGCM}
115typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/home/${LOGIN}/IGCM}
116
117#====================================================
118#- RUN_DIR_PATH : Temporary working directory (=> TMP)
119typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/home/${LOGIN}/RUN_DIR/tmp$$}
120
121#====================================================
122#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
123typeset -r OUTCOMMAND_PATH=/tmp
124
125#====================================================
126#- HOST_MPIRUN_COMMAND
127typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
128
129#====================================================
130#- Max number of arguments passed to nco operator or demigration command
131UNIX_MAX_LIMIT=360
132
133#====================================================
134#- set PackDefault to false on obelix
135PackDefault=false
136
137#====================================================
138#- Number of core per node (max number of OpenMP task)
139NUM_COREPERNODE=1
140
141#====================================================
142#- Default number of MPI task for IPSL coupled model
143#- required for backward compatibility
144#-
145DEFAULT_NUM_PROC_OCE=1
146DEFAULT_NUM_PROC_CPL=1
147(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
148DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
149
150#D-#==================================================
151#D-function IGCM_sys_defineArchives
152#D-* Purpose:
153#D-* Define ARCHIVE : Dedicated to large files
154#D-* Define STORAGE : Dedicated to small/medium files
155#D-* Define R_OUT   : Output tree located on ARCHIVE
156#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
157#D-* Define R_BUF   : Output tree located on STORAGE hosting files waiting for rebuild or pack processes
158#D-* if SpaceName=TEST nothing special will hapen
159#D-* Examples:
160#D-
161function IGCM_sys_defineArchives {
162  IGCM_debug_PushStack "IGCM_sys_defineArchives"
163
164  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
165    #====================================================
166    #- ARCHIVE (dedicated to large files)
167    ARCHIVE=${config_UserChoices_ARCHIVE}
168  else
169    #====================================================
170    #- ARCHIVE (dedicated to large files)
171    ARCHIVE=${ARCHIVE:=/home/${LOGIN}}
172  fi
173
174  if [ ! X${config_UserChoices_STORAGE} = X ]; then
175    #====================================================
176    #- STORAGE (dedicated to small/medium files)
177    STORAGE=${config_UserChoices_STORAGE}
178  else
179    #====================================================
180    #- STORAGE (dedicated to small/medium files)
181    STORAGE=${ARCHIVE}
182  fi
183
184  # ON DEFAULT MACHINE NO SPECIAL CASE WHEN X${config_UserChoices_SpaceName} = XTEST
185
186  #====================================================
187  #- R_OUT
188  R_OUT=${ARCHIVE}/IGCM_OUT
189
190  #====================================================
191  #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
192  R_FIG=${STORAGE}/IGCM_OUT
193
194  #====================================================
195  #- R_BUF (ONLY FOR double copy an scratch)
196  R_BUF=${STORAGE}/IGCM_OUT
197
198  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
199  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
200  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
201
202  IGCM_debug_PopStack "IGCM_sys_defineArchives"
203}
204
205#D-#==================================================
206#D-function IGCM_sys_RshArchive
207#D-* Purpose: Archive rsh command
208#D-* Examples:
209#D-
210function IGCM_sys_RshArchive {
211  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
212  /bin/ksh <<-EOF
213    ${@}
214EOF
215  status=$?
216  if [ ${status} -gt 0 ] ; then
217    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
218    IGCM_debug_Exit "IGCM_sys_RshArchive"
219  fi
220  IGCM_debug_PopStack "IGCM_sys_RshArchive"
221}
222
223#D-#==================================================
224#D-function IGCM_sys_RshArchive_NoError
225#D-* Purpose: Archive rsh command, without error
226#D-*          used only in monitoring.job
227#D-* Examples:
228#D-
229function IGCM_sys_RshArchive_NoError {
230  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
231  /bin/ksh <<-EOF
232    ${@} 2> /dev/null
233EOF
234  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
235}
236
237#D-#==================================================
238#D-function IGCM_sys_MkdirArchive
239#D-* Purpose: Mkdir on Archive
240#D-* Examples:
241#D-
242function IGCM_sys_MkdirArchive {
243  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
244  if ( $DEBUG_sys ) ; then
245    echo "IGCM_sys_MkdirArchive :" $@
246  fi
247  #- creation de repertoire sur le serveur fichier
248  if [ ! -d ${1} ]; then
249    \mkdir -p $1
250    status=$?
251
252    if [ ${status} -gt 0 ] ; then
253      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
254      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
255    fi
256  fi
257  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
258}
259
260#D-#==================================================
261#D-function IGCM_sys_TestDirArchive
262#D-* Purpose: Test Directory that must exists on Archive
263#D-* Examples:
264#D-
265function IGCM_sys_TestDirArchive {
266  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
267  if ( $DEBUG_sys ) ; then
268    echo "IGCM_sys_TestDirArchive :" $@
269  fi
270  typeset ExistFlag
271  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
272  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
273  return ${ExistFlag}
274}
275
276#D-#==================================================
277#D-function IGCM_sys_IsFileArchived
278#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
279#D-* Examples:
280#D-
281function IGCM_sys_IsFileArchived {
282  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
283  if ( $DEBUG_sys ) ; then
284    echo "IGCM_sys_IsFileArchived :" $@
285  fi
286  typeset IsArchivedFlag
287  # Never archived for this system
288  IsArchivedFlag=1
289  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
290
291  return ${IsArchivedFlag}
292}
293
294#D-#==================================================
295#D-function IGCM_sys_TestFileArchive
296#D-* Purpose: Test file that must NOT EXISTS on Archive
297#D-* Examples:
298#D-
299function IGCM_sys_TestFileArchive {
300  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
301  typeset ExistFlag
302  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
303  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
304
305  return ${ExistFlag}
306}
307
308#D-#==================================================
309#D-function IGCM_sys_CountFileArchive
310#D-* Purpose: Count files on Archive filesystem
311#D-* Examples:
312#D-
313function IGCM_sys_CountFileArchive {
314  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
315  ls ${@} 2>/dev/null | wc -l
316  if [ $? -gt 0 ] ; then
317    echo "IGCM_sys_CountFileArchive : erreur."
318  fi
319  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
320}
321
322#D-#==================================================
323#D-function IGCM_sys_Tree
324#D-* Purpose: Tree directories with files on ${ARCHIVE}
325#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
326#D-
327function IGCM_sys_Tree {
328  IGCM_debug_PushStack "IGCM_sys_Tree" $@
329  if ( $DEBUG_sys ) ; then
330    echo "IGCM_sys_Tree :" $@
331  fi
332
333  \tree -f $@
334
335  IGCM_debug_PopStack "IGCM_sys_Tree"
336}
337
338#D-#==================================================
339#D-function IGCM_sys_Qsub
340#D-* Purpose: Qsub new job
341#D-* Examples:
342#D-
343function IGCM_sys_Qsub {
344  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
345  if ( $DEBUG_sys ) ; then
346    echo "IGCM_sys_Qsub :" $@
347  fi
348  echo "${@} > ${SUBMIT_DIR}/${Script_Output} 2>&1 &"
349  ${@} > ${SUBMIT_DIR}/${Script_Output} 2>&1 &
350  if [ $? -gt 0 ] ; then
351    echo "IGCM_sys_Qsub : erreur ${options} $1"
352    IGCM_debug_Exit "IGCM_sys_Qsub"
353  fi
354  IGCM_debug_PopStack "IGCM_sys_Qsub"
355}
356
357#D-#==================================================
358#D-function IGCM_sys_QsubPost
359#D-* Purpose: Qsub new job on scalaire
360#D-* Examples:
361#D-
362function IGCM_sys_QsubPost {
363  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
364  if ( $DEBUG_sys ) ; then
365    echo "IGCM_sys_QsubPost :" $@
366  fi
367  echo "${libIGCM_POST}/$1.job > ${POST_DIR}/$1.${PeriodDateEnd}.out 2>&1 &"
368  ${libIGCM_POST}/$1.job > ${POST_DIR}/${Script_Post_Output}.out 2>&1 &
369  if [ $? -gt 0 ] ; then
370    echo "IGCM_sys_QsubPost : erreur " $@
371    IGCM_debug_Exit "IGCM_sys_QsubPost"
372  fi
373  IGCM_debug_PopStack "IGCM_sys_QsubPost"
374}
375
376#D-*************************
377#D- File transfer functions
378#D-*************************
379#D-
380
381#D-#==================================================
382#D-function IGCM_sys_RmRunDir
383#D-* Purpose: rm tmpdir (dummy function most of the time batch
384#D-                      scheduler will do the job)
385#D-* Examples:
386#D-
387function IGCM_sys_RmRunDir {
388  IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@
389  if ( $DEBUG_sys ) ; then
390    echo "IGCM_sys_RmRunDir :" $@
391    IGCM_debug_Print 1 "Dummy call, let the user do that."
392#    IGCM_sys_Rm -rf ${RUN_DIR}
393  fi
394  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
395}
396
397#D-#==================================================
398#D-function IGCM_sys_Put_Dir
399#D-* Purpose: Copy a complete directory on $(ARCHIVE)
400#D-* Examples:
401#D-
402function IGCM_sys_Put_Dir {
403  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
404  if ( $DEBUG_sys ) ; then
405    echo "IGCM_sys_Put_Dir :" $@
406  fi
407  if [ $DRYRUN = 0 ]; then
408    if [ ! -d ${1} ] ; then
409      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
410      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
411      return
412    fi
413
414    typeset status
415
416    # Only if we use rsync
417    #IGCM_sys_TestDirArchive $( dirname $2 )
418    #
419    #USUAL WAY
420    \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
421    status=$?
422
423    if [ ${status} -gt 0 ] ; then
424      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
425      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
426      IGCM_debug_Exit "IGCM_sys_Put_Dir"
427    else
428      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
429    fi
430  fi
431  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
432}
433
434#D-#==================================================
435#D-function IGCM_sys_Get_Dir
436#D-* Purpose: Copy a complete directory from ${ARCHIVE}
437#D-* Examples:
438#D-
439function IGCM_sys_Get_Dir {
440  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
441  if ( $DEBUG_sys ) ; then
442    echo "IGCM_sys_Get_Dir :" $@
443  fi
444  if [ $DRYRUN = 0 ]; then
445    typeset NB_ESSAI DELAI status i
446    # number of tentative
447    NB_ESSAI=3
448    # time delay between tentative
449    DELAI=2
450
451    #
452    # USUAL WAY
453    i=0
454    while [ $i -lt $NB_ESSAI ] ; do
455      \cp -ur $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
456      status=$?
457      if [ ${status} -gt 0 ] ; then
458        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
459        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
460        sleep $DELAI
461      else
462        break
463      fi
464      (( i = i + 1 ))
465    done
466
467    if [ ${status} -gt 0 ] ; then
468      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
469      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
470      IGCM_debug_Exit "IGCM_sys_Get_Dir"
471    else
472      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
473    fi
474  fi
475  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
476}
477
478#D-#==================================================
479#D-function IGCM_sys_Put_Rest
480#D-* Purpose: Put computied restarts on ${ARCHIVE}.
481#D-           File and target directory must exist.
482#D-* Examples:
483#D-
484function IGCM_sys_Put_Rest {
485  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
486  if ( $DEBUG_sys ) ; then
487    echo "IGCM_sys_Put_Rest :" $@
488  fi
489  if [ $DRYRUN = 0 ]; then
490    if [ ! -f ${1} ] ; then
491      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
492      IGCM_debug_Exit "IGCM_sys_Put_Rest"
493    fi
494
495    typeset status
496    #
497    # USUAL WAY
498    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
499    status=$?
500
501#       #RSYNC WITH NETWORK SSH CALL
502#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
503#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
504
505#       #RSYNC WITH NFS USE
506#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
507#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
508
509#       status=$?
510#       IGCM_sys_Rsync_out $status
511
512#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
513#       (( status=status+$? ))
514
515    if [ ${status} -gt 0 ] ; then
516      IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}"
517      [ -f ${1} ] && ls -l ${1}
518      [ -f ${2} ] && ls -l ${2}
519      [ -f ${2}/${1} ] && ls -l ${2}/${1}
520      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
521      IGCM_debug_Exit "IGCM_sys_Put_Rest"
522    else
523
524      if [ X${JobType} = XRUN ] ; then
525        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
526        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
527      fi
528
529      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
530    fi
531  fi
532  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
533}
534
535#D-#==================================================
536#D-function IGCM_sys_Put_Out
537#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
538#D-* Examples:
539#D-
540function IGCM_sys_Put_Out {
541  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
542  if ( $DEBUG_sys ) ; then
543    echo "IGCM_sys_Put_Out :" $@
544  fi
545
546  typeset status
547
548  if [ $DRYRUN = 0 ]; then
549    if [ ! -f ${1} ] ; then
550      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
551      IGCM_debug_PopStack "IGCM_sys_Put_Out"
552      return 1
553    fi
554    #
555    IGCM_sys_MkdirArchive $( dirname $2 )
556    #
557    if [ X${JobType} = XRUN ] ; then
558      if [ X${3} = X ] ; then
559        IGCM_sys_Chmod 444 ${1}
560      fi
561    fi
562    #
563
564    echo ${RSYNC} ${RSYNC_opt} $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
565    ${RSYNC} ${RSYNC_opt} $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
566    status=$?
567    IGCM_sys_Rsync_out $status
568
569    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
570    (( status=status+$? ))
571
572    if [ ${status} -gt 0 ] ; then
573      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
574      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
575      IGCM_debug_Exit "IGCM_sys_Put_Out"
576    else
577      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
578    fi
579  fi
580  IGCM_debug_PopStack "IGCM_sys_Put_Out"
581  return 0
582}
583
584#D-#==================================================
585#D-function IGCM_sys_Get
586#D-* Purpose: Get a file from ${ARCHIVE}
587#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
588#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
589function IGCM_sys_Get {
590  IGCM_debug_PushStack "IGCM_sys_Get" $@
591
592  typeset DEST status dm_liste
593
594  if ( $DEBUG_sys ) ; then
595    echo "IGCM_sys_Get :" $@
596  fi
597  if [ $DRYRUN -le 2 ]; then
598    if [ X${1} = X'/l' ] ; then
599      eval set +A dm_liste \${${2}}
600    else
601      dm_liste=${1}
602    fi
603    eval DEST=\${${#}}
604
605    # test if the (first) file is present in the old computation :
606    IGCM_sys_TestFileArchive ${dm_liste[0]}
607    status=$?
608    if [ ${status} -gt 0 ] ; then
609      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
610      IGCM_debug_Exit "IGCM_sys_Get"
611      return
612    fi
613
614    #USUAL WAY
615    \cp ${dm_liste[*]} ${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
616    status=$?
617
618    if [ ${status} -gt 0 ] ; then
619      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
620      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
621      IGCM_debug_Exit "IGCM_sys_Get"
622    else
623      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
624    fi
625  fi
626  IGCM_debug_PopStack "IGCM_sys_Get"
627}
628
629#D-#==================================================
630#D-function IGCM_sys_GetDate_Monitoring
631#D-* Purpose: get the last year for which the monitoring has been computed
632#D-* Examples:
633#D-
634function IGCM_sys_GetDate_Monitoring {
635  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
636  if ( $DEBUG_sys ) ; then
637    echo "IGCM_sys_GetDate_Monitoring :" $@
638  fi
639
640  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
641
642  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
643}
644
645#D-#==================================================
646#D-function IGCM_sys_Dods_Rm
647#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
648#D-* Examples:
649#D-
650function IGCM_sys_Dods_Rm {
651  if ( $DEBUG_sys ) ; then
652    echo "IGCM_sys_Dods_Rm :" $@
653  fi
654  return 0
655}
656
657#D-#==================================================
658#D-function IGCM_sys_Dods_Cp
659#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
660#D-* Examples:
661#D-
662function IGCM_sys_Dods_Cp {
663  if ( $DEBUG_sys ) ; then
664    echo "IGCM_sys_Dods_Cp :" $@
665  fi
666  return 0
667}
668
669#D-#==================================================
670#D-function IGCM_sys_Put_Dods
671#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
672#D-* Examples:
673#D-
674function IGCM_sys_Put_Dods {
675  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
676  if ( $DEBUG_sys ) ; then
677    echo "IGCM_sys_Put_Dods :" $@
678  fi
679  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
680}
681
682##############################################################
683# REBUILD OPERATOR
684
685#D-#==================================================
686#D-function IGCM_sys_sync
687#D-* Purpose: flush buffer on disk (dummy function on Ada)
688#D-* Examples:
689#D-
690function IGCM_sys_sync {
691  IGCM_debug_PushStack "IGCM_sys_sync" $@
692  if ( $DEBUG_sys ) ; then
693    echo "IGCM_sys_sync :" $@
694    echo "Dummy call, let the system do that."
695  fi
696  IGCM_debug_PopStack "IGCM_sys_sync"
697}
698
699############################################################
700# Activate Running Environnment Variables
701
702#D-#==================================================
703#D-function IGCM_sys_desactiv_variables
704#D-* Purpose: set environement variables prior to execution
705#D-* Examples:
706#D-
707function IGCM_sys_activ_variables {
708  IGCM_debug_PushStack "IGCM_sys_activ_variables"
709  if ( $DEBUG_sys ) ; then
710    echo "IGCM_sys_activ_variables"
711  fi
712
713# --------------------------------------------------------------------
714#D- MPI specifications
715# --------------------------------------------------------------------
716
717# --------------------------------------------------------------------
718#D- Other specifications
719# --------------------------------------------------------------------
720
721  IGCM_debug_PopStack "IGCM_sys_activ_variables"
722}
723
724############################################################
725# Desactivate Running Environnment Variables
726
727#D-#==================================================
728#D-function IGCM_sys_desactiv_variables
729#D-* Purpose: unset environement variables after execution
730#D-* Examples:
731#D-
732function IGCM_sys_desactiv_variables {
733  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
734  if ( $DEBUG_sys ) ; then
735    echo "IGCM_sys_desactiv_variables"
736  fi
737# --------------------------------------------------------------------
738#D- MPI specifications
739# --------------------------------------------------------------------
740
741# --------------------------------------------------------------------
742#D- Other specifications
743# --------------------------------------------------------------------
744
745  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
746}
747
748############################################################
749# Build MPI/OMP scripts run file (dummy function)
750
751#D-#==================================================
752#D-function IGCM_sys_build_run_file
753#D-* Purpose: build run file (deprecated)
754#D-* Examples:
755#D-
756function IGCM_sys_build_run_file {
757
758  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
759
760}
761
762############################################################
763# Build MPI/OMP scripts
764
765#D-#==================================================
766#D-function IGCM_sys_build_execution_scripts
767#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
768#D-* Examples:
769#D-
770function IGCM_sys_build_execution_scripts
771{
772  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
773  if ( $DEBUG_sys ) ; then
774    echo "IGCM_sys_build_execution_scripts " $@
775  fi
776
777  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
778  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
779  typeset num_corempi nombre_restant_node nombre_restant_comp
780
781  if ( ${OK_PARA_MPMD} ) ; then
782
783    if [ -f run_file ] ; then
784      IGCM_sys_Rm -f run_file
785    fi
786    touch run_file
787
788    if ( ${OK_PARA_OMP} ) ; then
789
790      #  Hosts treatment
791
792      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
793
794      i=0
795      rm -f hosts
796      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
797      for nodes in `cat hosts.tmp` ; do
798        host[$i]=$nodes
799        echo "${host[$i]} slots=1 max_slots=1" >> hosts
800        IGCM_debug_Print 1 ${host[$i]}
801        i=$((i+1))
802      done
803      rm -f hosts.tmp
804
805      listnodes=${host[*]}
806
807      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
808
809      # Initialisation
810
811      init_node=y
812      node_num_current=0
813      start_num=0
814      init_exec=n
815
816      # Build run_file
817
818      # First loop on the components for the coupler ie oasis (only if oasis3)
819      # the coupler ie oasis3 must be the first one
820      for comp in ${config_ListOfComponents[*]} ; do
821
822        if [ "X${comp}" = "XCPL" ]  ; then
823
824          eval ExeNameIn=\${config_Executable_${comp}[0]}
825          eval ExeNameOut=\${config_Executable_${comp}[1]}
826
827          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
828          echo ""  >> script_${ExeNameOut}.ksh
829          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
830          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
831          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
832          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
833          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
834
835          init_node=n
836
837          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
838          node_num_current=0
839          node_current=${host[${node_num_current}]}
840
841          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
842
843          init_exec=y
844          start_num=1
845
846        fi
847
848      done
849
850      # Then loop on the components (except for oasis)
851
852      for comp in ${config_ListOfComponents[*]} ; do
853
854        eval ExeNameIn=\${config_Executable_${comp}[0]}
855        eval ExeNameOut=\${config_Executable_${comp}[1]}
856
857        # Only if we really have an executable for the component :
858        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
859
860          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
861          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
862
863          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
864          # echo "set -vx" >> script_${ExeNameOut}.ksh
865          echo ""  >> script_${ExeNameOut}.ksh
866          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
867          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
868          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
869          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
870          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
871          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
872          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
873
874          node_num=0
875
876          # We define the number of MPI process to be assigned for the component
877
878          nombre_restant_comp=${comp_proc_mpi_loc}
879
880          # Loop on the allocated nodes
881
882          for node in ${listnodes} ; do
883
884            # We go to the current node
885            if [ ${node_num} = ${node_num_current} ] ; then
886
887              node_current=${host[${node_num_current}]}
888
889              # If first time on the node : initialisation
890
891              if [ ${init_node} = y ] ; then
892                nombre_restant_node=${NUM_COREPERNODE}
893              fi
894
895              # Test on the number of OMP threads
896
897              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
898                (( node_num = node_num + 1 ))
899                node_num_current=${node_num}
900                init_node=y
901                continue
902              fi
903
904              # Number of MPI process to assign
905
906              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
907
908              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
909                num_corempi=${nombre_restant_comp}
910              fi
911
912              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
913              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
914
915              if [ ${init_exec} = y ] ; then
916                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
917              else
918                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
919                init_exec=y
920              fi
921
922              ((  start_num = num_corempi + start_num ))
923
924            else
925
926              (( node_num = node_num + 1 ))
927              continue
928            fi
929
930            # Test on the number of core/process remaining on the node/component
931
932            if [ ${nombre_restant_node} = 0 ] ; then
933              (( node_num = node_num + 1 ))
934              node_num_current=${node_num}
935              init_node=y
936
937              if [ ${nombre_restant_comp} = 0 ] ; then
938                break 1
939              fi
940            else
941
942              node_num_current=${node_num}
943              init_node=n
944
945              if [ ${nombre_restant_comp} = 0 ] ; then
946                break 1
947              fi
948            fi
949          done
950        fi
951      done
952
953    else
954
955      # Then first loop on the components for the coupler ie oasis
956
957      ## the coupler ie oasis must be the first one
958      for comp in ${config_ListOfComponents[*]} ; do
959
960        eval ExeNameOut=\${config_Executable_${comp}[1]}
961
962        # for CPL component only
963        if [ "X${comp}" = "XCPL" ] ; then
964          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
965          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
966        fi
967      done
968
969      # Then second loop on the components
970
971      for comp in ${config_ListOfComponents[*]} ; do
972
973        eval ExeNameOut=\${config_Executable_${comp}[1]}
974
975        # Only if we really have an executable for the component and not the coupler ie oasis:
976        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
977          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
978          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
979        fi
980      done
981      IGCM_sys_Chmod u+x run_file
982
983      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
984
985    fi
986
987  else # Only one executable. launch it.
988
989    for comp in ${config_ListOfComponents[*]} ; do
990
991      # Only if we really have an executable for the component :
992      eval ExeNameOut=\${config_Executable_${comp}[1]}
993      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
994
995        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
996        echo ""  >> script_${ExeNameOut}.ksh
997        if ( ${OK_PARA_OMP} ) ; then
998          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
999          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1000        fi
1001        if  ( ${OK_PARA_MPI} ) ; then
1002          # Default : mpirun used if nb_proc gt 1
1003          # pour sortie out/err par process
1004          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1005          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1006          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1007          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1008        else
1009          # Default : mpirun is NOT used if nb_proc eq 1
1010          # pour sortie out/err par process
1011          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1012          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1013          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1014          EXECUTION="time ./script_${ExeNameOut}.ksh"
1015        fi
1016
1017        IGCM_debug_Print 1 "sys $( hostname ) : script_${ExeNameOut}.ksh contains"
1018        cat script_${ExeNameOut}.ksh
1019
1020      fi
1021
1022    done
1023
1024  fi
1025
1026  IGCM_debug_Print 1 "sys $( hostname ) : execution command is"
1027  IGCM_debug_Print 1 "$EXECUTION"
1028
1029  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1030}
1031
1032#D-#==================================================
1033#D-function IGCM_sys_check_path
1034#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1035#D-* do not point to an important use directory. Stop immediately in that case.
1036#D-* Examples:
1037#D-
1038function IGCM_sys_check_path {
1039  IGCM_debug_PushStack "IGCM_sys_check_path"
1040  if ( $DEBUG_sys ) ; then
1041    echo "IGCM_sys_check_path"
1042  fi
1043
1044  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1045    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1046    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1047    IGCM_debug_Exit "This will stop the job"
1048  fi
1049  IGCM_debug_PopStack "IGCM_sys_check_path"
1050}
1051
1052#D-#==================================================
1053#D-function IGCM_sys_check_quota. Dummy call here
1054#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1055#D-* Examples:
1056#D-
1057function IGCM_sys_check_quota {
1058  IGCM_debug_PushStack "IGCM_sys_check_quota"
1059  if ( $DEBUG_sys ) ; then
1060    echo "IGCM_sys_check_quota"
1061  fi
1062  IGCM_debug_PopStack "IGCM_sys_check_quota"
1063}
1064
1065#D-#==================================================
1066#D-function IGCM_sys_CountJobInQueue
1067#D-* Purpose: Check if job_name is currently
1068#D-  running or in queue
1069#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1070#D-
1071function IGCM_sys_CountJobInQueue {
1072  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1073  if ( $DEBUG_sys ) ; then
1074    echo "IGCM_sys_CountJobInQueue"
1075  fi
1076  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1077}
Note: See TracBrowser for help on using the repository browser.