source: trunk/libIGCM/libIGCM_config/libIGCM_config.ksh @ 1127

Last change on this file since 1127 was 1127, checked in by sdipsl, 10 years ago
  • Easier for now not to fill the stack for checking tasks. see #232
  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 52.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#===================================
15function IGCM_config_CommonConfiguration
16{
17  IGCM_debug_PushStack "IGCM_config_CommonConfiguration" $@
18
19  # Debug Print :
20  [ ${Verbosity} -gt 0 ] && echo
21  IGCM_debug_Print 1 "IGCM_config_CommonConfiguration" $@
22
23  # config.card path
24  configPath=$1
25
26  #==================================
27  typeset option auxprint CompatibilityTag
28
29  #==================================
30  # Read libIGCM compatibility version in config.card
31  IGCM_card_DefineVariableFromOption ${configPath} Compatibility libIGCM
32  CompatibilityTag=${config_Compatibility_libIGCM}
33
34  if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then
35    IGCM_debug_Exit "config.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ."
36  fi
37
38  #==================================
39  # Read UserChoices section:
40  [ ${Verbosity} -gt 0 ] && echo
41  IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
42
43  IGCM_card_DefineArrayFromSection ${configPath} UserChoices
44  for option in ${config_UserChoices[*]} ; do
45    IGCM_card_DefineVariableFromOption ${configPath} UserChoices ${option}
46    eval auxprint=\${config_UserChoices_${option}}
47    IGCM_debug_Print 3 "${option} : ${auxprint}"
48  done
49
50  #==================================
51  # Read Ensemble section:
52  [ ${Verbosity} -gt 0 ] && echo
53  IGCM_debug_Print 1 "DefineArrayFromOption  : config_Ensemble"
54
55  IGCM_card_DefineArrayFromSection ${configPath} Ensemble
56  for option in ${config_Ensemble[*]} ; do
57    IGCM_card_DefineVariableFromOption ${configPath} Ensemble ${option}
58    eval auxprint=\${config_Ensemble_${option}}
59    IGCM_debug_Print 3 "${option} : ${auxprint}"
60  done
61
62  #==================================
63  # Read Post section:
64  [ ${Verbosity} -gt 0 ] && echo
65  IGCM_debug_Print 1 "DefineArrayFromOption : config_Post"
66
67  IGCM_card_DefineArrayFromSection ${configPath} Post
68  for option in ${config_Post[*]} ; do
69    IGCM_card_DefineVariableFromOption ${configPath} Post ${option}
70    eval auxprint=\${config_Post_${option}}
71    IGCM_debug_Print 3 "${option} : ${auxprint}"
72  done
73  [ ${Verbosity} -gt 0 ] && echo
74
75  #==================================
76  # Define default value to keep compatibility with previous card: means before changes due to TGCC
77  # Apply some overrules to ensure proper usage of computing centres resources
78  #
79  if [ X${PackDefault} = Xtrue ] ; then
80    if [ X${config_UserChoices_SpaceName} = XTEST ]; then
81      # TEST simulations will not be packed and will stay on SCRATCHDIR filesystem
82      IGCM_debug_Print 1 "SpaceName=TEST. OVERRULE PackFrequency to NONE"
83      config_Post_PackFrequency=NONE
84    else
85      # Default to RebuildFrequency if nothing has been set up related to PackFrequency
86      [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency}
87    fi
88  else
89    # If we DO NOT apply pack in this computing center
90    config_Post_PackFrequency=NONE
91  fi
92
93  #====================================================
94  # Define ARCHIVE : Dedicated to large files
95  # Define STORAGE : Dedicated to small/medium files
96  # Define R_OUT   : Output tree located on ARCHIVE
97  # Define R_FIG   : Output tree located on STORAGE hosting figures (monitoring and atlas, and/or small files)
98  # Define R_BUF   : USELESS and DEPRECATED output tree.
99  IGCM_sys_defineArchives
100
101  #====================================================
102  # R_SAVE : Job output directory
103  # R_BUFR : Job output buffered directory
104
105  if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
106    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
107    if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
108      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
109      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
110      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
111      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
112    else
113      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
114      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
115      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
116      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
117    fi
118  else
119    if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
120      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
121      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
122      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
123      R_DODS=${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
124    else
125      R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
126      R_FIGR=${R_FIG}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
127      R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
128      R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName}
129    fi
130  fi
131
132  #====================================================
133  # Define R_OUT_KSH : Storage place for job output
134  # Define R_OUT_EXE : Storage place for binary used during simulation
135  R_OUT_KSH=${R_SAVE}/Out
136  R_OUT_EXE=${R_SAVE}/Exe
137
138  #====================================================
139  # Define R_BUF_KSH : Buffer place for job output
140  # Define R_BUF_EXE : Buffer place for binary used during simulation
141  R_BUF_KSH=${R_BUFR}/Out
142  R_BUF_EXE=${R_BUFR}/Exe
143
144  #====================================================
145  # Define REBUILD_DIR : where we store files needing rebuild process
146  REBUILD_DIR=${R_BUFR}/REBUILD
147  if [ ! X${TaskType} = Xchecking ] ; then
148    IGCM_sys_MkdirWork ${REBUILD_DIR}
149  fi
150
151  #====================================================
152  # DodsCopy : apply default value if not defined
153  if ( [ X${config_Post_DodsCopy} = X${NULL_STR} ] || [ X${config_Post_DodsCopy} = X ] ) ; then
154    config_Post_DodsCopy=TRUE
155  fi
156
157  #====================================================
158  # Define StackFileLocation : directory where we store stack files
159  # Define StackFileName : stack file containing call tree and instrumentation
160  # Stack file containing call tree will be stored there.
161  if ( $DEBUG_debug ) ; then
162    StackFileLocation=${StackFileLocation:=${R_BUF_KSH}}
163    [ ! -d ${StackFileLocation} ] && mkdir -p ${StackFileLocation}
164    if [ X${TaskType} = Xcomputing ]; then
165      StackFileName=computing.stack.$$
166    elif [ X${TaskType} = Xpost-processing ]; then
167      StackFileName=${Script_Post_Output}.stack.$$
168    elif [ X${TaskType} = Xchecking ]; then
169      StackFileName=checking.stack.$$
170    else
171      IGCM_debug_Exit "IGCM_config_CommonConfiguration unknown TaskType : ${TaskType}"
172      IGCM_debug_Verif_Exit
173    fi
174
175    # This boolean will trigger the filling of the stack
176    # Only now we know where things should be ...
177    # We don't fill the stack when we perform checking task
178    if [ ! X${TaskType} = Xchecking ] ; then
179      ActivateStackFilling=true
180    fi
181  fi
182
183  IGCM_debug_PopStack "IGCM_config_CommonConfiguration"
184}
185
186#===================================
187function IGCM_config_Initialize
188{
189  IGCM_debug_PushStack "IGCM_config_Initialize"
190
191  # Debug Print :
192  echo
193  IGCM_debug_Print 1 "IGCM_config_Initialize"
194
195  # Test modipsl tree existence.
196  IGCM_sys_TestDir ${MODIPSL}
197  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
198  IGCM_sys_TestDir ${libIGCM}
199  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
200  IGCM_sys_TestDir ${R_EXE}
201  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
202  IGCM_sys_TestDir ${SUBMIT_DIR}
203  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir"
204
205  if ( $DEBUG_debug ) ; then
206    echo "Keep trace of inital SUBMIT_DIR : "
207    ls -lta ${SUBMIT_DIR}
208  fi
209
210  #==================================
211  # Read ListOfComponents section:
212  echo
213  IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
214
215  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents
216  for comp in ${config_ListOfComponents[*]} ; do
217    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp}
218  done
219  IGCM_debug_Print 3 ${config_ListOfComponents[*]}
220
221  #==================================
222  # Read Executable section:
223  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable
224
225  #==================================
226  # Read Restarts section:
227  # Restarts : Gerneral rule or local for each component.
228  echo
229  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts"
230
231  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts
232  for option in ${config_Restarts[*]} ; do
233    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option}
234    eval auxprint=\${config_Restarts_${option}}
235    IGCM_debug_Print 3 "${option} : ${auxprint}"
236  done
237
238  #==================================
239  # Define Job Outputs Name
240  echo
241  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output"
242  Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'}
243  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}"
244  Exe_Output=out_execution
245  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}"
246
247  #===================================================================#
248  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
249  #             But available to any son functions                    #
250  #===================================================================#
251
252  # Convert yyyy-mm-dd date to gregorian yyyymmdd
253  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} )
254  DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   )
255
256  # Period Length In Days between DateBegin and DateEnd
257  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
258  if [ ${ExperienceLengthInDays} -lt 0 ] ; then
259    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that."
260    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates."
261    IGCM_debug_Verif_Exit
262  fi
263
264  # Day and Year of Initial State (Given in julian format)
265  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 ))
266  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 ))
267
268  #================================================================#
269  #                  Test and Prepare directories                  #
270  #================================================================#
271
272  # ==> 4 kinds of input files :
273  #     1) R_INIT  : Initial State Files   (Etat0, carteveg)
274  #     2) R_BC    : Boundary Conditions   (Forcages, lai)
275  #     3) Parameters files (allready define through ${SUBMIT_DIR})
276  #     4) Restarts files   (allready define in IGCM_config_Initialize)
277
278  # Here we offer the possibility to redefine R_INIT, R_BC
279  # and PeriodNb through config.card
280  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT}
281  echo
282  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb"
283  IGCM_debug_Print 3 "R_INIT=${R_INIT}"
284  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC}
285  IGCM_debug_Print 3  "R_BC=${R_BC}"
286  PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}}
287  IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)"
288
289  # SD ADA SPECIFIC #
290  #      TO FIX     #
291  #IGCM_sys_TestDirArchive ${R_IN}
292  #[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
293
294  if ( ${FirstInitialize} ) ; then
295    IGCM_sys_MkdirArchive   ${R_SAVE}
296    [ ! ${config_Post_PackFrequency} = NONE ] && IGCM_sys_Mkdir ${R_BUFR}
297  else
298    IGCM_sys_TestDirArchive ${R_SAVE}
299    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive ${R_SAVE}"
300
301    if [ ! ${config_Post_PackFrequency} = NONE ] ; then
302      IGCM_sys_TestDir ${R_BUFR}
303      [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir ${R_BUFR}"
304    fi
305
306    #Test state of run in run.card
307    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
308
309    if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
310      echo
311      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
312      IGCM_debug_Print 1 "Check post-processing jobs carefully by running ${libIGCM}/RunChecker.job -p ${SUBMIT_DIR}"
313      IGCM_debug_Print 1 "Then try running ${libIGCM}/clean_month.job to rerun one period"
314      IGCM_debug_Print 1 "Then try running ${libIGCM}/clean_year.job to rerun more."
315      IGCM_debug_Exit
316      IGCM_debug_Verif_Exit
317    fi
318  fi
319
320  #====================================================
321  # Experience type : DEB(ug), DEV(elopment), RUN
322  if [ X${JobType} != XRUN ] ; then
323    echo
324    echo "===================================================="
325    echo "libIGCM JOB is NOT in RUN type mode."
326    echo "!! OUTPUT files will NOT be PROTECTED !!"
327    echo "Be carefull : you can ERASE the result of this job !"
328
329    case ${JobType} in
330    DEB)
331      echo "DEBUG mode : activation of 'set -vx' mode."
332      echo "DEBUG mode : no protection for output files."
333      echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
334      ;;
335    DEV)
336      echo "DEVelopment mode : no protection for output files."
337      echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency."
338      ;;
339    esac
340
341    if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then
342      if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then
343        echo "------------"
344        echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency"
345        echo "          to PeriodLength : ${config_UserChoices_PeriodLength}"
346        echo "------------"
347        config_Post_RebuildFrequency=${config_UserChoices_PeriodLength}
348      fi
349    fi
350    echo "===================================================="
351    echo
352  fi
353
354  IGCM_debug_PopStack "IGCM_config_Initialize"
355}
356
357#===================================
358function IGCM_config_DaysInPeriodLength
359{
360  IGCM_debug_PushStack "IGCM_config_DaysInPeriodLength"
361
362  typeset i
363
364  # Determine number of day(s) in PeriodLength :
365  case ${config_UserChoices_PeriodLength} in
366  *Y|*y)
367    PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' )
368    echo
369    IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}"
370    PeriodLengthInDays=0
371    i=0
372    until [ $i -ge $PeriodLengthInYears ] ; do
373      (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))
374      (( i=i+1 ))
375    done
376    ;;
377  *M|*m)
378    PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' )
379    echo
380    IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}"
381    PeriodLengthInDays=0
382    i=0
383    until [ $i -ge $PeriodLengthInMonths ] ; do
384      if [ $(( 10#${month} + ${i} )) -lt 13 ] ; then
385        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( 10#${month} + ${i} )) ) ))
386      else
387        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( 10#${month} + ${i} - 12 )) ) ))
388      fi
389      (( i=i+1 ))
390    done
391    ;;
392  *D|*d)
393    PeriodLengthInMonths=0
394    PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' )
395    echo
396    IGCM_debug_Print 2 "Number of days for PeriodLength : ${PeriodLengthInDays}";;
397  *)
398    IGCM_debug_Exit "IGCM_config_DaysInPeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D."
399    IGCM_debug_Verif_Exit ;;
400  esac
401
402  IGCM_debug_PopStack "IGCM_config_DaysInPeriodLength"
403}
404
405#===================================
406function IGCM_config_DateCoherency
407{
408  IGCM_debug_PushStack "IGCM_config_DateCoherency"
409
410  echo
411  IGCM_debug_Print 1 "IGCM_config_DateCoherency"
412  echo
413
414  typeset Length VerifiedPeriodDateBegin VerifiedPeriodDateEnd
415
416  # check coherency between (PeriodDateBegin, PeriodDateEnd) and (DateBegin, CumulPeriod, PeriodLength)
417  # DateBegin + CumulPeriod*PeriodLength = PeriodDateBegin
418  echo
419
420  case ${config_UserChoices_PeriodLength} in
421  *Y|*y)
422    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInYears} ))Y )
423    ;;
424  *M|*m)
425    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInMonths} ))M )
426    ;;
427  *D|*d)
428    Length=$( IGCM_date_DaysInCurrentPeriod ${DateBegin} $(( ${CumulPeriod} * ${PeriodLengthInDays} ))D )
429    ;;
430  esac
431  VerifiedPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} ${Length}-1 )
432
433  if [ ${VerifiedPeriodDateEnd} != ${PeriodDateEnd} ] ; then
434    IGCM_debug_Print 1 "From run.card PeriodDateEnd is not consistent with DateBegin and CumulPeriod."
435    IGCM_debug_Print 1 "We have DateBegin = ${DateBegin}"
436    IGCM_debug_Print 1 "We have CumulPeriod = ${CumulPeriod}"
437    IGCM_debug_Print 1 "We have PeriodDateEnd = ${PeriodDateEnd}"
438    IGCM_debug_Print 1 "We have VerifiedPeriodDateEnd = ${VerifiedPeriodDateEnd}"
439    IGCM_debug_Print 1 "You must have change run.card in an inconsistent way."
440
441    IGCM_debug_Exit "STOP here to avoid further issues."
442  fi
443
444  # PeriodDateBegin + PeriodLength = PeriodDateEnd
445  VerifiedPeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${VerifiedPeriodDateEnd} $(( ${PeriodLengthInDays} * -1 )) )
446
447  IGCM_debug_PopStack "IGCM_config_DateCoherency"
448}
449
450
451#===================================
452function IGCM_config_Check
453{
454  IGCM_debug_PushStack "IGCM_config_Check"
455
456  # If one of the following modulo is not zero :
457  # we will issue an error then explain and exit in
458  # AA_job IGCM_debug_Verif_Exit call before binary submission
459
460  echo
461  IGCM_debug_Print 1 "IGCM_config_Check"
462  echo
463
464  typeset i
465
466  # Check RebuildFrequency against key frequencies : PeriodLength ; PackFrequency ; TimeSeriesFrequency ; SeasonalFrequency
467  if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then
468    AsynchronousRebuild=true
469    IGCM_debug_Print 1 "Asynchronous rebuild has been activated."
470    echo
471    # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero
472    IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength"
473    IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength
474    IGCM_debug_Print 1 "Check coherence between PackFrequency and RebuildFrequency"
475    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_Post_RebuildFrequency
476    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency"
477    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency
478    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency"
479    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency
480  else
481    AsynchronousRebuild=false
482    IGCM_debug_Print 1 "Asynchronous rebuild has not been activated"
483    IGCM_debug_Print 1 "Proceed with standard post-treatment pathway"
484    echo
485    #modulo (PeriodLength and TimeSeriesFrequency/SeasonalFrequency) must be zero
486    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength"
487    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength
488    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength"
489    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength
490  fi
491
492  # Check PackFrequency against other key frequencies
493  # Modulo (PackFrequency and TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero
494  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then
495    Pack=true
496    #
497    IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
498    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_UserChoices_PeriodLength
499    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PackFrequency"
500    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_PackFrequency
501    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PackFrequency"
502    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_PackFrequency
503  else
504    Pack=false
505  fi
506
507  # modulo (TimeSeriesFrequency and all Chunck2D) must be zero
508  NbJob=${#CHUNCK2D_SIZE[@]}
509  i=0
510  until [ $i -ge $NbJob ]; do
511    value=${CHUNCK2D_SIZE[${i}]}
512    IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency"
513    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
514    case ${value} in
515    *Y|*y) ;;
516    *)
517      IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card"
518      IGCM_debug_Exit "This will stop the job" ;;
519    esac
520    (( i=i+1 ))
521  done
522
523  # modulo (TimeSeriesFrequency and all Chunck3D) must be zero
524  NbJob=${#CHUNCK3D_SIZE[@]}
525  i=0
526  until [ $i -ge $NbJob ]; do
527    value=${CHUNCK3D_SIZE[${i}]}
528    IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency"
529    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency
530    case ${value} in
531    *Y|*y) ;;
532    *)
533      IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card"
534      IGCM_debug_Exit "This will stop the job" ;;
535    esac
536    (( i=i+1 ))
537  done
538
539  # check to be sure there is enough space on temporary filesystems to run
540  echo
541  IGCM_debug_Print 1 "Check if there is enough space on temporary filesystem"
542  IGCM_sys_check_quota
543
544  # check to be sure that RUN_DIR_PATH, that will be removed is not pointing to an important directory
545  echo
546  IGCM_debug_Print 1 "Check where RUN_DIR_PATH variable is pointing to"
547  IGCM_sys_check_path
548
549
550  IGCM_debug_PopStack "IGCM_config_Check"
551}
552
553#===================================
554function IGCM_config_PeriodStart
555{
556  IGCM_debug_PushStack "IGCM_config_PeriodStart"
557
558  echo
559  IGCM_debug_Print 1 "IGCM_config_PeriodStart"
560  echo
561
562  if ( ${FirstInitialize} ) ; then
563    #================================================#
564    #         Initialize date/period information     #
565    #================================================#
566
567    IGCM_date_GetYearMonthDay ${DateBegin} year month day
568    IGCM_config_DaysInPeriodLength
569
570    PeriodDateBegin=${DateBegin}
571    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) )
572    CumulPeriod=1
573
574    #=================================================#
575    #              Write updated run.card             #
576    #=================================================#
577
578    #Correct run.card Configuration for this period
579    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
580    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
581    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
582    if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then
583      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR}
584    fi
585
586    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
587
588  else
589    #================================================#
590    #         The file run.card allready exist       #
591    #================================================#
592
593    #Test state of run in run.card
594    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState
595    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then
596      echo
597      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!"
598      IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this"
599      echo
600      IGCM_debug_Exit
601      IGCM_debug_Verif_Exit
602    fi
603
604    #===================================#
605    #        Read updated run.card      #
606    #===================================#
607
608    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin
609    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd
610    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod
611
612    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} )
613    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} )
614    CumulPeriod=${run_Configuration_CumulPeriod}
615
616    LastPeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate $( IGCM_date_ConvertFormatToGregorian ${PeriodDateBegin} ) -1 )
617
618    if [ ${Period} = 1 ]; then
619      # save last Job output and current run.card
620      typeset Potential
621      IGCM_sys_Cd ${SUBMIT_DIR}
622      #
623      IGCM_debug_Print 2 "Save previous ksh job output"
624      for Potential in $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.[0-9][0-9][0-9][0-9][0-9][0-9] ) ; do
625        if [ X${Pack} = Xtrue ] ; then
626          ( IGCM_sys_TestFileBuffer  ${R_BUF_KSH}/${Potential} ) || IGCM_sys_Cp ${Potential} ${R_BUF_KSH}/${Potential}.$$
627        else
628          ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${Potential} ) || IGCM_sys_Cp ${Potential} ${R_OUT_KSH}/${Potential}.$$
629        fi
630      done
631      #
632      IGCM_debug_Print 2 "Save current run.card"
633      IGCM_card_CheckConflict run.card
634      if [ X${Pack} = Xtrue ] ; then
635        IGCM_sys_Cp ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/run.card
636      else
637        IGCM_sys_Cp ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card
638      fi
639      #
640      IGCM_sys_Cd ${RUN_DIR}
641    else
642      unset FileToBeDeleted
643    fi
644
645    # Determine number of day(s) in PeriodLength
646    IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
647    IGCM_config_DaysInPeriodLength
648
649    # Check coherency between (PeriodDateBegin, PeriodDateEnd) and (DateBegin, CumulPeriod, PeriodLength)
650    IGCM_config_DateCoherency
651    # And EXIT if not OK
652    IGCM_debug_Verif_Exit
653
654    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running"
655  fi
656
657  # BEGIN: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
658  # Compute year_m1 and year_p1 (year minus 1Y and year plus 1Y)
659  year_m1=$(( year - 1 ))
660  year_p1=$(( year + 1 ))
661  # Compute month_m1 (month minus 1M)
662  # Compute yyyymm_m1 (yyyymm minus 1M)
663  month_m1=$(( 10#${month} - 1 ))
664  if [ ${month_m1} = 0 ]; then
665    month_m1=12
666    yyyymm_m1=${year_m1}12
667  elif [ ${month_m1} -le 9 ]; then
668    month_m1=0${month_m1}
669    yyyymm_m1=${year}${month_m1}
670  else
671    yyyymm_m1=${year}${month_m1}
672  fi
673  # Compute month_p1 (month plus 1M)
674  # Compute yyyymm_p1 (yyyymm plus 1M)
675  month_p1=$(( 10#${month} + 1 ))
676  if [ ${month_p1} = 13 ]; then
677    month_p1=01
678    yyyymm_p1=${year_p1}01
679  elif [ ${month_p1} -le 9 ]; then
680    month_p1=0${month_p1}
681    yyyymm_p1=${year}${month_p1}
682  else
683    yyyymm_p1=${year}${month_p1}
684  fi
685  #IGCM_debug_Print 1 "jg 1 month_m1 = ${month_m1} month_p1 = ${month_p1} "
686  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_m1 = ${yyyymm_m1} "
687  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_p1 = ${yyyymm_p1} "
688
689  #===================================================================#
690  # Calculate CyclicYear to be used for looping over a given forcing  #
691  # period. Add CyclicBegin and CyclicEnd in config.card UserChoices. #
692  #===================================================================#
693
694  # To use the variable CyclicYear, one must add in config.card CyclicBegin and CyclicEnd.
695  # CyclicBegin is the first year in the cycle. CyclicEnd is the last year included in the cycle.
696  if ( [ ! X${config_UserChoices_CyclicBegin} = X ] && [ ! X${config_UserChoices_CyclicEnd} = X ] ) ; then
697    CycleNb=$(( ${config_UserChoices_CyclicEnd} - ${config_UserChoices_CyclicBegin} + 1 ))
698    CyclicYear_p1=NOTDEFINED
699
700    # For current year
701    yeartmp=$year
702    diffy=$(( $yeartmp - ${config_UserChoices_CyclicBegin} ))
703    while [ $diffy -lt 0 ] ; do
704      yeartmp=$(( ${yeartmp} + ${CycleNb} ))
705      diffy=$(( $yeartmp - ${config_UserChoices_CyclicBegin} ))
706    done
707    CyclicYear=$(( ( ${diffy} % ${CycleNb} ) + ${config_UserChoices_CyclicBegin} ))
708
709    # For next coming year
710    yeartmp=$(( $year + 1 ))
711    diffy=$(( $yeartmp - ${config_UserChoices_CyclicBegin} ))
712    while [ $diffy -lt 0 ] ; do
713      yeartmp=$(( ${yeartmp} + ${CycleNb} ))
714      diffy=$(( $yeartmp - ${config_UserChoices_CyclicBegin} ))
715    done
716    CyclicYear_p1=$(( ( ${diffy} % ${CycleNb} ) + ${config_UserChoices_CyclicBegin} ))
717
718    IGCM_debug_Print 1 "CyclicYear   = ${CyclicYear}, CyclicYear_p1 = ${CyclicYear_p1}, current year=$year"
719  else
720    CyclicYear="ERROR_CyclicYear_Variable_Not_Defined"
721    CyclicYear_p1="ERROR_CyclicYear_p1_Variable_Not_Defined"
722    IGCM_debug_Print 1 "CyclicYear wont be use without adding CyclicBegin and CyclicEnd in config.card"
723  fi
724
725  # END: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh
726
727  #===================================================================#
728  # Prepare variables available for ${COMP}.card and ${COMP}.driver   #
729  #             But available to any son functions                    #
730  #===================================================================#
731
732  # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !)
733  (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 ))
734
735  # Debug Print :
736  echo
737  IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution"
738  IGCM_debug_Print 1 "Year of simulation      : ${year}"
739  IGCM_debug_Print 1 "Month of simulation     : ${month}"
740  IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}"
741  IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}"
742  IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}"
743  IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}"
744  IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}"
745
746  #================================================================#
747  #         Prepare variables available for comp_finalyze          #
748  #================================================================#
749
750  # Period for save files
751  DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd}
752
753  # Prefix for save files of this period
754  PREFIX=${config_UserChoices_JobName}_${DatesPeriod}
755
756  # List of files that will be deleted in RUN_DIR after run
757  [ -f stack ] && FileToBeDeleted[0]="stack"
758
759  # Test if the same run as already been saved :
760  if [ X${JobType} = XRUN ] ; then
761    if [ ${DRYRUN} -le 0 ] ; then
762      if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
763        IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job."
764        IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files"
765        IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or "
766        IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory."
767        IGCM_debug_Print 1 " This exit has been initiated because at least ${R_BUF_KSH}/${PREFIX}_${Exe_Output} exists."
768        IGCM_debug_Verif_Exit
769      fi
770    fi
771  else
772    if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then
773      IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode."
774    fi
775  fi
776
777  #================================================================#
778  #       Prepare variables available for binary execution         #
779  #       Call function for creation of run script                 #
780  #       Only done once per job                                   #
781  #================================================================#
782
783  if [ ${Period} -eq 1 ]; then
784    typeset ExeNameIn ExeNameFirst CompNameFirst comp i j
785    typeset tempvar tempvarMPI tempvarNOD NbElts NbExec
786
787    PROCESSUS_NUMBER=0
788    NbExec=0
789    i=0
790
791    OK_PARA_MPI=false
792    OK_PARA_OMP=false
793    OK_PARA_NOD=false
794    OK_PARA_MPMD=false
795
796    for comp in ${config_ListOfComponents[*]} ; do
797
798      IGCM_debug_Print 1 ${comp}
799
800      eval ExeNameIn=\${config_Executable_${comp}[0]}
801
802      # NO order in config.card for parallelized values !
803      # just use suffix : MPI , OMP and NOD (for number of NODes.)
804
805      # NOD is the number of NODes allocated
806      eval ${comp}_PROC_NOD=0
807
808      # MPI is the number of MPI processus per nodes
809      eval ${comp}_PROC_MPI=0
810
811      # OMP is the number of OpenMP threads per MPI processus
812      eval ${comp}_PROC_OMP=0
813
814      # Only if we really have an executable for the component :
815      if ( [ "X${ExeNameIn}" != X\"\" ] && [ "X${ExeNameIn}" != "Xinca.dat" ] ) ; then
816
817        # Keep the first executable found and the first CompName
818        ExeNameFirst=${ExeNameIn}
819        CompNameFirst=${comp}
820
821        # Are we a second executable?
822        (( NbExec = NbExec + 1 ))
823
824        # set 1 MPI task, 1 OpenMP thread and 1 node as default
825        eval ${comp}_PROC_MPI=1
826        eval ${comp}_PROC_OMP=1
827        eval ${comp}_PROC_NOD=1
828
829        eval NbElts=\${#config_Executable_${comp}[@]}
830
831        if [ ${NbElts} -ge 2 ] ; then
832          (( j = 2 ))
833          while [ $j -lt ${NbElts} ] ; do
834            eval tempvar=\${config_Executable_${comp}[${j}]}
835            IGCM_debug_Print 2 ${tempvar}
836
837            if [ X${tempvar} = X ] ; then
838              IGCM_debug_Print 2 "Error reading MPI/OMP parameters !!!"
839              IGCM_debug_Exit "Check your config.card. Exit now"
840              IGCM_debug_Verif_Exit
841            fi
842
843            case ${tempvar} in
844            *[mM][pP][iI]*)
845              # Read MPI parameter for composante
846              eval ${comp}_PROC_MPI=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/MPI//" )
847              OK_PARA_MPI=true;;
848            *[oO][mM][pP]*)
849              # Read OMP parameter for composante
850              eval ${comp}_PROC_OMP=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/OMP//" )
851              OK_PARA_OMP=true;;
852            *[nN][oO][dD]*)
853              # Read NOD (NumBer of Nodes) parameter for composante
854              eval ${comp}_PROC_NOD=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/NOD//" )
855              OK_PARA_NOD=true
856              OK_PARA_MPI=true;;
857            esac
858            (( j = j + 1 ))
859          done
860        fi
861        eval tempvarMPI=\${${comp}_PROC_MPI}
862        eval tempvarNOD=\${${comp}_PROC_NOD}
863        eval tempvarOMP=\${${comp}_PROC_OMP}
864
865        (( PROCESSUS_NUMBER = PROCESSUS_NUMBER + tempvarMPI * tempvarNOD * tempvarOMP ))
866      fi
867      (( i=i+1 ))
868    done
869
870    # set MPMD mode if more than 2 executable names.
871    [ ${NbExec} -ge 2 ] && OK_PARA_MPMD=true
872
873    # Verification of BATCH_NUM_PROC_TOT total number of processors set in job header.
874    if [ X${BATCH_NUM_PROC_TOT} != X ] ; then
875      # BATCH_NUM_PROC_TOT is set
876      if ( ${OK_PARA_MPI} ) ; then
877        IGCM_debug_Print 1 "MPI/OMP/NOD found into config.card and BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} "
878      else
879        # with previous method.
880        if [ ${BATCH_NUM_PROC_TOT} -gt 1 ] ; then
881          # with more than 1 proc
882          if ( ${OK_PARA_MPMD} ) ; then
883            # with MPMD ie CPL/oasis method
884            IGCM_debug_Print 2 "Use default number of MPI tasks for this machine : "
885            IGCM_debug_Print 2 "${DEFAULT_NUM_PROC_OCE} for OCE"
886            IGCM_debug_Print 2 "${DEFAULT_NUM_PROC_CPL} for CPL"
887            IGCM_debug_Print 2 "${DEFAULT_NUM_PROC_ATM} for ATM"
888            OK_PARA_MPI=true
889            CPL_PROC_MPI=${DEFAULT_NUM_PROC_CPL}
890            OCE_PROC_MPI=${DEFAULT_NUM_PROC_OCE}
891            ATM_PROC_MPI=${DEFAULT_NUM_PROC_ATM}
892            PROCESSUS_NUMBER=${DEFAULT_NUM_PROC_TOTAL}
893          else
894            # with have only one executable
895            IGCM_debug_Print 2 "Use ${BATCH_NUM_PROC_TOT} MPI tasks for ${CompNameFirst} : ${ExeNameFirst} "
896            OK_PARA_MPI=true
897            eval ${CompNameFirst}_PROC_MPI=${BATCH_NUM_PROC_TOT}
898            PROCESSUS_NUMBER=${BATCH_NUM_PROC_TOT}
899          fi
900        else
901          PROCESSUS_NUMBER=1
902        fi
903      fi
904      # Verification with PBS parameter
905      if [ ${BATCH_NUM_PROC_TOT} -ne ${PROCESSUS_NUMBER} ] ; then
906        IGCM_debug_Exit "ERROR with parallelization parameters !"
907        IGCM_debug_Print 2 "Job header variable BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} "
908        IGCM_debug_Print 2 "is the total number of _processors_ reserved."
909        IGCM_debug_Print 2 "It is not equal to the sum of _processus_  = ${PROCESSUS_NUMBER}."
910        IGCM_debug_Verif_Exit
911      fi
912      NUM_PROC_CPL=${CPL_PROC_MPI} # for backward compatibility
913      NUM_PROC_OCE=${OCE_PROC_MPI} # for backward compatibility
914      NUM_PROC_ATM=${ATM_PROC_MPI} # for backward compatibility
915    else # BATCH_NUM_PROC_TOT=""
916      if ( ${OK_PARA_MPI} ) ; then
917        IGCM_debug_Exit "ERROR : missing value for ${BATCH_NUM_PROC_TOT} processors,"
918        IGCM_debug_Print 2 "You have parallel parameters in config->Executable->list."
919        IGCM_debug_Print 2 "Please add BATCH_NUM_PROC_TOT variable in job header as well."
920        IGCM_debug_Exit "Exit now."
921        IGCM_debug_Verif_Exit
922      else
923        # sequential case !
924        if [ ${PROCESSUS_NUMBER} -eq 0 ] ; then
925          (( PROCESSUS_NUMBER = 1 ))
926          IGCM_debug_Print 2 "PROCESSUS_NUMBER is all 0 (sequential use of old definition in config->Executable->list)."
927          IGCM_debug_Print 2 "We set it to 1."
928        fi
929      fi
930    fi
931
932    IGCM_debug_Print 1 "MPI/OMP treatment PROCESSUS_NUMBER = ${PROCESSUS_NUMBER}"
933
934    IGCM_sys_build_execution_scripts
935  fi
936
937  ExecutionFail=false
938
939  IGCM_debug_PopStack "IGCM_config_PeriodStart"
940}
941
942#===================================
943function IGCM_config_SaveSourceModifications
944{
945  IGCM_debug_PushStack "IGCM_config_SaveSourceModifications"
946
947  typeset ExeOutDateMax listVarEnv
948  ExeOutDateMax=$1
949
950  listVarEnv="ExeOutDateMax,R_OUT_EXE,PREFIX,SUBMIT_DIR"
951  IGCM_sys_RshMaster "\
952    . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh; \
953    export ExeOutDateMax=${ExeOutDateMax};\
954    export R_OUT_EXE=${R_OUT_EXE};\
955    export PREFIX=${PREFIX};\
956    export SUBMIT_DIR=${SUBMIT_DIR};\
957    export listVarEnv=${listVarEnv};\
958    Script_Output=out_SaveSourceModifications;\
959    IGCM_sys_Qsub ${libIGCM}/SaveSourceModifications.job ${ExeOutDateMax} ${R_OUT_EXE} ${PREFIX} ${SUBMIT_DIR}"
960
961  IGCM_debug_PopStack "IGCM_config_SaveSourceModifications"
962}
963
964#===================================
965function IGCM_config_PeriodEnd
966{
967  IGCM_debug_PushStack "IGCM_config_PeriodEnd"
968
969  echo
970  IGCM_debug_Print 1 "IGCM_config_PeriodEnd"
971  echo
972
973  if [ ${DRYRUN} -le 1 ] ; then
974
975    IGCM_debug_Print 1 "Check components binary : size and creation date"
976
977    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize
978    typeset comp i
979    typeset ExeNameIn ExeNameOut UpdateExe ExeSecDateMax
980
981    #==================================#
982    #        Get last Exe Size         #
983    #==================================#
984
985    (( i=0 ))
986    if ( ${FirstInitialize} ) ; then
987      run_Log_LastExeSize=""
988      for comp in ${config_ListOfComponents[*]} ; do
989        run_Log_LastExeSize[$i]=0
990        (( i=i+1 ))
991      done
992    else
993      IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize
994    fi
995    #==================================#
996    #         And Build ExeDate        #
997    #==================================#
998
999    # ExeDate = ATM_Jun_12_09:34-SRF_Jun_12_09:34-OCE_Jun_12_09:34-ICE_Jun_12_09:34-CPL_Jun_12_09:33
1000    # Would be nice to have next line but no way to format ls output (need to ls -l --time-style "+%Y-%m-%dT%H:%M")
1001    # ExeDate = ATM_2009-06-12T09:34+SRF_2009-06-12T09:34+OCE_2009-06-12T09:34+ICE_2009-06-12T09:34+CPL_2009-06-12T09:34
1002    ExeDate=""
1003    NextExeSize="( "
1004    (( i=0 ))
1005    UpdateExe=false
1006    (( ExeSecDateMax = 0 ))
1007    for comp in ${config_ListOfComponents[*]} ; do
1008
1009      IGCM_debug_Print 3 ${comp}
1010
1011      eval ExeNameIn=\${config_Executable_${comp}[0]}
1012      eval ExeNameOut=\${config_Executable_${comp}[1]}
1013      # Only if we really have an executable for the component :
1014      if [ X${ExeNameIn} = X\"\" ] ; then
1015        # If there is no exe file for this component
1016        (( ExeSize=0 ))
1017      else
1018        LS_bin=${R_EXE}/${ExeNameIn}
1019        IGCM_sys_FileSize ${LS_bin} ExeSize
1020
1021        set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} )
1022        if [ X${ExeDate} = X ] ; then
1023          # First component exe date
1024          ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]}
1025        else
1026          ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]}
1027        fi
1028        ExeDate=${ExeDate}_${LS_comp[7]}
1029      fi
1030
1031      if [ ${i} -eq 0 ] ; then
1032        # First component
1033        NextExeSize="( "${ExeSize}
1034      else
1035        NextExeSize=${NextExeSize}", "${ExeSize}
1036      fi
1037      LastCompExeSize=${run_Log_LastExeSize[$i]}
1038      (( i=i+1 ))
1039
1040      if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then
1041        if ( ${FirstInitialize} ) ; then
1042          IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !"
1043        else
1044          IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !"
1045          IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !"
1046          FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut}
1047        fi
1048        IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw
1049        UpdateExe=true
1050
1051        # SD : switch off for now
1052        #IGCM_sys_GetDate_FichWork ${LS_bin} ExeSecDate
1053        #if [ $ExeSecDateMax -lt $ExeSecDate ] ; then
1054        #  ExeSecDateMax=$ExeSecDate
1055        #fi
1056      fi
1057    done
1058
1059    # SD : switch off for now
1060    #if ( ${UpdateExe} ) ; then
1061    #  echo "Launch SaveSourceModifications."
1062    #  IGCM_config_SaveSourceModifications ${ExeSecDateMax}
1063    #fi
1064
1065    NextExeSize=${NextExeSize}" )"
1066    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Log LastExeSize "${NextExeSize}"
1067
1068    if [ ${DRYRUN} -le 1 ] ; then
1069      tail -1500 ${Exe_Output} > ${Exe_Output}_tail.txt
1070      ExeCpuLog=$( gawk -f ${libIGCM}/libIGCM_sys/IGCM_add_out.awk ${Exe_Output}_tail.txt )
1071      RET=$?
1072      if [ $RET -eq 0 ] ; then
1073        # ExeCpuLog variable contents 5 fields
1074        echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \
1075          gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \
1076            $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card
1077      fi
1078      FileToBeDeleted[${#FileToBeDeleted[@]}]=${Exe_Output}_tail.txt
1079    fi
1080
1081  fi
1082
1083  #==================================#
1084  #         Save Job output          #
1085  #==================================#
1086  if [ X${Pack} = Xtrue ] ; then
1087    IGCM_sys_PutBuffer_Out ${Exe_Output} ${R_BUF_KSH}/${PREFIX}_${Exe_Output}
1088  else
1089    IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output}
1090  fi
1091  FileToBeDeleted[${#FileToBeDeleted[@]}]=${Exe_Output}
1092
1093  # All was right ? no ? then we stop.
1094  IGCM_debug_Verif_Exit
1095
1096  # If all was OK, we can delete all files not necessary for next Job
1097  echo
1098  IGCM_debug_Print 1 "Files that will be deleted before next period-run : "
1099
1100  if [ ${DRYRUN} -le 2 ] ; then
1101    for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done
1102  else
1103    echo ${FileToBeDeleted[@]}
1104  fi
1105
1106  # Send some accounting element to the user if CumulPeriod=3
1107  if [ ${CumulPeriod} -eq 3 ] ; then
1108    echo
1109    IGCM_debug_Print 1 "Send email containing some accounting information : "
1110
1111    RealCpuTime=$( echo ${ExeCpuLog} | gawk '{print $3}' )
1112
1113    consumeHoursPerPeriod=$( echo "scale=6;${RealCpuTime}*${PROCESSUS_NUMBER}/3600" | bc )
1114
1115    consumeHoursPerWholeSimulation=$( echo "scale=6;${consumeHoursPerPeriod}/${PeriodLengthInDays}*${ExperienceLengthInDays}" | bc )
1116
1117    recommendedPeriodNb=$( echo "scale=6;24/${consumeHoursPerPeriod}*${PROCESSUS_NUMBER}" | bc )
1118
1119    IGCM_sys_SendMail Accounting
1120  fi
1121
1122  #=================================================#
1123  #         Modification of libIGCM behaviour       #
1124  #=================================================#
1125
1126  # To use this function, one must copy libIGCM.card from ${libIGCM} directory
1127  # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card,
1128  # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.
1129  if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then
1130    echo
1131    echo "########################################################################"
1132    echo "!!!                 Modification of libIGCM behaviour                !!!"
1133    echo
1134
1135    IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card"
1136    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges
1137    IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]}
1138
1139    # Special treatments for libIGCM internals
1140    for option in ${libIGCM_UserChanges[*]} ; do
1141      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option}
1142
1143      echo "We will change : ${option}."
1144      eval echo "Previous value : " \${${option}}
1145      eval echo "Change to : " \${libIGCM_UserChanges_${option}}
1146
1147      eval ${option}=\${libIGCM_UserChanges_${option}}
1148
1149      case ${option} in
1150      config_UserChoices_DateEnd)
1151        IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd
1152        DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} )
1153
1154        # Period Length In Days between DateBegin and DateEnd
1155        (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 ))
1156        if [ ${ExperienceLengthInDays} -lt 0 ] ; then
1157          IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that."
1158          IGCM_debug_Exit "IGCM_PeriodEnd have wrong dates."
1159          IGCM_debug_Verif_Exit
1160        fi
1161        ;;
1162      config_UserChoices_PeriodLength)
1163        IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}"
1164        ;;
1165      PeriodNb)
1166        IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)"
1167        ;;
1168      config_Post_RebuildFrequency)
1169        IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure"
1170        IGCM_post_Configure
1171        ;;
1172      config_Post_TimeSeriesFrequency)
1173        IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Configure"
1174        IGCM_post_Configure
1175        ;;
1176      config_Post_SeasonalFrequency)
1177        IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Configure"
1178        IGCM_post_Configure
1179        ;;
1180      esac
1181    done
1182
1183    echo
1184    echo "########################################################################"
1185    echo
1186  fi
1187
1188  #=================================================#
1189  #         Determine next computed period          #
1190  #=================================================#
1191
1192  PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 )
1193  IGCM_date_GetYearMonthDay $PeriodDateBegin year month day
1194  year_m1=$(( year - 1 ))
1195  year_p1=$(( year + 1 ))
1196  IGCM_config_DaysInPeriodLength
1197  PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) )
1198
1199  # Debug Print :
1200  echo
1201  IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution"
1202  IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}"
1203  IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}"
1204  IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}"
1205
1206  PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} )
1207  PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} )
1208
1209  (( CumulPeriod = CumulPeriod + 1 ))
1210
1211  # Debug Print :
1212  echo
1213  IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}"
1214  IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}"
1215  IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}"
1216
1217  #=================================================#
1218  #             Write updated run.card              #
1219  #=================================================#
1220
1221  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin}
1222  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd}
1223  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod}
1224
1225  if ( ${FirstInitialize} ) ; then
1226    # It's no more the first time
1227    FirstInitialize=false
1228  fi
1229
1230  IGCM_debug_PopStack "IGCM_config_PeriodEnd"
1231}
1232
1233#===================================
1234function IGCM_config_Finalize
1235{
1236  IGCM_debug_PushStack "IGCM_config_Finalize"
1237
1238  echo
1239  IGCM_debug_Print 1 "IGCM_config_Finalize"
1240  echo
1241
1242  if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then
1243    #==========================#
1244    # End of entire simulation #
1245    #==========================#
1246
1247    # Mail notification
1248    IGCM_sys_SendMail
1249    #
1250    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed"
1251    #
1252    IGCM_debug_Print 1 "Normal End of computation."
1253
1254    if ( $DEBUG_debug ) ; then
1255      if [ X${ActivateBigBro} = Xtrue ] ; then
1256        # RabbitMQ message code "END OF SIMULATION"
1257        code=0100
1258        # RabbitMQ message body
1259        Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
1260        # Fill the rabbitMQ queue
1261        IGCM_debug_sendAMQP
1262      fi
1263    fi
1264  else
1265    #=================#
1266    # Submit next job #
1267    #=================#
1268
1269    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue"
1270
1271    # Name of next Ksh Script output :
1272    Script_Output=${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )
1273
1274    IGCM_debug_Print 1 "Submit next job"
1275    # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR
1276    IGCM_sys_Cd ${SUBMIT_DIR}
1277    # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName}
1278    ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l )
1279    [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) )
1280    # Submit next job and come back
1281    IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName}
1282    IGCM_sys_Cd -
1283  fi
1284
1285  # Supress Non Deleted Boundary files
1286  #if [ ${DRYRUN} -le 2 ] ; then
1287  #  IGCM_comp_DelFixeBoundaryFiles
1288  #  ls -la
1289  #fi
1290
1291  # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_JobName}.${$}
1292  # Only for production run (No clean up in DEV or DEB mode)
1293  # and command sent from .. directory.
1294  IGCM_sys_Cd ..
1295  [ X${JobType} = XRUN ] && IGCM_sys_RmRunDir -rf ${RUN_DIR_PATH}
1296
1297  if ( $DEBUG_debug ) ; then
1298    # Inform the rabbitMQ queue
1299    if [ X${ActivateBigBro} = Xtrue ] ; then
1300      # RabbitMQ message code "WAITING"
1301      code=1100
1302      # RabbitMQ message body
1303      Body=$( echo "{${genericSimulationID},\"msgCode\":\"${code}\",\"msgUID\":\"$(uuidgen)\",\"msgTimestamp\":\"$( date +"%Y-%m-%dT%H:%M:%S.%N%z" )\"}" )
1304      # Fill the rabbitMQ queue
1305      IGCM_debug_sendAMQP
1306    fi
1307  fi
1308
1309  # To be sure we flush message buffer before exiting the job
1310  FlushAMQP=TRUE
1311
1312  IGCM_debug_PopStack "IGCM_config_Finalize"
1313}
1314
1315#===================================
Note: See TracBrowser for help on using the repository browser.