source: trunk/libIGCM/ins_job @ 1441

Last change on this file since 1441 was 1437, checked in by jgipsl, 6 years ago

For Irene:

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