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

Last change on this file since 1474 was 1459, checked in by jgipsl, 6 years ago

Removed variable R_IN_ECMWF (never used in reference experiment setups)

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