source: tags/libIGCM_v2.8/ins_job @ 1456

Last change on this file since 1456 was 1305, checked in by aclsce, 8 years ago

First implementation of Intel MPI environment for ADA-IDRIS machine (not fully validated, desactivated by default).

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