source: trunk/libIGCM/ins_job @ 1242

Last change on this file since 1242 was 1242, checked in by sdipsl, 9 years ago
  • IGCM_config_ConfigureExecution was buggy
  • Fix Ada headers edition
  • typo
  • has been tested
  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 11.8 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] [-p project]
27
28Options :
29  -h          : help
30  -v          : verbose mode
31  -e          : turn on ensemble mode (hindcast/forecast or date restart)
32  -p project  : add default project on curie
33"
34}
35function ins_job_Warning
36{
37   [[ ${x_v} = 'verbose' ]] && print - "\n############### WARNING ###############";
38   [[ ${x_v} = 'verbose' ]] && print - "File ${n_f} already exists\nin directory ${j}";
39   [[ ${x_v} = 'verbose' ]] && print - "You must delete this file to update !";
40}
41
42function ins_job_Check_JobName
43{
44  verif=${JobName##[a-zA-Z]*(?([.\-])[a-zA-Z0-9])}
45
46  if [ ${#verif} -ne 0 ] ; then
47    echo "################ ERROR ################"
48    echo "${JobName} is invalid."
49    echo "- JobName can only contain alphanumeric characters, \".\" and \"-\""
50    echo "- JobName must start with a letter"
51
52    ((NbErr=NbErr+1))
53
54    Status=1
55  else
56    Status=0
57  fi
58
59  return ${Status}
60}
61
62#-
63#     dirname     and      basename
64#-
65d_n=$(dirname ${0}); b_n=$(basename ${0});
66#-
67# Retrieving and validation of the options
68#-
69x_v='silencious';
70x_e=false;
71x_p=false;
72while getopts :hvep: V ; do
73  case $V in
74  (h)  ins_job_Usage; exit 0;;
75  (v)  x_v='verbose';;
76  (e)  x_e=true;;
77  (p)  x_p=true
78       ProjectID=${OPTARG} ;;
79  (:)  echo ${b_n}" : -"${OPTARG}" option : missing value" 1>&2;
80       exit 2;;
81  (\?) echo ${b_n}" : -"${OPTARG}" option : not supported" 1>&2;
82       exit 2;;
83  esac
84done
85[ ${x_v} = 'silencious' ] && export DEBUG_sys=false
86shift $(($OPTIND-1));
87#-
88# Define working files
89#-
90F_MOD=$(cd ${d_n}'/..';/bin/pwd;)
91# [[ ${F_MOD##*/} != 'modipsl' ]] && \
92#  { print - "directory 'modipsl' unreachable"; exit 3; }
93W_W=${d_n}'/../libIGCM'
94[[ ! -d ${W_W} ]] && { print - "${W_W} unreachable"; exit 3; }
95libIGCM=$(cd ${W_W};/bin/pwd;)
96F_JOB=${libIGCM}'/AA_job';
97[[ ! -f ${F_JOB} ]] && { print - "${F_JOB} unreachable"; exit 3; }
98F_RCI=${libIGCM}'/run.card.init';
99[[ ! -f ${F_RCI} ]] && { print - "${F_RCI} unreachable"; exit 3; }
100#-
101# Accessing to functions (without stack)
102#-
103DEBUG_debug=false
104MirrorlibIGCM=false
105TaskType=computing
106. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
107. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
108. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
109. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
110. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
111if [ $x_e = 'true' ] ; then
112  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
113fi
114
115#-
116[[ ${x_v} = 'verbose' ]] && \
117 {
118  print - "";
119  print - '--- Host        : '${SYSTEM};
120  print - '--- modipsl     : '${F_MOD};
121  print - '--- libIGCM     : '${libIGCM};
122  print - '--- basic job   : '${F_JOB};
123  print - '--- basic card  : '${F_RCI};
124 }
125#-
126[[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${SYSTEM}'";
127#-
128
129NbErr=0
130
131#-
132# Define Project ID to set up jobs header for Curie (TGCC)
133#-
134if ( ! ${x_p} ) ; then
135  if [ X"${SYSTEM}" == "Xcurie" ] ; then
136    ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 )
137    ProjectID=${ProjectID:="gen2211"}
138    answer=""
139    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 ) ) :"
140    read answer
141
142    if [ "X${answer}" != "X" ] ; then
143      ProjectID=${answer}
144    fi
145    [ "${ProjectID}" = "gencmip6" ] && ProjectNode="standard" || ProjectNode="xlarge"
146  fi
147else
148  if [ X"${SYSTEM}" != "Xcurie" ] ; then
149    print - "\nOption -p invalid with this host (${SYSTEM}): it will be ignored" 1>&2;
150  fi
151fi
152
153#-
154# Define the pattern string to substitute
155#-
156W_P='#-Q- '; W_W=${W_P}${SYSTEM};
157#-
158# Extract list of 'config.card' files
159# and create jobs with AA_job
160#-
161F_CFG='config.card';
162F_CFG_ENS='ensemble.card';
163SUBMIT_DIR_ENS=$( pwd )
164#for i in $(find ${d_n}/.. -name ${F_CFG} -print)
165for i in $(find $( pwd ) -name ${F_CFG} -print)
166do
167  j=$(cd ${i%/*};/bin/pwd;)
168  n_f=${F_RCI##*/};
169
170  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
171    # Do not treat config.card if it is in sub-directory of EXPERIMENTS
172    # Continue to next config.card
173    continue
174  else
175    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
176  fi
177
178  # Find out if new structure and set .resol filename
179  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
180    # New Structure
181    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
182    new_struct=yes
183    resolfile=$j/.resol
184  else
185    # Old Structure
186    new_struct=no
187    resolfile=$j/../.resol
188  fi
189
190  # Get all variables declared in section UserChoices in config.card
191  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
192  # Set default values
193  config_UserChoices_ExpType=""
194  RESOL_ATM_3D=this_is_a_test_string
195  RESOL=this_is_another_test_string
196  typeset option
197  for option in ${config_UserChoices[*]} ; do
198    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
199  done
200
201  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
202  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
203    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
204    echo TRUERESOL = $TRUERESOL
205    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
206    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
207  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
208    TRUERESOL=$( head -1 $resolfile  )
209    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
210    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
211  else
212    JobName=${config_UserChoices_JobName}
213  fi
214
215  # Check JobName validity : only alphanumerical characters, "-" and "." are authorized
216  ins_job_Check_JobName
217  RetCode=$?
218  [[ $RetCode -gt 0 ]] && continue
219
220  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
221
222  # Add specific treatment for new type of directory structure
223  if [ ${new_struct} == yes ] ; then
224
225    if [ "X${config_UserChoices_ExpType}" = X ] ; then
226      echo "\nERROR in ${j}/config.card"
227      echo "ins_job stops here"
228      echo "=> The variable ExpType must be added in config.card in section UserChoices"
229      echo "=> ExpType gives the directory for the .card configuration files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
230      exit 4
231    else
232      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
233    fi
234
235    if [ -d ${j}/${JobName} ] ; then
236      echo "Directory ${j}/${JobName} exist already, continue next config.card"
237      continue
238    fi
239    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
240    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
241    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
242    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
243    if [ -f ${F_CFG_ENS} ] ; then
244      cp -f ${j}/${F_CFG_ENS}  ${j}/${JobName}/.
245      SUBMIT_DIR_ENS=${j}/${JobName}
246    fi
247    rm -f ${j}/${F_CFG}
248    rm -f ${j}/${F_CFG_ENS}
249    rm -f ${j}/${F_CFG}.bak
250    j=${j}/${JobName}
251    [[ ${x_v} = 'verbose' ]] && echo new j=$j
252  fi
253  # end specific treatment for new type directory structure
254
255  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
256   {
257    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
258    \cp ${F_RCI} ${j};
259   }
260
261  #==================================
262  # Read ListOfComponents section:
263  #echo
264  #IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
265
266  IGCM_card_DefineArrayFromSection  ${j}'/'${F_CFG} ListOfComponents
267  for comp in ${config_ListOfComponents[*]} ; do
268    IGCM_card_DefineArrayFromOption  ${j}'/'${F_CFG} ListOfComponents ${comp}
269  done
270  #IGCM_debug_Print 3 ${config_ListOfComponents[*]}
271
272  #==================================
273  # Read Executable section:
274  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} Executable
275
276  # Define the execution context (MPMD, SPMD, MPI/OMP ...)
277  IGCM_config_ConfigureExecution ${j}'/'${F_CFG}
278
279  # coreNumber    : TOTAL NUMBER OF CORES
280  # mpiTasks      : TOTAL NUMBER OF MPI TASKS
281  # openMPthreads : NUMBER OF OpenMP THREADS
282
283  # File name for Job
284  n_f='Job_'${JobName};
285  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
286  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
287  sed -e "/^${W_W} */ s///" \
288      -e "/^${W_P}/d"       \
289      -e "s%::modipsl::%${F_MOD}%" \
290      -e "s/::Jobname::/${JobName}/" \
291      -e "s/::default_project::/${ProjectID}/" \
292      ${F_JOB} > ${j}'/'${n_f}
293  chmod u+x ${j}'/'${n_f}
294
295  # update Headers so that ressources description are accurate (MPMD/SPMD/...)
296  IGCM_sys_updateHeaders ${j}'/'${n_f}
297done
298
299#-
300# Extract list of AA_* files in libIGCM
301# and create jobs (for all except AA_job)
302#-
303for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)
304do
305  i_f=${i##*/};
306  [[ ${i_f} = 'AA_job' ]] && { continue; }
307  j=${i%/*}; n_f=${i_f#AA_}'.job';
308  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
309  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
310  sed -e "/^${W_W} */ s///" \
311      -e "s%::modipsl::%${F_MOD}%" \
312      -e "/^${W_P}/d"       \
313      -e "s/::default_node::/${ProjectNode}/" \
314      -e "s/::default_project::/${ProjectID}/" \
315      ${i} > ${j}'/'${n_f}
316  chmod u+x ${j}'/'${n_f}
317done
318#-
319# set default_project in libIGCM_sys_curie.ksh too.
320#-
321if [ X"${SYSTEM}" == "Xcurie" ] ; then
322  i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh
323  sed -i -e "s/::default_project::/${ProjectID}/" ${i}
324fi
325#-
326# Limited to hindcast/forecast and date restart Ensemble for the time being
327if [ ${x_e} = 'true' ] ; then
328  #.. Read input data from ensemble.card ..
329  SUBMIT_DIR=${SUBMIT_DIR_ENS}
330  RUN_DIR="${WORKDIR}/ENSEMBLE"
331  #
332  # Copy initial things around and define variables (hindcast/forecast case)
333  IGCM_sys_Cd ${SUBMIT_DIR}
334  IGCM_ensemble_Init
335
336  if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then
337    echo "WARNING: Parametric Ensemble is not implemented yet..."
338  fi
339
340  if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then
341    IGCM_sys_Cd ${SUBMIT_DIR}
342    IGCM_ensemble_DateInit
343    # As it says
344    IGCM_sys_Cd ${SUBMIT_DIR}
345    IGCM_ensemble_DatePeriodicStarts
346    # As it says
347    IGCM_sys_Cd ${SUBMIT_DIR}
348    IGCM_ensemble_DateNonPeriodicStarts
349    # Clean
350    IGCM_sys_Rm -rf ${RUN_DIR}
351  fi
352
353  if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then
354    IGCM_sys_Cd ${SUBMIT_DIR}
355    IGCM_ensemble_CastInit
356    # As it says
357    IGCM_sys_Cd ${SUBMIT_DIR}
358    IGCM_ensemble_CastPeriodicStarts
359    # As it says
360    IGCM_sys_Cd ${SUBMIT_DIR}
361    IGCM_ensemble_CastNonPeriodicStarts
362    # As it says
363    IGCM_sys_Cd ${SUBMIT_DIR}
364    IGCM_ensemble_CastMemberList
365    # Done
366    IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
367    IGCM_sys_Cd ${SUBMIT_DIR}
368    # Clean
369    IGCM_sys_Rm -rf ${RUN_DIR}
370  fi
371fi
372#-
373[[ ${x_v} = 'verbose' ]] && print - "";
374#-
375# That's all folks
376#-
377
378if [ ${NbErr} -ne 0 ] ; then
379  echo "################ ERROR ################"
380  echo "${NbErr} invalid JobName(s) found, check the log"
381fi
382
383
384exit 0;
Note: See TracBrowser for help on using the repository browser.