source: BOL/LMDZ_Setup_amaury/script_SIMU @ 4991

Last change on this file since 4991 was 4991, checked in by abarral, 2 weeks ago

Improve docs
Fix bug on sequential sim when running locally
Fix crash when running init without slurm (ce0l w/o OMP_NUM_THREADS=1)
Fix crash for climato=0 due to missing limit.nc

File size: 15.3 KB
Line 
1#!/bin/bash
2## Headers managed by sed
3#@JZ#JeanZay
4#@JZ#SBATCH --job-name=NOM_SIMU         # nom du job
5#@JZ# Nombre de processus MPI :
6#@JZ#SBATCH --ntasks=8
7#@JZ##### number of MPI processes per node : 40(procs/node on Jean-Zay) / cpus-per-task (ex : =5 for 8 OMP)
8#@JZ####SBATCH --ntasks-per-node=5    # if specified, also add "#SBATCH --nodes= ..."  with nodes=ntasks/(ntasks-per-node)
9#@JZ# nombre de threads OpenMP
10#@JZ#SBATCH --cpus-per-task=8
11#@JZ# de Slurm "multithread" fait bien reference a l'hyperthreading.
12#@JZ#SBATCH --hint=nomultithread       # 1 thread par coeur physique (pas d'hyperthreading)
13#@JZ#SBATCH --time=00:30:00            # Temps d execution maximum demande (HH:MM:SS)
14#@JZ#SBATCH --output=outNOM_SIMU%j     # Nom du fichier de sortie
15#@JZ#SBATCH --error=outNOM_SIMU%j      # Nom du fichier d'erreur (ici commun avec la sortie)
16#@JZ# To submit to test queue ; "time" (above) must be max 30 min
17#@JZ#TESTQ#SBATCH --qos=qos_cpu-dev
18#@SP#Spirit
19#@SP#SBATCH --job-name=NOM_SIMU
20#@SP#SBATCH --ntasks=8
21#@SP#SBATCH --cpus-per-task=8
22#@SP#SBATCH --hint=nomultithread
23#@SP#SBATCH --time=00:30:00
24#@SP#SBATCH --output=outNOM_SIMU%j
25#@SP#SBATCH --error=outNOM_SIMU%j
26#@ADS#Adastra
27#@ADS#SBATCH --job-name=NOM_SIMU
28#@ADS#SBATCH --ntasks=8
29#@ADS#SBATCH --cpus-per-task=8
30#@ADS#SBATCH --hint=nomultithread
31#@ADS#SBATCH --time=00:30:00
32#@ADS#SBATCH --output=outNOM_SIMU%j
33#@ADS#SBATCH --error=outNOM_SIMU%j
34
35set -eux
36
37# Number of MPI processes :
38ntasks=8
39# number of OpenMP threads
40nthreads=8
41export OMP_NUM_THREADS=$nthreads
42#@JZ#export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK  # For Jean-Zay (replacing the next 3 lines, commented out)
43# private memory for each thread
44export OMP_STACKSIZE=800M
45
46
47#@JZ#export OMP_PLACES=cores  # "binding" present in old script_SIMU, but terribly reduces performance on Spirit...
48ulimit -s unlimited
49#@SP ulimit -Ss 8192
50
51simul=NOM_SIMU
52
53reseau_local=0
54#veget=y
55veget=CMIP6
56if [[ $veget = "none" ]] ; then VEGET=n ; else VEGET=y ; fi
57
58isotopes=n
59# If isotopes=y, initialisation_iso will be changed to 0 in iso.def after the 1st run period, to read isotopes in restart files
60
61# Choice of aerosols : n / clim / spla
62aerosols=clim
63stopsim=201101
64ok_guide=y   # y/n guidage ou non
65climato=1
66
67echo '##############################################################'
68echo '# Gestion des repertoires de lancement                                 '
69echo '##############################################################'
70
71# Repertoires de la simulation
72SCRATCHD=$SCRATCH
73STORED=$STORE
74MAINDIR=LMDZOR96x95x79
75SIMU_dir=$MAINDIR/$simul
76SIMUDIR=$STORED/$SIMU_dir
77
78# Repertoires de travail
79WWORKD=$SCRATCHD/$SIMU_dir$$
80if [[ -d $WWORKD ]]; then  # useful when running on local computer, where jobs aren't submitted
81  rm -rf "$WWORKD"
82fi
83mkdir -p $WWORKD
84cd $WWORKD
85SCRIPTDIR=$SCRATCHD/$MAINDIR
86
87cp $STORED/$MAINDIR/lmdz_env.sh . ; . lmdz_env.sh
88ERADIR=$STORED/$MAINDIR/GUIDE
89if [ "$aerosols" = "spla" ] ; then ERA10mDIR=$STORED/$MAINDIR/ERA10m ; fi
90LIMITDIR=$STORED/$MAINDIR/LIMIT
91SPLADIR=$STORED/$MAINDIR/INPUT_SPLA
92DEFDIR=$SIMUDIR/DEF
93
94GET='ln -s'
95PUT='mv '
96
97
98echo '##################################################################'
99echo 'Gestion des mois et annees'
100echo '##################################################################'
101
102$GET $SIMUDIR/etat
103year=`tail -1 etat | awk ' { print $1 } ' | cut -c1-4`
104month=`tail -1 etat | awk ' { print $1 } ' | cut -c5-`
105echo year $year month $month
106
107if [ "$month" = "" ] ; then
108   paran=1
109   ym=$year
110   next=`expr $ym + 1`
111else
112   paran=0
113   if [ $month = 12 ] ; then
114      nextmonth=1
115      nextyear=`expr $year + 1`
116   else
117      nextmonth=`expr $month + 1`
118      nextyear=$year
119   fi
120   if [ `echo $nextmonth | wc -m` = 2  ] ; then
121      nextmonth=0$nextmonth
122   fi
123   ym=$year$month
124   next=$nextyear$nextmonth
125fi
126
127
128echo ym $ym
129echo mois ancien  : $ym
130echo mois nouveau : $next
131
132INI=${SPLADIR}/INITIAL
133PERIOD=${SPLADIR}/PERIOD00${month}/SUB
134
135echo '#################################################################'
136echo 'Modification de run.def et gcm.def pour prendre en compte la duree du'
137echo 'du mois en question.'
138echo 'le dayref est modifie pour tricher avec le calendrier (ecrit pour'
139echo 'une annee de 260 jours dans le modele).'
140echo 'On passe donc comme jour de reference le numero du jour du mois dans'
141echo 'une annee en 360 jours.'
142echo '#################################################################'
143
144# Choix du calendrier
145#AS: La condition if "$climato" = "0" suffit, car "$ok_guide" = "y" est interdit avec $climato" = "1" dans setup.sh (exit ligne 160)
146##calend=earth_360d
147##if [ "$ok_guide" = "y" -o "$climato" = "0" ] ; then calend=gregorian ; fi
148if [ "$climato" = "0" ] ; then calend=gregorian ; else calend=earth_360d ; fi
149bisextile=0
150if [[ $(( year % 4 )) = 0 && $calend = gregorian ]] ; then bisextile=1 ; fi
151if [ $paran = 0 ] ; then
152   if [ "$calend" = "gregorian" ] ; then
153      ndays=( 31 28 31 30 31 30 31 31 30 31 30 31 )
154      if [ $bisextile = 1 ] ; then ndays[1]=29 ; fi
155   else
156      ndays=( 30 30 30 30 30 30 30 30 30 30 30 30 )
157   fi
158   #Constants with a leading 0 are interpreted as octal numbers.
159   # You can remove the leading zero by parameter expansion: hour=${hour#0}
160
161   nday=${ndays[(( ${month#0} - 1 ))]}
162   ndayh=$nday
163   dayref=1 ; mm=1 ; while [ $mm -lt ${month#0} ] ; do
164    (( dayref = $dayref + ${ndays[(( $mm - 1 ))]} )) ; (( mm = $mm + 1 )) ; done
165else
166   dayref=1
167   if [ "$calend" = "gregorian" ] ; then
168      if [ $bisextile = 0 ] ; then nday=365 ; else nday=366 ; fi
169   else
170      nday=360 ; ndayh=30
171   fi
172fi
173
174echo CALENDRIER $calend : longueur du mois vrai $year $month $nday dayref=$dayref
175
176
177echo '####################################################################'
178echo '# On va chercher les fichiers necessaires a la simulation'
179echo '####################################################################'
180#Reminder : we are in $WWORKD = $SCRATCHD/$SIMU_dir = $SCRATCHD/$MAINDIR/$simul
181
182echo DEFDIR $DEFDIR
183echo SIMUDIR $SIMUDIR
184echo simul $simul
185
186if [ $reseau_local = 0 ] ; then mkdir DEF ; cd DEF ; $GET $DEFDIR/* . ; cd .. ; fi
187
188cp -f DEF/* .
189#---The following changes in .def files will only be visible in the running directory (on SCRATCH if $reseau_local = 0)
190# They concern variables that change during runtime : nday, dayref, anneeref, ndayh
191# The other "sed" were totally or partially moved in setup.sh, to be done in $MAINDIR/DEF/*.def, before creating $MAINDIR/$SIMU (more transparent)
192#sed -e 's/ok_guide=.*.$/ok_guide='$ok_guide'/' DEF/guide.def >| guide.def
193#sed -e 's/nday=.*.$/nday='$nday'/' -e 's/dayref=.*.$/dayref='${dayref}'/' -e 's/calend=.*.$/calend='$calend'/' -e 's/anneeref=.*.$/anneeref='$year'/' DEF/run.def >| run.def
194
195#=====!!!!!!!!====!!!!!!====!!!!+++====!!!!!!====!!!!!!!=====!!!!!!====z!!!====!!!!========!!!!!========!!!
196##POUR que des TESTS soyent tres RAPIDES (pour ex, verifier fichiers input), ON FORCE nday=1 jour  !!!
197#nday=1
198#=====!!!!!!!!====!!!!!!====!!!!+++====!!!!!!====!!!!!!!=====!!!!!!====z!!!====!!!!========!!!!!========!!!
199
200sed -e 's/nday=.*.$/nday='$nday'/' -e 's/dayref=.*.$/dayref='${dayref}'/' -e 's/anneeref=.*.$/anneeref='$year'/' DEF/run.def >| run.def
201sed -e 's/phys_out_filetimesteps=[[:space:]]*[0-9][0-9]day/phys_out_filetimesteps=  '$ndayh'day/'  DEF/config.def >| config.def
202#--- End of *.def changes in the $WWORKD only
203
204${GET} $SIMUDIR/start.$ym.nc start.nc
205${GET} $SIMUDIR/startphy.$ym.nc startphy.nc
206if [ $climato = 1 ] ; then
207   ${GET} $LIMITDIR/limit.nc limit.nc
208else
209   ${GET} $LIMITDIR/limit.$year.nc limit.nc
210fi
211
212
213echo '####################################################################'
214echo '# Imports des fichiers aerosols si flag_aerosol>0 dans config.def, '
215echo '# et si dans setup.sh on a "aerosols=clim" ou "aerosols=spla". '
216echo '# NOTE: Si "aerosols=n" dans setup.sh, script_SIMU met flag_aerosol=0 et on tourne SANS aerosols' 
217echo '####################################################################'
218if [ "`grep 'flag_aerosol=' config.def | head -1 | cut -d= -f2`" != 0 ] ; then
219  if [ $aerosols = clim ] ; then
220    # if [ $climato = 1 ] ; then suf=clim ; else suf=$year ; fi
221    suf=clim
222    # Le script pourrait être sophistique pour prendre des aerosols interannuels
223    ${GET} $LIMITDIR/aerosols.$suf.nc aerosols$year.nc
224    if [ ! -f aerosols1980.nc ] ; then ${GET} $LIMITDIR/aerosols.$suf.nc aerosols1980.nc ; fi
225    ${GET} $LIMITDIR/aerosols.nat.nc aerosols.nat.nc
226  fi
227
228  ## Ca doit etre la meme liste de fichiers rapatriee par setup.sh dans $LMDZ_INIT/SPLA_Init
229  ## et interpolee (setup.sh aussi) dans $SPLADIR
230  if [ $aerosols = spla ] ; then 
231    inputf="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
232                carbon_emissions.nc sulphur_emissions_antro.nc  \
233                sulphur_emissions_nat.nc  sulphur_emissions_volc.nc"
234    for file in $inputf ; do ${GET} $INI/$file . ; done
235
236    change="dust.nc "
237    for file in $change ; do ${GET} $PERIOD/$file . ; done
238
239    # Le calcul d'emissions de sels marins utilise les vents ERA-10m interpoles sur grille_s (lonv,latu) avec le script era2gcm_uv10m.sh
240    # NB : GET=ln -s ; ERA10mDIR contient lui-meme le lien ERA10m vers le repertoire des vents interpoles $REA_uv10m (REA=ERA5, ERAI ou OPERA)
241    ventl="u10m.nc v10m.nc"
242    for file in $ventl ; do ${GET} $ERA10mDIR/${year}/${month}/$file . ; done
243  fi
244fi
245
246#----------------------------------------
247# Noveaux forcages a activer a l'avenir
248#   (commentes en attendant) :
249#----------------------------------------
250#for file in climoz_LMDZ.nc solarforcing.nc  taulwstrat.2D.nc  tauswstrat.2D.nc ; do
251#   ${GET} $LIMITDIR/$file $file
252#done
253#----------------------------------------
254
255${GET} $SIMUDIR/gcm.e gcm.e ; chmod  +x gcm.e
256
257
258if [ $VEGET = y ] ; then
259    set +e ; for t in stomate sechiba ; do cp $SIMUDIR/start_$t.$ym.nc ${t}_rest_in.nc ; done ; set -e
260    if [ "`grep RIVER_ROUTING orchidee.def |grep -i y`" ] ; then
261      set +e ; ln -s $LMDZ_INIT/routing_simple.nc . ; ln -s $LMDZ_INIT/routing.nc .
262               cp $SIMUDIR/start_routing.$ym.nc routing_start.nc ; set -e
263    fi
264
265#For Orchidee trunk (post-CMIP6), orchidee_pft.def must be copied in addition to orchidee.def
266    \cp -f DEF/orchidee*.def .
267
268# Test sur sechiba_rest_in.nc,
269#  supposant que les restarts pour sechiba, stomate, et routing le cas echeant,
270#  sont soit tous dispo, soit tous absents
271    if [ ! -f sechiba_rest_in.nc ] ; then
272       echo '#########################################################'
273       echo "Autoinitialisation d'orchidee au besoin"
274       echo '#########################################################'
275       get="ln -s $LMDZ_INIT/"
276       for file in cartepente2d_15min.nc \
277          lai2D.nc soils_param.nc soil_bulk_and_ph.nc alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc ; do ${get}$file ; done
278
279       ln -sf alb_bg_modisopt_2D_ESA_v2.nc alb_bg.nc
280
281       echo ATTENTION : ON UTILISE LES FICHIERS DE L ANNEE 2000
282       ${get}PFTmap_15PFT.v1_2000.nc PFTmap.nc
283       ${get}woodharvest_2000.nc woodharvest.nc
284
285       sed -e 's/^SECHIBA_restart_in.*./SECHIBA_restart_in=NONE/' \
286           -e 's/^STOMATE_RESTART_FILEIN.*./STOMATE_RESTART_FILEIN=NONE/' \
287           -i orchidee.def
288
289      if [ $veget = 7994 ] ; then
290         get="ln -s $LMDZ_INIT/"
291         for file in ndep_nhx.nc ndep_noy.nc nfert_cropland.nc nfert_pasture.nc nmanure_cropland.nc nmanure_pasture.nc bnf.nc ; do ${get}$file ; done
292      fi
293
294    fi
295
296fi
297
298
299echo '#################################################################'
300echo    'Repertoire contenant les fichiers de reanalyses'
301echo '#################################################################'
302
303if [ "$ok_guide" = "y" ] ; then
304   \rm -f u.nc v.nc T.nc hur.nc
305   if [ -f u.nc ] ; then
306      echo PROBLEME D EFFACEMENT DES FICHIERS DE REANALYSES
307      exit
308   fi
309   for var in u v T hur ; do $GET $ERADIR/$year/$month/$var.nc $var.nc ; done
310   echo Fin du rapatriement des fichiers de guidage
311fi
312
313echo '##################################################################'
314echo    'liste des fichiers avant le lancement de la simulation'
315echo '##################################################################'
316ls -lrt
317#diff DEF ./
318
319echo '##################################################################'
320echo    'Lancement de la simulation'
321echo '##################################################################'
322
323time $RUNCMD $ntasks ./gcm.e > listing
324if [ ! -f restartphy.nc ] ; then
325echo PROBLEME PAS DE FICHIER RESTARTPHY
326exit
327fi
328
329echo '##################################################################'
330echo     'sauvegarde des fichiers de sortie'
331echo '##################################################################'
332
333# listing
334${PUT} listing ${SIMUDIR}/list$ym
335# if the listing for Orchidee is also needed, then uncomment the following line :
336#if [ $VEGET = y ] ; then ${PUT} out_orchidee_0000.0000 ${SIMUDIR}/out_orchidee$ym ; fi
337
338# restart(s)
339${PUT} restart.nc ${SIMUDIR}/start.$next.nc
340${PUT} restartphy.nc ${SIMUDIR}/startphy.$next.nc
341if [ $VEGET = y ] ; then for t in sechiba stomate ; do
342    f=${t}_rest_out.nc ; if [ -f $f ] ; then ${PUT} $f ${SIMUDIR}/start_$t.$next.nc ; fi ; done 
343    f=routing_restart.nc ; if [ -f $f ] ; then ${PUT} $f ${SIMUDIR}/start_routing.$next.nc ; fi
344fi
345
346# fichiers "histoires"
347# Si on tourne avec xios (et type="one_file") au lieu de ioipsl, on n'a pas besoin de rebuild, on doit juste copier les fichiers
348liste_out="histmth histday histhf histmthCOSP Xhistins XhistLES sechiba_history sechiba_history_4dim sechiba_out_2 stomate_history stomate_ipcc_history diag_routing dynzon"
349xios_used=0
350
351for fileout in $liste_out ; do
352  if [ -f  $fileout.nc ] ; then 
353     ${PUT} $fileout.nc ${SIMUDIR}/$fileout.$ym.nc
354     xios_used=1
355  fi
356done
357
358if [ $xios_used = 0 ] ; then
359  $GET $SIMUDIR/reb.sh
360  chmod +x reb.sh
361  ./reb.sh $ym $SIMUDIR $liste_out
362fi
363
364if [ -f guide_ins.nc ] ; then ${PUT} guide_ins.nc ${SIMUDIR}/guide_ins.$ym.nc ; fi
365
366echo '##################################################################'
367echo     'preparation et lancement de la simulation suivante'
368echo '##################################################################'
369
370# Gestion du fichier etat de controle de la simulation
371echo $ym OK >> etat
372echo $next a faire >> etat
373# ${PUT} etat $SIMUDIR/etat # Pas necessaire car etat est un lien vers $SIMUDIR/etat
374
375# set initialisation_iso to 0 for next run to read isotopes from restart files
376if [ $isotopes = y ] ; then
377   sed -i 's/^initialisation_iso=.*.$/initialisation_iso=0/' $SIMUDIR/DEF/iso.def
378fi
379set +e ; \rm out* sec* sta* list* rest* gcm.e aer* ; set -e
380
381# Arret si on est arrive au bout
382if [ $next =  $stopsim ] ; then
383   echo 'On arrive au bout, simulation next:'$next', stopsim:'$stopsim
384   # Cas particulier ou on veut chainer plusieurs simulations multi annuelles.
385   # pour le tuning automatique.
386   # Ici on passe de SCM_1-019 a SCM_1-029
387   if [ "${simul:0:3}" = "SCM" ] ; then
388      pre="SCM_1-"
389      num=`echo $simul | sed -e 's/'$pre'//'`
390      # (( num = $num + 10 )) change a cause d un probleme avec 008
391      num=`echo $num | awk ' { print $1 + 10 } '`
392      num=`printf "%03d\n" $num`
393      simul_new=$pre$num
394      cd $SCRIPTDIR
395      if [ $num -le 250 ] ; then
396         sed -e 's/^simul=.*.$/simul='$simul_new'/' -e 's/^\# @ job_nam.*.=.*.$/\# @ job_name = '$simul_new'/' tmp_$simul >| tmp_$simul_new
397         $SUBMITCMD tmp_$simul_new
398      fi
399   fi
400   exit
401fi
402
403
404echo '##################################################################'
405echo      'lancement de la simulation suivante tmp_'$simul' depuis :'
406echo '##################################################################'
407pwd
408
409
410cd $SCRIPTDIR
411$SUBMITCMD tmp_$simul
Note: See TracBrowser for help on using the repository browser.