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

Last change on this file since 1498 was 1459, checked in by jgipsl, 6 years ago

Removed variable R_IN_ECMWF (never used in reference experiment setups)

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