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

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