source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 5899

Last change on this file since 5899 was 5899, checked in by aclsce, 3 years ago

Modified libIGCM and configuration to run XIOS ensembles.

File size: 40.4 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Christian Laguerre
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision:: 1487                                     $ Revision of last commit
7# $Author:: jgipsl                                     $ Author of last commit
8# $Date:: 2019-08-28 17:42:23 +0200 (Wed, 28 Aug 2019) $ 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 obelix
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 [ X${TaskType} = Xcomputing ] ; then
99    IGCM_debug_Print 1 "Modules will be loaded later in IGCM_sys_activ_variables."
100else
101    . /home/orchideeshare/igcmg/MachineEnvironment/obelix/env_atlas_obelix
102fi
103
104[ ! X${TaskType} = Xchecking ] && IGCM_debug_Print 1 "List of loaded modules:"
105[ ! X${TaskType} = Xchecking ] && module list
106
107# Load python
108module load python/2.7.5
109
110#====================================================
111# Host specific DIRECTORIES
112#====================================================
113# For rebuild
114export PATH=${PATH}:/home/orchideeshare/igcmg/IOIPSL_PLUS/modipsl.tagv2_2_4.28082019/bin/
115
116#====================================================
117#- MirrorlibIGCM for frontend
118typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
119
120#====================================================
121#- libIGCM_POST for frontend
122typeset -r libIGCM_POST=${libIGCM}
123
124#====================================================
125#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
126typeset -r R_EXE="${MODIPSL}/bin"
127
128#====================================================
129#- SUBMIT_DIR : submission dir
130if [ X${PBS_O_WORKDIR} != X ] ; then
131  typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
132else
133  typeset -x SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
134fi
135
136#====================================================
137#- IN
138typeset -r R_IN=${R_IN:=/home/orchideeshare/igcmg/IGCM}
139
140#====================================================
141#- RUN_DIR_PATH : Temporary working directory (=> TMP)
142if [ X${PBS_JOBID} != X ] ; then
143  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/scratch/$PBS_O_LOGNAME.$PBS_JOBID}
144else
145  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/tmp/tmp$$}
146fi
147
148#====================================================
149#- OUTCOMMAND_PATH : tmp place to store command lines standard error and outputs
150typeset -r OUTCOMMAND_PATH=/tmp
151
152#====================================================
153#- HOST_MPIRUN_COMMAND
154typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
155
156#====================================================
157#- Max number of arguments passed to nco operator or demigration command
158UNIX_MAX_LIMIT=360
159
160#====================================================
161#- set PackDefault to false on obelix
162PackDefault=false
163
164#====================================================
165#- Default number of MPI task for IPSL coupled model
166#- required for backward compatibility
167#-
168DEFAULT_NUM_PROC_OCE=5
169DEFAULT_NUM_PROC_CPL=1
170(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
171
172#D-#==================================================
173#D-function IGCM_sys_defineArchives
174#D-* Purpose:
175#D-* Define ARCHIVE : Dedicated to large files
176#D-* Define STORAGE : Dedicated to small/medium files
177#D-* Define R_OUT   : Output tree located on ARCHIVE
178#D-* Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
179#D-* Define R_BUF   : Output tree located on STORAGE hosting files waiting for rebuild or pack processes
180#D-* if SpaceName=TEST nothing special will hapen
181#D-* Examples:
182#D-
183function IGCM_sys_defineArchives {
184  IGCM_debug_PushStack "IGCM_sys_defineArchives"
185
186  if [ ! X${config_UserChoices_ARCHIVE} = X ]; then
187    #====================================================
188    #- ARCHIVE (dedicated to large files)
189    ARCHIVE=${config_UserChoices_ARCHIVE}
190  else
191    #====================================================
192    #- ARCHIVE (dedicated to large files)
193    ARCHIVE=${ARCHIVE:=/home/scratch01/${LOGIN}}
194  fi
195
196  if [ ! X${config_UserChoices_STORAGE} = X ]; then
197    #====================================================
198    #- STORAGE (dedicated to small/medium files)
199    STORAGE=${config_UserChoices_STORAGE}
200  else
201    #====================================================
202    #- STORAGE (dedicated to small/medium files)
203    STORAGE=${ARCHIVE}
204  fi
205
206  # ON OBELIX NO SPECIAL CASE WHEN X${config_UserChoices_SpaceName} = XTEST
207
208  #====================================================
209  #- R_OUT
210  R_OUT=${ARCHIVE}/IGCM_OUT
211
212  #====================================================
213  #- R_FIG (hosting figures : monitoring and atlas, and/or small files)
214  R_FIG=${STORAGE}/IGCM_OUT
215
216  #====================================================
217  #- CMIP6 (hosting CMIP6 files produced by XIOS2 and configured by dr2xml)
218  CMIP6_BUF=${STORAGE}/IGCM_OUT
219
220  #====================================================
221  #- R_BUF (ONLY FOR double copy an scratch)
222  R_BUF=${STORAGE}/IGCM_OUT
223
224  IGCM_debug_Print 1 "R_OUT has been defined = ${R_OUT}"
225  IGCM_debug_Print 1 "R_BUF has been defined = ${R_BUF}"
226  IGCM_debug_Print 1 "R_FIG has been defined = ${R_FIG}"
227
228  IGCM_debug_PopStack "IGCM_sys_defineArchives"
229}
230
231#D-#==================================================
232#D-function IGCM_sys_RshArchive
233#D-* Purpose: Archive rsh command
234#D-* Examples:
235#D-
236function IGCM_sys_RshArchive {
237  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
238  /bin/ksh <<-EOF
239    ${@}
240EOF
241  status=$?
242  if [ ${status} -gt 0 ] ; then
243    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
244    IGCM_debug_Exit "IGCM_sys_RshArchive"
245  fi
246  IGCM_debug_PopStack "IGCM_sys_RshArchive"
247}
248
249#D-#==================================================
250#D-function IGCM_sys_RshArchive_NoError
251#D-* Purpose: Archive rsh command, without error
252#D-*          used only in monitoring.job
253#D-* Examples:
254#D-
255function IGCM_sys_RshArchive_NoError {
256  IGCM_debug_PushStack "IGCM_sys_RshArchive_NoError" $@
257  /bin/ksh <<-EOF
258    ${@} 2> /dev/null
259EOF
260  IGCM_debug_PopStack "IGCM_sys_RshArchive_NoError"
261}
262
263#D-#==================================================
264#D-function IGCM_sys_MkdirArchive
265#D-* Purpose: Mkdir on Archive
266#D-* Examples:
267#D-
268function IGCM_sys_MkdirArchive {
269  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
270  if ( $DEBUG_sys ) ; then
271    echo "IGCM_sys_MkdirArchive :" $@
272  fi
273  #- creation de repertoire sur le serveur fichier
274  if [ ! -d ${1} ]; then
275    \mkdir -p $1
276    status=$?
277
278    if [ ${status} -gt 0 ] ; then
279      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
280      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
281    fi
282  fi
283  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
284}
285
286#D-#==================================================
287#D-function IGCM_sys_TestDirArchive
288#D-* Purpose: Test Directory that must exists on Archive
289#D-* Examples:
290#D-
291function IGCM_sys_TestDirArchive {
292  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
293  if ( $DEBUG_sys ) ; then
294    echo "IGCM_sys_TestDirArchive :" $@
295  fi
296  typeset ExistFlag
297  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
298  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
299  return ${ExistFlag}
300}
301
302#D-#==================================================
303#D-function IGCM_sys_IsFileArchived
304#D-* Purpose: Test file that must NOT EXISTS on Archive based on filename only
305#D-* Examples:
306#D-
307function IGCM_sys_IsFileArchived {
308  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
309  if ( $DEBUG_sys ) ; then
310    echo "IGCM_sys_IsFileArchived :" $@
311  fi
312  typeset IsArchivedFlag
313  # Never archived for this system
314  IsArchivedFlag=1
315  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
316
317  return ${IsArchivedFlag}
318}
319
320#D-#==================================================
321#D-function IGCM_sys_TestFileArchive
322#D-* Purpose: Test file that must NOT EXISTS on Archive
323#D-* Examples:
324#D-
325function IGCM_sys_TestFileArchive {
326  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
327  typeset ExistFlag
328  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
329  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
330
331  return ${ExistFlag}
332}
333
334#D-#==================================================
335#D-function IGCM_sys_CountFileArchive
336#D-* Purpose: Count files on Archive filesystem
337#D-* Examples:
338#D-
339function IGCM_sys_CountFileArchive {
340  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
341  ls ${@} 2>/dev/null | wc -l
342  if [ $? -gt 0 ] ; then
343    echo "IGCM_sys_CountFileArchive : erreur."
344  fi
345  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
346}
347
348#D-#==================================================
349#D-function IGCM_sys_Tree
350#D-* Purpose: Tree directories with files on ${ARCHIVE}
351#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
352#D-
353function IGCM_sys_Tree {
354  IGCM_debug_PushStack "IGCM_sys_Tree" $@
355  if ( $DEBUG_sys ) ; then
356    echo "IGCM_sys_Tree :" $@
357  fi
358
359  \ls -lR ${@}
360
361  IGCM_debug_PopStack "IGCM_sys_Tree"
362}
363
364#D-#==================================================
365#D-function IGCM_sys_Qsub
366#D-* Purpose: Qsub new job
367#D-* Examples:
368#D-
369function IGCM_sys_Qsub {
370  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
371  if ( $DEBUG_sys ) ; then
372    echo "IGCM_sys_Qsub :" $@
373  fi
374  typeset options status
375  options="-o ${SUBMIT_DIR}/${Script_Output}"
376  /usr/local/bin/qsub ${options} $1 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
377  status=$?
378
379  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
380  if [ ${status} -gt 0 ] ; then
381    IGCM_debug_Print 2 "IGCM_sys_Qsub ${options} $1 : error code ${status}"
382    IGCM_debug_Exit "IGCM_sys_Qsub"
383  else
384    JobID=$( gawk {'print $1'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
385  fi
386  IGCM_debug_PopStack "IGCM_sys_Qsub"
387}
388
389#D-#==================================================
390#D-function IGCM_sys_QsubPost
391#D-* Purpose: Qsub new job on scalaire
392#D-* Examples:
393#D-
394function IGCM_sys_QsubPost {
395  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
396  if ( $DEBUG_sys ) ; then
397    echo "IGCM_sys_QsubPost :" $@
398  fi
399  typeset options status
400  options="-o ${POST_DIR}/${Script_Post_Output}.out -v ${listVarEnv}"
401  /usr/local/bin/qsub ${options} ${libIGCM_POST}/$1.job > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
402  status=$?
403
404  cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
405  if [ ${status} -gt 0 ] ; then
406    IGCM_debug_Print 2 "IGCM_sys_QsubPost ${options} ${libIGCM_POST}/$1.job : error code ${status}"
407    IGCM_debug_Exit "IGCM_sys_QsubPost"
408  else
409    JobID=$( gawk {'print $1'} ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )
410  fi
411  IGCM_debug_PopStack "IGCM_sys_QsubPost"
412}
413
414#D-*************************
415#D- File transfer functions
416#D-*************************
417#D-
418
419#D-#==================================================
420#D-function IGCM_sys_RmRunDir
421#D-* Purpose: rm tmpdir (dummy function most of the time batch
422#D-                      scheduler will do the job)
423#D-* Examples:
424#D-
425function IGCM_sys_RmRunDir {
426  IGCM_debug_PushStack "IGCM_sys_RmRunDir" $@
427  if ( $DEBUG_sys ) ; then
428    echo "IGCM_sys_RmRunDir :" $@
429    echo "Dummy call, let the scheduler do that."
430  fi
431  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
432}
433
434#D-#==================================================
435#D-function IGCM_sys_Put_Dir
436#D-* Purpose: Copy a complete directory on $(ARCHIVE)
437#D-* Examples:
438#D-
439function IGCM_sys_Put_Dir {
440  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
441  if ( $DEBUG_sys ) ; then
442    echo "IGCM_sys_Put_Dir :" $@
443  fi
444  if [ $DRYRUN = 0 ]; then
445    if [ ! -d ${1} ] ; then
446      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
447      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
448      return
449    fi
450
451    typeset status
452
453    # Only if we use rsync
454    #IGCM_sys_TestDirArchive $( dirname $2 )
455    #
456    #USUAL WAY
457    \cp -r $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
458    status=$?
459
460    if [ ${status} -gt 0 ] ; then
461      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
462      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
463      IGCM_debug_Exit "IGCM_sys_Put_Dir"
464    else
465      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
466    fi
467  fi
468  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
469}
470
471#D-#==================================================
472#D-function IGCM_sys_Get_Dir
473#D-* Purpose: Copy a complete directory from ${ARCHIVE}
474#D-* Examples:
475#D-
476function IGCM_sys_Get_Dir {
477  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
478  if ( $DEBUG_sys ) ; then
479    echo "IGCM_sys_Get_Dir :" $@
480  fi
481  if [ $DRYRUN = 0 ]; then
482    typeset NB_ESSAI DELAI status i
483    # number of tentative
484    NB_ESSAI=3
485    # time delay between tentative
486    DELAI=2
487
488    #
489    # USUAL WAY
490    i=0
491    while [ $i -lt $NB_ESSAI ] ; do
492      \cp -ur $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
493      status=$?
494      if [ ${status} -gt 0 ] ; then
495        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
496        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
497        sleep $DELAI
498      else
499        break
500      fi
501      (( i = i + 1 ))
502    done
503
504    if [ ${status} -gt 0 ] ; then
505      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
506      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
507      IGCM_debug_Exit "IGCM_sys_Get_Dir"
508    else
509      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
510    fi
511  fi
512  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
513}
514
515#D-#==================================================
516#D-function IGCM_sys_Put_Rest
517#D-* Purpose: Put computied restarts on ${ARCHIVE}.
518#D-           File and target directory must exist.
519#D-* Examples:
520#D-
521function IGCM_sys_Put_Rest {
522  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
523  if ( $DEBUG_sys ) ; then
524    echo "IGCM_sys_Put_Rest :" $@
525  fi
526  if [ $DRYRUN = 0 ]; then
527    if [ ! -f ${1} ] ; then
528      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
529      IGCM_debug_Exit "IGCM_sys_Put_Rest"
530    fi
531
532    typeset status
533    #
534    # USUAL WAY
535    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
536    status=$?
537
538#       #RSYNC WITH NETWORK SSH CALL
539#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
540#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
541
542#       #RSYNC WITH NFS USE
543#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
544#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
545
546#       status=$?
547#       IGCM_sys_Rsync_out $status
548
549#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
550#       (( status=status+$? ))
551
552    if [ ${status} -gt 0 ] ; then
553      IGCM_debug_Print 2 "IGCM_sys_Put_Rest : cp failed error code ${status}"
554      [ -f ${1} ] && ls -l ${1}
555      [ -f ${2} ] && ls -l ${2}
556      [ -f ${2}/${1} ] && ls -l ${2}/${1}
557      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
558      IGCM_debug_Exit "IGCM_sys_Put_Rest"
559    else
560
561      if [ X${JobType} = XRUN ] ; then
562        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
563        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
564      fi
565
566      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
567    fi
568  fi
569  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
570}
571
572#D-#==================================================
573#D-function IGCM_sys_Put_Out
574#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
575#D-* Examples:
576#D-
577function IGCM_sys_Put_Out {
578  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
579  if ( $DEBUG_sys ) ; then
580    echo "IGCM_sys_Put_Out :" $@
581  fi
582
583  typeset status
584
585  if [ $DRYRUN = 0 ]; then
586    if [ ! -f ${1} ] ; then
587      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
588      IGCM_debug_PopStack "IGCM_sys_Put_Out"
589      return 1
590    fi
591    #
592    IGCM_sys_MkdirArchive $( dirname $2 )
593    #
594    if [ X${JobType} = XRUN ] ; then
595      if [ X${3} = X ] ; then
596        IGCM_sys_Chmod 444 ${1}
597      fi
598    fi
599    #
600
601    echo ${RSYNC} ${RSYNC_opt} $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
602    ${RSYNC} ${RSYNC_opt} $1 $2 >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
603    status=$?
604    IGCM_sys_Rsync_out $status
605
606    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
607    (( status=status+$? ))
608
609    if [ ${status} -gt 0 ] ; then
610      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
611      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
612      IGCM_debug_Exit "IGCM_sys_Put_Out"
613    else
614      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
615    fi
616  fi
617  IGCM_debug_PopStack "IGCM_sys_Put_Out"
618  return 0
619}
620
621#D-#==================================================
622#D-function IGCM_sys_Get
623#D-* Purpose: Get a file from ${ARCHIVE}
624#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
625#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
626function IGCM_sys_Get {
627  IGCM_debug_PushStack "IGCM_sys_Get" $@
628
629  typeset DEST status dm_liste
630
631  if ( $DEBUG_sys ) ; then
632    echo "IGCM_sys_Get :" $@
633  fi
634  if [ $DRYRUN -le 2 ]; then
635    if [ X${1} = X'/l' ] ; then
636      eval set +A dm_liste \${${2}}
637    else
638      dm_liste=${1}
639    fi
640    eval DEST=\${${#}}
641
642    # test if the (first) file is present in the old computation :
643    IGCM_sys_TestFileArchive ${dm_liste[0]}
644    status=$?
645    if [ ${status} -gt 0 ] ; then
646      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
647      IGCM_debug_Exit "IGCM_sys_Get"
648      return
649    fi
650
651    #USUAL WAY
652    \cp ${dm_liste[*]} ${DEST} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
653    status=$?
654
655    if [ ${status} -gt 0 ] ; then
656      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
657      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
658      IGCM_debug_Exit "IGCM_sys_Get"
659    else
660      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
661    fi
662  fi
663  IGCM_debug_PopStack "IGCM_sys_Get"
664}
665
666#D-#==================================================
667#D-function IGCM_sys_GetDate_Monitoring
668#D-* Purpose: get the last year for which the monitoring has been computed
669#D-* Examples:
670#D-
671function IGCM_sys_GetDate_Monitoring {
672  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
673  if ( $DEBUG_sys ) ; then
674    echo "IGCM_sys_GetDate_Monitoring :" $@
675  fi
676
677  eval ${2}=$( cdo showyear ${1} 2> /dev/null | gawk '{ print $NF }' )
678
679  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
680}
681
682#D-#==================================================
683#D-function IGCM_sys_Dods_Rm
684#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
685#D-* Examples:
686#D-
687function IGCM_sys_Dods_Rm {
688  if ( $DEBUG_sys ) ; then
689    echo "IGCM_sys_Dods_Rm :" $@
690  fi
691  return 0
692}
693
694#D-#==================================================
695#D-function IGCM_sys_Dods_Cp
696#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
697#D-* Examples:
698#D-
699function IGCM_sys_Dods_Cp {
700  if ( $DEBUG_sys ) ; then
701    echo "IGCM_sys_Dods_Cp :" $@
702  fi
703  return 0
704}
705
706#D-#==================================================
707#D-function IGCM_sys_Put_Dods
708#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
709#D-* Examples:
710#D-
711function IGCM_sys_Put_Dods {
712  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
713  if ( $DEBUG_sys ) ; then
714    echo "IGCM_sys_Put_Dods :" $@
715  fi
716  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
717}
718
719##############################################################
720# REBUILD OPERATOR
721
722#D-#==================================================
723#D-function IGCM_sys_sync
724#D-* Purpose: flush buffer on disk (dummy function on Obelix)
725#D-* Examples:
726#D-
727function IGCM_sys_sync {
728  IGCM_debug_PushStack "IGCM_sys_sync" $@
729  if ( $DEBUG_sys ) ; then
730    echo "IGCM_sys_sync :" $@
731    echo "Dummy call, let the system do that."
732  fi
733  IGCM_debug_PopStack "IGCM_sys_sync"
734}
735
736############################################################
737# Activate Running Environnment Variables
738
739#D-#==================================================
740#D-function IGCM_sys_activ_variables
741#D-* Purpose: set environement variables prior to execution
742#D-* Examples:
743#D-
744function IGCM_sys_activ_variables {
745  IGCM_debug_PushStack "IGCM_sys_activ_variables"
746  if ( $DEBUG_sys ) ; then
747    echo "IGCM_sys_activ_variables"
748  fi
749
750# --------------------------------------------------------------------
751#D- MODULE specifications
752# --------------------------------------------------------------------
753  # Source the file EnvFile containing all module load needed to run the model.
754  # EnvFile can be specified in config.card. If this is the case and if the file exists,
755  # it will be used. Otherwise a default file will be used.
756  if [ ! X${config_UserChoices_EnvFile} = X ] && [ -f ${config_UserChoices_EnvFile} ] ; then
757      # EnvFile is set in config.card and the file exists
758      IGCM_debug_Print 1 "EnvFile set in config.card will be used"
759      EnvFile=${config_UserChoices_EnvFile}
760  else
761      IGCM_debug_Print 1 "IGCM_sys_active_variables : Default modules will be used"
762      EnvFile=/home/orchideeshare/igcmg/MachineEnvironment/obelix/env_atlas_obelix
763  fi
764  IGCM_debug_Print 1 "IGCM_sys_active_variables : Following EnvFile will be used :" 
765  IGCM_debug_Print 1 ${EnvFile}
766  . ${EnvFile}
767
768  IGCM_debug_Print 1 "IGCM_sys_active_variables : Now loaded modules for obelix. "
769  module list
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 Obelix, 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=6
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|6)
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,6 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
1077        if [ ${mpiTasks} -eq 1 ] && [ ${openMPthreads} -eq 1 ] ; then
1078          # Case with only one proc
1079          # mpirun should not be used at obelix for only one proc
1080          # Output text per process
1081          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1082          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1083          EXECUTION="time ./script_${ExeNameOut}.ksh"
1084        elif  ( ${OK_PARA_MPI} ) ; then
1085          # Default : mpirun used if nb_proc gt 1
1086          # Output text per process
1087          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1088          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1089          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1090        elif [ ${executionType} -eq 6 ] ; then
1091          # Sequentiel case: this is the same as the first case.
1092          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1093          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1094          EXECUTION="time ./script_${ExeNameOut}.ksh"
1095        else
1096          # Strange case.
1097          IGCM_debug_Exit "ERROR with OK_PARA_MPI"
1098          IGCM_debug_Print 2 "sys Obelix : OK_PARA_MPI=False and mpiTask/openMPthreds different from 1"
1099          IGCM_debug_Verif_Exit
1100        fi
1101
1102        IGCM_debug_Print 1 "sys Obelix : script_${ExeNameOut}.ksh contains"
1103        cat script_${ExeNameOut}.ksh
1104
1105      fi
1106
1107    done
1108
1109  fi
1110
1111  IGCM_debug_Print 1 "sys Obelix : execution command is"
1112  IGCM_debug_Print 1 "$EXECUTION"
1113
1114  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1115}
1116
1117#D-#==================================================
1118#D-function IGCM_sys_check_path
1119#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1120#D-* do not point to an important use directory. Stop immediately in that case.
1121#D-* Examples:
1122#D-
1123function IGCM_sys_check_path {
1124  IGCM_debug_PushStack "IGCM_sys_check_path"
1125  if ( $DEBUG_sys ) ; then
1126    echo "IGCM_sys_check_path"
1127  fi
1128
1129  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1130    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1131    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1132    IGCM_debug_Exit "This will stop the job"
1133  fi
1134  IGCM_debug_PopStack "IGCM_sys_check_path"
1135}
1136
1137#D-#==================================================
1138#D-function IGCM_sys_check_quota. Dummy call here
1139#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1140#D-* Examples:
1141#D-
1142function IGCM_sys_check_quota {
1143  IGCM_debug_PushStack "IGCM_sys_check_quota"
1144  if ( $DEBUG_sys ) ; then
1145    echo "IGCM_sys_check_quota"
1146  fi
1147
1148  # TO BE IMPLEMENTED
1149
1150  IGCM_debug_PopStack "IGCM_sys_check_quota"
1151}
1152
1153#D-#==================================================
1154#D-function IGCM_sys_projectAccounting
1155#D-* Purpose: store project accounting information in a file
1156#D-* Examples:
1157#D-
1158function IGCM_sys_projectAccounting {
1159  IGCM_debug_PushStack "IGCM_sys_projectAccounting"
1160  if ( $DEBUG_sys ) ; then
1161    echo "IGCM_sys_check_quota"
1162  fi
1163
1164  touch $1
1165
1166  IGCM_debug_PopStack "IGCM_sys_projectAccounting"
1167}
1168
1169#D-#==================================================
1170#D-function IGCM_sys_getJobSchedulerID
1171#D-* Purpose: Get the job ID during execution
1172#D-* Examples: IGCM_sys_getJobSchedulerID jobSchedulerID
1173#D-
1174function IGCM_sys_getJobSchedulerID {
1175  IGCM_debug_PushStack "IGCM_sys_getJobSchedulerID"
1176  if ( $DEBUG_sys ) ; then
1177    echo "IGCM_sys_getJobSchedulerID"
1178  fi
1179
1180  eval ${1}=$( echo ${PBS_JOBID} | awk -F. '{print $1}' )
1181
1182  IGCM_debug_PopStack "IGCM_sys_getJobSchedulerID"
1183}
1184
1185#D-#==================================================
1186#D-function IGCM_sys_GetJobID
1187#D-* Purpose: Get the job ID from the JobName
1188#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1189#D-
1190function IGCM_sys_GetJobID {
1191  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1192  if ( $DEBUG_sys ) ; then
1193    echo "IGCM_sys_GetJobID"
1194  fi
1195
1196  # With -f option, the full job name is given in the last column
1197  ID="$( qstat -u $2 | grep -w $1 | gawk '-F ' '{print $10}' )"
1198
1199  eval ${3}=${ID}
1200  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1201}
1202
1203#D-#==================================================
1204#D-function IGCM_sys_CountJobInQueue
1205#D-* Purpose: Count number of users job
1206#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1207#D-
1208function IGCM_sys_CountJobInQueue {
1209  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1210  if ( $DEBUG_sys ) ; then
1211    echo "IGCM_sys_CountJobInQueue"
1212  fi
1213  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1214}
1215
1216#D-#==================================================
1217#D-function IGCM_sys_atlas
1218#D-* Purpose: encapsulate atlas call so as to manage error code and curie specificity
1219#D-* Examples:
1220#D-
1221function IGCM_sys_atlas {
1222  IGCM_debug_PushStack "IGCM_sys_atlas" $@
1223  if ( $DEBUG_sys ) ; then
1224    echo "IGCM_sys_atlas :" $@
1225  fi
1226
1227  typeset status
1228
1229  \atlas $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1230  status=$?
1231  if [ ${status} -gt 0 ] ; then
1232    echo "IGCM_sys_atlas : error code ${status}"
1233    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1234    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1235    IGCM_debug_PopStack "IGCM_sys_atlas"
1236    return 1
1237  else
1238    IGCM_debug_PopStack "IGCM_sys_atlas"
1239    return 0
1240  fi
1241
1242  IGCM_debug_PopStack "IGCM_sys_atlas"
1243}
1244
1245
1246#D-#==================================================
1247#D-function IGCM_sys_rebuild_nemo
1248#D-* Purpose: rebuild nemo parallel files with general rebuild
1249#D-* Examples:
1250#D-
1251
1252function IGCM_sys_rebuild_nemo {
1253  IGCM_debug_PushStack "IGCM_sys_rebuild_nemo" $@
1254  if ( $DEBUG_sys ) ; then
1255    echo "IGCM_sys_rebuild_nemo :" $@
1256  fi
1257
1258  nemo_generic_restart_file_name_out=${1}
1259  nemo_extension_out=${3}
1260  shift ; shift ; shift
1261
1262  IGCM_sys_rebuild -o ${nemo_generic_restart_file_name_out}.${nemo_extension_out} $@
1263
1264  IGCM_debug_PopStack "IGCM_sys_rebuild_nemo"
1265}
1266
Note: See TracBrowser for help on using the repository browser.