source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ciclad.ksh @ 1286

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