source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 1186

Last change on this file since 1186 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 Date Author Rev
File size: 30.8 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sébastien Denvil
5# Contact: Sebastien.Denvil__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 for IITM IBM machine
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=iitm01
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# Submit command
78typeset SUBMIT=${SUBMIT:=/usr/lpp/LoadL/full/bin/llsubmit}
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=iitm01
85typeset -r REMOTE_RSYNC=/usr/bin/rsync
86
87#====================================================
88# Set environment tools (ferret, nco, cdo, rebuild, ...)
89#====================================================
90# Not applicable here. Only rebuild path
91export export PATH=${PATH}:/gpfs1/home/sebastien/REBUILD/
92
93#====================================================
94# Host specific DIRECTORIES
95#====================================================
96
97#====================================================
98#- MirrorlibIGCM for frontend
99typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
100
101#====================================================
102#- libIGCM_POST for frontend
103typeset -r libIGCM_POST=${libIGCM}
104
105#====================================================
106#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
107typeset -r R_EXE="${MODIPSL}/bin"
108
109#====================================================
110#- SUBMIT_DIR : submission dir
111typeset SUBMIT_DIR=${SUBMIT_DIR:=${LOADL_STEP_INITDIR}}
112
113#====================================================
114#- IN
115typeset -r R_IN=${R_IN:=/gpfs1/home/sabin}
116typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/gpfs1/home/sabin}
117
118#====================================================
119#- RUN_DIR_PATH : Temporary working directory (=> TMP)
120typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=$( echo ${HOME} | sed -e "s/gpfs1/gpfs3/" )/RUN/${LOADL_STEP_ID}}
121
122#====================================================
123#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
124typeset -r OUTCOMMAND_PATH=/tmp
125
126#====================================================
127#- HOST_MPIRUN_COMMAND
128typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="/usr/bin/time poe"}
129
130#====================================================
131#- Max number of arguments passed to nco operator or demigration command
132UNIX_MAX_LIMIT=360
133
134#====================================================
135#- set PackDefault to false on iitm
136PackDefault=false
137
138#====================================================
139#- Number of core per node (max number of OpenMP task)
140NUM_COREPERNODE=2
141
142#====================================================
143#- Default number of MPI task for IPSL coupled model
144#- required for backward compatibility
145#-
146DEFAULT_NUM_PROC_OCE=5
147DEFAULT_NUM_PROC_CPL=1
148(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
149DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
150
151#D-#==================================================
152#D-function IGCM_sys_defineArchives
153#D-* Purpose:
154#D-* Define ARCHIVE : Dedicated to large files
155#D-* Define STORAGE : Dedicated to small/medium files
156#D-* Define R_OUT   : Output tree located on ARCHIVE
157#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
158#D-* Define R_BUF   : Output tree located on STORAGE hosting files waiting for rebuild or pack processes
159#D-* if SpaceName=TEST nothing special will hapen
160#D-* Examples:
161#D-
162function IGCM_sys_defineArchives {
163  IGCM_debug_PushStack "IGCM_sys_defineArchives"
164
165  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
166    #====================================================
167    #- ARCHIVE (dedicated to large files)
168    ARCHIVE=${config_UserChoices_ARCHIVE}
169  else
170    #====================================================
171    #- ARCHIVE (dedicated to large files)
172    ARCHIVE=$( echo ${HOME} | sed -e "s/gpfs1/gpfs3/" )
173  fi
174
175  if [ ! X${config_UserChoices_STORAGE} = X ]; then
176    #====================================================
177    #- STORAGE (dedicated to small/medium files)
178    STORAGE=${config_UserChoices_STORAGE}
179  else
180    #====================================================
181    #- STORAGE (dedicated to small/medium files)
182    STORAGE=${ARCHIVE}
183  fi
184
185  # ON OBELIX NO SPECIAL CASE WHEN X${config_UserChoices_SpaceName} = XTEST
186
187  #====================================================
188  #- R_OUT
189  R_OUT=${ARCHIVE}/IGCM_OUT
190
191  #====================================================
192  #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
193  R_FIG=${WORKDIR}/IGCM_OUT
194
195  #====================================================
196  #- R_BUF (ONLY FOR double copy an scratch)
197  R_BUF=${WORKDIR}/IGCM_OUT
198
199  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
200  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
201  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
202
203  IGCM_debug_PopStack "IGCM_sys_defineArchives"
204}
205
206#D-#==================================================
207#D-function IGCM_sys_RshArchive
208#D-* Purpose: Archive rsh command
209#D-* Examples:
210#D-
211function IGCM_sys_RshArchive {
212  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
213  /bin/ksh <<-EOF
214    ${@}
215EOF
216  status=$?
217  if [ ${status} -gt 0 ] ; then
218    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
219    IGCM_debug_Exit "IGCM_sys_RshArchive"
220  fi
221  IGCM_debug_PopStack "IGCM_sys_RshArchive"
222}
223
224#D-#==================================================
225#D-function IGCM_sys_RshArchive_NoError
226#D-* Purpose: Archive rsh command, without error
227#D-*          used only in monitoring.job
228#D-* Examples:
229#D-
230function IGCM_sys_RshArchive_NoError {
231  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
232  /bin/ksh <<-EOF
233    ${@} 2> /dev/null
234EOF
235  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
236}
237
238#D-#==================================================
239#D-function IGCM_sys_MkdirArchive
240#D-* Purpose: Mkdir on Archive
241#D-* Examples:
242#D-
243function IGCM_sys_MkdirArchive {
244  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
245  if ( $DEBUG_sys ) ; then
246    echo "IGCM_sys_MkdirArchive :" $@
247  fi
248  #- creation de repertoire sur le serveur fichier
249  if [ ! -d ${1} ]; then
250    \mkdir -p $1
251    status=$?
252
253    if [ ${status} -gt 0 ] ; then
254      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
255      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
256    fi
257  fi
258  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
259}
260
261#D-#==================================================
262#D-function IGCM_sys_TestDirArchive
263#D-* Purpose: Test Directory that must exists on Archive
264#D-* Examples:
265#D-
266function IGCM_sys_TestDirArchive {
267  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
268  if ( $DEBUG_sys ) ; then
269    echo "IGCM_sys_TestDirArchive :" $@
270  fi
271  typeset ExistFlag
272  ExistFlag=$( IGCM_sys_RshArchive "[ -d $1 ] && echo 0 || echo 1" )
273  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
274  return ${ExistFlag}
275}
276
277#D-#==================================================
278#D-function IGCM_sys_IsFileArchived
279#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
280#D-* Examples:
281#D-
282function IGCM_sys_IsFileArchived {
283  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
284  if ( $DEBUG_sys ) ; then
285    echo "IGCM_sys_IsFileArchived :" $@
286  fi
287  typeset IsArchivedFlag
288  IsArchivedFlag=$( [ "X$( echo $@ | grep \/gpfs3 )" != "X" ] && echo 0 || echo 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=$( IGCM_sys_RshArchive "[ -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  #Command depends on targeted file system
316  DEBUG_sys=false IGCM_sys_IsFileArchived $1
317  if [ $? = 0 ] ; then
318    IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
319    status=$?
320  else
321    ls ${@} 2>/dev/null | wc -l
322    status=$?
323  fi
324  if [ ${status} -gt 0 ] ; then
325    echo "IGCM_sys_CountFileArchive : erreur."
326  fi
327  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
328}
329
330#D-#==================================================
331#D-function IGCM_sys_Qsub
332#D-* Purpose: Qsub new job
333#D-* Examples:
334#D-
335function IGCM_sys_Qsub {
336  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
337
338  typeset status
339
340  if ( $DEBUG_sys ) ; then
341    echo "IGCM_sys_Qsub :" $@
342  fi
343  # We have to change output/error file
344  [ ${#@} = 1 ] &&  REP_FOR_JOB=${SUBMIT_DIR}
345  [ ${#@} = 2 ] &&  REP_FOR_JOB=${2}
346  sed -e "s:\# \@ output *= .*:\# \@ output = ${Script_Output}:" \
347    -e "s:\# \@ error *= .*:\# \@ error = ${Script_Output}:"   \
348    $1 > ${REP_FOR_JOB}/JOB_FOR_IGCM
349  cd $REP_FOR_JOB ; /usr/lpp/LoadL/full/bin/llsubmit JOB_FOR_IGCM > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 ; status=$? ; cd - ;
350
351  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
352  if [ ${status} -gt 0 ] ; then
353    IGCM_debug_Print 2 "IGCM_sys_Qsub $1 : error code ${status}"
354    IGCM_debug_Exit "IGCM_sys_Qsub"
355  else
356    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ | tail -1 | sed -e s/\"//g )
357    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM
358  fi
359  IGCM_debug_PopStack "IGCM_sys_Qsub"
360}
361
362#D-#==================================================
363#D-function IGCM_sys_QsubPost
364#D-* Purpose: Qsub new job on scalaire
365#D-* Examples:
366#D-
367function IGCM_sys_QsubPost {
368  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
369
370  typeset status
371
372  if ( $DEBUG_sys ) ; then
373    echo "IGCM_sys_QsubPost :" $@
374  fi
375  # We have to change output/error file
376  [ ${#@} = 1 ] &&  REP_FOR_JOB=${POST_DIR}
377  [ ${#@} = 2 ] &&  REP_FOR_JOB=${2}
378
379  sed -e "s:\# \@ output *= .*:\# \@ output = ${Script_Post_Output}.out:" \
380    -e "s:\# \@ error *= .*:\# \@ error = ${Script_Post_Output}.out:"   \
381    ${libIGCM_POST}/$1.job > ${REP_FOR_JOB}/JOB_FOR_IGCM
382
383  cd $REP_FOR_JOB ; /usr/lpp/LoadL/full/bin/llsubmit JOB_FOR_IGCM > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 ; status=$? ; cd - ;
384
385  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
386  if [ ${status} -gt 0 ] ; then
387    IGCM_debug_Print 2 "IGCM_sys_QsubPost $1 : error code ${status}"
388    IGCM_debug_Exit "IGCM_sys_QsubPost"
389  else
390    JobID=$( gawk {'print $4'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ | tail -1 | sed -e s/\"//g )
391    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM
392  fi
393  IGCM_debug_PopStack "IGCM_sys_QsubPost"
394}
395
396#D-*************************
397#D- File transfer functions
398#D-*************************
399#D-
400
401#D-#==================================================
402#D-function IGCM_sys_RmRunDir
403#D-* Purpose: rm tmpdir (dummy function most of the time batch
404#D-                      scheduler will do the job)
405#D-* Examples:
406#D-
407function IGCM_sys_RmRunDir {
408  IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@
409  if ( $DEBUG_sys ) ; then
410    echo "IGCM_sys_RmRunDir :" $@
411  fi
412
413  typeset status
414
415  echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
416  \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
417  status=$?
418
419  if [ ${status} -gt 0 ] ; then
420    IGCM_debug_Print 1 "IGCM_sys_RmRunDir : rm error code is ${status}."
421    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
422    IGCM_debug_Exit "IGCM_sys_RmRunDir"
423  else
424    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
425  fi
426  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
427}
428
429#D-#==================================================
430#D-function IGCM_sys_Put_Dir
431#D-* Purpose: Copy a complete directory on $(ARCHIVE)
432#D-* Examples:
433#D-
434function IGCM_sys_Put_Dir {
435  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
436  if ( $DEBUG_sys ) ; then
437    echo "IGCM_sys_Put_Dir :" $@
438  fi
439  if [ $DRYRUN = 0 ]; then
440    if [ ! -d ${1} ] ; then
441      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
442      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
443      return
444    fi
445
446    typeset status
447
448    # Only if we use rsync
449    #IGCM_sys_TestDirArchive $( dirname $2 )
450    #
451    #USUAL WAY
452    \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
453    status=$?
454
455    if [ ${status} -gt 0 ] ; then
456      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
457      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
458      IGCM_debug_Exit "IGCM_sys_Put_Dir"
459    else
460      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
461    fi
462  fi
463  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
464}
465
466#D-#==================================================
467#D-function IGCM_sys_Get_Dir
468#D-* Purpose: Copy a complete directory from ${ARCHIVE}
469#D-* Examples:
470#D-
471function IGCM_sys_Get_Dir {
472  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
473  if ( $DEBUG_sys ) ; then
474    echo "IGCM_sys_Get_Dir :" $@
475  fi
476  if [ $DRYRUN = 0 ]; then
477    if [ ! -d ${1} ] ; then
478      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
479      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
480      return
481    fi
482
483    typeset status
484
485    #USUAL WAY
486    \cp -ur $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
487    status=$?
488
489    if [ ${status} -gt 0 ] ; then
490      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
491      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
492      IGCM_debug_Exit "IGCM_sys_Get_Dir"
493    else
494      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
495    fi
496  fi
497  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
498}
499
500#D-#==================================================
501#D-function IGCM_sys_Put_Rest
502#D-* Purpose: Put computied restarts on ${ARCHIVE}.
503#D-           File and target directory must exist.
504#D-* Examples:
505#D-
506function IGCM_sys_Put_Rest {
507  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
508  if ( $DEBUG_sys ) ; then
509    echo "IGCM_sys_Put_Rest :" $@
510  fi
511  if [ $DRYRUN = 0 ]; then
512    if [ ! -f ${1} ] ; then
513      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
514      IGCM_debug_Exit "IGCM_sys_Put_Rest"
515    fi
516
517    typeset status
518    #
519    if [ X${JobType} = XRUN ] ; then
520      IGCM_sys_Chmod 444 ${1}
521    fi
522    #
523    # Only if we use rsync
524    #IGCM_sys_MkdirArchive $( dirname $2 )
525    #
526    #USUAL WAY
527    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
528    status=$?
529
530    if [ ${status} -gt 0 ] ; then
531      IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}"
532      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
533      IGCM_debug_Exit "IGCM_sys_Put_Rest"
534    else
535      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
536    fi
537  fi
538  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
539}
540
541#D-#==================================================
542#D-function IGCM_sys_Put_Out
543#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
544#D-* Examples:
545#D-
546function IGCM_sys_Put_Out {
547  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
548  if ( $DEBUG_sys ) ; then
549    echo "IGCM_sys_Put_Out :" $@
550  fi
551
552  typeset status
553
554  if [ $DRYRUN = 0 ]; then
555    if [ ! -f ${1} ] ; then
556      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
557      IGCM_debug_PopStack "IGCM_sys_Put_Out"
558      return 1
559    fi
560    #
561    IGCM_sys_MkdirArchive $( dirname $2 )
562    #
563    if [ X${JobType} = XRUN ] ; then
564      if [ X${3} = X ] ; then
565        IGCM_sys_Chmod 444 ${1}
566      fi
567    fi
568    #
569    #USUAL WAY
570    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
571    status=$?
572
573    if [ ${status} -gt 0 ] ; then
574      IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status}"
575      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
576      IGCM_debug_Exit "IGCM_sys_Put_Out"
577    else
578      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
579    fi
580  fi
581  IGCM_debug_PopStack "IGCM_sys_Put_Out"
582  return 0
583}
584
585#D-#==================================================
586#D-function IGCM_sys_Get
587#D-* Purpose: Get a file from ${ARCHIVE}
588#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
589#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
590function IGCM_sys_Get {
591  IGCM_debug_PushStack "IGCM_sys_Get" $@
592
593  typeset DEST status dm_liste
594
595  if ( $DEBUG_sys ) ; then
596    echo "IGCM_sys_Get :" $@
597  fi
598  if [ $DRYRUN -le 2 ]; then
599    if [ X${1} = X'/l' ] ; then
600      eval set +A dm_liste \${${2}}
601    else
602      dm_liste=${1}
603    fi
604    eval DEST=\${${#}}
605
606    # test if the (first) file is present in the old computation :
607    DEBUG_sys=false IGCM_sys_IsFileArchived ${dm_liste[0]}
608    if [ $? = 0 ] ; then
609      IGCM_sys_TestFileArchive ${dm_liste[0]}
610      status=$?
611    else
612      IGCM_sys_TestFileBuffer ${dm_liste[0]}
613      status=$?
614    fi
615
616    if [ ${status} -gt 0 ] ; then
617      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
618      IGCM_debug_Exit "IGCM_sys_Get"
619      return
620    fi
621
622    #USUAL WAY
623    \cp ${dm_liste[*]} ${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
624    status=$?
625
626    if [ ${status} -gt 0 ] ; then
627      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
628      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
629      IGCM_debug_Exit "IGCM_sys_Get"
630    else
631      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
632    fi
633  fi
634  IGCM_debug_PopStack "IGCM_sys_Get"
635}
636
637#D-#==================================================
638#D-function IGCM_sys_Dods_Rm
639#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
640#D-* Examples:
641#D-
642function IGCM_sys_Dods_Rm {
643  if ( $DEBUG_sys ) ; then
644    echo "IGCM_sys_Dods_Rm :" $@
645  fi
646  return 0
647}
648
649#D-#==================================================
650#D-function IGCM_sys_Dods_Cp
651#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
652#D-* Examples:
653#D-
654function IGCM_sys_Dods_Cp {
655  if ( $DEBUG_sys ) ; then
656    echo "IGCM_sys_Dods_Cp :" $@
657  fi
658  return 0
659}
660
661#D-#==================================================
662#D-function IGCM_sys_Put_Dods
663#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
664#D-* Examples:
665#D-
666function IGCM_sys_Put_Dods {
667  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
668  if ( $DEBUG_sys ) ; then
669    echo "IGCM_sys_Put_Dods :" $@
670  fi
671  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
672}
673
674##############################################################
675# REBUILD OPERATOR
676
677#D-#==================================================
678#D-function IGCM_sys_sync
679#D-* Purpose: flush buffer on disk (dummy function on Ada)
680#D-* Examples:
681#D-
682function IGCM_sys_sync {
683  IGCM_debug_PushStack "IGCM_sys_sync" $@
684  if ( $DEBUG_sys ) ; then
685    echo "IGCM_sys_sync :" $@
686    echo "Dummy call, let the system do that."
687  fi
688  IGCM_debug_PopStack "IGCM_sys_sync"
689}
690
691############################################################
692# Activate Running Environnment Variables
693
694#D-#==================================================
695#D-function IGCM_sys_desactiv_variables
696#D-* Purpose: set environement variables prior to execution
697#D-* Examples:
698#D-
699function IGCM_sys_activ_variables {
700  IGCM_debug_PushStack "IGCM_sys_activ_variables"
701  if ( $DEBUG_sys ) ; then
702    echo "IGCM_sys_activ_variables"
703  fi
704
705# --------------------------------------------------------------------
706#D- MPI specifications
707# --------------------------------------------------------------------
708
709# --------------------------------------------------------------------
710#D- Other specifications
711# --------------------------------------------------------------------
712
713  IGCM_debug_PopStack "IGCM_sys_activ_variables"
714}
715
716############################################################
717# Desactivate Running Environnment Variables
718
719#D-#==================================================
720#D-function IGCM_sys_desactiv_variables
721#D-* Purpose: unset environement variables after execution
722#D-* Examples:
723#D-
724function IGCM_sys_desactiv_variables {
725  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
726  if ( $DEBUG_sys ) ; then
727    echo "IGCM_sys_desactiv_variables"
728  fi
729# --------------------------------------------------------------------
730#D- MPI specifications
731# --------------------------------------------------------------------
732
733# --------------------------------------------------------------------
734#D- Other specifications
735# --------------------------------------------------------------------
736
737  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
738}
739
740############################################################
741# Build MPI/OMP scripts run file (dummy function)
742
743#D-#==================================================
744#D-function IGCM_sys_build_run_file
745#D-* Purpose: build run file (deprecated)
746#D-* Examples:
747#D-
748function IGCM_sys_build_run_file {
749
750  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
751
752}
753
754############################################################
755# Build MPI/OMP scripts
756
757#D-#==================================================
758#D-function IGCM_sys_build_execution_scripts
759#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
760#D-* Examples:
761#D-
762function IGCM_sys_build_execution_scripts
763{
764  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
765  if ( $DEBUG_sys ) ; then
766    echo "IGCM_sys_build_execution_scripts " $@
767  fi
768
769  typeset NbNodes_Job NbProc_Job comp_proc_mpi_loc comp_proc_omp_loc mpi_count
770
771  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
772    IGCM_debug_Exit "IGCM_sys_iitm build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
773  fi
774
775  if ( ${OK_PARA_MPMD} ) ; then
776
777    if [ -f run_file ] ; then
778      IGCM_sys_Rm -f run_file
779    fi
780    touch run_file
781
782    if ( ${OK_PARA_OMP} ) ; then
783# NEW : 2 Noeuds
784# @ task_geometry={(0)(1,2,3)}
785# Nombre de processus demandes
786      echo "Job_${config_UserChoices_JobName} includes task_geometry = \c"
787      cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g"
788      echo "Job_${config_UserChoices_JobName} includes task_geometry  with NbNodes = \c"
789      cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" | wc -c
790      NbNodes_Job=$(( $( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "task_geometry" | sed -e "s/[^(]*([^(]*/(/g" | wc -c ) - 1 ))
791
792      if [ ${NbNodes_Job} -eq 0 ] ; then
793        IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no task_geometry defined with OpenMP run."
794        exit 1
795      fi
796    else
797
798# OLD :
799# @ total_tasks = 3
800# @ environment = "BATCH_NUM_PROC_TOT=3"
801# Pas d OpenMP
802# @ resources = ConsumableCpus(1)
803
804      echo "Job_${config_UserChoices_JobName} includes total_tasks = \c"
805      cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "total_tasks" | sed -e "s/.*total_tasks = //"
806      NbProc_Job=$( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep "total_tasks" | sed -e "s/.*total_tasks = //" )
807      NbProc_Job=${NbProc_Job:=0}
808      if [ ${NbProc_Job} -eq 0 ] ; then
809        IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no total_tasks defined with MPI only run."
810        exit 1
811      fi
812      if ( $( egrep '^# *@ *resources *= *ConsumableCpus\(1\)' ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} >/dev/null 2>&1 ) ) ; then
813        IGCM_debug_Print 2 "ressources =  ConsumableCpus(1) line found into Job_${config_UserChoices_JobName}"
814      else
815        IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources = line not found. Job should include resources = ConsumableCpus(1) "
816        exit 1
817      fi
818    fi
819
820# run_file construction
821
822# Then first loop on the components for the coupler ie oasis
823
824### the coupler ie oasis must be the first one
825    for comp in ${config_ListOfComponents[*]} ; do
826
827      eval ExeNameIn=\${config_Executable_${comp}[0]}
828      eval ExeNameOut=\${config_Executable_${comp}[1]}
829
830      # for CPL component only
831      if [ "X${comp}" = "XCPL" ] ; then
832
833        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
834        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
835
836        if ( ${OK_PARA_MPI} ) ; then
837          (( mpi_count = 1 ))
838          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
839            if ( ${OK_PARA_OMP} ) ; then
840              echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
841            else
842              echo "./${ExeNameOut}" >> run_file
843            fi
844            (( mpi_count = mpi_count + 1 ))
845          done
846        else
847          if ( ${OK_PARA_OMP} ) ; then
848            echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
849          else
850            echo "./${ExeNameOut} " >> run_file
851          fi
852        fi
853      fi
854    done
855
856# Then second loop on the components
857
858    for comp in ${config_ListOfComponents[*]} ; do
859
860      eval ExeNameIn=\${config_Executable_${comp}[0]}
861      eval ExeNameOut=\${config_Executable_${comp}[1]}
862
863      # Only if we really have an executable for the component and not the coupler ie oasis:
864      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
865
866        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
867        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
868
869        if ( ${OK_PARA_MPI} ) ; then
870          (( mpi_count = 1 ))
871          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
872            if ( ${OK_PARA_OMP} ) ; then
873              echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
874            else
875              echo "./${ExeNameOut}" >> run_file
876            fi
877            (( mpi_count = mpi_count + 1 ))
878          done
879        else
880          if ( ${OK_PARA_OMP} ) ; then
881            echo "env OMP_NUM_THREADS=${comp_proc_omp_loc} ./${ExeNameOut} " >> run_file
882          else
883                    # to be tested : no MPI only OpenMP into MPMD mode
884            echo "./${ExeNameOut} " >> run_file
885          fi
886        fi
887      fi
888    done
889
890    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
891
892    IGCM_sys_Chmod u+x run_file
893    if ( $DEBUG_sys ) ; then
894      echo "run_file contains : "
895      cat run_file
896    fi
897
898  # Only one executable (SPMD mode).
899  else
900
901    for comp in ${config_ListOfComponents[*]} ; do
902
903      # Only if we really have an executable for the component :
904      eval ExeNameOut=\${config_Executable_${comp}[1]}
905      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
906        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
907      fi
908
909    done
910
911  fi
912
913  IGCM_debug_Print 1 "sys iitm : execution command is"
914  IGCM_debug_Print 1 "$EXECUTION"
915
916  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
917}
918
919#D-#==================================================
920#D-function IGCM_sys_check_path
921#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
922#D-* do not point to an important use directory. Stop immediately in that case.
923#D-* Examples:
924#D-
925function IGCM_sys_check_path {
926  IGCM_debug_PushStack "IGCM_sys_check_path"
927  if ( $DEBUG_sys ) ; then
928    echo "IGCM_sys_check_path"
929  fi
930
931  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${WORKDIR} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
932    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
933    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
934    IGCM_debug_Exit "This will stop the job"
935  fi
936  IGCM_debug_PopStack "IGCM_sys_check_path"
937}
938
939#D-#==================================================
940#D-function IGCM_sys_check_quota. Dummy call here
941#D-* Purpose: check user quota. Stop the simulation if quota above 90%
942#D-* Examples:
943#D-
944function IGCM_sys_check_quota {
945  IGCM_debug_PushStack "IGCM_sys_check_quota"
946  if ( $DEBUG_sys ) ; then
947    echo "IGCM_sys_check_quota"
948  fi
949  IGCM_debug_PopStack "IGCM_sys_check_quota"
950}
951
952#D-#==================================================
953#D-function IGCM_sys_CountJobInQueue
954#D-* Purpose: Check if job_name is currently
955#D-  running or in queue
956#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
957#D-
958function IGCM_sys_CountJobInQueue {
959  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
960  if ( $DEBUG_sys ) ; then
961    echo "IGCM_sys_CountJobInQueue"
962  fi
963
964  # Print only the full (-W) JobName (%jn)
965  NbRun=$( llq -W -f %jn | grep -c "$1" )
966
967  eval ${2}=${NbRun}
968
969  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
970}
Note: See TracBrowser for help on using the repository browser.