-
Notifications
You must be signed in to change notification settings - Fork 0
/
bodega
executable file
·271 lines (169 loc) · 4.59 KB
/
bodega
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
#!/bin/bash
_debug() {
local readonly msg="$1"
echo "."
echo "bodega >> [Debug] << ${msg}"
echo "."
}
_error() {
local readonly msg="$1"
echo "."
echo "."
echo "bodega >> [Error] << ${msg}"
echo "."
echo "."
return 1
}
_error_fatal() {
local readonly msg="$1"
echo "."
echo "."
echo "bodega >> [Fatal Error] << ${msg}"
echo "."
echo "."
exit 1
}
_hw_check() {
local cpu_arch
local cpu_count
read cpu_arch <<< $( uname -p )
read cpu_count <<< $( getconf _NPROCESSORS_ONLN )
[[ ${cpu_arch} =~ ${1,,} ]] \
&& [[ ${cpu_count} =~ ${2,,} ]]
}
_os_check_linux() {
[[ -f /etc/os-release ]] && . /etc/os-release \
&& [[ ${1,,} =~ ${ID}${ID:+|}${ID_LIKE// /|} ]] \
&& [[ ${VERSION_ID} =~ ${2,,} ]] \
&& [[ ${CPE_NAME} =~ ${3,,} ]] \
&& return 0
return 1
}
_os_check_macos() {
echo
}
_denote_varlist_outset() {
local outset_vars
read outset_vars <<< $(
set 2>/dev/null | while read a
do [[ $a == *=* ]] || break
echo -n "${a:+ }${a/=*}"
done
)
BODEGA_VARLIST_OUTSET="${outset_vars}"
}
_uptake_varlist_outset() {
local uptake_vars="$@"
local outset_vars
read match_vars <<< $(
echo $BODEGA_VARLIST_OUTSET ${uptake_vars} | tr ' ' '\n' | sort | uniq -d | tr '\n' ' '
)
read outset_vars <<< $(
echo $BODEGA_VARLIST_OUTSET ${match_vars} | tr ' ' '\n' | sort | uniq -u | tr '\n' ' '
)
BODEGA_VARLIST_OUTSET="${outset_vars}"
}
_accrue_varlist_cmake_definitions() {
local current_vars
local latest_vars
local cmake_vars
read current_vars <<< $(
set 2>/dev/null | while read a
do [[ $a == *=* ]] || break
echo -n "${a:+ }${a/=*}"
done
)
# find the symmetric difference of the two var sets (outset and current)
read latest_vars <<< $(
echo $BODEGA_VARLIST_OUTSET ${current_vars} | tr ' ' '\n' | sort | uniq -u | tr '\n' ' '
)
# isolate new vars that serve as cmake definitions
read cmake_vars <<< $(
echo ${latest_vars} | tr ' ' '\n' | grep "^CMAKE_*" | tr '\n' ' '
)
BODEGA_VARLIST_CMAKE_DEFINITIONS="${cmake_vars}"
}
_render_cmdline_cmake_definitions() {
read cmake_defs <<< $(
echo $BODEGA_VARLIST_CMAKE_DEFINITIONS | tr ' ' '\n' | while read a
do [[ -n $a ]] || break
echo -n "${a:+ }-D${a}=${!a}"
done
echo
)
BODEGA_CMDLINE_CMAKE_DEFINITIONS="${cmake_defs}"
}
_enact_defaults_cmake() {
CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Release}
}
_setup_nersc_cori_haswell() {
# AVX2 only
module load cmake
}
_setup_nersc_cori_knl_cross_compile_scenario() {
# AVX512
module load cmake
# use flags to force cross-compile
CMAKE_C_FLAGS="-axMIC-AVX512,AVX2"
CMAKE_Fortran_FLAGS="-axMIC-AVX512,AVX2"
# https://github.com/ORNL-Fusion/stellinstall/blob/02da8103a846ef80190adf052abacd9741447708/trunk/setup_cmake#L279
# -DEXTRA_FLAGS="-qopenmp -axMIC-AVX512,AVX"
echo
}
_setup_nersc_cori() {
module load cmake
# use intel compiler and openmpi wrapper
CMAKE_Fortran_COMPILER=/opt/intel/compilers_and_libraries_2019.3.199/linux/bin/intel64/ifort
module load openmpi
}
_setup_macos_github() {
CMAKE_Fortran_COMPILER=/usr/local/opt/gfortran/bin/gfortran
}
_setup_ubuntu_github() {
cat /etc/os-release
}
_setup_windows_github() {
echo
}
__bodega_build() {
_denote_varlist_outset
_uptake_varlist_outset \
CMAKE_BUILD_TYPE \
CMAKE_Fortran_COMPILER
_enact_defaults_cmake
_accrue_varlist_cmake_definitions
[[ $NERSC_HOST =~ cori ]] \
&& _hw_check "x86_64" "64|272" \
&& _os_check_linux "rhel" "7.6" \
&& _setup_nersc_cori
[[ $BODEGA_OS == "macos-latest" ]] \
&& _setup_macos_github
[[ $BODEGA_OS == "ubuntu-latest" ]] \
&& _setup_ubuntu_github \
&& _debug "BODEGA_OS is $BODEGA_OS"
_accrue_varlist_cmake_definitions
_render_cmdline_cmake_definitions
echo; echo; _debug "print CMake definitions - BEGIN"
echo; echo $BODEGA_CMDLINE_CMAKE_DEFINITIONS | tr ' ' '\n'
echo; echo; _debug "print CMake definitions - END"
echo; echo
mkdir -p ./build && cd $_
cmake $BODEGA_CMDLINE_CMAKE_DEFINITIONS .. && make
# differentiate by:
# - compute_env: [ nersc github docker ]
# - os_type: [ ubuntu macos ]
# - mpi_wrapper: [ openmpi mpich intel ]
# -
}
__bodega_test() {
cd ./build && make test
}
BODEGA_VARLIST_OUTSET=''
BODEGA_VARLIST_CMAKE_DEFINITIONS=''
BODEGA_CMDLINE_CMAKE_DEFINITIONS=''
[[ -n "$1" ]] && "__bodega_$1" "$@"
#BODEGA_BUILD_TYPE
#BODEGA_OS
#source ./cmake_definitions
#-DCMAKE_BUILD_TYPE=Debug
#-DCMAKE_BUILD_TYPE=Release