source: tags/libIGCM_v3.0_beta1/ins_job

Last change on this file was 1399, checked in by sdipsl, 7 years ago

CMIP6 workflow. Merging trunk into branch 'branch' r:1375:1398

  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 14.7 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}
220elif [ X"${SYSTEM}" == "Xlxiv8" ] || [ X"${SYSTEM}" == "Xifort_CICLAD" ] ; then
221  # obelix, ciclad, climserv
222  echo ""
223  echo "You need to check and maybe adapt headers in the main job especially the line: "
224  echo "  #PBS -l nodes=x:ppn=y "
225  echo "where x is the number of nodes, y the number of cores per node and x*y is the total number of cores for the job. "
226  echo "y must not be bigger than the maximum numer of cores per node on the machine (often 8 or 16)."
227fi # if [ X"${SYSTEM}" == "Xcurie" ]
228
229#-
230# Define the pattern string to substitute
231#-
232W_P='#-Q- '; W_W=${W_P}${SYSTEM};
233#-
234# Extract list of 'config.card' files
235# and create jobs with AA_job
236#-
237F_CFG='config.card';
238F_CFG_ENS='ensemble.card';
239SUBMIT_DIR_ENS=$( pwd )
240for i in $( pwd )/config.card
241do
242  if [ ! -f $i ] ; then
243    echo ""
244    echo "################## WARNING ##################"
245    echo "No config.card available in current directory"
246    echo ""
247    continue
248  fi
249
250
251  j=$(cd ${i%/*};/bin/pwd;)
252  n_f=${F_RCI##*/};
253
254  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
255    # Do not treat config.card if it is in sub-directory of EXPERIMENTS
256    # Continue to next config.card
257    continue
258  else
259    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
260  fi
261
262  # Find out if new structure and set .resol filename
263  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
264    # New Structure
265    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
266    new_struct=yes
267    resolfile=$j/.resol
268  else
269    # Old Structure
270    new_struct=no
271    resolfile=$j/../.resol
272  fi
273
274  # Get all variables declared in section UserChoices in config.card
275  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
276  # Set default values
277  config_UserChoices_ExpType=""
278  RESOL_ATM_3D=this_is_a_test_string
279  RESOL=this_is_another_test_string
280  typeset option
281  for option in ${config_UserChoices[*]} ; do
282    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
283  done
284
285  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
286  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
287    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
288    echo TRUERESOL = $TRUERESOL
289    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
290    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
291  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
292    TRUERESOL=$( head -1 $resolfile  )
293    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
294    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
295  else
296    JobName=${config_UserChoices_JobName}
297  fi
298
299  # Check JobName validity : only alphanumerical characters, "-" and "." are authorized
300  ins_job_Check_JobName
301  RetCode=$?
302  [[ $RetCode -gt 0 ]] && continue
303
304  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
305
306  # Add specific treatment for new type of directory structure
307  if [ ${new_struct} == yes ] ; then
308
309    if [ "X${config_UserChoices_ExpType}" = X ] ; then
310      echo "\nERROR in ${j}/config.card"
311      echo "ins_job stops here"
312      echo "=> The variable ExpType must be added in config.card in section UserChoices"
313      echo "=> ExpType gives the directory for the .card configuration files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
314      exit 4
315    else
316      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
317    fi
318
319    if [ -d ${j}/${JobName} ] ; then
320      echo "Directory ${j}/${JobName} exists already. It will not be overwritten."
321      echo "Remove the existing directory or change JobName before relaunching ins_job."
322      continue
323    fi
324    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
325    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
326    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
327    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
328    if [ -f ${F_CFG_ENS} ] ; then
329      cp -f ${j}/${F_CFG_ENS}  ${j}/${JobName}/.
330      SUBMIT_DIR_ENS=${j}/${JobName}
331    fi
332    rm -f ${j}/${F_CFG}
333    rm -f ${j}/${F_CFG_ENS}
334    rm -f ${j}/${F_CFG}.bak
335    j=${j}/${JobName}
336    [[ ${x_v} = 'verbose' ]] && echo new j=$j
337  fi
338  # end specific treatment for new type directory structure
339
340  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
341   {
342    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
343    \cp ${F_RCI} ${j};
344   }
345
346  #==================================
347  # Read ListOfComponents section:
348  #echo
349  #IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
350
351  IGCM_card_DefineArrayFromSection  ${j}'/'${F_CFG} ListOfComponents
352  for comp in ${config_ListOfComponents[*]} ; do
353    IGCM_card_DefineArrayFromOption  ${j}'/'${F_CFG} ListOfComponents ${comp}
354  done
355  #IGCM_debug_Print 3 ${config_ListOfComponents[*]}
356
357  #==================================
358  # Read Executable section:
359  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} Executable
360
361  # Define the execution context (MPMD, SPMD, MPI/OMP ...)
362  IGCM_config_ConfigureExecution ${j}'/'${F_CFG}
363
364  # coreNumber    : TOTAL NUMBER OF CORES
365  # mpiTasks      : TOTAL NUMBER OF MPI TASKS
366  # openMPthreads : NUMBER OF OpenMP THREADS
367
368  # File name for Job
369  n_f='Job_'${JobName};
370  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
371  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
372  sed -e "/^${W_W} */ s///" \
373      -e "/^${W_P}/d"       \
374      -e "s%::modipsl::%${F_MOD}%" \
375      -e "s/::Jobname::/${JobName}/" \
376      -e "s/::default_project::/${ProjectID}/" \
377      ${F_JOB} > ${j}'/'${n_f}
378  chmod u+x ${j}'/'${n_f}
379
380  # update Headers so that ressources description are accurate (MPMD/SPMD/...)
381  IGCM_sys_updateHeaders ${j}'/'${n_f}
382done
383
384#-
385# Extract list of AA_* files in libIGCM
386# and create jobs (for all except AA_job)
387#-
388for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)
389do
390  i_f=${i##*/};
391  [[ ${i_f} = 'AA_job' ]] && { continue; }
392  j=${i%/*}; n_f=${i_f#AA_}'.job';
393  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
394  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
395  sed -e "/^${W_W} */ s///" \
396      -e "s%::modipsl::%${F_MOD}%" \
397      -e "/^${W_P}/d"       \
398      -e "s/::default_node::/${ProjectNode}/" \
399      -e "s/::default_core::/${ProjectCore}/" \
400      -e "s/::default_project::/${ProjectID}/" \
401      ${i} > ${j}'/'${n_f}
402  chmod u+x ${j}'/'${n_f}
403done
404#-
405# set default_project in libIGCM_sys_curie.ksh too.
406#-
407if [ X"${SYSTEM}" == "Xcurie" ] ; then
408  i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh
409  sed -i -e "s/::default_project::/${ProjectID}/" ${i}
410fi
411#-
412# Limited to hindcast/forecast and date restart Ensemble for the time being
413if [ ${x_e} = 'true' ] ; then
414  #.. Read input data from ensemble.card ..
415  SUBMIT_DIR=${SUBMIT_DIR_ENS}
416  RUN_DIR="${WORKDIR}/ENSEMBLE_TMP"
417  #
418  # Copy initial things around and define variables (hindcast/forecast case)
419  IGCM_sys_Cd ${SUBMIT_DIR}
420  IGCM_ensemble_Init
421
422  if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then
423    echo "WARNING: Parametric Ensemble is not implemented yet..."
424  fi
425
426  if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then
427    IGCM_sys_Cd ${SUBMIT_DIR}
428    IGCM_ensemble_DateInit
429    # As it says
430    IGCM_sys_Cd ${SUBMIT_DIR}
431    IGCM_ensemble_DatePeriodicStarts
432    # As it says
433    IGCM_sys_Cd ${SUBMIT_DIR}
434    IGCM_ensemble_DateNonPeriodicStarts
435    # Clean
436    IGCM_sys_Rm -rf ${RUN_DIR}
437  fi
438
439  if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then
440    IGCM_sys_Cd ${SUBMIT_DIR}
441    IGCM_ensemble_CastInit
442    # As it says
443    IGCM_sys_Cd ${SUBMIT_DIR}
444    IGCM_ensemble_CastPeriodicStarts
445    # As it says
446    IGCM_sys_Cd ${SUBMIT_DIR}
447    IGCM_ensemble_CastNonPeriodicStarts
448    # As it says
449    IGCM_sys_Cd ${SUBMIT_DIR}
450    IGCM_ensemble_CastMemberList
451    # Done
452    #IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
453    IGCM_sys_Cd ${SUBMIT_DIR}
454    # Clean
455    IGCM_sys_Rm -rf ${RUN_DIR}
456  fi
457fi
458#-
459[[ ${x_v} = 'verbose' ]] && print - "";
460#-
461# That's all folks
462#-
463
464if [ ${NbErr} -ne 0 ] ; then
465  echo "################ ERROR ################"
466  echo "${NbErr} invalid JobName(s) found, check the log"
467fi
468
469
470exit 0;
Note: See TracBrowser for help on using the repository browser.