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

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