source: BOL/LMDZ_Setup_amaury/script_SIMU @ 5152

Last change on this file since 5152 was 5078, checked in by abarral, 2 months ago

update cdo env for adastra
force simu in exclusive mode
force back OMP=2 for orchCMIP6+xios

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