forked from NOAA-EMC/RDASApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·184 lines (166 loc) · 4.7 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
#!/bin/bash
# build.sh
# 1 - determine host, load modules on supported hosts; proceed w/o otherwise
# 2 - configure; build; install
# 4 - optional, run unit tests
module purge
set -eu
START=$(date +%s)
dir_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $dir_root/ush/detect_machine.sh
# ==============================================================================
usage() {
set +x
echo
echo "Usage: $0 -p <prefix> | -t <target> -h"
echo
echo " -p installation prefix <prefix> DEFAULT: <none>"
echo " -c additional CMake options DEFAULT: <none>"
echo " -v build with verbose output DEFAULT: NO"
echo " -j number of build jobs DEFAULT: 4 on Orion, 6 on other machines"
echo " -f force a clean build DEFAULT: NO"
echo " -s only build a subset of the bundle DEFAULT: NO"
echo " -m select dycore DEFAULT: FV3andMPAS"
echo " -x build super executables DEFAULT: NO"
echo " -h display this message and quit"
echo
exit 1
}
# ==============================================================================
# Defaults:
INSTALL_PREFIX=""
CMAKE_OPTS=""
BUILD_TARGET="${MACHINE_ID:-'localhost'}"
BUILD_VERBOSE="NO"
CLEAN_BUILD="NO"
BUILD_JCSDA="YES"
BUILD_SUPER_EXE="NO"
DYCORE="FV3andMPAS"
COMPILER="${COMPILER:-intel}"
while getopts "p:c:m:j:hvfsx" opt; do
case $opt in
p)
INSTALL_PREFIX=$OPTARG
;;
c)
CMAKE_OPTS=$OPTARG
;;
m)
DYCORE=$OPTARG
;;
j)
BUILD_JOBS=$OPTARG
;;
v)
BUILD_VERBOSE=YES
;;
f)
CLEAN_BUILD=YES
;;
s)
BUILD_JCSDA=NO
;;
x)
BUILD_SUPER_EXE=YES
;;
h|\?|:)
usage
;;
esac
done
case ${BUILD_TARGET} in
hera | orion | hercules | jet | gaea )
echo "Building RDASApp on $BUILD_TARGET"
echo " Build initiated `date`"
[[ "${BUILD_TARGET}" != *gaea* ]] && source $dir_root/ush/module-setup.sh
module use $dir_root/modulefiles
module load RDAS/$BUILD_TARGET.$COMPILER
CMAKE_OPTS+=" -DMPIEXEC_EXECUTABLE=$MPIEXEC_EXEC -DMPIEXEC_NUMPROC_FLAG=$MPIEXEC_NPROC -DBUILD_GSIBEC=ON -DMACHINE_ID=$MACHINE_ID"
module list
;;
*)
echo "Building RDASApp on unknown target: $BUILD_TARGET"
exit
;;
esac
# Set default number of build jobs based on machine
if [[ $BUILD_TARGET == 'orion' ]]; then # lower due to memory limit on login nodes
BUILD_JOBS=${BUILD_JOBS:-4}
else # hera, hercules, jet, gaea
BUILD_JOBS=${BUILD_JOBS:-6}
fi
BUILD_DIR=${BUILD_DIR:-$dir_root/build}
if [[ $CLEAN_BUILD == 'YES' ]]; then
[[ -d ${BUILD_DIR} ]] && rm -rf ${BUILD_DIR}
elif [[ -d ${BUILD_DIR} ]]; then
printf "Build directory (${BUILD_DIR}) already exists\n"
printf "Please choose what to do:\n\n"
printf "[r]emove the existing directory\n"
printf "[c]ontinue building in the existing directory\n"
printf "[q]uit this build script\n"
read -p "Choose an option (r/c/q):" choice
case ${choice} in
[Rr]* ) rm -rf ${BUILD_DIR} ;;
[Cc]* ) ;;
* ) exit ;;
esac
fi
mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
# If INSTALL_PREFIX is not empty; install at INSTALL_PREFIX
[[ -n "${INSTALL_PREFIX:-}" ]] && CMAKE_OPTS+=" -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}"
# activate tests based on if this is cloned within the global-workflow
WORKFLOW_BUILD=${WORKFLOW_BUILD:-"OFF"}
CMAKE_OPTS+=" -DWORKFLOW_TESTS=${WORKFLOW_BUILD}"
# determine which dycore to use
if [[ $DYCORE == 'FV3' ]]; then
CMAKE_OPTS+=" -DFV3_DYCORE=ON"
builddirs="fv3-jedi iodaconv"
elif [[ $DYCORE == 'MPAS' ]]; then
CMAKE_OPTS+=" -DFV3_DYCORE=OFF -DMPAS_DYCORE=ON"
builddirs="mpas-jedi iodaconv"
elif [[ $DYCORE == 'FV3andMPAS' ]]; then
CMAKE_OPTS+=" -DFV3_DYCORE=ON -DMPAS_DYCORE=ON"
builddirs="fv3-jedi mpas-jedi iodaconv"
else
echo "$DYCORE is not a valid dycore option. Valid options are FV3 or MPAS"
exit 1
fi
# Link in MPAS-JEDI test data
if [[ $DYCORE == 'MPAS' || $DYCORE == 'FV3andMPAS' ]]; then
# Link in case data
echo "Linking in test data for MPAS-JEDI case"
$dir_root/rrfs-test/scripts/link_mpasjedi_expr.sh
fi
CMAKE_OPTS+=" -DMPIEXEC_MAX_NUMPROCS:STRING=120 -DBUILD_SUPER_EXE=$BUILD_SUPER_EXE"
# Configure
echo "Configuring ..."
set -x
cmake \
${CMAKE_OPTS:-} \
$dir_root/bundle
set +x
# Build
echo "Building ..."
set -x
if [[ $BUILD_JCSDA == 'YES' ]]; then
make -j $BUILD_JOBS VERBOSE=$BUILD_VERBOSE
else
for b in $builddirs; do
cd $b
make -j $BUILD_JOBS VERBOSE=$BUILD_VERBOSE
cd ../
done
fi
set +x
# Install
if [[ -n ${INSTALL_PREFIX:-} ]]; then
echo "Installing ..."
set -x
make install
set +x
fi
echo build finished: `date`
END=$(date +%s)
DIFF=$((END - START))
echo "Time taken to run the code: $DIFF seconds"
exit 0