source: tags/libIGCM_v2.8.2/libIGCM_sys/libIGCM_sys_ciclad.ksh @ 1368

Last change on this file since 1368 was 1358, checked in by sdipsl, 8 years ago
  • load python module before netcdf modules. So that netcdf/hdf libraries path from python wont affect dynamically linked binaries to "classic" netcdf/hdf librairies.
  • export explicitely PCMDI_MP variable
  • Property svn:keywords set to Revision Date Author
File size: 39.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien 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 ciclad
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 user names project maxCpuTime
65# $hostname ou hostname
66typeset HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=${MASTER:=$( hostname )}
71# project name
72typeset PROJECT=NONE
73# jobWarningDelay in seconds
74typeset jobWarningDelay=${PBS_WALLTIME}
75
76#D-
77#D-#==================================================
78#D-Program used in libIGCM
79#D-#==================================================
80
81# Submit command
82typeset SUBMIT=${SUBMIT:=qsub}
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=${MASTER}
89
90#====================================================
91# Access to module command
92#====================================================
93. /usr/share/Modules/init/ksh
94
95#====================================================
96# Set environment tools (ferret, nco, cdo, rebuild, ...)
97#====================================================
98if [ $CENTER == IPSL-ciclad ] ; then
99    # At ciclad
100    export PATH=${PATH}:/home/igcmg/rebuild/src_X64_CICLAD/modipsl_v2_2_3_netcdf4.2/bin/
101    module load python/2.7-anaconda > /dev/null 2>&1
102    . /home/igcmg/.atlas_env_ciclad_ksh
103else
104    # At climserv use the same files stored at ciclad but adapt the path
105    export PATH=${PATH}:/ciclad-home/igcmg/rebuild/src_X64_CICLAD/modipsl_v2_2_3_netcdf4.2/bin/
106    module load python/2.7-anaconda > /dev/null 2>&1
107    . /ciclad-home/igcmg/.atlas_env_ciclad_ksh
108fi
109
110[ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
111[ ! X${TaskType} = Xchecking ] && module list
112
113#====================================================
114# Host specific DIRECTORIES
115#====================================================
116
117#====================================================
118#- MirrorlibIGCM for frontend
119typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
120
121#====================================================
122#- libIGCM_POST for frontend
123typeset -r libIGCM_POST=${libIGCM}
124
125#====================================================
126#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
127typeset -r R_EXE="${MODIPSL}/bin"
128
129#====================================================
130#- SUBMIT_DIR : submission dir
131if [ X${PBS_O_WORKDIR} != X ] ; then
132  typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
133else
134  typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
135fi
136
137#====================================================
138#- IN
139typeset -r R_IN=${R_IN:=/prodigfs/ipslfs/igcmg/IGCM}
140typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/prodigfs/ipslfs/igcmg/IGCM}
141
142#====================================================
143#- RUN_DIR_PATH : Temporary working directory (=> TMP)
144if [ X${PBS_JOBID} != X ] ; then
145    if [ $CENTER == IPSL-ciclad ] ; then
146        typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/data/${LOGIN}/RUN_DIR/${PBS_JOBID}_${$}}
147    else
148        typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/homedata/${LOGIN}/RUN_DIR/${PBS_JOBID}_${$}}
149    fi
150else
151  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/tmp/tmp$$}
152fi
153
154#====================================================
155#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
156typeset -r OUTCOMMAND_PATH=/tmp
157
158#====================================================
159#- HOST_MPIRUN_COMMAND
160typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
161
162#====================================================
163#- Max number of arguments passed to nco operator or demigration command
164UNIX_MAX_LIMIT=360
165
166#====================================================
167#- set PackDefault to false on ciclad
168PackDefault=false
169
170#====================================================
171#- Default number of MPI task for IPSL coupled model
172#- required for backward compatibility
173#-
174DEFAULT_NUM_PROC_OCE=5
175DEFAULT_NUM_PROC_CPL=1
176(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
177
178#D-#==================================================
179#D-function IGCM_sys_defineArchives
180#D-* Purpose:
181#D-* Define ARCHIVE : Dedicated to large files
182#D-* Define STORAGE : Dedicated to small/medium files
183#D-* Define R_OUT   : Output tree located on ARCHIVE
184#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
185#D-* Define R_BUF   : Output tree located on STORAGE hosting files waiting for rebuild or pack processes
186#D-* if SpaceName=TEST nothing special will hapen
187#D-* Examples:
188#D-
189function IGCM_sys_defineArchives {
190  IGCM_debug_PushStack "IGCM_sys_defineArchives"
191
192  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
193    #====================================================
194    #- ARCHIVE (dedicated to large files)
195    ARCHIVE=${config_UserChoices_ARCHIVE}
196  else
197    #====================================================
198    #- ARCHIVE (dedicated to large files)
199    if [ $CENTER == IPSL-ciclad ] ; then
200        # At ciclad
201        ARCHIVE=${ARCHIVE:=/data/${LOGIN}}
202    else
203        # At climserv
204        ARCHIVE=${ARCHIVE:=/homedata/${LOGIN}}
205    fi
206  fi
207
208  if [ ! X${config_UserChoices_STORAGE} = X ]; then
209    #====================================================
210    #- STORAGE (dedicated to small/medium files)
211    STORAGE=${config_UserChoices_STORAGE}
212  else
213    #====================================================
214    #- STORAGE (dedicated to small/medium files)
215    STORAGE=${ARCHIVE}
216  fi
217
218  # ON CICLAD NO SPECIAL CASE WHEN X${config_UserChoices_SpaceName} = XTEST
219
220  #====================================================
221  #- R_OUT
222  R_OUT=${ARCHIVE}/IGCM_OUT
223
224  #====================================================
225  #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
226  R_FIG=${STORAGE}/IGCM_OUT
227
228  #====================================================
229  #- R_BUF (ONLY FOR double copy an scratch)
230  R_BUF=${STORAGE}/IGCM_OUT
231
232  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
233  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
234  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
235
236  IGCM_debug_PopStack "IGCM_sys_defineArchives"
237}
238
239#D-#==================================================
240#D-function IGCM_sys_RshArchive
241#D-* Purpose: Archive rsh command
242#D-* Examples:
243#D-
244function IGCM_sys_RshArchive {
245  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
246  /bin/ksh <<-EOF
247    ${@}
248EOF
249  status=$?
250  if [ ${status} -gt 0 ] ; then
251    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
252    IGCM_debug_Exit "IGCM_sys_RshArchive"
253  fi
254  IGCM_debug_PopStack "IGCM_sys_RshArchive"
255}
256
257#D-#==================================================
258#D-function IGCM_sys_RshArchive_NoError
259#D-* Purpose: Archive rsh command, without error
260#D-*          used only in monitoring.job
261#D-* Examples:
262#D-
263function IGCM_sys_RshArchive_NoError {
264  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
265  /bin/ksh <<-EOF
266    ${@} 2> /dev/null
267EOF
268  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
269}
270
271#D-#==================================================
272#D-function IGCM_sys_MkdirArchive
273#D-* Purpose: Mkdir on Archive
274#D-* Examples:
275#D-
276function IGCM_sys_MkdirArchive {
277  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
278  if ( $DEBUG_sys ) ; then
279    echo "IGCM_sys_MkdirArchive :" $@
280  fi
281  #- creation de repertoire sur le serveur fichier
282  if [ ! -d ${1} ]; then
283    \mkdir -p $1
284    status=$?
285
286    if [ ${status} -gt 0 ] ; then
287      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
288      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
289    fi
290  fi
291  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
292}
293
294#D-#==================================================
295#D-function IGCM_sys_TestDirArchive
296#D-* Purpose: Test Directory that must exists on Archive
297#D-* Examples:
298#D-
299function IGCM_sys_TestDirArchive {
300  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
301  if ( $DEBUG_sys ) ; then
302    echo "IGCM_sys_TestDirArchive :" $@
303  fi
304  typeset ExistFlag
305  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
306  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
307  return ${ExistFlag}
308}
309
310#D-#==================================================
311#D-function IGCM_sys_IsFileArchived
312#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
313#D-* Examples:
314#D-
315function IGCM_sys_IsFileArchived {
316  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
317  if ( $DEBUG_sys ) ; then
318    echo "IGCM_sys_IsFileArchived :" $@
319  fi
320  typeset IsArchivedFlag
321  # Never archived for this system
322  IsArchivedFlag=1
323  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
324
325  return ${IsArchivedFlag}
326}
327
328#D-#==================================================
329#D-function IGCM_sys_TestFileArchive
330#D-* Purpose: Test file that must NOT EXISTS on Archive
331#D-* Examples:
332#D-
333function IGCM_sys_TestFileArchive {
334  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
335  typeset ExistFlag
336  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
337  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
338
339  return ${ExistFlag}
340}
341
342#D-#==================================================
343#D-function IGCM_sys_CountFileArchive
344#D-* Purpose: Count files on Archive filesystem
345#D-* Examples:
346#D-
347function IGCM_sys_CountFileArchive {
348  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
349  ls ${@} 2>/dev/null | wc -l
350  if [ $? -gt 0 ] ; then
351    echo "IGCM_sys_CountFileArchive : erreur."
352  fi
353  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
354}
355
356#D-#==================================================
357#D-function IGCM_sys_Tree
358#D-* Purpose: Tree directories with files on ${ARCHIVE}
359#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
360#D-
361function IGCM_sys_Tree {
362  IGCM_debug_PushStack "IGCM_sys_Tree" $@
363  if ( $DEBUG_sys ) ; then
364    echo "IGCM_sys_Tree :" $@
365  fi
366
367  \ls -lR ${@}
368
369  IGCM_debug_PopStack "IGCM_sys_Tree"
370}
371
372#D-#==================================================
373#D-function IGCM_sys_Qsub
374#D-* Purpose: Qsub new job
375#D-* Examples:
376#D-
377function IGCM_sys_Qsub {
378  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
379  if ( $DEBUG_sys ) ; then
380    echo "IGCM_sys_Qsub :" $@
381  fi
382  typeset options status
383  options="-o ${SUBMIT_DIR}/${Script_Output}"
384  /usr/bin/qsub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
385  status=$?
386
387  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
388  if [ ${status} -gt 0 ] ; then
389    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
390    IGCM_debug_Exit "IGCM_sys_Qsub"
391  else
392    JobID=$( gawk {'print $1'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
393  fi
394  IGCM_debug_PopStack "IGCM_sys_Qsub"
395}
396
397#D-#==================================================
398#D-function IGCM_sys_QsubPost
399#D-* Purpose: Qsub new job on scalaire
400#D-* Examples:
401#D-
402function IGCM_sys_QsubPost {
403  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
404  if ( $DEBUG_sys ) ; then
405    echo "IGCM_sys_QsubPost :" $@
406  fi
407  typeset options status
408  options="-o ${POST_DIR}/${Script_Post_Output}.out -v ${listVarEnv}"
409  /usr/bin/qsub ${options} ${libIGCM_POST}/$1.job > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
410  status=$?
411
412  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
413  if [ ${status} -gt 0 ] ; then
414    IGCM_debug_Print 2 "IGCM_sys_QsubPost ${options} ${libIGCM_POST}/$1.job : error code ${status}"
415    IGCM_debug_Exit "IGCM_sys_QsubPost"
416  else
417    JobID=$( gawk {'print $1'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
418  fi
419  IGCM_debug_PopStack "IGCM_sys_QsubPost"
420}
421
422#D-*************************
423#D- File transfer functions
424#D-*************************
425#D-
426
427#D-#==================================================
428#D-function IGCM_sys_RmRunDir
429#D-* Purpose: rm tmpdir (dummy function most of the time batch
430#D-                      scheduler will do the job)
431#D-* Examples:
432#D-
433function IGCM_sys_RmRunDir {
434  IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@
435  if ( $DEBUG_sys ) ; then
436    echo "IGCM_sys_RmRunDir :" $@
437  fi
438
439  typeset status
440
441  echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
442  \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
443  status=$?
444
445  if [ ${status} -gt 0 ] ; then
446    IGCM_debug_Print 1 "IGCM_sys_RmRunDir : rm error code is ${status}."
447    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
448    IGCM_debug_Exit "IGCM_sys_RmRunDir"
449  else
450    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
451  fi
452  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
453}
454
455#D-#==================================================
456#D-function IGCM_sys_Put_Dir
457#D-* Purpose: Copy a complete directory on $(ARCHIVE)
458#D-* Examples:
459#D-
460function IGCM_sys_Put_Dir {
461  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
462  if ( $DEBUG_sys ) ; then
463    echo "IGCM_sys_Put_Dir :" $@
464  fi
465  if [ $DRYRUN = 0 ]; then
466    if [ ! -d ${1} ] ; then
467      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
468      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
469      return
470    fi
471
472    typeset status
473
474    # Only if we use rsync
475    #IGCM_sys_TestDirArchive $( dirname $2 )
476    #
477    #USUAL WAY
478    \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
479    status=$?
480
481    if [ ${status} -gt 0 ] ; then
482      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
483      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
484      IGCM_debug_Exit "IGCM_sys_Put_Dir"
485    else
486      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
487    fi
488  fi
489  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
490}
491
492#D-#==================================================
493#D-function IGCM_sys_Get_Dir
494#D-* Purpose: Copy a complete directory from ${ARCHIVE}
495#D-* Examples:
496#D-
497function IGCM_sys_Get_Dir {
498  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
499  if ( $DEBUG_sys ) ; then
500    echo "IGCM_sys_Get_Dir :" $@
501  fi
502  if [ $DRYRUN = 0 ]; then
503    typeset NB_ESSAI DELAI status i
504    # number of tentative
505    NB_ESSAI=3
506    # time delay between tentative
507    DELAI=2
508
509    #
510    # USUAL WAY
511    i=0
512    while [ $i -lt $NB_ESSAI ] ; do
513      \cp -ur $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
514      status=$?
515      if [ ${status} -gt 0 ] ; then
516        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
517        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
518        sleep $DELAI
519      else
520        break
521      fi
522      (( i = i + 1 ))
523    done
524
525    if [ ${status} -gt 0 ] ; then
526      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
527      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
528      IGCM_debug_Exit "IGCM_sys_Get_Dir"
529    else
530      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
531    fi
532  fi
533  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
534}
535
536#D-#==================================================
537#D-function IGCM_sys_Put_Rest
538#D-* Purpose: Put computied restarts on ${ARCHIVE}.
539#D-           File and target directory must exist.
540#D-* Examples:
541#D-
542function IGCM_sys_Put_Rest {
543  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
544  if ( $DEBUG_sys ) ; then
545    echo "IGCM_sys_Put_Rest :" $@
546  fi
547  if [ $DRYRUN = 0 ]; then
548    if [ ! -f ${1} ] ; then
549      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
550      IGCM_debug_Exit "IGCM_sys_Put_Rest"
551    fi
552
553    typeset status
554    #
555    # USUAL WAY
556    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
557    status=$?
558
559#       #RSYNC WITH NETWORK SSH CALL
560#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
561#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
562
563#       #RSYNC WITH NFS USE
564#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
565#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
566
567#       status=$?
568#       IGCM_sys_Rsync_out $status
569
570#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
571#       (( status=status+$? ))
572
573    if [ ${status} -gt 0 ] ; then
574      IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}"
575      [ -f ${1} ] && ls -l ${1}
576      [ -f ${2} ] && ls -l ${2}
577      [ -f ${2}/${1} ] && ls -l ${2}/${1}
578      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
579      IGCM_debug_Exit "IGCM_sys_Put_Rest"
580    else
581
582      if [ X${JobType} = XRUN ] ; then
583        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
584        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
585      fi
586
587      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
588    fi
589  fi
590  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
591}
592
593#D-#==================================================
594#D-function IGCM_sys_Put_Out
595#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
596#D-* Examples:
597#D-
598function IGCM_sys_Put_Out {
599  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
600  if ( $DEBUG_sys ) ; then
601    echo "IGCM_sys_Put_Out :" $@
602  fi
603
604  typeset status
605
606  if [ $DRYRUN = 0 ]; then
607    if [ ! -f ${1} ] ; then
608      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
609      IGCM_debug_PopStack "IGCM_sys_Put_Out"
610      return 1
611    fi
612    #
613    IGCM_sys_MkdirArchive $( dirname $2 )
614    #
615    if [ X${JobType} = XRUN ] ; then
616      if [ X${3} = X ] ; then
617        IGCM_sys_Chmod 444 ${1}
618      fi
619    fi
620    #
621
622    echo ${RSYNC} ${RSYNC_opt} $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
623    ${RSYNC} ${RSYNC_opt} $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
624    status=$?
625    IGCM_sys_Rsync_out $status
626
627    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
628    (( status=status+$? ))
629
630    if [ ${status} -gt 0 ] ; then
631      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
632      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
633      IGCM_debug_Exit "IGCM_sys_Put_Out"
634    else
635      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
636    fi
637  fi
638  IGCM_debug_PopStack "IGCM_sys_Put_Out"
639  return 0
640}
641
642#D-#==================================================
643#D-function IGCM_sys_Get
644#D-* Purpose: Get a file from ${ARCHIVE}
645#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
646#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
647function IGCM_sys_Get {
648  IGCM_debug_PushStack "IGCM_sys_Get" $@
649
650  typeset DEST status dm_liste
651
652  if ( $DEBUG_sys ) ; then
653    echo "IGCM_sys_Get :" $@
654  fi
655  if [ $DRYRUN -le 2 ]; then
656    if [ X${1} = X'/l' ] ; then
657      eval set +A dm_liste \${${2}}
658    else
659      dm_liste=${1}
660    fi
661    eval DEST=\${${#}}
662
663    # test if the (first) file is present in the old computation :
664    IGCM_sys_TestFileArchive ${dm_liste[0]}
665    status=$?
666    if [ ${status} -gt 0 ] ; then
667      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
668      IGCM_debug_Exit "IGCM_sys_Get"
669      return
670    fi
671
672    #USUAL WAY
673    \cp ${dm_liste[*]} ${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
674    status=$?
675
676    if [ ${status} -gt 0 ] ; then
677      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
678      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
679      IGCM_debug_Exit "IGCM_sys_Get"
680    else
681      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
682    fi
683  fi
684  IGCM_debug_PopStack "IGCM_sys_Get"
685}
686
687#D-#==================================================
688#D-function IGCM_sys_GetDate_Monitoring
689#D-* Purpose: get the last year for which the monitoring has been computed
690#D-* Examples:
691#D-
692function IGCM_sys_GetDate_Monitoring {
693  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
694  if ( $DEBUG_sys ) ; then
695    echo "IGCM_sys_GetDate_Monitoring :" $@
696  fi
697
698  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
699
700  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
701}
702
703#D-#==================================================
704#D-function IGCM_sys_Dods_Rm
705#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
706#D-* Examples:
707#D-
708function IGCM_sys_Dods_Rm {
709  if ( $DEBUG_sys ) ; then
710    echo "IGCM_sys_Dods_Rm :" $@
711  fi
712  return 0
713}
714
715#D-#==================================================
716#D-function IGCM_sys_Dods_Cp
717#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
718#D-* Examples:
719#D-
720function IGCM_sys_Dods_Cp {
721  if ( $DEBUG_sys ) ; then
722    echo "IGCM_sys_Dods_Cp :" $@
723  fi
724  return 0
725}
726
727#D-#==================================================
728#D-function IGCM_sys_Put_Dods
729#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
730#D-* Examples:
731#D-
732function IGCM_sys_Put_Dods {
733  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
734  if ( $DEBUG_sys ) ; then
735    echo "IGCM_sys_Put_Dods :" $@
736  fi
737  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
738}
739
740##############################################################
741# REBUILD OPERATOR
742
743#D-#==================================================
744#D-function IGCM_sys_sync
745#D-* Purpose: flush buffer on disk (dummy function on Ciclad)
746#D-* Examples:
747#D-
748function IGCM_sys_sync {
749  IGCM_debug_PushStack "IGCM_sys_sync" $@
750  if ( $DEBUG_sys ) ; then
751    echo "IGCM_sys_sync :" $@
752    echo "Dummy call, let the system do that."
753  fi
754  IGCM_debug_PopStack "IGCM_sys_sync"
755}
756
757############################################################
758# Activate Running Environnment Variables
759
760#D-#==================================================
761#D-function IGCM_sys_activ_variables
762#D-* Purpose: set environement variables prior to execution
763#D-* Examples:
764#D-
765function IGCM_sys_activ_variables {
766  IGCM_debug_PushStack "IGCM_sys_activ_variables"
767  if ( $DEBUG_sys ) ; then
768    echo "IGCM_sys_activ_variables"
769  fi
770
771# --------------------------------------------------------------------
772#D- MPI specifications
773# --------------------------------------------------------------------
774
775# --------------------------------------------------------------------
776#D- Other specifications
777# --------------------------------------------------------------------
778
779  ulimit -s unlimited
780
781  IGCM_debug_PopStack "IGCM_sys_activ_variables"
782}
783
784############################################################
785# Desactivate Running Environnment Variables
786
787#D-#==================================================
788#D-function IGCM_sys_desactiv_variables
789#D-* Purpose: unset environement variables after execution
790#D-* Examples:
791#D-
792function IGCM_sys_desactiv_variables {
793  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
794  if ( $DEBUG_sys ) ; then
795    echo "IGCM_sys_desactiv_variables"
796  fi
797# --------------------------------------------------------------------
798#D- MPI specifications
799# --------------------------------------------------------------------
800
801# --------------------------------------------------------------------
802#D- Other specifications
803# --------------------------------------------------------------------
804
805  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
806}
807
808############################################################
809# Update job headers to be used by the scheduler
810
811#D-#==================================================
812#D-function IGCM_sys_updateHeaders
813#D-* Purpose: Update job headers to be used by the scheduler
814#D-* Examples: IGCM_sys_updateHeaders /path/to/Job_MYEXP
815#D-
816function IGCM_sys_updateHeaders {
817  IGCM_debug_PushStack "IGCM_sys_updateHeaders"
818  if ( $DEBUG_sys ) ; then
819    echo "IGCM_sys_updateHeaders"
820  fi
821  typeset file
822  file=$1
823
824  if [ ${executionType} -eq 1 ] ; then
825    # MPMD + MPI
826    sed -e "/::openMPthreads::/d"                  \
827        -e "s/::JobNumProcTot::/${coreNumber}/"    \
828      ${file} > ${file}.tmp
829
830  elif [ ${executionType} -eq 2 ] ; then
831    # MPMD + MPI + OMP
832    sed -e "s/::openMPthreads::/${openMPthreads}/" \
833        -e "s/::JobNumProcTot::/${coreNumber}/"    \
834      ${file} > ${file}.tmp
835
836  elif [ ${executionType} -eq 3 ] ; then
837    # SPMD + MPI/OMP
838    sed -e "s/::openMPthreads::/${openMPthreads}/" \
839        -e "s/::JobNumProcTot::/${mpiTasks}/"      \
840      ${file} > ${file}.tmp
841
842  elif [ ${executionType} -eq 4 ] ; then
843    # SPMD + MPI only
844    sed -e "s/::JobNumProcTot::/${mpiTasks}/"      \
845        -e "/::openMPthreads::/d"                  \
846      ${file} > ${file}.tmp
847
848  elif [ ${executionType} -eq 5 ] ; then
849    # SPMD + OMP only
850    sed -e "s/::openMPthreads::/${openMPthreads}/" \
851        -e "/::JobNumProcTot::/d"                  \
852      ${file} > ${file}.tmp
853
854  elif [ ${executionType} -eq 6 ] ; then
855    # SEQUENTIAL THEN
856    sed -e "s/::JobNumProcTot::/1/"                \
857        -e "/::openMPthreads::/d"                  \
858      ${file} > ${file}.tmp
859
860  fi
861
862  IGCM_sys_Mv ${file}.tmp ${file}
863
864  IGCM_debug_PopStack "IGCM_sys_updateHeaders"
865}
866
867############################################################
868# Build MPI/OMP scripts run file (dummy function)
869
870#D-#==================================================
871#D-function IGCM_sys_build_run_file
872#D-* Purpose: build run file (deprecated)
873#D-* Examples:
874#D-
875function IGCM_sys_build_run_file {
876  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
877}
878
879############################################################
880# Build MPI/OMP scripts
881
882#D-#==================================================
883#D-function IGCM_sys_build_execution_scripts
884#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
885#D-* Examples:
886#D-
887function IGCM_sys_build_execution_scripts
888{
889  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
890  if ( $DEBUG_sys ) ; then
891    echo "IGCM_sys_build_execution_scripts " $@
892  fi
893
894  EXECUTION=${HOST_MPIRUN_COMMAND}
895
896  # MPMD mode
897  if ( ${OK_PARA_MPMD} ) ; then
898
899    # Only MPI (MPMD)
900    if  ( ! ${OK_PARA_OMP} ) ; then
901
902      if [ -f run_file ] ; then
903        IGCM_sys_Rm -f run_file
904      fi
905      touch run_file
906
907      # Build run_file
908
909      # First loop on the components for the coupler ie oasis (only if oasis3)
910      # the coupler ie oasis3 must be the first one
911      for comp in ${config_ListOfComponents[*]} ; do
912
913        eval ExeNameIn=\${config_Executable_${comp}[0]}
914        eval ExeNameOut=\${config_Executable_${comp}[1]}
915
916        # for CPL component only
917        if [ "X${comp}" = "XCPL" ]  && [ "X${ExeNameOut}" != X\"\" ] ; then
918          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
919          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
920          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
921        fi
922      done
923
924      # Then second loop on the components
925      for comp in ${config_ListOfComponents[*]} ; do
926
927        eval ExeNameIn=\${config_Executable_${comp}[0]}
928        eval ExeNameOut=\${config_Executable_${comp}[1]}
929
930        # Only if we really have an executable for the component and not the coupler ie oasis:
931        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
932
933          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
934          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
935          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
936        fi
937      done
938
939      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
940
941      IGCM_sys_Chmod u+x run_file
942      if ( $DEBUG_sys ) ; then
943        echo "run_file contains : "
944        cat run_file
945      fi
946 
947    # MPI-OpenMP (MPMD)
948    else
949
950      #  Hosts treatment
951      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
952
953      i=0
954      rm -f hosts
955      IGCM_debug_Print 1 "sys Ciclad, Hosts available :"
956      for nodes in `cat hosts.tmp` ; do
957        host[$i]=$nodes
958        echo "${host[$i]} slots=1 max_slots=1" >> hosts
959        IGCM_debug_Print 1 ${host[$i]}
960        i=$((i+1))
961      done
962      rm -f hosts.tmp
963
964      listnodes=${host[*]}
965
966      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
967
968      # Initialisation
969      rank=0
970      current_core=0
971      core_per_node=8
972      init_exec=n
973
974      # Loop on the components
975      for comp in ${config_ListOfComponents[*]} ; do
976
977        eval ExeNameIn=\${config_Executable_${comp}[0]}
978        eval ExeNameOut=\${config_Executable_${comp}[1]}
979
980        # Not possible if oasis has an executable (i.e old version of oasis3)
981        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" = "XCPL" ] ) ; then
982          IGCM_debug_Exit "ERROR MPMD with hybrid MPI-OpenMP is not available with oasis3 version"
983          IGCM_debug_Print 2 "Only available with oasis3-MCT version coupler"
984          IGCM_debug_Verif_Exit
985        fi
986
987        # Only if we really have an executable for the component :
988        if [ "X${ExeNameOut}" != X\"\" ] ; then
989
990          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
991          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
992
993          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
994          echo ""  >> script_${ExeNameOut}.ksh
995          if [ ${comp_proc_omp_loc} -gt 1 ] ; then
996
997            # Check if the number of threads is correct
998            case ${comp_proc_omp_loc} in
999            2|4|8)
1000              IGCM_debug_Print 1 "You run ${ExeNameOut} on ${comp_proc_omp_loc} OMP threads"
1001              ;;
1002            *)
1003              IGCM_debug_Exit "ERROR with OMP parameters !"
1004              IGCM_debug_Print 2 "${comp_proc_omp_loc} is not possible as number of OMP threads"
1005              IGCM_debug_Print 2 "Only 2,4,8 as number of OMP threads are possible "
1006              IGCM_debug_Verif_Exit
1007              ;;
1008            esac
1009            #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1010            #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1011            #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1012            echo "export OMP_STACKSIZE=200M" >> script_${ExeNameOut}.ksh
1013            echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1014          fi
1015
1016          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1017          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK )) " >> script_${ExeNameOut}.ksh
1018          echo "MYMPIRANK=\$(printf '%3.3d\n' \${MYMPIRANK})" >> script_${ExeNameOut}.ksh
1019          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}" >> script_${ExeNameOut}.ksh
1020          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1021
1022          if [ ${init_exec} = y ] ; then
1023            EXECUTION="${EXECUTION} : -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1024          else
1025            EXECUTION="${EXECUTION} -np ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1026            init_exec=y
1027          fi
1028
1029          # Build rankfile : method used to assign cores and nodes for the MPI process
1030          # Ex :
1031          #rank 0=curie5296 slot=0,1,2,3
1032          #rank 1=curie5296 slot=4,5,6,7
1033          # Example of final command :
1034          # mpirun -hostfile hosts -rankfile rankfile -np 27 ./script_lmdz.x.ksh : -np 5 ./script_opa.xx.ksh
1035          # with script_lmdz.x.ksh :
1036          # #!/bin/ksh
1037          #export OMP_STACKSIZE=200M
1038          #export OMP_NUM_THREADS=4
1039          #./lmdz.x
1040
1041          for nb_proc_mpi in `seq 0 $(($comp_proc_mpi_loc-1))`; do
1042            (( index_host = current_core / core_per_node ))
1043            host_value=${host[${index_host}]}
1044            (( slot =  current_core % core_per_node ))
1045            virg=","
1046            string_final=""
1047            for index in `seq $slot $(($slot+$comp_proc_omp_loc-1))`; do
1048              string=$index$virg
1049              string_final=$string_final$string
1050            done
1051            string_final=$( echo $string_final | sed "s/.$//" )
1052            echo "rank $rank=$host_value slot=$string_final" >> rankfile
1053            (( rank = rank + 1 ))
1054            (( current_core = current_core + comp_proc_omp_loc ))
1055          done
1056        fi
1057      done
1058    fi
1059
1060  # Only one executable (SPMD mode).
1061  else
1062
1063    for comp in ${config_ListOfComponents[*]} ; do
1064
1065      # Only if we really have an executable for the component :
1066      eval ExeNameOut=\${config_Executable_${comp}[1]}
1067      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1068
1069        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1070        echo ""  >> script_${ExeNameOut}.ksh
1071        if ( ${OK_PARA_OMP} ) ; then
1072          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1073          echo "export OMP_STACKSIZE=200M" >> script_${ExeNameOut}.ksh
1074          echo "export OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1075        fi
1076        if  ( ${OK_PARA_MPI} ) ; then
1077          # Default : mpirun used if nb_proc gt 1
1078          # pour sortie out/err par process
1079          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1080          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1081          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1082          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1083        else
1084          # Default : mpirun is NOT used if nb_proc eq 1
1085          # pour sortie out/err par process
1086          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1087          #echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1088          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1089          EXECUTION="time ./script_${ExeNameOut}.ksh"
1090        fi
1091
1092        IGCM_debug_Print 1 "sys Ciclad : script_${ExeNameOut}.ksh contains"
1093        cat script_${ExeNameOut}.ksh
1094
1095      fi
1096
1097    done
1098
1099  fi
1100
1101  IGCM_debug_Print 1 "sys Ciclad : execution command is"
1102  IGCM_debug_Print 1 "$EXECUTION"
1103
1104  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1105}
1106
1107#D-#==================================================
1108#D-function IGCM_sys_check_path
1109#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1110#D-* do not point to an important use directory. Stop immediately in that case.
1111#D-* Examples:
1112#D-
1113function IGCM_sys_check_path {
1114  IGCM_debug_PushStack "IGCM_sys_check_path"
1115  if ( $DEBUG_sys ) ; then
1116    echo "IGCM_sys_check_path"
1117  fi
1118
1119  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1120    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1121    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1122    IGCM_debug_Exit "This will stop the job"
1123  fi
1124  IGCM_debug_PopStack "IGCM_sys_check_path"
1125}
1126
1127#D-#==================================================
1128#D-function IGCM_sys_check_quota. Dummy call here
1129#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1130#D-* Examples:
1131#D-
1132function IGCM_sys_check_quota {
1133  IGCM_debug_PushStack "IGCM_sys_check_quota"
1134  if ( $DEBUG_sys ) ; then
1135    echo "IGCM_sys_check_quota"
1136  fi
1137
1138  # TO BE IMPLEMENTED
1139
1140  IGCM_debug_PopStack "IGCM_sys_check_quota"
1141}
1142
1143#D-#==================================================
1144#D-function IGCM_sys_projectAccounting
1145#D-* Purpose: store project accounting information in a file
1146#D-* Examples:
1147#D-
1148function IGCM_sys_projectAccounting {
1149  IGCM_debug_PushStack "IGCM_sys_projectAccounting"
1150  if ( $DEBUG_sys ) ; then
1151    echo "IGCM_sys_check_quota"
1152  fi
1153
1154  touch $1
1155
1156  IGCM_debug_PopStack "IGCM_sys_projectAccounting"
1157}
1158
1159#D-#==================================================
1160#D-function IGCM_sys_getJobSchedulerID
1161#D-* Purpose: Get the job ID during execution
1162#D-* Examples: IGCM_sys_getJobSchedulerID jobSchedulerID
1163#D-
1164function IGCM_sys_getJobSchedulerID {
1165  IGCM_debug_PushStack "IGCM_sys_getJobSchedulerID"
1166  if ( $DEBUG_sys ) ; then
1167    echo "IGCM_sys_getJobSchedulerID"
1168  fi
1169
1170  eval ${1}=$( echo ${PBS_JOBID} | awk -F. '{print $1}' )
1171
1172  IGCM_debug_PopStack "IGCM_sys_getJobSchedulerID"
1173}
1174
1175#D-#==================================================
1176#D-function IGCM_sys_GetJobID
1177#D-* Purpose: Get the job ID from the JobName
1178#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1179#D-
1180function IGCM_sys_GetJobID {
1181  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1182  if ( $DEBUG_sys ) ; then
1183    echo "IGCM_sys_GetJobID"
1184  fi
1185
1186  # With -f option, the full job name is given in the last column
1187  ID="$( qstat -u $2 | grep -w $1 | gawk '-F ' '{print $10}' )"
1188
1189  eval ${3}=${ID}
1190  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1191}
1192
1193#D-#==================================================
1194#D-function IGCM_sys_CountJobInQueue
1195#D-* Purpose: Count number of users job
1196#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1197#D-
1198function IGCM_sys_CountJobInQueue {
1199  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1200  if ( $DEBUG_sys ) ; then
1201    echo "IGCM_sys_CountJobInQueue"
1202  fi
1203  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1204}
1205
1206#D-#==================================================
1207#D-function IGCM_sys_atlas
1208#D-* Purpose: encapsulate atlas call so as to manage error code and curie specificity
1209#D-* Examples:
1210#D-
1211function IGCM_sys_atlas {
1212  IGCM_debug_PushStack "IGCM_sys_atlas" $@
1213  if ( $DEBUG_sys ) ; then
1214    echo "IGCM_sys_atlas :" $@
1215  fi
1216
1217  typeset status
1218
1219  \atlas $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1220  status=$?
1221  if [ ${status} -gt 0 ] ; then
1222    echo "IGCM_sys_atlas : error code ${status}"
1223    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1224    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1225    IGCM_debug_PopStack "IGCM_sys_atlas"
1226    return 1
1227  else
1228    IGCM_debug_PopStack "IGCM_sys_atlas"
1229    return 0
1230  fi
1231
1232  IGCM_debug_PopStack "IGCM_sys_atlas"
1233}
1234
Note: See TracBrowser for help on using the repository browser.