source: trunk/libIGCM/ins_job @ 1315

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