Skip to content

Commit e96b65f

Browse files
committed
First Attempt - CESM Compilers for MOM Standalone
1 parent 91298d6 commit e96b65f

15 files changed

Lines changed: 1122 additions & 199 deletions

standalone/build/build_examples.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ ${MKMF_ROOT}/list_paths ${FMS_ROOT}/src
110110
echo "${SHR_ROOT}/src/shr_kind_mod.F90" >> path_names
111111
echo "${SHR_ROOT}/src/shr_const_mod.F90" >> path_names
112112
${MKMF_ROOT}/mkmf -t ${TEMPLATE} -p libfms.a -c "-Duse_libMPI -Duse_netCDF -DSPMD" path_names
113-
make -j${JOBS} ${REPRO_OR_DEBUG}=1 libfms.a
113+
make -j${JOBS} NETCDF=3 ${REPRO_OR_DEBUG}=1 libfms.a
114114

115115
# 2) Build MOM6
116116
cd ${INTERFACE_ROOT}/standalone/build
117117
mkdir -p ${BLD_ROOT}/MOM6
118118
cd ${BLD_ROOT}/MOM6
119119
${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/{*,*/*}}/
120120
${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} ${REPRO_OR_DEBUG}=1 MOM6
121+
make -j${JOBS} NETCDF=3 ${REPRO_OR_DEBUG}=1 MOM6
122122

123-
echo "Finished build at `date`"
123+
echo "Finished build at `date`"
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
USE_CESM=""
22+
DEBUG=0 # Set to False, or REPRO Mode!
23+
24+
# Parse command line arguments
25+
while [[ "$#" -gt 0 ]]; do
26+
case $1 in
27+
--compiler)
28+
COMPILER="$2"
29+
shift ;;
30+
--machine)
31+
MACHINE="$2"
32+
shift ;;
33+
--cesm)
34+
USE_CESM="_cesm" ;;
35+
--debug)
36+
DEBUG=1 ;;
37+
*)
38+
echo "Unknown parameter passed: $1"
39+
echo "Usage: $0 [--compiler <compiler>] [--machine <machine>]"
40+
exit 1 ;;
41+
esac
42+
shift
43+
done
44+
echo "Using compiler: $COMPILER"
45+
echo "Using machine: $MACHINE"
46+
echo "Using CESM: $USE_CESM"
47+
48+
TEMPLATE=${TEMPLATE_DIR}/${MACHINE}-${COMPILER}${USE_CESM}.mk
49+
50+
# Throw error if template does not exist:
51+
if [ ! -f $TEMPLATE ]; then
52+
echo "ERROR: Template file $TEMPLATE does not exist."
53+
echo "Templates are based on the machine and compiler arguments: machine-compiler.mk. Available templates are:"
54+
ls ${TEMPLATE_DIR}/*.mk
55+
echo "Exiting."
56+
exit 1
57+
fi
58+
59+
# Set -j option based on the MACHINE argument
60+
case $MACHINE in
61+
"homebrew" )
62+
JOBS=2
63+
;;
64+
"ubuntu" )
65+
JOBS=4
66+
;;
67+
"ncar")
68+
JOBS=32
69+
;;
70+
*)
71+
echo "Invalid machine type for make -j option: $MACHINE"
72+
exit 1
73+
;;
74+
esac
75+
76+
if [ "${DEBUG}" == 1 ]; then
77+
BLD_ROOT=${COMPILER}-debug
78+
else
79+
BLD_ROOT=${COMPILER}
80+
fi
81+
82+
if [ "${USE_CESM}" == "_cesm" ]; then
83+
BLD_ROOT=${BLD_ROOT}-cesm
84+
fi
85+
86+
87+
# Load modules for NCAR
88+
if [ "$MACHINE" == "ncar" ]; then
89+
HOST=`hostname`
90+
# Load modules if on derecho
91+
if [ ! "${HOST:0:5}" == "crhtc" ] && [ ! "${HOST:0:6}" == "casper" ]; then
92+
module --force purge
93+
. /glade/u/apps/derecho/23.09/spack/opt/spack/lmod/8.7.24/gcc/7.5.0/c645/lmod/lmod/init/sh
94+
module load cesmdev/1.0 ncarenv/23.09
95+
case $COMPILER in
96+
"intel" )
97+
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
98+
;;
99+
"gnu" )
100+
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
101+
;;
102+
"nvhpc" )
103+
module load craype nvhpc/24.3 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
104+
;;
105+
*)
106+
echo "Not loading any special modules for ${COMPILER}"
107+
;;
108+
esac
109+
fi
110+
fi
111+
112+
# 1) Build FMS
113+
cd ${INTERFACE_ROOT}/standalone/build
114+
mkdir -p ${BLD_ROOT}/FMS
115+
cd ${BLD_ROOT}/FMS
116+
${MKMF_ROOT}/list_paths ${FMS_ROOT}/src
117+
# We need shr_const_mod.F90 and shr_kind_mod.F90 from ${SHR_ROOT}/src
118+
# to build FMS
119+
echo "${SHR_ROOT}/src/shr_kind_mod.F90" >> path_names
120+
echo "${SHR_ROOT}/src/shr_const_mod.F90" >> path_names
121+
${MKMF_ROOT}/mkmf -t ${TEMPLATE} -p libfms.a -c "-Duse_libMPI -Duse_netCDF -DSPMD" path_names
122+
make -j${JOBS} DEBUG=${DEBUG} libfms.a
123+
124+
# 2) Build MOM6
125+
cd ${INTERFACE_ROOT}/standalone/build
126+
mkdir -p ${BLD_ROOT}/MOM6
127+
cd ${BLD_ROOT}/MOM6
128+
${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/{*,*/*}}/
129+
${MKMF_ROOT}/mkmf -t ${TEMPLATE} -o '-I../FMS' -p MOM6 -l '-L../FMS -lfms' -c '-Duse_libMPI -Duse_netCDF -DSPMD' path_names
130+
make -j${JOBS} DEBUG=${DEBUG} MOM6
131+
132+
echo "Finished build at `date`"

