source: BOL/LMDZ_Setup_amaury/script_SIMU

Last change on this file was 5006, checked in by abarral, 2 days ago

load env in era2gcm_tuto.sh
fix jeanzay detection
minor bugfix

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