source: BOL/LMDZ_Setup_amaury/script_SIMU @ 4980

Last change on this file since 4980 was 4980, checked in by abarral, 4 weeks ago

(WIP) update spirit arch
update script_SIMU env
fix setup.sh, add netcdf option
fix aerosols detection

File size: 15.2 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$$
80mkdir -p $WWORKD
81cd $WWORKD
82SCRIPTDIR=$SCRATCHD/$MAINDIR
83
84cp $STORED/$MAINDIR/lmdz_env.sh . ; . lmdz_env.sh
85ERADIR=$STORED/$MAINDIR/GUIDE
86if [ "$aerosols" = "spla" ] ; then ERA10mDIR=$STORED/$MAINDIR/ERA10m ; fi
87LIMITDIR=$STORED/$MAINDIR/LIMIT
88SPLADIR=$STORED/$MAINDIR/INPUT_SPLA
89DEFDIR=$SIMUDIR/DEF
90
91GET='ln -s'
92PUT='mv '
93
94
95echo '##################################################################'
96echo 'Gestion des mois et annees'
97echo '##################################################################'
98
99$GET $SIMUDIR/etat
100year=`tail -1 etat | awk ' { print $1 } ' | cut -c1-4`
101month=`tail -1 etat | awk ' { print $1 } ' | cut -c5-`
102echo year $year month $month
103
104if [ "$month" = "" ] ; then
105   paran=1
106   ym=$year
107   next=`expr $ym + 1`
108else
109   paran=0
110   if [ $month = 12 ] ; then
111      nextmonth=1
112      nextyear=`expr $year + 1`
113   else
114      nextmonth=`expr $month + 1`
115      nextyear=$year
116   fi
117   if [ `echo $nextmonth | wc -m` = 2  ] ; then
118      nextmonth=0$nextmonth
119   fi
120   ym=$year$month
121   next=$nextyear$nextmonth
122fi
123
124
125echo ym $ym
126echo mois ancien  : $ym
127echo mois nouveau : $next
128
129INI=${SPLADIR}/INITIAL
130PERIOD=${SPLADIR}/PERIOD00${month}/SUB
131
132echo '#################################################################'
133echo 'Modification de run.def et gcm.def pour prendre en compte la duree du'
134echo 'du mois en question.'
135echo 'le dayref est modifie pour tricher avec le calendrier (ecrit pour'
136echo 'une annee de 260 jours dans le modele).'
137echo 'On passe donc comme jour de reference le numero du jour du mois dans'
138echo 'une annee en 360 jours.'
139echo '#################################################################'
140
141# Choix du calendrier
142#AS: La condition if "$climato" = "0" suffit, car "$ok_guide" = "y" est interdit avec $climato" = "1" dans setup.sh (exit ligne 160)
143##calend=earth_360d
144##if [ "$ok_guide" = "y" -o "$climato" = "0" ] ; then calend=gregorian ; fi
145if [ "$climato" = "0" ] ; then calend=gregorian ; else calend=earth_360d ; fi
146bisextile=0
147if [[ $(( year % 4 )) = 0 && $calend = gregorian ]] ; then bisextile=1 ; fi
148if [ $paran = 0 ] ; then
149   if [ "$calend" = "gregorian" ] ; then
150      ndays=( 31 28 31 30 31 30 31 31 30 31 30 31 )
151      if [ $bisextile = 1 ] ; then ndays[1]=29 ; fi
152   else
153      ndays=( 30 30 30 30 30 30 30 30 30 30 30 30 )
154   fi
155   #Constants with a leading 0 are interpreted as octal numbers.
156   # You can remove the leading zero by parameter expansion: hour=${hour#0}
157
158   nday=${ndays[(( ${month#0} - 1 ))]}
159   ndayh=$nday
160   dayref=1 ; mm=1 ; while [ $mm -lt ${month#0} ] ; do
161    (( dayref = $dayref + ${ndays[(( $mm - 1 ))]} )) ; (( mm = $mm + 1 )) ; done
162else
163   dayref=1
164   if [ "$calend" = "gregorian" ] ; then
165      if [ $bisextile = 0 ] ; then nday=365 ; else nday=366 ; fi
166   else
167      nday=360 ; ndayh=30
168   fi
169fi
170
171echo CALENDRIER $calend : longueur du mois vrai $year $month $nday dayref=$dayref
172
173
174echo '####################################################################'
175echo '# On va chercher les fichiers necessaires a la simulation'
176echo '####################################################################'
177#Reminder : we are in $WWORKD = $SCRATCHD/$SIMU_dir = $SCRATCHD/$MAINDIR/$simul
178
179echo DEFDIR $DEFDIR
180echo SIMUDIR $SIMUDIR
181echo simul $simul
182
183if [ $reseau_local = 0 ] ; then mkdir DEF ; cd DEF ; $GET $DEFDIR/* . ; cd .. ; fi
184
185cp -f DEF/* .
186#---The following changes in .def files will only be visible in the running directory (on SCRATCH if $reseau_local = 0)
187# They concern variables that change during runtime : nday, dayref, anneeref, ndayh
188# The other "sed" were totally or partially moved in setup.sh, to be done in $MAINDIR/DEF/*.def, before creating $MAINDIR/$SIMU (more transparent)
189#sed -e 's/ok_guide=.*.$/ok_guide='$ok_guide'/' DEF/guide.def >| guide.def
190#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
191
192#=====!!!!!!!!====!!!!!!====!!!!+++====!!!!!!====!!!!!!!=====!!!!!!====z!!!====!!!!========!!!!!========!!!
193##POUR que des TESTS soyent tres RAPIDES (pour ex, verifier fichiers input), ON FORCE nday=1 jour  !!!
194#nday=1
195#=====!!!!!!!!====!!!!!!====!!!!+++====!!!!!!====!!!!!!!=====!!!!!!====z!!!====!!!!========!!!!!========!!!
196
197sed -e 's/nday=.*.$/nday='$nday'/' -e 's/dayref=.*.$/dayref='${dayref}'/' -e 's/anneeref=.*.$/anneeref='$year'/' DEF/run.def >| run.def
198sed -e 's/phys_out_filetimesteps=[[:space:]]*[0-9][0-9]day/phys_out_filetimesteps=  '$ndayh'day/'  DEF/config.def >| config.def
199#--- End of *.def changes in the $WWORKD only
200
201${GET} $SIMUDIR/start.$ym.nc start.nc
202${GET} $SIMUDIR/startphy.$ym.nc startphy.nc
203if [ $climato = 1 ] ; then
204   ${GET} $LIMITDIR/limit.nc limit.nc
205else
206   ${GET} $LIMITDIR/limit.$year.nc limit.nc
207fi
208
209
210echo '####################################################################'
211echo '# Imports des fichiers aerosols si flag_aerosol>0 dans config.def, '
212echo '# et si dans setup.sh on a "aerosols=clim" ou "aerosols=spla". '
213echo '# NOTE: Si "aerosols=n" dans setup.sh, script_SIMU met flag_aerosol=0 et on tourne SANS aerosols' 
214echo '####################################################################'
215if [ "`grep 'flag_aerosol=' config.def | head -1 | cut -d= -f2`" != 0 ] ; then
216  if [ $aerosols = clim ] ; then
217    # if [ $climato = 1 ] ; then suf=clim ; else suf=$year ; fi
218    suf=clim
219    # Le script pourrait être sophistique pour prendre des aerosols interannuels
220    ${GET} $LIMITDIR/aerosols.$suf.nc aerosols$year.nc
221    if [ ! -f aerosols1980.nc ] ; then ${GET} $LIMITDIR/aerosols.$suf.nc aerosols1980.nc ; fi
222    ${GET} $LIMITDIR/aerosols.nat.nc aerosols.nat.nc
223  fi
224
225  ## Ca doit etre la meme liste de fichiers rapatriee par setup.sh dans $LMDZ_INIT/SPLA_Init
226  ## et interpolee (setup.sh aussi) dans $SPLADIR
227  if [ $aerosols = spla ] ; then 
228    inputf="wth.dat cly.dat donnees_lisa.nc SOILSPEC.data \
229                carbon_emissions.nc sulphur_emissions_antro.nc  \
230                sulphur_emissions_nat.nc  sulphur_emissions_volc.nc"
231    for file in $inputf ; do ${GET} $INI/$file . ; done
232
233    change="dust.nc "
234    for file in $change ; do ${GET} $PERIOD/$file . ; done
235
236    # Le calcul d'emissions de sels marins utilise les vents ERA-10m interpoles sur grille_s (lonv,latu) avec le script era2gcm_uv10m.sh
237    # NB : GET=ln -s ; ERA10mDIR contient lui-meme le lien ERA10m vers le repertoire des vents interpoles $REA_uv10m (REA=ERA5, ERAI ou OPERA)
238    ventl="u10m.nc v10m.nc"
239    for file in $ventl ; do ${GET} $ERA10mDIR/${year}/${month}/$file . ; done
240  fi
241fi
242
243#----------------------------------------
244# Noveaux forcages a activer a l'avenir
245#   (commentes en attendant) :
246#----------------------------------------
247#for file in climoz_LMDZ.nc solarforcing.nc  taulwstrat.2D.nc  tauswstrat.2D.nc ; do
248#   ${GET} $LIMITDIR/$file $file
249#done
250#----------------------------------------
251
252${GET} $SIMUDIR/gcm.e gcm.e ; chmod  +x gcm.e
253
254
255if [ $VEGET = y ] ; then
256    set +e ; for t in stomate sechiba ; do cp $SIMUDIR/start_$t.$ym.nc ${t}_rest_in.nc ; done ; set -e
257    if [ "`grep RIVER_ROUTING orchidee.def |grep -i y`" ] ; then
258      set +e ; ln -s $LMDZ_INIT/routing_simple.nc . ; ln -s $LMDZ_INIT/routing.nc .
259               cp $SIMUDIR/start_routing.$ym.nc routing_start.nc ; set -e
260    fi
261
262#For Orchidee trunk (post-CMIP6), orchidee_pft.def must be copied in addition to orchidee.def
263    \cp -f DEF/orchidee*.def .
264
265# Test sur sechiba_rest_in.nc,
266#  supposant que les restarts pour sechiba, stomate, et routing le cas echeant,
267#  sont soit tous dispo, soit tous absents
268    if [ ! -f sechiba_rest_in.nc ] ; then
269       echo '#########################################################'
270       echo "Autoinitialisation d'orchidee au besoin"
271       echo '#########################################################'
272       get="ln -s $LMDZ_INIT/"
273       for file in cartepente2d_15min.nc \
274          lai2D.nc soils_param.nc soil_bulk_and_ph.nc alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc ; do ${get}$file ; done
275
276       ln -sf alb_bg_modisopt_2D_ESA_v2.nc alb_bg.nc
277
278       echo ATTENTION : ON UTILISE LES FICHIERS DE L ANNEE 2000
279       ${get}PFTmap_15PFT.v1_2000.nc PFTmap.nc
280       ${get}woodharvest_2000.nc woodharvest.nc
281
282       sed -e 's/^SECHIBA_restart_in.*./SECHIBA_restart_in=NONE/' \
283           -e 's/^STOMATE_RESTART_FILEIN.*./STOMATE_RESTART_FILEIN=NONE/' \
284           -i orchidee.def
285
286      if [ $veget = 7994 ] ; then
287         get="ln -s $LMDZ_INIT/"
288         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
289      fi
290
291    fi
292
293fi
294
295
296echo '#################################################################'
297echo    'Repertoire contenant les fichiers de reanalyses'
298echo '#################################################################'
299
300if [ "$ok_guide" = "y" ] ; then
301   \rm -f u.nc v.nc T.nc hur.nc
302   if [ -f u.nc ] ; then
303      echo PROBLEME D EFFACEMENT DES FICHIERS DE REANALYSES
304      exit
305   fi
306   for var in u v T hur ; do $GET $ERADIR/$year/$month/$var.nc $var.nc ; done
307   echo Fin du rapatriement des fichiers de guidage
308fi
309
310echo '##################################################################'
311echo    'liste des fichiers avant le lancement de la simulation'
312echo '##################################################################'
313ls -lrt
314#diff DEF ./
315
316echo '##################################################################'
317echo    'Lancement de la simulation'
318echo '##################################################################'
319
320time $RUNCMD $ntasks ./gcm.e > listing
321if [ ! -f restartphy.nc ] ; then
322echo PROBLEME PAS DE FICHIER RESTARTPHY
323exit
324fi
325
326echo '##################################################################'
327echo     'sauvegarde des fichiers de sortie'
328echo '##################################################################'
329
330# listing
331${PUT} listing ${SIMUDIR}/list$ym
332# if the listing for Orchidee is also needed, then uncomment the following line :
333#if [ $VEGET = y ] ; then ${PUT} out_orchidee_0000.0000 ${SIMUDIR}/out_orchidee$ym ; fi
334
335# restart(s)
336${PUT} restart.nc ${SIMUDIR}/start.$next.nc
337${PUT} restartphy.nc ${SIMUDIR}/startphy.$next.nc
338if [ $VEGET = y ] ; then for t in sechiba stomate ; do
339    f=${t}_rest_out.nc ; if [ -f $f ] ; then ${PUT} $f ${SIMUDIR}/start_$t.$next.nc ; fi ; done 
340    f=routing_restart.nc ; if [ -f $f ] ; then ${PUT} $f ${SIMUDIR}/start_routing.$next.nc ; fi
341fi
342
343# fichiers "histoires"
344# 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
345liste_out="histmth histday histhf histmthCOSP Xhistins XhistLES sechiba_history sechiba_history_4dim sechiba_out_2 stomate_history stomate_ipcc_history diag_routing dynzon"
346xios_used=0
347
348for fileout in $liste_out ; do
349  if [ -f  $fileout.nc ] ; then 
350     ${PUT} $fileout.nc ${SIMUDIR}/$fileout.$ym.nc
351     xios_used=1
352  fi
353done
354
355if [ $xios_used = 0 ] ; then
356  $GET $SIMUDIR/reb.sh
357  chmod +x reb.sh
358  ./reb.sh $ym $SIMUDIR $liste_out
359fi
360
361if [ -f guide_ins.nc ] ; then ${PUT} guide_ins.nc ${SIMUDIR}/guide_ins.$ym.nc ; fi
362
363echo '##################################################################'
364echo     'preparation et lancement de la simulation suivante'
365echo '##################################################################'
366
367# Gestion du fichier etat de controle de la simulation
368echo $ym OK >> etat
369echo $next a faire >> etat
370# ${PUT} etat $SIMUDIR/etat # Pas necessaire car etat est un lien vers $SIMUDIR/etat
371
372# set initialisation_iso to 0 for next run to read isotopes from restart files
373if [ $isotopes = y ] ; then
374   sed -i 's/^initialisation_iso=.*.$/initialisation_iso=0/' $SIMUDIR/DEF/iso.def
375fi
376set +e ; \rm out* sec* sta* list* rest* gcm.e aer* ; set -e
377
378# Arret si on est arrive au bout
379if [ $next =  $stopsim ] ; then
380   echo 'On arrive au bout, simulation next:'$next', stopsim:'$stopsim
381   # Cas particulier ou on veut chainer plusieurs simulations multi annuelles.
382   # pour le tuning automatique.
383   # Ici on passe de SCM_1-019 a SCM_1-029
384   if [ "${simul:0:3}" = "SCM" ] ; then
385      pre="SCM_1-"
386      num=`echo $simul | sed -e 's/'$pre'//'`
387      # (( num = $num + 10 )) change a cause d un probleme avec 008
388      num=`echo $num | awk ' { print $1 + 10 } '`
389      num=`printf "%03d\n" $num`
390      simul_new=$pre$num
391      cd $SCRIPTDIR
392      if [ $num -le 250 ] ; then
393         sed -e 's/^simul=.*.$/simul='$simul_new'/' -e 's/^\# @ job_nam.*.=.*.$/\# @ job_name = '$simul_new'/' tmp_$simul >| tmp_$simul_new
394         $SUBMITCMD tmp_$simul_new
395      fi
396   fi
397   exit
398fi
399
400
401echo '##################################################################'
402echo      'lancement de la simulation suivante tmp_'$simul' depuis :'
403echo '##################################################################'
404pwd
405
406
407cd $SCRIPTDIR
408$SUBMITCMD tmp_$simul
Note: See TracBrowser for help on using the repository browser.