source: BOL/LMDZ_Setup/lmdz_env.sh @ 5875

Last change on this file since 5875 was 5848, checked in by fhourdin, 7 weeks ago

era2gcm.sh + cdo jean-zay

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