source: trunk/libIGCM/ins_job @ 1356

Last change on this file since 1356 was 1322, checked in by sdipsl, 8 years ago
  • bugfix
  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 14.3 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${answer}" = "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} exist already, continue next config.card"
316      continue
317    fi
318    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
319    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
320    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
321    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
322    if [ -f ${F_CFG_ENS} ] ; then
323      cp -f ${j}/${F_CFG_ENS}  ${j}/${JobName}/.
324      SUBMIT_DIR_ENS=${j}/${JobName}
325    fi
326    rm -f ${j}/${F_CFG}
327    rm -f ${j}/${F_CFG_ENS}
328    rm -f ${j}/${F_CFG}.bak
329    j=${j}/${JobName}
330    [[ ${x_v} = 'verbose' ]] && echo new j=$j
331  fi
332  # end specific treatment for new type directory structure
333
334  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
335   {
336    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
337    \cp ${F_RCI} ${j};
338   }
339
340  #==================================
341  # Read ListOfComponents section:
342  #echo
343  #IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
344
345  IGCM_card_DefineArrayFromSection  ${j}'/'${F_CFG} ListOfComponents
346  for comp in ${config_ListOfComponents[*]} ; do
347    IGCM_card_DefineArrayFromOption  ${j}'/'${F_CFG} ListOfComponents ${comp}
348  done
349  #IGCM_debug_Print 3 ${config_ListOfComponents[*]}
350
351  #==================================
352  # Read Executable section:
353  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} Executable
354
355  # Define the execution context (MPMD, SPMD, MPI/OMP ...)
356  IGCM_config_ConfigureExecution ${j}'/'${F_CFG}
357
358  # coreNumber    : TOTAL NUMBER OF CORES
359  # mpiTasks      : TOTAL NUMBER OF MPI TASKS
360  # openMPthreads : NUMBER OF OpenMP THREADS
361
362  # File name for Job
363  n_f='Job_'${JobName};
364  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
365  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
366  sed -e "/^${W_W} */ s///" \
367      -e "/^${W_P}/d"       \
368      -e "s%::modipsl::%${F_MOD}%" \
369      -e "s/::Jobname::/${JobName}/" \
370      -e "s/::default_project::/${ProjectID}/" \
371      ${F_JOB} > ${j}'/'${n_f}
372  chmod u+x ${j}'/'${n_f}
373
374  # update Headers so that ressources description are accurate (MPMD/SPMD/...)
375  IGCM_sys_updateHeaders ${j}'/'${n_f}
376done
377
378#-
379# Extract list of AA_* files in libIGCM
380# and create jobs (for all except AA_job)
381#-
382for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)
383do
384  i_f=${i##*/};
385  [[ ${i_f} = 'AA_job' ]] && { continue; }
386  j=${i%/*}; n_f=${i_f#AA_}'.job';
387  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
388  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
389  sed -e "/^${W_W} */ s///" \
390      -e "s%::modipsl::%${F_MOD}%" \
391      -e "/^${W_P}/d"       \
392      -e "s/::default_node::/${ProjectNode}/" \
393      -e "s/::default_core::/${ProjectCore}/" \
394      -e "s/::default_project::/${ProjectID}/" \
395      ${i} > ${j}'/'${n_f}
396  chmod u+x ${j}'/'${n_f}
397done
398#-
399# set default_project in libIGCM_sys_curie.ksh too.
400#-
401if [ X"${SYSTEM}" == "Xcurie" ] ; then
402  i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh
403  sed -i -e "s/::default_project::/${ProjectID}/" ${i}
404fi
405#-
406# Limited to hindcast/forecast and date restart Ensemble for the time being
407if [ ${x_e} = 'true' ] ; then
408  #.. Read input data from ensemble.card ..
409  SUBMIT_DIR=${SUBMIT_DIR_ENS}
410  RUN_DIR="${WORKDIR}/ENSEMBLE"
411  #
412  # Copy initial things around and define variables (hindcast/forecast case)
413  IGCM_sys_Cd ${SUBMIT_DIR}
414  IGCM_ensemble_Init
415
416  if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then
417    echo "WARNING: Parametric Ensemble is not implemented yet..."
418  fi
419
420  if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then
421    IGCM_sys_Cd ${SUBMIT_DIR}
422    IGCM_ensemble_DateInit
423    # As it says
424    IGCM_sys_Cd ${SUBMIT_DIR}
425    IGCM_ensemble_DatePeriodicStarts
426    # As it says
427    IGCM_sys_Cd ${SUBMIT_DIR}
428    IGCM_ensemble_DateNonPeriodicStarts
429    # Clean
430    IGCM_sys_Rm -rf ${RUN_DIR}
431  fi
432
433  if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then
434    IGCM_sys_Cd ${SUBMIT_DIR}
435    IGCM_ensemble_CastInit
436    # As it says
437    IGCM_sys_Cd ${SUBMIT_DIR}
438    IGCM_ensemble_CastPeriodicStarts
439    # As it says
440    IGCM_sys_Cd ${SUBMIT_DIR}
441    IGCM_ensemble_CastNonPeriodicStarts
442    # As it says
443    IGCM_sys_Cd ${SUBMIT_DIR}
444    IGCM_ensemble_CastMemberList
445    # Done
446    IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
447    IGCM_sys_Cd ${SUBMIT_DIR}
448    # Clean
449    IGCM_sys_Rm -rf ${RUN_DIR}
450  fi
451fi
452#-
453[[ ${x_v} = 'verbose' ]] && print - "";
454#-
455# That's all folks
456#-
457
458if [ ${NbErr} -ne 0 ] ; then
459  echo "################ ERROR ################"
460  echo "${NbErr} invalid JobName(s) found, check the log"
461fi
462
463
464exit 0;
Note: See TracBrowser for help on using the repository browser.