source: BOL/script_SIMU @ 4609

Last change on this file since 4609 was 4609, checked in by asima, 3 years ago

Initial import of LMDZ_configure environment.
Folder's content is identical to TEST_PROD from
https://lmdz.lmd.jussieu.fr/pub/Training/Archive/tutorial_prod.tar_v20230705.

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