1+ ! /bin/bash -e
2+ # ## For NCAR machines, this script should be run as
3+ # ## $ qcmd -- ./build_examples.sh
4+
5+ echo " Starting build at ` date` "
6+
7+ # Save various paths to use as shortcuts
8+ cd ../..
9+ INTERFACE_ROOT=` pwd -P`
10+ MKMF_ROOT=${INTERFACE_ROOT} /standalone/mkmf
11+ TEMPLATE_DIR=${INTERFACE_ROOT} /standalone/templates
12+ MOM_ROOT=${INTERFACE_ROOT} /MOM6
13+ cd ../..
14+ CESM_ROOT=` pwd -P`
15+ SHR_ROOT=${CESM_ROOT} /share
16+ FMS_ROOT=${CESM_ROOT} /libraries/FMS
17+
18+ # Default compiler
19+ COMPILER=" intel"
20+ MACHINE=" ncar"
21+ DEBUG=0 # Set to False, or REPRO Mode!
22+
23+ # Parse command line arguments
24+ while [[ " $# " -gt 0 ]]; do
25+ case $1 in
26+ --compiler)
27+ COMPILER=" $2 "
28+ shift ;;
29+ --machine)
30+ MACHINE=" $2 "
31+ shift ;;
32+ --debug)
33+ DEBUG=1 ;;
34+ * )
35+ echo " Unknown parameter passed: $1 "
36+ echo " Usage: $0 [--compiler <compiler>] [--machine <machine>]"
37+ exit 1 ;;
38+ esac
39+ shift
40+ done
41+ echo " Using compiler: $COMPILER "
42+ echo " Using machine: $MACHINE "
43+
44+ TEMPLATE=${TEMPLATE_DIR} /${MACHINE} -${COMPILER} .mk
45+
46+ # Throw error if template does not exist:
47+ if [ ! -f $TEMPLATE ]; then
48+ echo " ERROR: Template file $TEMPLATE does not exist."
49+ echo " Templates are based on the machine and compiler arguments: machine-compiler.mk. Available templates are:"
50+ ls ${TEMPLATE_DIR} /* .mk
51+ echo " Exiting."
52+ exit 1
53+ fi
54+
55+ # Set -j option based on the MACHINE argument
56+ case $MACHINE in
57+ " homebrew" )
58+ JOBS=2
59+ ;;
60+ " ubuntu" )
61+ JOBS=4
62+ ;;
63+ " ncar" )
64+ JOBS=32
65+ ;;
66+ * )
67+ echo " Invalid machine type for make -j option: $MACHINE "
68+ exit 1
69+ ;;
70+ esac
71+
72+ if [ " ${DEBUG} " == 1 ]; then
73+ BLD_ROOT=${COMPILER} -debug
74+ else
75+ BLD_ROOT=${COMPILER}
76+ fi
77+
78+
79+ # Load modules for NCAR
80+ if [ " $MACHINE " == " ncar" ]; then
81+ HOST=` hostname`
82+ # Load modules if on derecho
83+ if [ ! " ${HOST: 0: 5} " == " crhtc" ] && [ ! " ${HOST: 0: 6} " == " casper" ]; then
84+ module --force purge
85+ . /glade/u/apps/derecho/23.09/spack/opt/spack/lmod/8.7.24/gcc/7.5.0/c645/lmod/lmod/init/sh
86+ module load cesmdev/1.0 ncarenv/23.09
87+ case $COMPILER in
88+ " intel" )
89+ module load craype intel/2023.2.1 mkl ncarcompilers/1.0.0 cmake cray-mpich/8.1.27 netcdf-mpi/4.9.2 parallel-netcdf/1.12.3 parallelio/2.6.2 esmf/8.6.0
90+ ;;
91+ " gnu" )
92+ module load craype gcc/12.2.0 cray-libsci/23.02.1.1 ncarcompilers/1.0.0 cmake cray-mpich/8.1.27 netcdf-mpi/4.9.2 parallel-netcdf/1.12.3 parallelio/2.6.2-debug esmf/8.6.0-debug
93+ ;;
94+ " nvhpc" )
95+ module load craype nvhpc/23.7 ncarcompilers/1.0.0 cmake cray-mpich/8.1.27 netcdf-mpi/4.9.2 parallel-netcdf/1.12.3 parallelio/2.6.2 esmf/8.6.0
96+ ;;
97+ * )
98+ echo " Not loading any special modules for ${COMPILER} "
99+ ;;
100+ esac
101+ fi
102+ fi
103+
104+ # 1) Build FMS
105+ cd ${INTERFACE_ROOT} /standalone/build
106+ mkdir -p ${BLD_ROOT} /FMS
107+ cd ${BLD_ROOT} /FMS
108+ ${MKMF_ROOT} /list_paths ${FMS_ROOT} /src
109+ # We need shr_const_mod.F90 and shr_kind_mod.F90 from ${SHR_ROOT}/src to build FMS
110+ echo " ${SHR_ROOT} /src/shr_kind_mod.F90" >> path_names
111+ echo " ${SHR_ROOT} /src/shr_const_mod.F90" >> path_names
112+ ${MKMF_ROOT} /mkmf -t ${TEMPLATE} -p libfms.a -c " -Duse_libMPI -Duse_netCDF -DSPMD" path_names
113+ make -j${JOBS} DEBUG=${DEBUG} libfms.a
114+
115+ # 2) Build MOM6
116+ cd ${INTERFACE_ROOT} /standalone/build
117+ mkdir -p ${BLD_ROOT} /MOM6
118+ cd ${BLD_ROOT} /MOM6
119+ ${MKMF_ROOT} /list_paths -l ${MOM_ROOT} /{config_src/infra/FMS2,config_src/memory/dynamic_symmetric,config_src/drivers/solo_driver,../externals/MARBL/src,config_src/external,src/{* ,* /* }}/
120+ ${MKMF_ROOT} /mkmf -t ${TEMPLATE} -o ' -I../FMS' -p MOM6 -l ' -L../FMS -lfms' -c ' -Duse_libMPI -Duse_netCDF -DSPMD' path_names
121+ make -j${JOBS} DEBUG=${DEBUG} MOM6
122+
123+ echo " Finished build at ` date` "
0 commit comments