source: branches/libIGCM_MPI_OpenMP/libIGCM_sys/libIGCM_sys_titane.ksh @ 592

Last change on this file since 592 was 592, checked in by mafoipsl, 12 years ago

Second merge of libIGCM_MPI_OpenMP branch with libIGCM trunk, revision 591.

  • Property svn:keywords set to Revision Author Date
File size: 60.2 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Arnaud Caubel
5# Contact: Arnaud.Caubel__at__lsce.ipsl.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 Titane
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 |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=titane
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81# ie storage filesystem
82typeset -r STOREHOST=${MASTER}
83
84#====================================================
85# Source default environment
86#====================================================
87. /etc/profile
88
89#====================================================
90# Set environment tools (ferret, nco, cdo)
91#====================================================
92. /home/cont003/p86ipsl/.atlas_env_titane_ksh
93
94module switch nco/3.9.4 nco/3.9.4_netcdf4
95
96#====================================================
97# Specific for ocean additionnal diagnostic
98export FER_GO="$FER_GO /home/cont003/p86denv/IGCM_POST_UTIL/JNL /home/cont003/p86denv/GRAF /home/cont003/p86denv/GRAF/GO"
99export FER_PALETTE="$FER_PALETTE /home/cont003/p86denv/GRAF/PALET"
100
101#====================================================
102# Host specific DIRECTORIES
103#====================================================
104
105# ============ CESIUM START ============ #
106
107#====================================================
108#- Mirror libIGCM from titane to cesium if needed
109#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
110#if [ ! ${ROOTSYS} = "home" ] ; then
111#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
112#else
113#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
114#fi
115
116#====================================================
117#- libIGCM_POST
118#if ( ${MirrorlibIGCM} ) ; then
119#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
120#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
121#else
122#  typeset -r libIGCM_POST=${libIGCM}
123#fi
124
125# ============ CESIUM  END  ============ #
126
127#====================================================
128#- MirrorlibIGCM for frontend
129typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
130
131#====================================================
132#- libIGCM_POST for frontend
133typeset -r libIGCM_POST=${libIGCM}
134
135#====================================================
136#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
137typeset -r R_EXE="${MODIPSL}/bin"
138
139#====================================================
140#- SUBMIT_DIR : submission dir
141typeset SUBMIT_DIR=${SUBMIT_DIR:=${LS_SUBCWD}}
142
143#====================================================
144#- ARCHIVE (dedicated to large files)
145typeset -r ARCHIVE=${CCCSTOREDIR}
146
147#- ARCHIVE (dedicated to small/medium files)
148typeset -r STORAGE=${CCCWORKDIR}
149
150#====================================================
151#- IN
152typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
153typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/dmnfs/cont003/p24data}
154
155#====================================================
156#- R_OUT
157typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
158
159#====================================================
160#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
161typeset -r R_FIG=${STORAGE}/IGCM_OUT
162
163#====================================================
164#- R_BUF (ONLY FOR double copy an scratch)
165typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
166
167#====================================================
168#- BIG_DIR : BIG_DIR to store files waiting for rebuild
169typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
170
171#====================================================
172#- OUT_POST
173typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
174
175#====================================================
176#- RUN_DIR_PATH : Temporary working directory (=> TMP)
177if [ ! X${LSB_QUEUE} = Xmono ] ; then
178  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/RUN_DIR/${LSB_JOBID}}
179else
180  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/TMPDIR_IGCM/${LSB_JOBID}}
181fi
182
183#====================================================
184#- HOST_MPIRUN_COMMAND
185typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
186
187#====================================================
188#- Max number of arguments passed to nco operator or demigration command
189UNIX_MAX_LIMIT=360
190
191NUM_COREPERNODE=8
192       
193#====================================================
194#- Default number of MPI task for IPSL coupled model
195#- required for backward compatibility
196#-
197DEFAULT_NUM_PROC_OCE=5
198DEFAULT_NUM_PROC_CPL=1
199DEFAULT_NUM_PROC_ATM=26
200DEFAULT_NUM_PROC_TOTAL=32
201
202#D-#==================================================
203#D-function IGCM_sys_RshMaster
204#D-* Purpose: Connection to frontend machine.
205#D-* Examples:
206#D-
207function IGCM_sys_RshMaster {
208  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
209  /bin/ksh <<-EOF
210    export libIGCM=${libIGCM}
211    export DEBUG_debug=${DEBUG_debug}
212    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
213    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
214    ${@}
215EOF
216  if [ $? -gt 0 ] ; then
217    echo "IGCM_sys_RshMaster : erreur."
218    IGCM_debug_Exit "IGCM_sys_RshMaster"
219  fi
220  IGCM_debug_PopStack "IGCM_sys_RshMaster"
221}
222
223#D-#==================================================
224#D-function IGCM_sys_RshArchive
225#D-* Purpose: Archive rsh command
226#D-* Examples:
227#D-
228function IGCM_sys_RshArchive {
229  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
230  /bin/ksh <<-EOF
231    ${@}
232EOF
233  if [ $? -gt 0 ] ; then
234    echo "IGCM_sys_RshArchive : erreur."
235    IGCM_debug_Exit "IGCM_sys_RshArchive"
236  fi
237  IGCM_debug_PopStack "IGCM_sys_RshArchive"
238}
239
240#D-#==================================================
241#D-function IGCM_sys_RshPost
242#D-* Purpose: Post-process rsh command
243#D-* Examples:
244#D-
245function IGCM_sys_RshPost {
246  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
247  if ( $DEBUG_sys ) ; then
248    echo "IGCM_sys_RshPost :" $@
249  fi
250
251  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
252  #cat tmp_IGCM_sys_RshPost_$$
253  # keep standard input (stdin) for the loop onto temporary file
254  cat >tmp_IGCM_sys_RshPost_$$
255
256# ============ FRONTEND START ============ #
257
258  /bin/ksh <tmp_IGCM_sys_RshPost_$$
259  if [ $? -gt 0 ] ; then
260    echo "IGCM_sys_RshPost : erreur."
261    IGCM_debug_Exit "IGCM_sys_RshPost"
262  fi
263  # delete temporary file
264  \rm tmp_IGCM_sys_RshPost_$$
265
266# ============ FRONTEND  END  ============ #
267
268# ============ CESIUM START ============ #
269#  typeset NB_ESSAI DELAI status i
270#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
271#    #little hack so that rebuild submission is done on titane not an cesium
272#   
273#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
274#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
275#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
276#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
277#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
278#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
279#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
280#   
281#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
282#    cat tmp_IGCM_sys_RshPost_$$
283#
284#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
285#    if [ $? -gt 0 ] ; then
286#      echo "IGCM_sys_RshPost : erreur."
287#      IGCM_debug_Exit "IGCM_sys_RshPost"
288#    fi
289#    # delete temporary file
290#    \rm tmp_IGCM_sys_RshPost_$$
291#
292#  else
293#    # number of tentative
294#    NB_ESSAI=10
295#    # time delay between tentative
296#    DELAI=10
297#    i=0
298#    while [ $i -ne $NB_ESSAI ] ; do
299#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
300#      status=$?
301#      if [ ${status} -ne 0 ];
302#      then
303#       sleep $DELAI
304#      else
305#       break
306#      fi
307#      let i=$i+1
308#    done
309#    # delete temporary file
310#    \rm tmp_IGCM_sys_RshPost_$$
311#
312#    if [ ${status} -gt 0 ] ; then
313#      echo "IGCM_sys_RshPost : erreur."
314#      IGCM_debug_Exit "IGCM_sys_RshPost"
315#    fi
316#  fi
317
318# ============ CESIUM  END  ============ #
319
320  IGCM_debug_PopStack "IGCM_sys_RshPost"
321}
322
323#D-#==================================================
324#D-function IGCM_sys_SendMail
325#D-* Purpose: Send mail when simulation is over
326#D-* Examples:
327#D-
328function IGCM_sys_SendMail {
329  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
330  if ( $DEBUG_sys ) ; then
331    echo "IGCM_sys_SendMail :" $@
332  fi
333
334  if ( ${ExitFlag} ) ; then
335    status=failed
336  else
337    status=completed
338  fi
339
340    cat  << END_MAIL > job_end.mail
341Dear ${LOGIN},
342
343  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
344  Job started : ${DateBegin}
345  Job ended   : ${DateEnd}
346  Output files are available in ${R_SAVE}
347  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
348END_MAIL
349
350    if [ ! -z ${config_UserChoices_MailName} ] ; then
351        mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
352    elif [ -f ~/.forward ] ; then
353        mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
354    fi
355    sleep 10
356    rm -f job_end.mail
357
358  if [ $? -gt 0 ] ; then
359    echo "IGCM_sys_SendMail : erreur."
360    IGCM_debug_Exit "IGCM_sys_SendMail"
361  fi
362  IGCM_debug_PopStack "IGCM_sys_SendMail"
363}
364
365#D-#==================================================
366#D-function IGCM_sys_Mkdir
367#D-* Purpose: Master locale mkdir command
368#D-* Examples:
369#D-
370function IGCM_sys_Mkdir {
371  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
372  if ( $DEBUG_sys ) ; then
373    echo "IGCM_sys_Mkdir :" $@
374  fi
375  if [ ! -d ${1} ]; then
376    \mkdir -p $1
377    if [ $? -gt 0 ] ; then
378      echo "IGCM_sys_Mkdir : erreur."
379      IGCM_debug_Exit "IGCM_sys_Mkdir"
380    fi
381  fi
382  # vérification :
383  if [ ! -d ${1} ] ; then
384    echo "IGCM_sys_Mkdir : erreur."
385    IGCM_debug_Exit "IGCM_sys_Mkdir"
386  fi
387  IGCM_debug_PopStack "IGCM_sys_Mkdir"
388}
389
390#D-#==================================================
391#D-function IGCM_sys_MkdirArchive
392#D-* Purpose: Mkdir on Archive
393#D-* Examples:
394#D-
395function IGCM_sys_MkdirArchive {
396  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
397  if ( $DEBUG_sys ) ; then
398    echo "IGCM_sys_MkdirArchive :" $@
399  fi
400  #- creation de repertoire sur le serveur fichier
401  if [ ! -d ${1} ]; then 
402    \mkdir -p $1
403    if [ $? -gt 0 ] ; then
404      echo "IGCM_sys_MkdirArchive : erreur."
405      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
406    fi
407  fi
408  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
409}
410
411#D-#==================================================
412#D-function IGCM_sys_MkdirWork
413#D-* Purpose: Mkdir on Work
414#D-* Examples:
415#D-
416function IGCM_sys_MkdirWork {
417  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
418  if ( $DEBUG_sys ) ; then
419    echo "IGCM_sys_MkdirWork :" $@
420  fi
421  #- creation de repertoire sur le serveur fichier
422  if [ ! -d ${1} ]; then 
423    \mkdir -p $1
424    if [ $? -gt 0 ] ; then
425      echo "IGCM_sys_MkdirWork : erreur."
426      IGCM_debug_Exit "IGCM_sys_MkdirWork"
427    fi
428  fi
429  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
430}
431
432#D-#==================================================
433#D-function IGCM_sys_Cd
434#D-* Purpose: master cd command
435#D-* Examples:
436#D-
437function IGCM_sys_Cd {
438  IGCM_debug_PushStack "IGCM_sys_Cd" $@
439  if ( $DEBUG_sys ) ; then
440    echo "IGCM_sys_Cd :" $@
441  fi
442  \cd $1
443  if [ $? -gt 0 ] ; then
444    echo "IGCM_sys_Cd : erreur."
445    IGCM_debug_Exit "IGCM_sys_Cd"
446  fi
447  IGCM_debug_PopStack "IGCM_sys_Cd"
448}
449
450#D-#==================================================
451#D-function IGCM_sys_Chmod
452#D-* Purpose: Chmod
453#D-* Examples:
454#D-
455function IGCM_sys_Chmod {
456  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
457  if ( $DEBUG_sys ) ; then
458    echo "IGCM_sys_Chmod :" $@
459  fi
460  if [ $DRYRUN -le 1 ]; then
461    \chmod $@
462    if [ $? -gt 0 ] ; then
463      echo "IGCM_sys_Chmod : erreur."
464      IGCM_debug_Exit "IGCM_sys_Chmod"
465    fi
466  else
467    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
468  fi
469  IGCM_debug_PopStack "IGCM_sys_Chmod"
470}
471
472#D-#==================================================
473#D-function IGCM_sys_FileSize
474#D-* Purpose: Filesize
475#D-* Examples:
476#D-
477function IGCM_sys_FileSize {
478  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
479
480  typeset sizeF
481  set +A sizeF -- $( ls -la ${1} )
482  if [ $? -gt 0 ] ; then
483    IGCM_debug_Exit "IGCM_sys_FileSize"
484  fi
485  eval ${2}=${sizeF[4]}
486
487  IGCM_debug_PopStack "IGCM_sys_FileSize"
488}
489
490#D-#==================================================
491#D-function IGCM_sys_TestDir
492#D-* Purpose: Test Directory that must exists
493#D-* Examples:
494#D-
495function IGCM_sys_TestDir {
496  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
497  if ( $DEBUG_sys ) ; then
498    echo "IGCM_sys_TestDir :" $@
499  fi
500  typeset ExistFlag
501  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
502  IGCM_debug_PopStack "IGCM_sys_TestDir"
503
504  return ${ExistFlag}
505}
506
507#D-#==================================================
508#D-function IGCM_sys_TestDirArchive
509#D-* Purpose: Test Directory that must exists on Archive
510#D-* Examples:
511#D-
512function IGCM_sys_TestDirArchive {
513  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
514  if ( $DEBUG_sys ) ; then
515    echo "IGCM_sys_TestDirArchive :" $@
516  fi
517  typeset ExistFlag
518  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
519  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
520
521  return ${ExistFlag}
522}
523
524#D-#==================================================
525#D-function IGCM_sys_IsFileArchived
526#D-* Purpose: Test file that must NOT EXISTS on Archive
527#D-* Examples:
528#D-
529function IGCM_sys_IsFileArchived {
530  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
531  if ( $DEBUG_sys ) ; then
532    echo "IGCM_sys_IsFileArchived :" $@
533  fi
534  typeset IsArchivedFlag
535  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/dmnfs ) != X ] && echo 0 || echo 1 )
536  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
537
538  return ${IsArchivedFlag}
539}
540
541#D-#==================================================
542#D-function IGCM_sys_TestFileArchive
543#D-* Purpose: Test file that must NOT EXISTS on Archive
544#D-* Examples:
545#D-
546function IGCM_sys_TestFileArchive {
547  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
548  if ( $DEBUG_sys ) ; then
549    echo "IGCM_sys_TestFileArchive :" $@
550  fi
551  typeset ExistFlag
552  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
553  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
554
555  return ${ExistFlag}
556}
557
558#D-#==================================================
559#D-function IGCM_sys_TestFileBuffer
560#D-* Purpose: Test file that must NOT EXISTS on Buffer
561#D-* Examples:
562#D-
563function IGCM_sys_TestFileBuffer {
564  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
565  typeset ExistFlag
566  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
567  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
568
569  return ${ExistFlag}
570}
571
572#D-#==================================================
573#D-function IGCM_sys_CountFileArchive
574#D-* Purpose: Count files on Archive filesystem
575#D-* Examples:
576#D-
577function IGCM_sys_CountFileArchive {
578  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
579  ls ${@} 2>/dev/null | wc -l
580  if [ $? -gt 0 ] ; then
581    echo "IGCM_sys_CountFileArchive : erreur."
582  fi
583  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
584}
585
586#D-#==================================================
587#D-function IGCM_sys_CountFileBuffer
588#D-* Purpose: Count files on Scratch filesystem
589#D-* Examples:
590#D-
591function IGCM_sys_CountFileBuffer {
592  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
593  ls ${@} 2>/dev/null | wc -l
594  if [ $? -gt 0 ] ; then
595    echo "IGCM_sys_CountFileBuffer : erreur."
596  fi
597  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
598}
599
600#D-#==================================================
601#D-function IGCM_sys_Tree
602#D-* Purpose: Tree directories with files on ${ARCHIVE}
603#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
604#D-
605function IGCM_sys_Tree {
606  IGCM_debug_PushStack "IGCM_sys_Tree" $@
607  if ( $DEBUG_sys ) ; then
608    echo "IGCM_sys_Tree :" $@
609  fi
610
611  \ls -lR ${@}
612
613  IGCM_debug_PopStack "IGCM_sys_Tree"
614}
615
616#D-#==================================================
617#D-function IGCM_sys_Tar
618#D-* Purpose: master tar command
619#D-* Examples:
620#D-
621function IGCM_sys_Tar {
622  IGCM_debug_PushStack "IGCM_sys_Tar" $@
623  if ( $DEBUG_sys ) ; then
624    echo "IGCM_sys_Tar :" $@
625  fi
626  \tar cf $@
627  if [ $? -gt 0 ] ; then
628    echo "IGCM_sys_Tar : erreur."
629    IGCM_debug_Exit "IGCM_sys_Tar"
630  fi
631  IGCM_debug_PopStack "IGCM_sys_Tar"
632}
633
634#D-#==================================================
635#D-function IGCM_sys_UnTar
636#D-* Purpose: master un-tar command
637#D-* Examples:
638#D-
639function IGCM_sys_UnTar {
640  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
641  if ( $DEBUG_sys ) ; then
642    echo "IGCM_sys_UnTar :" $@
643  fi
644  \tar xvf $1
645  if [ $? -gt 0 ] ; then
646    echo "IGCM_sys_UnTar : erreur."
647    IGCM_debug_Exit "IGCM_sys_UnTar"
648  fi
649  IGCM_debug_PopStack "IGCM_sys_UnTar"
650}
651
652#D-#==================================================
653#D-function IGCM_sys_Qsub
654#D-* Purpose: Qsub new job
655#D-* Examples:
656#D-
657function IGCM_sys_Qsub {
658  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
659  if ( $DEBUG_sys ) ; then
660    echo "IGCM_sys_Qsub :" $@
661  fi
662  typeset options
663  if [ ${config_UserChoices_JobName}.${CumulPeriod} = "." ] ; then
664    options=" -o ${Script_Output} -e ${Script_Output}"
665  else
666    options=" -o ${Script_Output} -e ${Script_Output} -r ${config_UserChoices_JobName}.${CumulPeriod}"
667  fi
668
669  /usr/local/bin/ccc_msub ${options} < $1
670  if [ $? -gt 0 ] ; then
671    echo "IGCM_sys_Qsub : erreur ${options} $1"
672    IGCM_debug_Exit "IGCM_sys_Qsub"
673  fi
674  IGCM_debug_PopStack "IGCM_sys_Qsub"
675}
676
677#D-#==================================================
678#D-function IGCM_sys_QsubPost
679#D-* Purpose: Qsub new job on scalaire
680#D-* Examples:
681#D-
682function IGCM_sys_QsubPost {
683  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
684  if ( $DEBUG_sys ) ; then
685    echo "IGCM_sys_QsubPost :" $@
686  fi
687
688  # Need to export listVarEnv for cesium
689  # NO Need to export listVarEnv for titane
690# ============ FRONTEND START ============ #
691
692  /usr/local/bin/ccc_msub -p ${BRIDGE_MSUB_PROJECT} -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job
693
694# ============ FRONTEND  END  ============ #
695
696# ============ CESIUM START ============ #
697#  typeset NB_ESSAI DELAI status i
698#  # number of tentative
699#  NB_ESSAI=10
700#  # time delay between tentative
701#  DELAI=10
702#  (( i = 0 ))
703#  while [ $i -lt $NB_ESSAI ] ; do
704#    /usr/local/bin/ccc_msub -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.e.out -E "-v ${listVarEnv}" ${libIGCM_POST}/$1.job
705#    status=$?
706#    if [ ${status} -gt 0 ]; then
707#      sleep $DELAI
708#    else
709#      break
710#    fi
711#    (( i = i + 1 ))
712#  done
713# ============ CESIUM  END  ============ #
714
715  if [ $? -gt 0 ] ; then
716    echo "IGCM_sys_QsubPost : erreur " $@
717    IGCM_debug_Exit "IGCM_sys_QsubPost"
718  fi
719  IGCM_debug_PopStack "IGCM_sys_QsubPost"
720}
721
722#D-*************************
723#D- File transfer functions
724#D-*************************
725#D-
726
727#D-#==================================================
728#D-function IGCM_sys_Rsync_out
729#D-* Purpose: treat return val of rsync
730#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
731#D-  Error values and explanations can depend on your system version.
732function IGCM_sys_Rsync_out {
733  RET=$1
734  if [ ! $RET ] ; then
735    echo "rsync error !"
736  fi
737
738  if [ $MYLANG = "fr" ]; then
739    case $RET in
740    0)  return ;;
741    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
742      echo "Erreur de syntaxe ou d'utilisation."
743      return;;
744    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
745      echo "Incompatibilité de protocole."
746      return;;
747    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
748      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
749      echo "répertoires"
750      return;;
751    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
752      echo "Action demandée non supportée : une tentative de manipulation de"
753      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
754      echo "été faite ; ou une option qui est supportée par le  client  mais"
755      echo "pas par le serveur a été spécifiée."
756      return;;
757    10) echo "Erreur de rsync ; RERR_SOCKETIO"
758      echo "Erreur dans le socket d'entrée sortie"
759      return;;
760    11) echo "Erreur de rsync ; RERR_FILEIO"
761      echo "Erreur d'entrée sortie fichier"
762      return;;
763    12) echo "Erreur de rsync ; RERR_STREAMIO"
764      echo "Erreur dans flux de donnée du protocole rsync"
765      return;;
766    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
767      echo "Erreur avec les diagnostics du programme"
768      return;;
769    14) echo "Erreur de rsync ; RERR_IPC"
770      echo "Erreur dans le code IPC"
771      return;;
772    20) echo "Erreur de rsync ; RERR_SIGNAL"
773      echo "SIGUSR1 ou SIGINT reçu"
774      return;;
775    21) echo "Erreur de rsync ; RERR_WAITCHILD"
776      echo "Une erreur retournée par waitpid()"
777      return;;
778    22) echo "Erreur de rsync ; RERR_MALLOC"
779      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
780      return;;
781    23) echo ""
782      echo "Erreur fichier inexistant"
783      return;;
784    30) echo "Erreur de rsync ; RERR_TIMEOUT"
785      echo "Temps d'attente écoulé dans l'envoi/réception de données"
786      return;;
787    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
788      return;;
789    esac
790  elif [ $MYLANG = "en" ] ; then
791    case $RET in
792    0)  return;;               
793    1)  echo "rsync error : Syntax or usage error "
794      return;;
795    2)  echo "rsync error : Protocol incompatibility "
796      return;;
797    3)  echo "rsync error : Errors selecting input/output files, dirs"
798      return;;
799    4)  echo "rsync error : Requested action not supported: an attempt"
800      echo "was made to manipulate 64-bit files on a platform that cannot support"
801      echo "them; or an option was specified that is supported by the client and"
802      echo "not by the server."
803      return;;
804    5)  echo "rsync error : Error starting client-server protocol"
805      return;;
806    10) echo "rsync error : Error in socket I/O "
807      return;;
808    11) echo "rsync error : Error in file I/O "
809      return;;
810    12) echo "rsync error : Error in rsync protocol data stream "
811      return;;
812    13) echo "rsync error : Errors with program diagnostics "
813      return;;
814    14) echo "rsync error : Error in IPC code "
815      return;;
816    20) echo "rsync error : Received SIGUSR1 or SIGINT "
817      return;;
818    21) echo "rsync error : Some error returned by waitpid() "
819      return;;
820    22) echo "rsync error : Error allocating core memory buffers "
821      return;;
822    23) echo "rsync error : Partial transfer due to error"
823      return;;
824    24) echo "rsync error : Partial transfer due to vanished source files"
825      return;;
826    30) echo "rsync error : Timeout in data send/receive "
827      return;;
828    *)  echo "rsync error : return code of rsync unknown :" $RET
829      return;;
830    esac
831  else
832    echo "unknown language $MYLANG."
833    return
834  fi
835}
836
837#D-#==================================================
838#D-function IGCM_sys_Miror_libIGCM
839#D-* Purpose: Mirror libIGCM PATH and lib to cesium
840#D-* Examples:
841#D-
842function IGCM_sys_Mirror_libIGCM {
843  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
844  if ( $DEBUG_sys ) ; then
845    echo "IGCM_sys_Mirror_libIGCM"
846  fi
847
848  typeset RET DEST
849
850  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
851
852  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
853  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
854  RET=$?
855
856  if [ ${RET} -gt 0 ] ; then
857    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
858    cat out_rsync
859  fi
860  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
861}
862
863#====================================================
864#- Call IGCM_sys_Mirror_libIGCM now !
865if ( $MirrorlibIGCM ) ; then
866  IGCM_sys_Mirror_libIGCM
867fi
868
869#D-#==================================================
870#D-function IGCM_sys_Cp
871#D-* Purpose: generic cp
872#D-* Examples:
873#D-
874function IGCM_sys_Cp {
875  IGCM_debug_PushStack "IGCM_sys_Cp" $@
876  if ( $DEBUG_sys ) ; then
877    echo "IGCM_sys_Cp :" $@
878  fi
879
880  typeset RET
881
882  echo cp $@ > out_rsync 2>&1
883  \cp $@ >> out_rsync 2>&1
884  RET=$?
885
886  if [ ${RET} -gt 0 ] ; then
887    echo "IGCM_sys_Cp : error."
888    cat out_rsync
889    IGCM_debug_Exit "IGCM_sys_Cp"
890  else
891    \rm out_rsync
892  fi
893  IGCM_debug_PopStack "IGCM_sys_Cp"
894}
895
896#D-#==================================================
897#D-function IGCM_sys_Rm
898#D-* Purpose: generic rm
899#D-* Examples:
900#D-
901function IGCM_sys_Rm {
902  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
903  if ( $DEBUG_sys ) ; then
904    echo "IGCM_sys_Rm :" $@
905  fi
906
907  typeset RET
908
909  echo rm $@ > out_rsync 2>&1
910  \rm $@ >> out_rsync 2>&1
911  RET=$?
912
913  if [ ${RET} -gt 0 ] ; then
914    echo "IGCM_sys_Rm : error."
915    cat out_rsync
916    IGCM_debug_Exit "IGCM_sys_Rm"
917  else
918    \rm out_rsync
919  fi
920  IGCM_debug_PopStack "IGCM_sys_Rm"
921}
922
923#D-#==================================================
924#D-function IGCM_sys_RmRunDir
925#D-* Purpose: rm tmpdir (dummy function most of the time batch
926#D-                      scheduler will do the job)
927#D-* Examples:
928#D-
929function IGCM_sys_RmRunDir {
930  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
931  if ( $DEBUG_sys ) ; then
932    echo "IGCM_sys_RmRunDir :" $@
933  fi
934
935  typeset RET
936
937  echo rm $@ > out_rsync 2>&1
938  \rm $@ >> out_rsync 2>&1
939  RET=$?
940
941  if [ ${RET} -gt 0 ] ; then
942    echo "IGCM_sys_RmRunDir : error."
943    cat out_rsync
944    IGCM_debug_Exit "IGCM_sys_RmRunDir"
945  else
946    \rm out_rsync
947  fi
948  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
949}
950
951#D-#==================================================
952#D-function IGCM_sys_Mv
953#D-* Purpose: generic move
954#D-* Examples:
955#D-
956function IGCM_sys_Mv {
957  IGCM_debug_PushStack "IGCM_sys_Mv" $@
958  if ( $DEBUG_sys ) ; then
959    echo "IGCM_sys_Mv :" $@
960  fi
961
962  if [ $DRYRUN = 0 ]; then
963
964    typeset RET
965   
966    echo mv $@ > out_rsync 2>&1
967    \mv $@ >> out_rsync 2>&1
968    RET=$?
969   
970    if [ ${RET} -gt 0 ] ; then
971      echo "IGCM_sys_Mv : error in mv."
972      cat out_rsync
973      IGCM_debug_Exit "IGCM_sys_Mv"
974    else
975      \rm out_rsync
976    fi
977  else
978    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
979  fi
980
981  IGCM_debug_PopStack "IGCM_sys_Mv"
982}
983
984#D-#==================================================
985#D-function IGCM_sys_Put_Dir
986#D-* Purpose: Copy a complete directory on $(ARCHIVE)
987#D-* Examples:
988#D-
989function IGCM_sys_Put_Dir {
990  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
991  if ( $DEBUG_sys ) ; then
992    echo "IGCM_sys_Put_Dir :" $@
993  fi
994  if [ $DRYRUN = 0 ]; then
995    if [ ! -d ${1} ] ; then
996      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
997      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
998      return
999    fi
1000
1001    typeset RET
1002
1003    # Only if we use rsync
1004    #IGCM_sys_TestDirArchive $( dirname $2 )
1005    #
1006    #USUAL WAY
1007    \cp -r $1 $2 > out_rsync 2>&1
1008    RET=$?
1009
1010    if [ ${RET} -gt 0 ] ; then
1011      echo "IGCM_sys_Put_Dir : error."
1012      cat out_rsync
1013      IGCM_debug_Exit "IGCM_sys_Put_Dir"
1014    else
1015      \rm out_rsync
1016    fi
1017  else
1018    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1019  fi
1020  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
1021}
1022
1023#D-#==================================================
1024#D-function IGCM_sys_Get_Dir
1025#D-* Purpose: Copy a complete directory from ${ARCHIVE}
1026#D-* Examples:
1027#D-
1028function IGCM_sys_Get_Dir {
1029  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
1030  if ( $DEBUG_sys ) ; then
1031    echo "IGCM_sys_Get_Dir :" $@
1032  fi
1033  if [ $DRYRUN = 0 ]; then
1034#    if [ ! -d ${1} ] ; then
1035#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
1036#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1037#      return
1038#    fi
1039
1040    typeset RET
1041
1042    # Only if we use rsync
1043    #IGCM_sys_TestDirArchive $( dirname $2 )
1044    #
1045    # USUAL WAY
1046    # add dmfind/dmget (to demigrate all offline files) :
1047    #dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget
1048    \cp -r $1 $2 > out_rsync 2>&1
1049    RET=$?
1050
1051    if [ ${RET} -gt 0 ] ; then
1052      echo "IGCM_sys_Get_Dir : error."
1053      cat out_rsync
1054      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1055    else
1056      \rm out_rsync
1057    fi
1058  else
1059    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1060  fi
1061  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1062}
1063
1064#D-#==================================================
1065#D-function IGCM_sys_Get_Master
1066#D-* Purpose: Copy a complete directory from MASTER filesystem
1067#D-* Examples:
1068#D-
1069function IGCM_sys_Get_Master {
1070  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1071  if ( $DEBUG_sys ) ; then
1072    echo "IGCM_sys_Get_Master :" $@
1073  fi
1074  if [ $DRYRUN = 0 ]; then
1075    if [ ! -d ${1} ] ; then
1076      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1077      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1078      return
1079    fi
1080
1081    typeset RET
1082
1083    #USUAL WAY
1084    \cp -r $1 $2 > out_rsync 2>&1
1085    RET=$?
1086
1087    if [ ${RET} -gt 0 ] ; then
1088      echo "IGCM_sys_Get_Master : error."
1089      cat out_rsync
1090      IGCM_debug_Exit "IGCM_sys_Get_Master"
1091    else
1092      \rm out_rsync
1093    fi
1094  else
1095    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1096  fi
1097  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1098}
1099
1100#D-#==================================================
1101#D-function IGCM_sys_Put_Rest
1102#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1103#D-           File and target directory must exist.
1104#D-* Examples:
1105#D-
1106function IGCM_sys_Put_Rest {
1107  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1108  if ( $DEBUG_sys ) ; then
1109    echo "IGCM_sys_Put_Rest :" $@
1110  fi
1111  if [ $DRYRUN = 0 ]; then
1112    if [ ! -f ${1} ] ; then
1113      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1114      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1115    fi
1116
1117    typeset RET
1118    #
1119    if [ X${JobType} = XRUN ] ; then
1120      IGCM_sys_Chmod 444 ${1}
1121    fi
1122
1123    #
1124    # USUAL WAY
1125    \cp $1 $2 > out_rsync 2>&1
1126    RET=$?
1127
1128#       #RSYNC WITH NETWORK SSH CALL
1129#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1130#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1131
1132#       #RSYNC WITH NFS USE
1133#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1134#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1135
1136#       RET=$?
1137#       IGCM_sys_Rsync_out $RET
1138
1139#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1140#       (( RET=RET+$? ))
1141
1142    if [ ${RET} -gt 0 ] ; then
1143      echo "IGCM_sys_Put_Rest : error."
1144      cat out_rsync
1145      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1146    else
1147      \rm out_rsync
1148    fi
1149  else
1150    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1151  fi
1152  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1153}
1154
1155#D-#==================================================
1156#D-function IGCM_sys_PutBuffer_Rest
1157#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1158#D-           File and target directory must exist.
1159#D-* Examples:
1160#D-
1161function IGCM_sys_PutBuffer_Rest {
1162  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1163  if ( $DEBUG_sys ) ; then
1164    echo "IGCM_sys_PutBuffer_Rest :" $@
1165  fi
1166  if [ $DRYRUN = 0 ]; then
1167    if [ ! -f ${1} ] ; then
1168      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1169      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1170    fi
1171
1172    typeset RET
1173    #
1174    if [ X${JobType} = XRUN ] ; then
1175      IGCM_sys_Chmod 444 ${1}
1176    fi
1177
1178    #
1179    # USUAL WAY
1180    \cp $1 $2 > out_rsync 2>&1
1181    RET=$?
1182
1183    if [ ${RET} -gt 0 ] ; then
1184      echo "IGCM_sys_PutBuffer_Rest : error."
1185      cat out_rsync
1186      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1187    else
1188      \rm out_rsync
1189    fi
1190  else
1191    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1192  fi
1193  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1194}
1195
1196#D-#==================================================
1197#D-function IGCM_sys_Put_Out
1198#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1199#D-* Examples:
1200#D-
1201function IGCM_sys_Put_Out {
1202  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1203  if ( $DEBUG_sys ) ; then
1204    echo "IGCM_sys_Put_Out :" $@
1205  fi
1206  if [ $DRYRUN = 0 ]; then
1207    if [ ! -f ${1} ] ; then
1208      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1209      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1210      return 1
1211    fi
1212    #
1213    IGCM_sys_MkdirArchive $( dirname $2 )
1214    #
1215    typeset RET
1216
1217    #=====================================================
1218    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1219    #=====================================================
1220
1221    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1222    #if [ $? -eq 0 ] ; then
1223    #    typeset WORKPATH FILEPATH
1224    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1225    #    IGCM_sys_MkdirWork ${WORKPATH}
1226    #    FILEPATH=${WORKPATH}/$( basename $2 )
1227    #    #
1228    #    IGCM_sys_Cp ${1} ${FILEPATH}
1229    #fi
1230
1231    if [ X${JobType} = XRUN ] ; then
1232      if [ X${3} = X ] ; then
1233        IGCM_sys_Chmod 444 ${1}
1234      fi
1235    fi
1236    #
1237    # USUAL WAY
1238    \cp $1 $2 > out_rsync 2>&1
1239    RET=$?
1240
1241#       #RSYNC WITH NETWORK SSH CALL
1242#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1243#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1244
1245#       #RSYNC WITH NFS USE
1246#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1247#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1248
1249#       RET=$?
1250#       IGCM_sys_Rsync_out $RET
1251
1252#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1253#       (( RET=RET+$? ))
1254
1255    if [ ${RET} -gt 0 ] ; then
1256      echo "IGCM_sys_Put_Out : error."
1257      cat out_rsync
1258      IGCM_debug_Exit "IGCM_sys_Put_Out"
1259    else
1260      \rm out_rsync
1261    fi
1262  else
1263    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1264  fi
1265  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1266  return 0
1267}
1268
1269#D-#==================================================
1270#D-function IGCM_sys_PutBuffer_Out
1271#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1272#D-* Examples:
1273#D-
1274function IGCM_sys_PutBuffer_Out {
1275  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1276  if ( $DEBUG_sys ) ; then
1277    echo "IGCM_sys_PutBuffer_Out :" $@
1278  fi
1279  if [ $DRYRUN = 0 ]; then
1280    if [ ! -f ${1} ] ; then
1281      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1282      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1283      return 1
1284    fi
1285    #
1286    IGCM_sys_Mkdir $( dirname $2 )
1287    #
1288    typeset RET
1289
1290    if [ X${JobType} = XRUN ] ; then
1291      if [ X${3} = X ] ; then
1292        IGCM_sys_Chmod 444 ${1}
1293      fi
1294    fi
1295    #
1296    # USUAL WAY
1297    \cp $1 $2 > out_rsync 2>&1
1298    RET=$?
1299
1300    if [ ${RET} -gt 0 ] ; then
1301      echo "IGCM_sys_PutBuffer_Out : error."
1302      cat out_rsync
1303      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1304    else
1305      \rm out_rsync
1306    fi
1307  else
1308    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1309  fi
1310  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1311  return 0
1312}
1313
1314#D-#==================================================
1315#D-function IGCM_sys_Get
1316#D-* Purpose: Get a file from ${ARCHIVE}
1317#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1318#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1319function IGCM_sys_Get {
1320  IGCM_debug_PushStack "IGCM_sys_Get" $@
1321
1322  typeset DEST RET dm_liste ifile target file_work
1323
1324  if ( $DEBUG_sys ) ; then
1325    echo "IGCM_sys_Get :" $@
1326  fi
1327  if [ $DRYRUN -le 2 ]; then
1328    if [ X${1} = X'/l' ] ; then
1329      # test if the first file is present in the old computation :
1330      eval set +A dm_liste \${${2}}
1331    else
1332      eval set +A dm_liste ${1}
1333    fi
1334    eval DEST=\${${#}}
1335
1336    #=====================================================
1337    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1338    #=====================================================
1339
1340    # Is it an R_OUT file (not R_IN) ?
1341    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1342    #if [ $? -eq 0 ] ; then
1343    #    # Yes  ? then we try to get it in SCRATCHDIR
1344    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1345    #    if [ -f ${file_work[0]} ] ; then
1346    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1347    #   IGCM_debug_PopStack "IGCM_sys_Get"
1348    #   return
1349    #    fi
1350    #fi
1351
1352    # test if the (first) file is present in the old computation :
1353    IGCM_sys_TestFileArchive ${dm_liste[0]}
1354    RET=$?
1355    if [ ${RET} -gt 0 ] ; then
1356      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1357      IGCM_debug_Exit "IGCM_sys_Get"
1358    fi
1359
1360    #dmget ${dm_liste[*]} > out_rsync 2>&1
1361    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1362    RET=$?
1363    if [ ${RET} -gt 0 ] ; then
1364      echo "WARNING IGCM_sys_Get : demigration error."
1365      cat out_rsync
1366      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1367    fi
1368
1369    #if [ ${RET} -gt 0 ] ; then
1370    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1371    #   cat out_rsync
1372    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1373    #   sleep 30
1374    #   echo "We try another time"
1375    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1376    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1377    #   RET=$?
1378    #   if [ ${RET} -gt 0 ] ; then
1379    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1380    #       cat out_rsync
1381    #       IGCM_debug_Exit "IGCM_sys_Get"
1382    #   fi
1383    #    else
1384    #   echo "ERROR IGCM_sys_Get : demigration error :"
1385    #   cat out_rsync
1386    #   IGCM_debug_Exit "IGCM_sys_Get"
1387    #    fi
1388    #fi
1389
1390    #USUAL WAY
1391    if [ X${1} = X'/l' ] ; then
1392      (( RET=0 ))
1393      for target in ${dm_liste[*]} ; do
1394        local_file=$( basename ${target} )
1395        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1396        (( RET = RET + $? ))
1397      done
1398    else
1399      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1400      RET=$?
1401    fi
1402
1403#       #RSYNC WITH NETWORK SSH CALL
1404#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1405#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1406
1407#       #RSYNC WITH NFS USE
1408#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1409#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1410
1411#       RET=$?
1412#       IGCM_sys_Rsync_out $RET
1413
1414#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1415#       (( RET=RET+$? ))
1416
1417    if [ ${RET} -gt 0 ] ; then
1418      echo "IGCM_sys_Get : copy error."
1419      cat out_rsync
1420      IGCM_debug_Exit "IGCM_sys_Get"
1421    else
1422      \rm out_rsync
1423    fi
1424  else
1425    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1426  fi
1427  IGCM_debug_PopStack "IGCM_sys_Get"
1428}
1429
1430#D-#==================================================
1431#D-function IGCM_sys_GetBuffer
1432#D-* Purpose: Get a file from ${SCRATCHDIR}
1433#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1434#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1435function IGCM_sys_GetBuffer {
1436  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1437
1438  typeset DEST RET buf_liste ifile target file_work
1439
1440  if ( $DEBUG_sys ) ; then
1441    echo "IGCM_sys_GetBuffer :" $@
1442  fi
1443  if [ $DRYRUN -le 2 ]; then
1444    if [ X${1} = X'/l' ] ; then
1445      # test if the first file is present in the old computation :
1446      eval set +A buf_liste \${${2}}
1447    else
1448      eval set +A buf_liste ${1}
1449    fi
1450    eval DEST=\${${#}}
1451
1452    #USUAL WAY
1453    if [ X${1} = X'/l' ] ; then
1454      (( RET=0 ))
1455      for target in ${buf_liste[*]} ; do
1456        local_file=$( basename ${target} )
1457        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1458        (( RET = RET + $? ))
1459      done
1460    else
1461      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1462      RET=$?
1463    fi
1464
1465    if [ ${RET} -gt 0 ] ; then
1466      echo "IGCM_sys_GetBuffer : copy error."
1467      cat out_rsync
1468      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1469    else
1470      \rm out_rsync
1471    fi
1472  else
1473    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1474  fi
1475  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1476}
1477
1478#D-#==================================================
1479#D-function IGCM_sys_GetDate_FichWork
1480#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1481#D-* Examples:
1482#D-
1483function IGCM_sys_GetDate_FichWork {
1484  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1485  if ( $DEBUG_sys ) ; then
1486    echo "IGCM_sys_GetDate_FichWork :" $@
1487  fi
1488  typeset dateF
1489  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1490  eval ${2}=${dateF[5]}
1491
1492    # donne la date filesys d'un fichier sur la machine work
1493  IGCM_debug_PopStack "IGCM_sys_FichWork"
1494}
1495
1496#D-#==================================================
1497#D-function IGCM_sys_GetDate_FichArchive
1498#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1499#D-* Examples:
1500#D-
1501function IGCM_sys_GetDate_FichArchive {
1502  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1503  if ( $DEBUG_sys ) ; then
1504    echo "IGCM_sys_GetDate_FichArchive :" $@
1505  fi
1506  typeset dateF
1507  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1508  eval ${2}=${dateF[5]}
1509
1510  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1511}
1512
1513#D-#==================================================
1514#D-function IGCM_sys_Dods_Rm
1515#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1516#D-* Examples:
1517#D-
1518function IGCM_sys_Dods_Rm {
1519  if ( $DEBUG_sys ) ; then
1520    echo "IGCM_sys_Dods_Rm :" $@
1521  fi
1522  typeset RET
1523  RET=0
1524  if [ $DRYRUN = 0 ]; then
1525
1526#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1527#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1528#      echo "Nothing has been done."
1529#      return
1530#    fi
1531
1532    /ccc/cont003/home/dsm/p86maf/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1533    RET=$?
1534   
1535#       if [ ${RET} -gt 0 ] ; then
1536#           echo "IGCM_sys_Dods_Rm : error."
1537#           cat out_dods_rm
1538#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1539#       else
1540#           rm out_dods_rm
1541#       fi
1542
1543  else
1544    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1545  fi
1546  return $RET
1547}
1548
1549#D-#==================================================
1550#D-function IGCM_sys_Dods_Cp
1551#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1552#D-* Examples:
1553#D-
1554function IGCM_sys_Dods_Cp {
1555  if ( $DEBUG_sys ) ; then
1556    echo "IGCM_sys_Dods_Cp :" $@
1557  fi
1558  typeset RET
1559  RET=0
1560  if [ $DRYRUN = 0 ]; then
1561
1562#    if [ ! -d ${R_SAVE}/${1} ] ; then
1563#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1564#      echo "Nothing has been done."
1565#      return
1566#    fi
1567
1568    /ccc/cont003/home/dsm/p86maf/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1569    RET=$?
1570
1571#       if [ ${RET} -gt 0 ] ; then
1572#           echo "IGCM_sys_Dods_Cp : error."
1573#           cat out_dods_cp
1574#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1575#       else
1576#           rm out_dods_cp
1577#       fi
1578
1579  else
1580    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1581  fi
1582  return $RET
1583}
1584
1585#D-#==================================================
1586#D-function IGCM_sys_Put_Dods
1587#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1588#D-* Examples:
1589#D-
1590function IGCM_sys_Put_Dods {
1591  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1592  if ( $DEBUG_sys ) ; then
1593    echo "IGCM_sys_Put_Dods :" $@
1594  fi
1595  set -vx
1596  typeset RET
1597  if [ $DRYRUN = 0 ]; then
1598    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1599      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1600      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1601      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1602      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1603      return
1604    fi
1605
1606    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1607      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1608      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1609      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1610      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1611      return
1612    fi
1613    #
1614    if [ -d ${R_SAVE}/${1} ] ; then
1615      cd ${R_SAVE}
1616    elif [ -d ${R_FIGR}/${1} ] ; then
1617      cd ${R_FIGR}
1618    fi
1619
1620    IGCM_sys_Dods_Rm ${1}
1621    IGCM_sys_Dods_Cp ${1}
1622    RET=0
1623   
1624    if [ ${RET} -gt 0 ] ; then
1625      echo "IGCM_sys_Put_Dods : error."
1626      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1627    fi
1628  else
1629    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1630  fi
1631  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1632}
1633
1634##############################################################
1635# REBUILD OPERATOR
1636
1637function IGCM_sys_rebuild {
1638  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1639  if ( $DEBUG_sys ) ; then
1640    echo "IGCM_sys_rebuild :" $@
1641  fi
1642  /home/cont003/p86ipsl/X64/bin/rebuild -f -o $@
1643  if [ $? -gt 0 ] ; then
1644    echo "IGCM_sys_rebuild : erreur ${@}."
1645    IGCM_debug_Exit "rebuild"
1646  fi
1647
1648  IGCM_debug_PopStack "IGCM_sys_rebuild"
1649}
1650
1651############################################################
1652# Activate Running Environnment Variables
1653
1654function IGCM_sys_activ_variables {
1655  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1656  if ( $DEBUG_sys ) ; then
1657    echo "IGCM_sys_activ_variables"
1658  fi
1659
1660  typeset max_omp
1661
1662  ulimit -s unlimited
1663
1664  (( max_omp = 0 ))
1665  for comp in ${config_ListOfComponents[*]} ; do
1666       
1667    eval ExeNameIn=\${config_Executable_${comp}[0]}
1668    eval ExeNameOut=\${config_Executable_${comp}[1]}
1669   
1670    # Only if we really have an executable for the component :
1671    if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1672      eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1673      if [ ${comp_proc_omp_loc} -gt ${max_omp} ] ; then
1674        (( max_omp = comp_proc_omp_loc ))
1675      fi
1676    fi
1677  done
1678  if [ ${max_omp} -gt 1 ] ; then
1679    module load openmp/${max_omp}thds
1680  fi
1681
1682  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1683}
1684
1685############################################################
1686# Desactivate Running Environnment Variables
1687
1688function IGCM_sys_desactiv_variables {
1689  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1690  if ( $DEBUG_sys ) ; then
1691    echo "IGCM_sys_desactiv_variables"
1692  fi
1693  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1694}
1695
1696############################################################
1697# Build MPI/OMP scripts run file (dummy function)
1698
1699function IGCM_sys_build_run_file {
1700
1701IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1702
1703}
1704
1705############################################################
1706# Build MPI/OMP scripts
1707function IGCM_sys_build_execution_scripts
1708{
1709  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1710  if ( $DEBUG_sys ) ; then
1711    echo "IGCM_sys_build_execution_scripts " $@
1712  fi
1713  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1714  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1715  typeset num_corempi nombre_restant_node nombre_restant_comp
1716
1717  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1718    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1719  fi
1720
1721  if ( ${OK_PARA_MPMD} ) ; then
1722
1723    if [ -f run_file ] ; then
1724      IGCM_sys_Rm -f run_file
1725    fi
1726    touch run_file
1727
1728    if ( ${OK_PARA_OMP} ) ; then
1729
1730      #  Hosts treatment
1731
1732      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1733       
1734      i=0
1735      rm -f hosts
1736      IGCM_debug_Print 1 "sys Titane, Hosts avaible :"
1737      for nodes in `cat hosts.tmp` ; do
1738        host[$i]=$nodes
1739        echo "${host[$i]} slots=8 max_slots=8" >> hosts
1740        IGCM_debug_Print 1 ${host[$i]}
1741        i=$((i+1))
1742      done
1743      rm -f hosts.tmp
1744           
1745      listnodes=${host[*]}
1746           
1747      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts" 
1748       
1749      # Initialisation
1750
1751      init_node=y
1752      node_num_current=0
1753      start_num=0
1754      init_exec=n
1755
1756      # Test : if oasis is there, we put it at the first position
1757           
1758      for comp in ${config_ListOfComponents[*]} ; do
1759               
1760        if [ "X${comp}" = "XCPL" ]  ; then
1761                   
1762          eval ExeNameIn=\${config_Executable_${comp}[0]}
1763          eval ExeNameOut=\${config_Executable_${comp}[1]}
1764                   
1765          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1766          echo ""  >> script_${ExeNameOut}.ksh
1767          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1768          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1769          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1770          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1771          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1772                   
1773          init_node=n
1774                   
1775          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1776          node_num_current=0
1777          node_current=${host[${node_num_current}]}
1778                   
1779          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh" 
1780                   
1781          init_exec=y
1782          start_num=1
1783                   
1784        fi
1785               
1786      done
1787           
1788      # Then loop on the components (except for oasis)
1789
1790      for comp in ${config_ListOfComponents[*]} ; do
1791               
1792        eval ExeNameIn=\${config_Executable_${comp}[0]}
1793        eval ExeNameOut=\${config_Executable_${comp}[1]}
1794               
1795        # Only if we really have an executable for the component :
1796        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1797
1798          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1799          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1800                   
1801          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1802          # echo "set -vx" >> script_${ExeNameOut}.ksh
1803          echo ""  >> script_${ExeNameOut}.ksh
1804          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1805          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1806          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1807          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1808          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1809          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1810          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1811                   
1812          node_num=0
1813                   
1814          # We define the number of MPI process to be assigned for the component
1815
1816          nombre_restant_comp=${comp_proc_mpi_loc}
1817                   
1818          # Loop on the allocated nodes
1819
1820          for node in ${listnodes} ; do
1821
1822            # We go to the current node
1823            if [ ${node_num} = ${node_num_current} ] ; then
1824
1825              node_current=${host[${node_num_current}]}
1826
1827              # If first time on the node : initialisation
1828
1829              if [ ${init_node} = y ] ; then
1830                nombre_restant_node=${NUM_COREPERNODE}
1831              fi
1832                           
1833              # Test on the number of OMP threads
1834
1835              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1836                (( node_num = node_num + 1 ))
1837                node_num_current=${node_num}
1838                init_node=y
1839                continue
1840              fi
1841
1842              # Number of MPI process to assign
1843
1844              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1845                           
1846              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1847                num_corempi=${nombre_restant_comp}
1848              fi
1849
1850              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1851              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1852                           
1853              if [ ${init_exec} = y ] ; then
1854                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1855              else     
1856                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1857                init_exec=y
1858              fi
1859
1860              ((  start_num = num_corempi + start_num ))
1861                           
1862            else
1863                           
1864              (( node_num = node_num + 1 )) 
1865              continue
1866            fi
1867                       
1868            # Test on the number of core/process remaining on the node/component
1869                       
1870            if [ ${nombre_restant_node} = 0 ] ; then
1871              (( node_num = node_num + 1 ))
1872              node_num_current=${node_num}
1873              init_node=y
1874
1875              if [ ${nombre_restant_comp} = 0 ] ; then
1876                break 1
1877              fi
1878            else
1879
1880              node_num_current=${node_num}
1881              init_node=n
1882                           
1883              if [ ${nombre_restant_comp} = 0 ] ; then
1884                break 1
1885              fi
1886            fi
1887          done
1888        fi
1889      done
1890           
1891    else
1892
1893        # Then first loop on the components for the coupler ie oasis
1894
1895        ## the coupler ie oasis must be the first one
1896        for comp in ${config_ListOfComponents[*]} ; do
1897           
1898            eval ExeNameOut=\${config_Executable_${comp}[1]}
1899               
1900        # for CPL component only
1901            if [ "X${comp}" = "XCPL" ] ; then
1902                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1903                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1904            fi
1905        done
1906
1907        # Then second loop on the components
1908
1909        for comp in ${config_ListOfComponents[*]} ; do
1910               
1911            eval ExeNameOut=\${config_Executable_${comp}[1]}
1912               
1913            # Only if we really have an executable for the component and not the coupler ie oasis:
1914            if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1915                eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1916                echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1917            fi
1918        done
1919        IGCM_sys_Chmod u+x run_file
1920
1921        EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1922         
1923    fi
1924
1925  else # Only one executable. launch it.
1926
1927      for comp in ${config_ListOfComponents[*]} ; do
1928
1929          # Only if we really have an executable for the component :
1930          eval ExeNameOut=\${config_Executable_${comp}[1]}
1931          if ( [ "X${ExeNameOut}" != X\"\" ] ) ; then   
1932               
1933              echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1934              echo ""  >> script_${ExeNameOut}.ksh
1935              if ( ${OK_PARA_OMP} ) ; then
1936                  eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1937                  echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh       
1938              fi
1939              if  ( ${OK_PARA_MPI} ) ; then 
1940                  # Default : mpirun used if nb_proc gt 1
1941                  # pour sortie out/err par process
1942                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1943                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1944                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1945                  EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1946              else
1947                  # Default : mpirun is NOT used if nb_proc eq 1
1948                  # pour sortie out/err par process
1949                  # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1950                  echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1951                  IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1952                  EXECUTION="time ./script_${ExeNameOut}.ksh"
1953              fi
1954          fi
1955      done
1956     
1957  fi
1958
1959  IGCM_debug_Print 1 "sys Titane : La commande d execution est "
1960  IGCM_debug_Print 1 $EXECUTION
1961
1962  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1963}
1964
1965
1966
1967##############################################################
1968# NCO OPERATOR
1969
1970function IGCM_sys_ncap2 {
1971  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1972  if ( $DEBUG_sys ) ; then
1973    echo "IGCM_sys_ncap2 :" $@
1974  fi
1975  ncap2 "$@"
1976  if [ $? -gt 0 ] ; then
1977    echo "IGCM_sys_ncap2 : erreur ${@}."
1978    IGCM_debug_Exit "ncap2"
1979  fi
1980
1981  IGCM_debug_PopStack "IGCM_sys_ncap2"
1982}
1983
1984function IGCM_sys_ncatted {
1985  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1986  if ( $DEBUG_sys ) ; then
1987    echo "IGCM_sys_ncatted :" $@
1988  fi
1989  ncatted "$@"
1990  if [ $? -gt 0 ] ; then
1991    echo "IGCM_sys_ncatted : erreur ${@}."
1992    IGCM_debug_Exit "ncatted"
1993  fi
1994
1995  IGCM_debug_PopStack "IGCM_sys_ncatted"
1996}
1997
1998function IGCM_sys_ncbo {
1999  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2000  if ( $DEBUG_sys ) ; then
2001    echo "IGCM_sys_ncbo :" $@
2002  fi
2003  ncbo $@
2004  if [ $? -gt 0 ] ; then
2005    echo "IGCM_sys_ncbo : erreur ${@}."
2006    IGCM_debug_Exit "ncbo"
2007  fi
2008
2009  IGCM_debug_PopStack "IGCM_sys_ncbo"
2010}
2011
2012function IGCM_sys_ncdiff {
2013  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2014  if ( $DEBUG_sys ) ; then
2015    echo "IGCM_sys_ncdiff :" $@
2016  fi
2017  ncdiff $@
2018  if [ $? -gt 0 ] ; then
2019    echo "IGCM_sys_ncdiff : erreur ${@}."
2020    IGCM_debug_Exit "ncdiff"
2021  fi
2022
2023  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2024}
2025
2026function IGCM_sys_ncea {
2027  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2028  if ( $DEBUG_sys ) ; then
2029    echo "IGCM_sys_ncea :" $@
2030  fi
2031  ncea $@
2032  if [ $? -gt 0 ] ; then
2033    echo "IGCM_sys_ncea : erreur ${@}."
2034    IGCM_debug_Exit "ncea"
2035  fi
2036
2037  IGCM_debug_PopStack "IGCM_sys_ncea"
2038}
2039
2040function IGCM_sys_ncecat {
2041  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2042  if ( $DEBUG_sys ) ; then
2043    echo "IGCM_sys_ncecat :" $@
2044  fi
2045  ncecat $@
2046  if [ $? -gt 0 ] ; then
2047    echo "IGCM_sys_ncecat : erreur ${@}."
2048    IGCM_debug_Exit "ncecat"
2049  fi
2050
2051  IGCM_debug_PopStack "IGCM_sys_ncecat"
2052}
2053
2054function IGCM_sys_ncflint {
2055  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2056  if ( $DEBUG_sys ) ; then
2057    echo "IGCM_sys_ncflint :" $@
2058  fi
2059  ncflint $@
2060  if [ $? -gt 0 ] ; then
2061    echo "IGCM_sys_ncflint : erreur ${@}."
2062    IGCM_debug_Exit "ncflint"
2063  fi
2064
2065  IGCM_debug_PopStack "IGCM_sys_ncflint"
2066}
2067
2068function IGCM_sys_ncks {
2069  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2070  if ( $DEBUG_sys ) ; then
2071    echo "IGCM_sys_ncks :" $@
2072  fi
2073  ncks $@
2074  if [ $? -gt 0 ] ; then
2075    echo "IGCM_sys_ncks : erreur ${@}."
2076    IGCM_debug_Exit "ncks"
2077  fi
2078
2079  IGCM_debug_PopStack "IGCM_sys_ncks"
2080}
2081
2082function IGCM_sys_ncpdq {
2083  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2084  if ( $DEBUG_sys ) ; then
2085    echo "IGCM_sys_ncpdq :" $@
2086  fi
2087  ncpdq $@
2088  if [ $? -gt 0 ] ; then
2089    echo "IGCM_sys_ncpdq : erreur ${@}."
2090    IGCM_debug_Exit "ncpdq"
2091  fi
2092
2093  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2094}
2095
2096function IGCM_sys_ncra {
2097  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2098  if ( $DEBUG_sys ) ; then
2099    echo "IGCM_sys_ncra :" $@
2100  fi
2101  ncra $@
2102  if [ $? -gt 0 ] ; then
2103    echo "IGCM_sys_ncra : erreur ${@}."
2104    IGCM_debug_Exit "ncra"
2105  fi
2106
2107  IGCM_debug_PopStack "IGCM_sys_ncra"
2108}
2109
2110function IGCM_sys_ncrcat {
2111  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2112  if ( $DEBUG_sys ) ; then
2113    echo "IGCM_sys_ncrcat :" $@
2114  fi
2115  ncrcat --omp_num_threads 2 $@
2116  if [ $? -gt 0 ] ; then
2117    echo "IGCM_sys_ncrcat : erreur ${@}."
2118#       IGCM_debug_Exit "ncrcat"
2119  fi
2120
2121  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2122}
2123
2124function IGCM_sys_ncrename {
2125  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2126  if ( $DEBUG_sys ) ; then
2127    echo "IGCM_sys_ncrename :" $@
2128  fi
2129  ncrename $@
2130  if [ $? -gt 0 ] ; then
2131    echo "IGCM_sys_ncrename : erreur ${@}."
2132    IGCM_debug_Exit "ncrename"
2133  fi
2134
2135  IGCM_debug_PopStack "IGCM_sys_ncrename"
2136}
2137
2138function IGCM_sys_ncwa {
2139  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2140  if ( $DEBUG_sys ) ; then
2141    echo "IGCM_sys_ncwa :" $@
2142  fi
2143  ncwa $@
2144  if [ $? -gt 0 ] ; then
2145    echo "IGCM_sys_ncwa : erreur ${@}."
2146    IGCM_debug_Exit "ncwa"
2147  fi
2148
2149  IGCM_debug_PopStack "IGCM_sys_ncwa"
2150}
2151
2152##############################################################
2153# CDO OPERATOR
2154
2155function IGCM_sys_cdo {
2156  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2157  if ( $DEBUG_sys ) ; then
2158    echo "IGCM_sys_cdo :" $@
2159  fi
2160  \cdo $@
2161  if [ $? -gt 0 ] ; then
2162    echo "IGCM_sys_cdo : erreur ${@}."
2163    IGCM_debug_PopStack "IGCM_sys_cdo"
2164    return 1
2165  else
2166    IGCM_debug_PopStack "IGCM_sys_cdo"
2167    return 0
2168  fi
2169
2170  IGCM_debug_PopStack "IGCM_sys_cdo"
2171}
Note: See TracBrowser for help on using the repository browser.