standalone/templates/ncar-gnu.mk

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,42 @@ LD = mpif90 $(MAIN_PROGRAM)
1515
# flags #
1616
#########
1717

18-
DEBUG =
19-
REPRO =
20-
VERBOSE =
21-
OPENMP =
18+
DEBUG = 0
2219

2320
MAKEFLAGS += --jobs=$(shell grep '^processor' /proc/cpuinfo | wc -l)
2421

2522
FPPFLAGS :=
2623

2724
FFLAGS := -fcray-pointer -fdefault-double-8 -fdefault-real-8 -Waliasing -ffree-line-length-none -fno-range-check -fallow-argument-mismatch
28-
FFLAGS += -I$(shell nc-config --includedir)
2925
FFLAGS += $(shell pkg-config --cflags-only-I mpich2-c)
30-
FFLAGS_OPT = -O3
3126
FFLAGS_REPRO = -O2 -fbounds-check
3227
FFLAGS_DEBUG = -O0 -g -W -fbounds-check -fbacktrace -ffpe-trap=invalid,zero,overflow
33-
FFLAGS_OPENMP = -fopenmp
34-
FFLAGS_VERBOSE =
3528

3629
CFLAGS := -D__IFC
37-
CFLAGS += -I$(shell nc-config --includedir)
30+
3831
CFLAGS += $(shell pkg-config --cflags-only-I mpich2-c)
39-
CFLAGS_OPT = -O2
40-
CFLAGS_OPENMP = -fopenmp
32+
CFLAGS_REPRO = -O2
4133
CFLAGS_DEBUG = -O0 -g
4234

43-
# Optional Testing compile flags. Mutually exclusive from DEBUG, REPRO, and OPT
44-
# *_TEST will match the production if no new option(s) is(are) to be tested.
45-
FFLAGS_TEST = -O2
46-
CFLAGS_TEST = -O2
4735

4836
LDFLAGS :=
49-
LDFLAGS_OPENMP := -fopenmp
50-
LDFLAGS_VERBOSE :=
5137

