source: trunk/libIGCM/ins_job @ 1385

Last change on this file since 1385 was 1371, checked in by jgipsl, 7 years ago

Consider also default value for ProjectID and change to devcmip6 if needed.

  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 14.4 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Jacques Belier
5# Contact:
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#- Installation of jobs according to environment
15#---------------------------------------------------------------------
16function ins_job_Usage
17{
18print - "
19ins_job installs the jobs in the directories
20which contain a file config.card
21
22ins_job must be launched on the host
23on which the job will be submitted
24
25Usage :
26  ${b_n} [-h] [-v] [-e]
27  or on curie/TGCC :
28  ${b_n} [-h] [-v] [-e] [-p project] [-c number of cores]
29  or on ada /IDRIS
30  ${b_n} [-h] [-v] [-e] [-m MPI environment]
31Options :
32  -h                  : help
33  -v                  : verbose mode
34  -e                  : turn on ensemble mode (hindcast/forecast or date restart)
35on curie only :
36  -p project          : add default project on curie
37  -c number of cores  : add default number of cores for postprocessing on curie 1-16 or 1-128
38on ada only :
39  - m MPI environment : add default MPI environment (Intel MPI or IBM MPI)
40"
41}
42function ins_job_Warning
43{
44   [[ ${x_v} = 'verbose' ]] && print - "\n############### WARNING ###############";
45   [[ ${x_v} = 'verbose' ]] && print - "File ${n_f} already exists\nin directory ${j}";
46   [[ ${x_v} = 'verbose' ]] && print - "You must delete this file to update !";
47}
48
49function ins_job_Check_JobName
50{
51  verif=${JobName##[a-zA-Z]*(?([.\-])[a-zA-Z0-9])}
52
53  if [ ${#verif} -ne 0 ] ; then
54    echo "################ ERROR ################"
55    echo "${JobName} is invalid."
56    echo "- JobName can only contain alphanumeric characters, \".\" and \"-\""
57    echo "- JobName must start with a letter"
58
59    ((NbErr=NbErr+1))
60
61    Status=1
62  else
63    Status=0
64  fi
65
66  return ${Status}
67}
68
69#-
70#     dirname     and      basename
71#-
72d_n=$(dirname ${0}); b_n=$(basename ${0});
73#-
74# Retrieving and validation of the options
75#-
76x_v='silencious';
77x_e=false;
78x_p=false;
79x_c=false;
80x_m=false;
81while getopts :hvec:p:m: V ; do
82  case $V in
83  (h)  ins_job_Usage; exit 0;;
84  (v)  x_v='verbose';;
85  (e)  x_e=true;;
86  (p)  x_p=true
87       ProjectID=${OPTARG} ;;
88  (c)  x_c=true
89       ProjectCore=${OPTARG} ;;
90  (m)  x_m=true
91       MPIEnvironment=${OPTARG} ;;
92  (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
93       exit 2;;
94  (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
95       exit 2;;
96  esac
97done
98[ ${x_v} = 'silencious' ] && export DEBUG_sys=false
99shift $(($OPTIND-1));
100#-
101# Define working files
102#-
103F_MOD=$(cd ${d_n}'/..';/bin/pwd;)
104# [[ ${F_MOD##*/} != 'modipsl' ]] && \
105#  { print - "directory 'modipsl' unreachable"; exit 3; }
106W_W=${d_n}'/../libIGCM'
107[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
108libIGCM=$(cd ${W_W};/bin/pwd;)
109F_JOB=${libIGCM}'/AA_job';
110[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
111F_RCI=${libIGCM}'/run.card.init';
112[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
113#-
114# Accessing to functions (without stack)
115#-
116# No verbosity (0, 1, 2, 3)
117Verbosity=0
118# No de debug
119DEBUG_debug=false
120# Dont move libIGCM
121MirrorlibIGCM=false
122# Behave like computing job
123TaskType=computing
124# Source libIGCM
125. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
126. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
127. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
128. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
129. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
130if [ $x_e = 'true' ] ; then
131  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
132fi
133
134#-
135[[ ${x_v} = 'verbose' ]] && \
136 {
137  print - "";
138  print - '--- Host        : '${SYSTEM};
139  print - '--- modipsl     : '${F_MOD};
140  print - '--- libIGCM     : '${libIGCM};
141  print - '--- basic job   : '${F_JOB};
142  print - '--- basic card  : '${F_RCI};
143 }
144#-
145[[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${SYSTEM}'";
146#-
147
148NbErr=0
149
150#-
151# Define Project parameters to set up jobs header for Curie (TGCC)
152# on curie define ProjectID  and ProjectCore : option or answer
153# on curie ProjectNode forced to standard since 16/3/2016
154#-
155
156if [ X"${SYSTEM}" == "Xcurie" ] ; then
157  if ( ! ${x_p} ) ; then
158    ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 )
159    ProjectID=${ProjectID:="devcmip6"}
160    answer=""
161    print - "Hit Enter or give project ID (default is ${ProjectID}), possible projects are $( echo $( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | sort -u ) ) :"
162    read answer
163
164    if [ "X${answer}" != "X" ] ; then
165      ProjectID=${answer}
166    fi
167
168    if [ "X${ProjectID}" = "Xgencmip6" ] ; then
169      ProjectID=devcmip6
170    fi
171  fi # if ( ! ${x_p} )
172
173  #- ProjectNode forced to standard since 16/3/2016
174  ProjectNode="standard"
175
176  echo  ProjectID is ${ProjectID} and ProjectNode for PostProcessing is ${ProjectNode}
177
178  #- ProjectNode is known (standard since 16/3/2016) set ProjectCoreMax
179  ProjectCoreMax="16"
180
181  if ( ! ${x_c} ) ; then
182    #- ProjectNode is known (standard since 16/3/2016), set ProjectCore to default or answer
183    ProjectCore="4"
184    answerOK=false
185
186    while ( ! ${answerOK} ) ; do
187      answer=""
188      print - "Hit Enter or give NUMBER OF CORES required for post-processing (default is \"${ProjectCore}\"), possible numbers of cores are \"1\" to \"${ProjectCoreMax}\" : "
189      read answer
190      [ "X${answer}" == "X" ] || [ ${answer} -ge 1 -a ${answer} -le ${ProjectCoreMax} ] && answerOK=true
191    done
192
193    if [ "X${answer}" != "X" ] ; then
194      ProjectCore=${answer}
195    fi
196
197  fi # if ( ! ${x_c} )
198
199  echo ProjectCore is ${ProjectCore}
200  #- ProjectCore is set (option or answer)
201  # let check minimum/maximum value 1/${ProjectCoreMax}
202
203elif [ X"${SYSTEM}" == "Xada" ] ; then
204  if ( ! ${x_m} ) ; then
205    MPIEnvironment=IBM
206    # Intel MPI Environment.
207    answerOK=false     
208    while ( ! ${answerOK} ) ; do
209      answer=""
210      print - "Hit Enter or give MPI Environement (default is ${MPIEnvironment}), possible MPI environments are IBM (MPI IBM) and Intel (MPI Intel) :"
211      read answer
212      [ "X${answer}" == "X" ] || [ "X${answer}" == "XIBM" ] || [ "X${answer}" == "XIntel" ] && answerOK=true
213    done
214
215    if [ "X${answer}" != "X" ] ; then
216      MPIEnvironment=${answer}
217    fi
218  fi # if ( ! ${x_pm} )
219  echo MPIEnvironment is ${MPIEnvironment}
220else
221  echo No option for Header regarding ProjectID, ProjectNode, ProjectCore or MPIEnvironment because we are not on curie or ada
222fi # if [ X"${SYSTEM}" == "Xcurie" ]
223
224#-
225# Define the pattern string to substitute
226#-
227W_P='#-Q- '; W_W=${W_P}${SYSTEM};
228#-
229# Extract list of 'config.card' files
230# and create jobs with AA_job
231#-
232F_CFG='config.card';
233F_CFG_ENS='ensemble.card';
234SUBMIT_DIR_ENS=$( pwd )
235for i in $( pwd )/config.card
236do
237  if [ ! -f $i ] ; then
238    echo ""
239    echo "################## WARNING ##################"
240    echo "No config.card available in current directory"
241    echo ""
242    continue
243  fi
244
245
246  j=$(cd ${i%/*};/bin/pwd;)
247  n_f=${F_RCI##*/};
248
249  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
250    # Do not treat config.card if it is in sub-directory of EXPERIMENTS
251    # Continue to next config.card
252    continue
253  else
254    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
255  fi
256
257  # Find out if new structure and set .resol filename
258  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
259    # New Structure
260    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
261    new_struct=yes
262    resolfile=$j/.resol
263  else
264    # Old Structure
265    new_struct=no
266    resolfile=$j/../.resol
267  fi
268
269  # Get all variables declared in section UserChoices in config.card
270  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
271  # Set default values
272  config_UserChoices_ExpType=""
273  RESOL_ATM_3D=this_is_a_test_string
274  RESOL=this_is_another_test_string
275  typeset option
276  for option in ${config_UserChoices[*]} ; do
277    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
278  done
279
280  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
281  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
282    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
283    echo TRUERESOL = $TRUERESOL
284    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
285    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
286  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
287    TRUERESOL=$( head -1 $resolfile  )
288    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
289    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
290  else
291    JobName=${config_UserChoices_JobName}
292  fi
293
294  # Check JobName validity : only alphanumerical characters, "-" and "." are authorized
295  ins_job_Check_JobName
296  RetCode=$?
297  [[ $RetCode -gt 0 ]] && continue
298
299  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
300
301  # Add specific treatment for new type of directory structure
302  if [ ${new_struct} == yes ] ; then
303
304    if [ "X${config_UserChoices_ExpType}" = X ] ; then
305      echo "\nERROR in ${j}/config.card"
306      echo "ins_job stops here"
307      echo "=> The variable ExpType must be added in config.card in section UserChoices"
308      echo "=> ExpType gives the directory for the .card configuration files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
309      exit 4
310    else
311      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
312    fi
313
314    if [ -d ${j}/${JobName} ] ; then
315      echo "Directory ${j}/${JobName} exists already. It will not be overwritten."
316      echo "Remove the existing directory or change JobName before relaunching ins_job."
317      continue
318    fi
319    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
320    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
321    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
322    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
323    if [ -f ${F_CFG_ENS} ] ; then
324      cp -f ${j}/${F_CFG_ENS}  ${j}/${JobName}/.
325      SUBMIT_DIR_ENS=${j}/${JobName}
326    fi
327    rm -f ${j}/${F_CFG}
328    rm -f ${j}/${F_CFG_ENS}
329    rm -f ${j}/${F_CFG}.bak
330    j=${j}/${JobName}
331    [[ ${x_v} = 'verbose' ]] && echo new j=$j
332  fi
333  # end specific treatment for new type directory structure
334
335  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
336   {
337    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
338    \cp ${F_RCI} ${j};
339   }
340
341  #==================================
342  # Read ListOfComponents section:
343  #echo
344  #IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
345
346  IGCM_card_DefineArrayFromSection  ${j}'/'${F_CFG} ListOfComponents
347  for comp in ${config_ListOfComponents[*]} ; do
348    IGCM_card_DefineArrayFromOption  ${j}'/'${F_CFG} ListOfComponents ${comp}
349  done
350  #IGCM_debug_Print 3 ${config_ListOfComponents[*]}
351
352  #==================================
353  # Read Executable section:
354  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} Executable
355
356  # Define the execution context (MPMD, SPMD, MPI/OMP ...)
357  IGCM_config_ConfigureExecution ${j}'/'${F_CFG}
358
359  # coreNumber    : TOTAL NUMBER OF CORES
360  # mpiTasks      : TOTAL NUMBER OF MPI TASKS
361  # openMPthreads : NUMBER OF OpenMP THREADS
362
363  # File name for Job
364  n_f='Job_'${JobName};
365  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
366  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
367  sed -e "/^${W_W} */ s///" \
368      -e "/^${W_P}/d"       \
369      -e "s%::modipsl::%${F_MOD}%" \
370      -e "s/::Jobname::/${JobName}/" \
371      -e "s/::default_project::/${ProjectID}/" \
372      ${F_JOB} > ${j}'/'${n_f}
373  chmod u+x ${j}'/'${n_f}
374
375  # update Headers so that ressources description are accurate (MPMD/SPMD/...)
376  IGCM_sys_updateHeaders ${j}'/'${n_f}
377done
378
379#-
380# Extract list of AA_* files in libIGCM
381# and create jobs (for all except AA_job)
382#-
383for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)
384do
385  i_f=${i##*/};
386  [[ ${i_f} = 'AA_job' ]] && { continue; }
387  j=${i%/*}; n_f=${i_f#AA_}'.job';
388  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
389  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
390  sed -e "/^${W_W} */ s///" \
391      -e "s%::modipsl::%${F_MOD}%" \
392      -e "/^${W_P}/d"       \
393      -e "s/::default_node::/${ProjectNode}/" \
394      -e "s/::default_core::/${ProjectCore}/" \
395      -e "s/::default_project::/${ProjectID}/" \
396      ${i} > ${j}'/'${n_f}
397  chmod u+x ${j}'/'${n_f}
398done
399#-
400# set default_project in libIGCM_sys_curie.ksh too.
401#-
402if [ X"${SYSTEM}" == "Xcurie" ] ; then
403  i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh
404  sed -i -e "s/::default_project::/${ProjectID}/" ${i}
405fi
406#-
407# Limited to hindcast/forecast and date restart Ensemble for the time being
408if [ ${x_e} = 'true' ] ; then
409  #.. Read input data from ensemble.card ..
410  SUBMIT_DIR=${SUBMIT_DIR_ENS}
411  RUN_DIR="${WORKDIR}/ENSEMBLE_TMP"
412  #
413  # Copy initial things around and define variables (hindcast/forecast case)
414  IGCM_sys_Cd ${SUBMIT_DIR}
415  IGCM_ensemble_Init
416
417  if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then
418    echo "WARNING: Parametric Ensemble is not implemented yet..."
419  fi
420
421  if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then
422    IGCM_sys_Cd ${SUBMIT_DIR}
423    IGCM_ensemble_DateInit
424    # As it says
425    IGCM_sys_Cd ${SUBMIT_DIR}
426    IGCM_ensemble_DatePeriodicStarts
427    # As it says
428    IGCM_sys_Cd ${SUBMIT_DIR}
429    IGCM_ensemble_DateNonPeriodicStarts
430    # Clean
431    IGCM_sys_Rm -rf ${RUN_DIR}
432  fi
433
434  if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then
435    IGCM_sys_Cd ${SUBMIT_DIR}
436    IGCM_ensemble_CastInit
437    # As it says
438    IGCM_sys_Cd ${SUBMIT_DIR}
439    IGCM_ensemble_CastPeriodicStarts
440    # As it says
441    IGCM_sys_Cd ${SUBMIT_DIR}
442    IGCM_ensemble_CastNonPeriodicStarts
443    # As it says
444    IGCM_sys_Cd ${SUBMIT_DIR}
445    IGCM_ensemble_CastMemberList
446    # Done
447    #IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
448    IGCM_sys_Cd ${SUBMIT_DIR}
449    # Clean
450    IGCM_sys_Rm -rf ${RUN_DIR}
451  fi
452fi
453#-
454[[ ${x_v} = 'verbose' ]] && print - "";
455#-
456# That's all folks
457#-
458
459if [ ${NbErr} -ne 0 ] ; then
460  echo "################ ERROR ################"
461  echo "${NbErr} invalid JobName(s) found, check the log"
462fi
463
464
465exit 0;
Note: See TracBrowser for help on using the repository browser.