source: trunk/libIGCM/ins_job @ 1429

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