5238
ifneq ($(REPRO),)
53-
CFLAGS += $(CFLAGS_REPRO)
54-
FFLAGS += $(FFLAGS_REPRO)
55-
else ifneq ($(DEBUG),)
39+
40+
ifeq ($(DEBUG),1)
5641
CFLAGS += $(CFLAGS_DEBUG)
5742
FFLAGS += $(FFLAGS_DEBUG)
58-
else ifneq ($(TEST),)
59-
CFLAGS += $(CFLAGS_TEST)
60-
FFLAGS += $(FFLAGS_TEST)
6143
else
62-
CFLAGS += $(CFLAGS_OPT)
63-
FFLAGS += $(FFLAGS_OPT)
64-
endif
65-
66-
ifneq ($(OPENMP),)
67-
CFLAGS += $(CFLAGS_OPENMP)
68-
FFLAGS += $(FFLAGS_OPENMP)
69-
LDFLAGS += $(LDFLAGS_OPENMP)
70-
endif
71-
72-
ifneq ($(VERBOSE),)
73-
CFLAGS += $(CFLAGS_VERBOSE)
74-
FFLAGS += $(FFLAGS_VERBOSE)
75-
LDFLAGS += $(LDFLAGS_VERBOSE)
44+
CFLAGS += $(CFLAGS_REPRO)
45+
FFLAGS += $(FFLAGS_REPRO)
7646
endif
7747

78-
ifeq ($(NETCDF),3)
48+
FFLAGS += -I$(shell nc-config --includedir)
49+
CFLAGS += -I$(shell nc-config --includedir)
7950
# add the use_LARGEFILE cppdef
8051
ifneq ($(findstring -Duse_netCDF,$(CPPDEFS)),)
8152
CPPDEFS += -Duse_LARGEFILE
8253
endif
83-
endif
8454

