source: BOL/LMDZ_Setup/script_SIMU @ 4851

Last change on this file since 4851 was 4851, checked in by asima, 2 months ago

Correction to avoid crash with "More processors requested than permitted" on Jean-Zay.
The problem seemed solved by rev 4796, but apparently it was a short-time solution.

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