source: BOL/LMDZ_Setup/lmdz_env.sh @ 5557

Last change on this file since 5557 was 5552, checked in by fhourdin, 4 days ago

New post processing and some fix on environment

File size: 11.4 KB
Line 
1#!/bin/bash
2########################################################
3# This file loads the required modules and sets the paths for simulations
4# To modify the paths:
5#    1) In the <set_env> function, find the section corresponding to your machine
6#    2) Modify the variables, which are documented in the *) section of <set_env>
7# See the end of <set_env> for the explanation of each
8########################################################
9
10# <root_dir> will be set by sed by setup.sh here
11pwd
12
13root_dir=.
14check_loc=1
15
16echo root_dir $root_dir
17if [[ ! -d $root_dir ]]; then
18  echo "STOP in $PWD/lmdz_env.sh: root_dir $root_dir not found, either you are running on an unsupported cluster, or the initialisation failed midway"; exit 1
19fi
20pwd
21echo root_dir $root_dir
22if [[ ! -f $root_dir/lmdz_env.sh ]]; then
23  echo "STOP in $PWD/lmdz_env.sh: lmdz_env.sh not found on root_dir $root_dir, either you are running on an unsupported cluster, or the initialisation failed midway"; exit 1
24fi
25if [[ ! -f $root_dir/.lmdz_setup_root_dir  && $check_loc = 1 ]]; then
26  echo "STOP in $PWD/lmdz_env.sh: file .lmdz_setup_root_dir not found in root_dir $root_dir"; exit 1
27fi
28
29pub_store=1
30PARALLEL=1
31
32function get_hostname {
33  if grep -q "Adastra" /etc/motd 2>/dev/null ; then
34    hostname="adastra"
35  elif which idrquota &> /dev/null; then
36    hostname="jean-zay"
37  else
38    hostname=$(hostname)
39  fi
40}
41
42function set_env {  # Platform-specific
43  case ${hostname:0:5} in
44#-------------------------------------------------------------------------
45    jean-) # Jean-zay, Idris-CNRS super computer
46#-------------------------------------------------------------------------
47      module purge
48      compilo=19.0.4 # available 2013.0, 2017.2
49      module load intel-compilers/$compilo
50      #module load intel-mpi/$compilo
51      module load intel-mkl/$compilo
52      module load hdf5/1.10.5-mpi
53      module load netcdf/4.7.2-mpi
54      module load netcdf-fortran/4.5.2-mpi
55      module load subversion/1.9.7
56      #Pour module gcc, voir : https://trac.lmd.jussieu.fr/LMDZ/wiki/PortageJeanZay
57      #module load gcc/6.5.0
58      module load nco
59      module load cdo
60      # Imputation de la consommation sur le groupe (projet) actif par defaut,
61      #   idrproj indique le groupe (projet) actif par defaut
62      #   idrproj -d newproj   redefinit "newproj" en tant que  projet actif,
63      #        alors $STORE, $WORK etc vont designer les espaces de "newproj")
64      account="lmd"  # $(idrproj | grep active | awk '{ print $1}') doesn't work on compute nodes
65      ARCH="X64_JEANZAY_PBIOIPSL"
66      SIMRUNBASEDIR="$SCRATCH/$(basename $root_dir)"
67      LMDZD="$WORK/LMDZD"
68      LMDZ_INIT="$WORK/LMDZ/pub"
69      NB_MPI_MAX=2000
70      NB_OMP_MAX=20
71      NB_CORE_PER_NODE_MAX=0
72      MPICMD="srun -n"
73      RUNBASHCMD="srun -A $account@cpu --label -n 1 -c"
74      #SUBMITCMD="sbatch -A $account@cpu"
75      submitcmd() {
76         sbatch -A $account@cpu $1
77      }
78      ;;
79#-------------------------------------------------------------------------
80    spiri) # Spirit : IPSL cluster
81#-------------------------------------------------------------------------
82      module purge
83      module load subversion/1.13.0
84      module load gcc/11.2.0
85      module load openmpi/4.0.7
86      module load cdo/2.3.0
87
88      ARCH="X64_MESOIPSL-GNU"
89      SIMRUNBASEDIR="$SCRATCH/$(basename $root_dir)"
90      LMDZD="$root_dir/LMDZD"
91      LMDZ_INIT="$HOME/LMDZ/pub"
92      NB_MPI_MAX=5
93      NB_OMP_MAX=1
94      NB_CORE_PER_NODE_MAX=0
95      N_HYPERTHREADING=1
96      MPICMD="mpirun -np"  # on spirit, we can't run MPI using srun from within sbatch
97      RUNBASHCMD="bash"
98      #SUBMITCMD="sbatch"
99      submitcmd() {
100         sbatch $1
101      }
102      ;;
103#-------------------------------------------------------------------------
104    adast) # Adastra, Cines computing center
105#-------------------------------------------------------------------------
106      module purge
107      module load PrgEnv-gnu  # we need to load the env because lmdz links some shared libraries
108      module load gcc/13.2.0  # required, see https://dci.dci-gitlab.cines.fr/webextranet/user_support/index.html#prgenv-and-compilers
109      export CRAY_CPU_TARGET=x86-64  # to suppress warnings during Cmake netcdf95 build
110      export FI_CXI_RX_MATCH_MODE=hybrid  # 09/24 otherwise we get random SIGABRT e.g. "libfabric:2490616:1725895288::cxi:core:cxip_ux_onload_cb():2657<warn> c1456: RXC (0x5130:21) PtlTE 84:[Fatal] LE resources not recovered during flow control. FI_CXI_RX_MATCH_MODE=[hybrid|software] is required"
111
112      function cdo {  # cdo is available as a spack cmd which requires a specific, incompatible env
113        unset cdo
114        module purge
115        # Commentaire conserve pour l'option "develop". Ca a marché puis plus
116        #module load develop GCC-CPU-4.0.0 cdo/2.4.2-omp-mpi
117        module load GCC-CPU-3.2.0 cdo/2.4.2-omp-mpi
118        cdo "$@"
119        set_env
120      }
121
122      function ferret {
123        unset ferret
124        module purge
125        module load GCC-CPU-3.1.0
126        module load ferret
127        ferret "$@"
128        set_env
129      }
130
131      account=$(/usr/sbin/my_project.py -l 2>&1 | head -1 | cut -d " " -f 3- | cut -c 5-)
132      ARCH="X64_ADASTRA-GNU"
133      SIMRUNBASEDIR="$SCRATCHDIR/$(basename $root_dir)"
134      LMDZD="$WORKDIR/LMDZD"
135      LMDZ_INIT="$WORKDIR/LMDZ/pub"
136      NB_MPI_MAX=2000
137      NB_OMP_MAX=200
138      NB_CORE_PER_NODE_MAX=192
139      N_HYPERTHREADING=1  # Adastra has SMT=2 enabled, but we found no actual performance improvement for the latlon model. Maybe useful for Dynamico ?
140      MPICMD="srun -n"
141#      RUNBASHCMD="srun --label --account=$account --constraint=GENOA --ntasks-per-node=1 -n 1 --time=00:15:00 -c"
142      RUNBASHCMD="bash"  # On Adastra the docs says we can use login nodes for compilation
143      #SUBMITCMD="env $(env | grep -E "SLURM_|SBATCH_|SRUN_" | cut -d= -f1 | awk '{print "-u " $0}' | tr '\n' ' ' ) sbatch --constraint=GENOA --account=$account"  # we need to remove the existing SLURM variables otherwise they may be unexpectedly inherited by the submitted script
144      submitcmd() {
145        env $(env | grep -E "SLURM_|SBATCH_|SRUN_" | cut -d= -f1 | awk '{print "-u " $0}' | tr '\n' ' ' ) sbatch --constraint=GENOA --account=$account $1
146      }  # we need to remove the existing SLURM variables otherwise they may be unexpectedly inherited by the submitted script
147      ;;
148#-------------------------------------------------------------------------
149    *)  # Local machine.
150#-------------------------------------------------------------------------
151      SIMRUNBASEDIR="$root_dir/SCRATCH/"  # Where the simulations will be executed ($SIMRUNBASEDIR/LMDZ_Setup/...)
152      LMDZD="$root_dir/../LMDZD"  # Where the sources will be downloaded and compiled
153      if [[ $pub_store ]] ; then LMDZ_INIT="$HOME/LMDZ/pub" ; else LMDZ_INIT="$root_dir/LMDZ/pub" ; fi
154      # Old fortran versions
155      if [ $( gfortran --version | head -1  | awk ' { print $NF } ' | cut -d. -f1 ) -le 9 ] ; then 
156          gfortranv=gfortran9 ; archdir="-arch_dir arch"
157          if [ ! -d $LMDZD/arch ] ; then mkdir -p $LMDZD ; cd $LMDZD ; 
158            wget http://lmdz.lmd.jussieu.fr/pub/src_archives/misc/arch/LMDZ/arch-local-gfortran9.tar
159            tar xvf arch-local-gfortran9.tar
160            cd -
161          fi
162      else
163          gfortranv=gfortran ; archdir=
164      fi
165      if [[ $PARALLEL = 0 ]] ; then
166         ARCH="local-${gfortranv} $archdir"  # The arch file to use
167         NB_MPI_MAX=1  # Max number of MPI cores (only for running simulations)
168         NB_OMP_MAX=1  # Max number of OMP threads (only for running simulations)
169         MPICMD="" # command to run an mpi executable, as $MPICMD <nprocs> <script>
170      else
171         ARCH="local-${gfortranv}-parallel $archdir"  # The arch file to use
172         NB_MPI_MAX=2  # Max number of MPI cores (only for running simulations)
173         NB_OMP_MAX=2  # Max number of OMP threads (only for running simulations)
174         MPICMD="mpirun -np" # command to run an mpi executable, as $MPICMD <nprocs> <script>
175      fi
176
177      NB_CORE_PER_NODE_MAX=0  # Max number of cores per node (real cores, not hyperthreading - only for running simulations, cluster-specific)
178      N_HYPERTHREADING=1  # How many hyperthreading threads per physical core
179      RUNBASHCMD="bash" # command to run a bash job, as $runbashcmd (nthreads) <script> [nthreads only supplied if =/="bash"]
180      #SUBMITCMD="."  # command to sumbit a job, as $submitcmd <script>
181      submitcmd() {
182         nohup bash $1 > out.$$ 2>err.$$ &
183      }
184      ;;
185  esac
186}
187
188#-----------------------------------------------------------------------------------------------------
189function wget_pub() { # geting file from http:lmdz... and saving on $LMDZ_INIT
190#-----------------------------------------------------------------------------------------------------
191  local dir=$1
192  local file=$2
193  local target_dir=$LMDZ_INIT/$dir
194  if [ ! -f $target_dir/$file ] ; then
195     mkdir -p $target_dir
196     cd $target_dir
197     wget --no-check-certificate -nv "http://lmdz.lmd.jussieu.fr/pub/$dir/$file"
198     cd -
199  fi
200}
201
202#-----------------------------------------------------------------------------------------------------
203function cp_from_pub() { # geting file from http:lmdz... and saving on $LMDZ_INIT
204#-----------------------------------------------------------------------------------------------------
205  local dir=$1
206  local file=$2
207  cp -f $LMDZ_INIT/$dir/$file .
208}
209
210#-----------------------------------------------------------------------------------------------------
211function ln_from_pub() { # geting file from http:lmdz... and saving on $LMDZ_INIT
212#-----------------------------------------------------------------------------------------------------
213  local dir=$1
214  local file=$2
215  ln -sf $LMDZ_INIT/$dir/$file .
216}
217
218#-----------------------------------------------------------------------------------------------------
219function get_input_files() {
220#-----------------------------------------------------------------------------------------------------
221  local method=$1
222  local target=$2
223  case $target in
224
225      Orchidee) local files="PFTmap_IPCC_2000.nc cartepente2d_15min.nc routing.nc routing_simple.nc lai2D.nc \
226      alb_bg_modisopt_2D_ESA_v2.nc reftemp.nc \
227      soils_param.nc woodharvest_2000.nc PFTmap_15PFT.v1_2000.nc soil_bulk_and_ph.nc  \
228      ndep_nhx.nc ndep_noy.nc nfert_cropland.nc nfert_pasture.nc nmanure_cropland.nc nmanure_pasture.nc bnf.nc" ;;
229
230      AerChem) local files="aerosols1850_from_inca.nc aerosols9999_from_inca.nc" ;;
231
232      SPLA_WA/emissions) local files="donnees_lisa.nc SOILSPEC.data              \
233         cly.dat $( for i in $(seq -w 1 12 ) ; do echo dust$i.nc ; done ) wth.dat   \
234         carbon_emissions.nc sulphur_emissions_antro.nc sulphur_emissions_nat.nc \
235         sulphur_emissions_volc.nc" ;;
236
237      *) echo target $target non available in get_input_files ; exit 1 ;;
238  esac
239
240  if [[ $method != wget_pub && $method != ln_from_pub ]] ; then
241     echo method $method not available in get_input_files ; exit 1
242  fi
243  for file in $files ; do $method 3DInputData/$target $file ; done
244
245}
246
247get_hostname
248echo "Setting up lmdz_env on $hostname"
249set_env
250
251# A reactiver eventuellement pour permettre que les variables soient exportées dans les sous-shell
252# Mais certaines ne sont pas déclarées suivant les configs comme N_HYPERTHREADING
253#
254# export ARCH=$ARCH
255# export SIMRUNBASEDIR=$SIMRUNBASEDIR
256# export LMDZD=$LMDZD
257# export LMDZ_INIT=$LMDZ_INIT
258# export NB_MPI_MAX=$NB_MPI_MAX
259# export NB_OMP_MAX=$NB_OMP_MAX
260# export NB_CORE_PER_NODE_MAX=$NB_CORE_PER_NODE_MAX
261# export N_HYPERTHREADING=$N_HYPERTHREADING
262# export MPICMD=$MPICMD
263# export RUNBASHCMD=$RUNBASHCMD
Note: See TracBrowser for help on using the repository browser.