-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.sh
executable file
·306 lines (261 loc) · 6.15 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/bin/bash
set -u
set -o pipefail
usage() {
echo "Usage: $0 gnu | intel | intel_llvm [-all] [-ufslibs] [-preproc] [-model] [-post]"
exit 1
}
[[ $# -lt 2 ]] && usage
export COMPILER=$1
shift
if [[ $COMPILER == gnu ]]; then
export CC=${CC:-gcc}
export CXX=${CXX:-g++}
export FC=${FC:-gfortran}
export MPICC=${MPICC:-mpicc}
export MPICXX=${MPICXX:-mpicxx}
export MPIF90=${MPIF90:-mpif90}
elif [[ $COMPILER == intel ]]; then
if [[ $(command -v ftn) ]]; then
# Special case on Cray systems
export CC=${CC:-cc}
export CXX=${CXX:-CC}
export FC=${FC:-ftn}
export MPICC=${MPICC:-cc}
export MPICXX=${MPICXX:-CC}
export MPIF90=${MPIF90:-ftn}
else
export CC=${CC:-icc}
export CXX=${CXX:-icpc}
export FC=${FC:-ifort}
export MPICC=${MPICC:-mpiicc}
export MPICXX=${MPICXX:-mpiicpc}
export MPIF90=${MPIF90:-mpiifort}
fi
elif [[ $COMPILER == intel_llvm ]]; then
export CC=${CC:-icx}
export CXX=${CXX:-icpx}
export FC=${FC:-ifx}
export MPICC=${MPICC:-mpiicx}
export MPICXX=${MPICXX:-mpiicpx}
export MPIF90=${MPIF90:-mpiifx}
export I_MPI_CC=${CC}
export I_MPI_CXX=${CXX}
export I_MPI_F90=${FC}
else
usage
fi
BUILD_UFSLIBS=no
BUILD_PREPROC=no
BUILD_MODEL=no
BUILD_POST=no
while [[ $# -gt 0 ]]; do
opt=$1
case $opt in
-all)
BUILD_UFSLIBS=yes
BUILD_PREPROC=yes
BUILD_MODEL=yes
BUILD_POST=yes
shift
;;
-ufslibs)
BUILD_UFSLIBS=yes
shift
;;
-preproc)
BUILD_PREPROC=yes
shift
;;
-model)
BUILD_MODEL=yes
shift
;;
-post)
BUILD_POST=yes
shift
;;
*)
echo "unknown option ${opt}"
usage
esac
done
echo "BUILD_UFSLIBS = ${BUILD_UFSLIBS}"
echo "BUILD_PREPROC = ${BUILD_PREPROC}"
echo "BUILD_MODEL = ${BUILD_MODEL}"
echo "BUILD_POST = ${BUILD_POST}"
MYDIR=$(dirname "$(realpath "$0")")
readonly MYDIR
export OMPI_CC=${CC}
export OMPI_CXX=${CXX}
export OMPI_FC=${FC}
# print compiler version
echo
echo "CC = ${CC}"
echo "CXX = ${CXX}"
echo "FC = ${FC}"
which ${CC}
which ${CXX}
which ${FC}
${CC} --version | head -1
${CXX} --version | head -1
${FC} --version | head -1
echo
echo "MPICC = ${MPICC}"
echo "MPICXX = ${MPICXX}"
echo "MPIF90 = ${MPIF90}"
which ${MPICC}
which ${MPICXX}
which ${MPIF90}
${MPICC} --version | head -1
${MPICXX} --version | head -1
${MPIF90} --version | head -1
echo
cmake --version | head -1
echo
#
# ufslibs
#
if [ $BUILD_UFSLIBS == yes ]; then
SECONDS=0
printf '%-.30s ' "Building ufslibs .........................."
(
cd libs/ufslibs
rm -rf build install
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install
make -j 8
) > log_ufslibs 2>&1
status=$?
if [ $status -eq 0 ]; then
printf 'done [%4d sec]\n' ${SECONDS}
else
printf 'FAILED [%4d sec]\n' ${SECONDS}
echo
echo "---------------------------------------------------------------"
echo "--- log_ufslibs"
cat log_ufslibs
echo "---------------------------------------------------------------"
for f in libs/ufslibs/build/*-prefix/src/*-stamp/*-*-*.log; do
echo
echo "---------------------------------------------------------------"
echo "--- $f"
cat $f
echo "---------------------------------------------------------------"
done
exit 1
fi
fi
export CC=${MPICC}
export CXX=${MPICXX}
export FC=${MPIF90}
ufslibs_install_prefix=${MYDIR}/libs/ufslibs/install
export ZLIB_ROOT=${ufslibs_install_prefix}/zlib
export PNG_ROOT=${ufslibs_install_prefix}/libpng
export NetCDF_ROOT=${ufslibs_install_prefix}/netcdf
export PIO_ROOT=${ufslibs_install_prefix}/pio
export ESMFMKFILE=${ufslibs_install_prefix}/esmf/lib/esmf.mk
export ESMF_ROOT=${ufslibs_install_prefix}/esmf
export FMS_ROOT=${ufslibs_install_prefix}/fms
export bacio_ROOT=${ufslibs_install_prefix}/bacio
export g2_ROOT=${ufslibs_install_prefix}/g2
export g2tmpl_ROOT=${ufslibs_install_prefix}/g2tmpl
export ip_ROOT=${ufslibs_install_prefix}/ip
export sp_ROOT=${ufslibs_install_prefix}/sp
export w3emc_ROOT=${ufslibs_install_prefix}/w3emc
export crtm_ROOT=${ufslibs_install_prefix}/crtm
export GFTL_ROOT=${ufslibs_install_prefix}/gftl
export GFTL_SHARED_ROOT=${ufslibs_install_prefix}/gftl_shared
export MAPL_ROOT=${ufslibs_install_prefix}/mapl
export SCOTCH_ROOT=${ufslibs_install_prefix}/scotch
#
# preproc
#
if [ $BUILD_PREPROC == yes ]; then
SECONDS=0
printf '%-.30s ' "Building preproc ..........................."
(
cd src/preproc
rm -rf build
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX="${MYDIR}" -DBUILD_TESTING=OFF -DGBLEVENTS=OFF
make -j 8
make install
) > log_preproc 2>&1
status=$?
if [ $status -eq 0 ]; then
printf 'done [%4d sec]\n' ${SECONDS}
else
printf 'FAILED [%4d sec]\n' ${SECONDS}
cat log_preproc
exit 1
fi
fi
#
# model
#
if [ $BUILD_MODEL == yes ]; then
SECONDS=0
printf '%-.30s ' "Building model ..........................."
(
cd src/model
rm -rf build
mkdir build
cd build
cmake .. -DAPP=ATM \
-DCCPP_SUITES="FV3_GFS_v16" \
-D32BIT=ON \
-DINLINE_POST=ON \
-DPARALLEL_NETCDF=ON \
-DCMAKE_INSTALL_PREFIX=install
# cmake .. -DAPP=S2S \
# -DCCPP_SUITES="FV3_GFS_v16_coupled" \
# -DCMAKE_INSTALL_PREFIX=install
# cmake .. -DAPP=ATMAERO \
# -DCCPP_SUITES="FV3_GFS_v16" \
# -DCMAKE_INSTALL_PREFIX=install
# cmake .. -DAPP=S2SWA \
# -DCCPP_SUITES="FV3_GFS_v17_coupled_p8_ugwpv1" \
# -D32BIT=ON \
# -DPDLIB=ON \
# -DCMAKE_INSTALL_PREFIX=install
make -j 8
make install
cp ufs_model ${MYDIR}/bin/ufs_model
) > log_model 2>&1
status=$?
if [ $status -eq 0 ]; then
printf 'done [%4d sec]\n' ${SECONDS}
else
printf 'FAILED [%4d sec]\n' ${SECONDS}
cat log_model
exit 1
fi
fi
#
# post
#
if [ $BUILD_POST == yes ]; then
SECONDS=0
printf '%-.30s ' "Building post ..........................."
(
cd src/model/FV3/upp
rm -rf build
mkdir build
cd build
cmake .. -DBUILD_WITH_NEMSIO=OFF
make -j 8
cp sorc/ncep_post.fd/upp.x ${MYDIR}/bin/ufs_post
) > log_post 2>&1
status=$?
if [ $status -eq 0 ]; then
printf 'done [%4d sec]\n' ${SECONDS}
else
printf 'FAILED [%4d sec]\n' ${SECONDS}
cat log_post
exit 1
fi
fi
echo "Done!"