8555
LIBS := $(shell nf-config --flibs) $(shell pkg-config --libs mpich2-f90)
8656
LDFLAGS += $(LIBS)
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# template for the GNU fortran compiler
2+
3+
############
4+
# commands #
5+
############
6+
FC = mpif90
7+
CC = gcc
8+
CXX = g++
9+
LD = mpif90 $(MAIN_PROGRAM)
10+
11+
#########
12+
# flags #
13+
#########
14+
15+
DEBUG =
16+
17+
MAKEFLAGS += --jobs=$(shell grep '^processor' /proc/cpuinfo | wc -l)
18+
19+
FPPFLAGS :=
20+
FC_AUTO_R8 := -fdefault-real-8 -fdefault-double-8
21+
FFLAGS := $(FC_AUTO_R8) -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none -fallow-argument-mismatch -fallow-invalid-boz -fcray-pointer
22+
FFLAGS_REPRO = -O
23+
FFLAGS_DEBUG = -g -Wall -Og -fbacktrace -ffpe-trap=zero,overflow -fcheck=bounds
24+
25+
26+
CFLAGS := -std=gnu99
27+
CFLAGS_REPRO = -O
28+
CFLAGS_DEBUG = -g -Wall -Og -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds
29+
30+
LDFLAGS :=
31+
32+
33+
ifeq ($(DEBUG),1)
34+
CFLAGS += $(CFLAGS_DEBUG)
35+
FFLAGS += $(FFLAGS_DEBUG)
36+
else
37+
CFLAGS += $(CFLAGS_REPRO)
38+
FFLAGS += $(FFLAGS_REPRO)
39+
endif
40+
41+
42+
# NetCDF Flags
43+
FFLAGS += -I$(shell nc-config --includedir)
44+
CFLAGS += -I$(shell nc-config --includedir)
45+
# add the use_LARGEFILE cppdef
46+
ifneq ($(findstring -Duse_netCDF,$(CPPDEFS)),)
47+
CPPDEFS += -Duse_LARGEFILE
48+
endif
49+
50+
# More CPPDefs
51+
CPPDEFS += -DFORTRANUNDERSCORE -DNO_R16 -DCPRGNU -DLINUX -DHAVE_GETTID
52+
# Linking Flags
53+
LIBS := $(shell nf-config --flibs) $(shell pkg-config --libs mpich2-f90)
54+
LDFLAGS += $(LIBS)
55+
56+
#---------------------------------------------------------------------------
57+
# you should never need to change any lines below.
58+
59+
# see the MIPSPro F90 manual for more details on some of the file extensions
60+
# discussed here.
61+
# this makefile template recognizes fortran sourcefiles with extensions
62+
# .f, .f90, .F, .F90. Given a sourcefile <file>.<ext>, where <ext> is one of
63+
# the above, this provides a number of default actions:
64+
65+
# make <file>.opt create an optimization report
66+
# make <file>.o create an object file
67+
# make <file>.s create an assembly listing
68+
# make <file>.x create an executable file, assuming standalone
69+
# source
70+
# make <file>.i create a preprocessed file (for .F)
71+
# make <file>.i90 create a preprocessed file (for .F90)
72+
73+
# The macro TMPFILES is provided to slate files like the above for removal.
74+
75+
RM = rm -f
76+
SHELL = /bin/csh -f
77+
TMPFILES = .*.m *.B *.L *.i *.i90 *.l *.s *.mod *.opt
78+
79+
.SUFFIXES: .F .F90 .H .L .T .f .f90 .h .i .i90 .l .o .s .opt .x
80+
81+
.f.L:
82+
$(FC) $(FFLAGS) -c -listing $*.f
83+
.f.opt:
84+
$(FC) $(FFLAGS) -c -opt_report_level max -opt_report_phase all -opt_report_file $*.opt $*.f
85+
.f.l:
86+
$(FC) $(FFLAGS) -c $(LIST) $*.f
87+
.f.T:
88+
$(FC) $(FFLAGS) -c -cif $*.f
89+
.f.o:
90+
$(FC) $(FFLAGS) -c $*.f
91+
.f.s:
92+
$(FC) $(FFLAGS) -S $*.f
93+
.f.x:
94+
$(FC) $(FFLAGS) -o $*.x $*.f *.o $(LDFLAGS)
95+
.f90.L:
96+
$(FC) $(FFLAGS) -c -listing $*.f90
97+
.f90.opt:
98+
$(FC) $(FFLAGS) -c -opt_report_level max -opt_report_phase all -opt_report_file $*.opt $*.f90
99+
.f90.l:
100+
$(FC) $(FFLAGS) -c $(LIST) $*.f90
101+
.f90.T:
102+
$(FC) $(FFLAGS) -c -cif $*.f90
103+
.f90.o:
104+
$(FC) $(FFLAGS) -c $*.f90
105+
.f90.s:
106+
$(FC) $(FFLAGS) -c -S $*.f90
107+
.f90.x:
108+
$(FC) $(FFLAGS) -o $*.x $*.f90 *.o $(LDFLAGS)
109+
.F.L:
110+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -listing $*.F
111+
.F.opt:
112+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -opt_report_level max -opt_report_phase all -opt_report_file $*.opt $*.F
113+
.F.l:
114+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c $(LIST) $*.F
115+
.F.T:
116+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -cif $*.F
117+
.F.f:
118+
$(FC) $(CPPDEFS) $(FPPFLAGS) -EP $*.F > $*.f
119+
.F.i:
120+
$(FC) $(CPPDEFS) $(FPPFLAGS) -P $*.F
121+
.F.o:
122+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c $*.F
123+
.F.s:
124+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -S $*.F
125+
.F.x:
126+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -o $*.x $*.F *.o $(LDFLAGS)
127+
.F90.L:
128+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -listing $*.F90
129+
.F90.opt:
130+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -opt_report_level max -opt_report_phase all -opt_report_file $*.opt $*.F90
131+
.F90.l:
132+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c $(LIST) $*.F90
133+
.F90.T:
134+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -cif $*.F90
135+
.F90.f90:
136+
$(FC) $(CPPDEFS) $(FPPFLAGS) -EP $*.F90 > $*.f90
137+
.F90.i90:
138+
$(FC) $(CPPDEFS) $(FPPFLAGS) -P $*.F90
139+
.F90.o:
140+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c $*.F90
141+
.F90.s:
142+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -c -S $*.F90
143+
.F90.x:
144+
$(FC) $(CPPDEFS) $(FPPFLAGS) $(FFLAGS) -o $*.x $*.F90 *.o $(LDFLAGS)

0 commit comments

Comments
 (0)