source: BOL/LMDZ_Setup_amaury/script_SIMU @ 4958

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

(WIP) remove $GROUPE & prepare adastra env

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