source: trunk/libIGCM/ins_job @ 1271

Last change on this file since 1271 was 1271, checked in by jgipsl, 9 years ago

Now ins_job only treats the config.card in the directory from where the script is launched. See ticket #269

  • Property svn:executable set to *
  • Property svn:keywords set to Revision Author Date
File size: 12.0 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#-
103# No verbosity (0, 1, 2, 3)
104Verbosity=0
105# No de debug
106DEBUG_debug=false
107# Dont move libIGCM
108MirrorlibIGCM=false
109# Behave like computing job
110TaskType=computing
111# Source libIGCM
112. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
113. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
114. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
115. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
116. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
117if [ $x_e = 'true' ] ; then
118  . ${libIGCM}/libIGCM_ensemble/libIGCM_ensemble.ksh
119fi
120
121#-
122[[ ${x_v} = 'verbose' ]] && \
123 {
124  print - "";
125  print - '--- Host        : '${SYSTEM};
126  print - '--- modipsl     : '${F_MOD};
127  print - '--- libIGCM     : '${libIGCM};
128  print - '--- basic job   : '${F_JOB};
129  print - '--- basic card  : '${F_RCI};
130 }
131#-
132[[ ${x_v} = 'verbose' ]] && print - "\nInstallation of jobs for '${SYSTEM}'";
133#-
134
135NbErr=0
136
137#-
138# Define Project ID to set up jobs header for Curie (TGCC)
139#-
140if ( ! ${x_p} ) ; then
141  if [ X"${SYSTEM}" == "Xcurie" ] ; then
142    ProjectID=$( ccc_myproject | gawk '{ if ( $3 ~ /^project$/ && $4 !~ /^tgcc/ ) { print $4 } }' | head -n 1 )
143    ProjectID=${ProjectID:="gen2211"}
144    answer=""
145    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 ) ) :"
146    read answer
147
148    if [ "X${answer}" != "X" ] ; then
149      ProjectID=${answer}
150    fi
151    [ "${ProjectID}" = "gencmip6" ] && ProjectNode="standard" || ProjectNode="xlarge"
152  fi
153else
154  if [ X"${SYSTEM}" != "Xcurie" ] ; then
155    print - "\nOption -p invalid with this host (${SYSTEM}): it will be ignored" 1>&2;
156  fi
157fi
158
159#-
160# Define the pattern string to substitute
161#-
162W_P='#-Q- '; W_W=${W_P}${SYSTEM};
163#-
164# Extract list of 'config.card' files
165# and create jobs with AA_job
166#-
167F_CFG='config.card';
168F_CFG_ENS='ensemble.card';
169SUBMIT_DIR_ENS=$( pwd )
170for i in $( pwd )/config.card
171do
172  if [ ! -f $i ] ; then
173    echo ""
174    echo "################## WARNING ##################"
175    echo "No config.card available in current directory"
176    echo ""
177    continue
178  fi
179
180
181  j=$(cd ${i%/*};/bin/pwd;)
182  n_f=${F_RCI##*/};
183
184  if [ ! X$( echo ${j} | grep EXPERIMENTS ) = X ] ; then
185    # Do not treat config.card if it is in sub-directory of EXPERIMENTS
186    # Continue to next config.card
187    continue
188  else
189    [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
190  fi
191
192  # Find out if new structure and set .resol filename
193  if [ -d ${j}/EXPERIMENTS ] && [ -d ${j}/GENERAL ] ; then
194    # New Structure
195    [[ ${x_v} = 'verbose' ]] && echo "This is new configuration structure"
196    new_struct=yes
197    resolfile=$j/.resol
198  else
199    # Old Structure
200    new_struct=no
201    resolfile=$j/../.resol
202  fi
203
204  # Get all variables declared in section UserChoices in config.card
205  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} UserChoices
206  # Set default values
207  config_UserChoices_ExpType=""
208  RESOL_ATM_3D=this_is_a_test_string
209  RESOL=this_is_another_test_string
210  typeset option
211  for option in ${config_UserChoices[*]} ; do
212    IGCM_card_DefineVariableFromOption ${j}'/'${F_CFG} UserChoices ${option}
213  done
214
215  # Find the JobName : JobName might contain the variable RESOL_ATM_3D that will be replaced by what is in .resol file
216  if [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL_ATM_3D} ) = X ] ; then
217    TRUERESOL=$( tail -1 $resolfile | awk "-F=" '{print $2}' )
218    echo TRUERESOL = $TRUERESOL
219    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL_ATM_3D}/${TRUERESOL}/" )
220    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
221  elif [ ! X$( echo ${config_UserChoices_JobName} | grep ${RESOL} ) = X ] ; then
222    TRUERESOL=$( head -1 $resolfile  )
223    JobName=$( echo ${config_UserChoices_JobName} | sed -e "s/${RESOL}/${TRUERESOL}/" )
224    IGCM_card_WriteOption ${j}'/'${F_CFG} UserChoices JobName ${JobName}
225  else
226    JobName=${config_UserChoices_JobName}
227  fi
228
229  # Check JobName validity : only alphanumerical characters, "-" and "." are authorized
230  ins_job_Check_JobName
231  RetCode=$?
232  [[ $RetCode -gt 0 ]] && continue
233
234  [[ ${x_v} = 'verbose' ]] && echo "JobName=${JobName}"
235
236  # Add specific treatment for new type of directory structure
237  if [ ${new_struct} == yes ] ; then
238
239    if [ "X${config_UserChoices_ExpType}" = X ] ; then
240      echo "\nERROR in ${j}/config.card"
241      echo "ins_job stops here"
242      echo "=> The variable ExpType must be added in config.card in section UserChoices"
243      echo "=> ExpType gives the directory for the .card configuration files for the wanted experiement. For exemple ExpType=IPSLCM5/historical"
244      exit 4
245    else
246      [[ ${x_v} = 'verbose' ]] && echo "ExpType= ${config_UserChoices_ExpType}"
247    fi
248
249    if [ -d ${j}/${JobName} ] ; then
250      echo "Directory ${j}/${JobName} exist already, continue next config.card"
251      continue
252    fi
253    echo "=> Submit directory ${JobName} will be created with cards from EXPERIMENTS/${config_UserChoices_ExpType}"
254    cp -r ${j}/EXPERIMENTS/${config_UserChoices_ExpType} ${j}/${JobName}
255    cp -r ${j}/GENERAL/* ${j}/${JobName}/.
256    cp -f ${j}/${F_CFG}  ${j}/${JobName}/.
257    if [ -f ${F_CFG_ENS} ] ; then
258      cp -f ${j}/${F_CFG_ENS}  ${j}/${JobName}/.
259      SUBMIT_DIR_ENS=${j}/${JobName}
260    fi
261    rm -f ${j}/${F_CFG}
262    rm -f ${j}/${F_CFG_ENS}
263    rm -f ${j}/${F_CFG}.bak
264    j=${j}/${JobName}
265    [[ ${x_v} = 'verbose' ]] && echo new j=$j
266  fi
267  # end specific treatment for new type directory structure
268
269  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; } || \
270   {
271    [[ ${x_v} = 'verbose' ]] && print - "\nCopying file ${F_RCI}\nin directory ${j}";
272    \cp ${F_RCI} ${j};
273   }
274
275  #==================================
276  # Read ListOfComponents section:
277  #echo
278  #IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents"
279
280  IGCM_card_DefineArrayFromSection  ${j}'/'${F_CFG} ListOfComponents
281  for comp in ${config_ListOfComponents[*]} ; do
282    IGCM_card_DefineArrayFromOption  ${j}'/'${F_CFG} ListOfComponents ${comp}
283  done
284  #IGCM_debug_Print 3 ${config_ListOfComponents[*]}
285
286  #==================================
287  # Read Executable section:
288  IGCM_card_DefineArrayFromSection ${j}'/'${F_CFG} Executable
289
290  # Define the execution context (MPMD, SPMD, MPI/OMP ...)
291  IGCM_config_ConfigureExecution ${j}'/'${F_CFG}
292
293  # coreNumber    : TOTAL NUMBER OF CORES
294  # mpiTasks      : TOTAL NUMBER OF MPI TASKS
295  # openMPthreads : NUMBER OF OpenMP THREADS
296
297  # File name for Job
298  n_f='Job_'${JobName};
299  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
300  [[ ${x_v} = 'verbose' ]] && print - "\nWorking with file ${F_CFG}\nin directory ${j}\nfor ${n_f}";
301  sed -e "/^${W_W} */ s///" \
302      -e "/^${W_P}/d"       \
303      -e "s%::modipsl::%${F_MOD}%" \
304      -e "s/::Jobname::/${JobName}/" \
305      -e "s/::default_project::/${ProjectID}/" \
306      ${F_JOB} > ${j}'/'${n_f}
307  chmod u+x ${j}'/'${n_f}
308
309  # update Headers so that ressources description are accurate (MPMD/SPMD/...)
310  IGCM_sys_updateHeaders ${j}'/'${n_f}
311done
312
313#-
314# Extract list of AA_* files in libIGCM
315# and create jobs (for all except AA_job)
316#-
317for i in $(find ${libIGCM} -maxdepth 1 -name "AA_*" -print)
318do
319  i_f=${i##*/};
320  [[ ${i_f} = 'AA_job' ]] && { continue; }
321  j=${i%/*}; n_f=${i_f#AA_}'.job';
322  [[ -f ${j}'/'${n_f} ]] && { ins_job_Warning; continue; }
323  [[ ${x_v} = 'verbose' ]] && print - "\nIn directory ${j}\n${i_f} -> ${n_f}"
324  sed -e "/^${W_W} */ s///" \
325      -e "s%::modipsl::%${F_MOD}%" \
326      -e "/^${W_P}/d"       \
327      -e "s/::default_node::/${ProjectNode}/" \
328      -e "s/::default_project::/${ProjectID}/" \
329      ${i} > ${j}'/'${n_f}
330  chmod u+x ${j}'/'${n_f}
331done
332#-
333# set default_project in libIGCM_sys_curie.ksh too.
334#-
335if [ X"${SYSTEM}" == "Xcurie" ] ; then
336  i=${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh
337  sed -i -e "s/::default_project::/${ProjectID}/" ${i}
338fi
339#-
340# Limited to hindcast/forecast and date restart Ensemble for the time being
341if [ ${x_e} = 'true' ] ; then
342  #.. Read input data from ensemble.card ..
343  SUBMIT_DIR=${SUBMIT_DIR_ENS}
344  RUN_DIR="${WORKDIR}/ENSEMBLE"
345  #
346  # Copy initial things around and define variables (hindcast/forecast case)
347  IGCM_sys_Cd ${SUBMIT_DIR}
348  IGCM_ensemble_Init
349
350  if [[ ${ensemble_Ens_PARAMETRIC_active} = 'y' ]] ; then
351    echo "WARNING: Parametric Ensemble is not implemented yet..."
352  fi
353
354  if [[ ${ensemble_Ens_DATE_active} = 'y' ]] ; then
355    IGCM_sys_Cd ${SUBMIT_DIR}
356    IGCM_ensemble_DateInit
357    # As it says
358    IGCM_sys_Cd ${SUBMIT_DIR}
359    IGCM_ensemble_DatePeriodicStarts
360    # As it says
361    IGCM_sys_Cd ${SUBMIT_DIR}
362    IGCM_ensemble_DateNonPeriodicStarts
363    # Clean
364    IGCM_sys_Rm -rf ${RUN_DIR}
365  fi
366
367  if [[ ${ensemble_Ens_PERTURB_active} = 'y' ]] ; then
368    IGCM_sys_Cd ${SUBMIT_DIR}
369    IGCM_ensemble_CastInit
370    # As it says
371    IGCM_sys_Cd ${SUBMIT_DIR}
372    IGCM_ensemble_CastPeriodicStarts
373    # As it says
374    IGCM_sys_Cd ${SUBMIT_DIR}
375    IGCM_ensemble_CastNonPeriodicStarts
376    # As it says
377    IGCM_sys_Cd ${SUBMIT_DIR}
378    IGCM_ensemble_CastMemberList
379    # Done
380    IGCM_sys_Cp ${RUN_DIR}/CreatedDir.txt ${SUBMIT_DIR}
381    IGCM_sys_Cd ${SUBMIT_DIR}
382    # Clean
383    IGCM_sys_Rm -rf ${RUN_DIR}
384  fi
385fi
386#-
387[[ ${x_v} = 'verbose' ]] && print - "";
388#-
389# That's all folks
390#-
391
392if [ ${NbErr} -ne 0 ] ; then
393  echo "################ ERROR ################"
394  echo "${NbErr} invalid JobName(s) found, check the log"
395fi
396
397
398exit 0;
Note: See TracBrowser for help on using the repository browser.