source: branches/libIGCM_CESMEP/libIGCM_sys/libIGCM_sys_mesoipsl.ksh @ 1585

Last change on this file since 1585 was 1585, checked in by ssenesi, 13 months ago

merge branch libIGCM_CESMEP with trunk that handles RedHat8 on Irene

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