-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcibw-build-mpi.sh
executable file
·367 lines (334 loc) · 10.1 KB
/
cibw-build-mpi.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#!/bin/bash
set -euo pipefail
mpiname="${MPINAME:-mpich}"
PROJECT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
PACKAGE=$PROJECT/package
SOURCE=${SOURCE:-$PACKAGE/source}
WORKDIR=${WORKDIR:-$PACKAGE/workdir}
DESTDIR=${DESTDIR:-$PACKAGE/install}
PREFIX=${PREFIX:-"/opt/$mpiname"}
if test "$mpiname" = "mpich"; then
version=$(sed -n 's/MPICH_VERSION=\(.*\)/\1/p' "$SOURCE"/maint/Version)
options=(
CC=cc
CXX=c++
--prefix="$PREFIX"
--with-device=ch4:"${variant:-ofi}"
--with-pm=hydra:gforker
--with-libfabric=embedded
--with-ucx=embedded
--with-hwloc=embedded
--with-yaksa=embedded
--disable-cxx
--disable-doc
--disable-static
--disable-opencl
--disable-libxml2
--disable-dependency-tracking
)
if test "${version%%.*}" -lt 4; then
options=("${options[@]/--disable-cxx}")
export FCFLAGS=-fallow-argument-mismatch
export FFLAGS=-fallow-argument-mismatch
fi
if test "$(uname)" = Darwin; then
export MPICH_MPICC_LDFLAGS="-Wl,-rpath,$PREFIX/lib"
export MPICH_MPICXX_LDFLAGS="-Wl,-rpath,$PREFIX/lib"
export MPICH_MPIFORT_LDFLAGS="-Wl,-rpath,$PREFIX/lib"
fi
disable_doc='s/^\(install-data-local:\s\+\)\$/\1#\$/'
sed -i.orig "$disable_doc" "$SOURCE"/Makefile.in
fi
if test "$mpiname" = "openmpi"; then
options=(
CC=cc
CXX=c++
--prefix="$PREFIX"
--disable-dlopen
--disable-oshmem
--without-ofi
--without-ucx
--without-psm2
--without-cuda
--without-rocm
--with-pmix=internal
--with-prrte=internal
--with-libevent=internal
--with-hwloc=internal
--disable-static
--disable-opencl
--disable-libxml2
--disable-libompitrace
--enable-mpi-fortran=mpifh
--disable-dependency-tracking
)
fi
if test "$(uname)" = Darwin; then
export MACOSX_DEPLOYMENT_TARGET="11.0"
if test "$(uname -m)" = x86_64; then
export MACOSX_DEPLOYMENT_TARGET="10.9"
export ac_cv_func_aligned_alloc="no" # macOS>=10.15
fi
fi
case $(uname) in
Linux) njobs=$(nproc);;
Darwin) njobs=$(sysctl -n hw.physicalcpu);;
esac
mkdir -p "$WORKDIR"
cd "$WORKDIR"
echo running configure
"$SOURCE"/configure "${options[@]}" || cat config.log
echo running make with "${njobs:-1}" jobs
make -j "${njobs:-1}" install DESTDIR="$DESTDIR"
fixup-mpich() {
cd "${DESTDIR}${PREFIX}"
rm -f include/*cxx.h
rm -f include/*.mod
rm -f include/*f.h
rm -fr include/rdma
rm -f bin/mpif77
rm -f bin/mpif90
rm -f bin/mpifort
rm -f bin/parkill
rm -f lib/libmpl.*
rm -f lib/libopa.*
rm -f lib/lib*mpi.a
rm -f lib/lib*mpi.la
rm -f lib/lib*mpich*.*
rm -f lib/lib*mpicxx.*
rm -f lib/lib*mpifort.*
rm -fr lib/pkgconfig
rm -fr share
cd "${DESTDIR}${PREFIX}"
rm -f bin/io_demo
rm -f bin/ucx_read_profile
rm -f lib/libuc[mpst]*.la
rm -f lib/ucx/libuct_*.la
rm -fr lib/cmake
headers=(mpi.h)
scripts=(mpicc mpic++ mpicxx)
executables=(mpichversion mpivars)
cd "${DESTDIR}${PREFIX}/include"
for header in "${headers[@]}"; do
sed -i.orig 's:^#include "mpicxx.h"::g' "$header"
rm "$header".orig
done
cd "${DESTDIR}${PREFIX}/bin"
for script in "${scripts[@]}"; do
test ! -L "$script" || continue
# shellcheck disable=SC2016
topdir='$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE:-$0}")/.." \&\& pwd)'
sed -i.orig s@^prefix=.*@prefix="$topdir"@ "$script"
sed -i.orig s:"$PREFIX":\"\$\{prefix\}\":g "$script"
sed -i.orig s:-Wl,-commons,use_dylibs::g "$script"
sed -i.orig s:/usr/bin/bash:/bin/bash:g "$script"
sed -i.orig s:-lmpicxx::g "$script"
rm "$script".orig
done
if test "$(uname)" = Linux; then
libmpi="libmpi.so.12"
cd "${DESTDIR}${PREFIX}/bin"
for exe in "${executables[@]}"; do
patchelf --set-rpath "\$ORIGIN/../lib" "$exe"
done
cd "${DESTDIR}${PREFIX}/lib"
if test -f "$libmpi".*.*; then
mv "$(readlink "$libmpi")" "$libmpi"
ln -sf "$libmpi" "${libmpi%.*}"
fi
if test -f libucp.so; then
patchelf --set-rpath "\$ORIGIN" "$libmpi"
for lib in libuc[mpst]*.so.?; do
if test -f "$lib".*; then
mv "$(readlink "$lib")" "$lib"
ln -sf "$lib" "${lib%.*}"
fi
patchelf --set-rpath "\$ORIGIN" "$lib"
for exe in "${executables[@]}"; do
patchelf --remove-needed "$lib" "../bin/$exe"
done
done
patchelf --add-rpath "\$ORIGIN/ucx" libuct.so.?
for lib in ucx/libuct_*.so.?; do
if test -f "$lib".*; then
mv "$(dirname "$lib")/$(readlink "$lib")" "$lib"
ln -srf "$lib" "${lib%.*}"
fi
patchelf --set-rpath "\$ORIGIN/.." "$lib"
done
fi
fi
if test "$(uname)" = Darwin; then
libdir="$PREFIX/lib"
libmpi="libmpi.12.dylib"
libpmpi="libpmpi.12.dylib"
cd "${DESTDIR}${PREFIX}/bin"
for exe in "${executables[@]}"; do
install_name_tool -change "$libdir/$libmpi" "@rpath/$libmpi" "$exe"
install_name_tool -change "$libdir/$libpmpi" "@rpath/$libpmpi" "$exe"
install_name_tool -add_rpath "@executable_path/../lib/" "$exe"
done
cd "${DESTDIR}${PREFIX}/lib"
for lib in "$libmpi" "$libpmpi"; do
install_name_tool -id "@rpath/$lib" "$lib"
install_name_tool -add_rpath "@loader_path/" "$lib"
done
install_name_tool -change "$libdir/$libpmpi" "@rpath/$libpmpi" "$libmpi"
fi
} # fixup-mpich()
fixup-openmpi() {
cd "${DESTDIR}${PREFIX}"
rm -fr include/ev*
rm -fr include/hwloc*
rm -fr include/pmix*
rm -fr include/prte*
rm -f include/mpif*.h
rm -f include/*/*/*mpifh.h
rm -f bin/ev*
rm -f bin/hwloc*
rm -f bin/lstopo*
#rm -f bin/pmix_info
rm -f bin/palloc
rm -f bin/pattrs
rm -f bin/pctrl
rm -f bin/pevent
rm -f bin/plookup
rm -f bin/pps
rm -f bin/pquery
#rm -f bin/prte_info
#rm -f bin/prte
#rm -f bin/prted
#rm -f bin/prterun
rm -f bin/prun
rm -f bin/psched
rm -f bin/pterm
rm -fr sbin
rm -f bin/pmixcc
rm -f bin/mpif77
rm -f bin/mpif90
rm -f bin/mpifort
rm -f bin/oshrun
rm -f lib/*.mod
rm -f lib/lib*.a
rm -f lib/lib*.la
rm -f lib/libmpi_mpifh*.*
rm -f lib/libmpi_usempi*.*
rm -f lib/libompitrace.*
rm -fr lib/openmpi
rm -fr lib/pkgconfig
rm -fr share/bash-completion
rm -fr share/doc
rm -fr share/man
rm -fr share/hwloc
rm -fr share/prte/rst
rm -f share/openmpi/mpif77-wrapper-data.txt
rm -f share/openmpi/mpif90-wrapper-data.txt
rm -f share/openmpi/mpifort-wrapper-data.txt
rm -f share/pmix/pmixcc-wrapper-data.txt
rm -f share/*/*.supp
rm -f share/*/*/example.conf
cd "${DESTDIR}${PREFIX}/bin"
unset executables
for exe in 'mpirun' 'ompi*' 'pmix*' 'prte*' 'opal*' 'orte*'; do
while IFS= read -r filename
do executables+=("$(basename "$filename")")
done < <(find . -name "$exe" -type f)
done
cd "${DESTDIR}${PREFIX}/lib"
unset libraries
for lib in 'lib*.so.*' 'lib*.*.dylib'; do
while IFS= read -r filename
do libraries+=("$(basename "$filename")")
done < <(find . -name "$lib" -type f)
done
if test "$(uname)" = Linux; then
cd "${DESTDIR}${PREFIX}/bin"
for exe in "${executables[@]}"; do
patchelf --set-rpath "\$ORIGIN/../lib" "$exe"
done
cd "${DESTDIR}${PREFIX}/lib"
for lib in lib*.so; do
patchelf --set-rpath "\$ORIGIN" "$lib"
soname=$(patchelf --print-soname "$lib")
if test -L "$soname"; then
mv "$(readlink "$soname")" "$soname"
ln -sf "$soname" "$lib"
fi
done
fi
if test "$(uname)" = Darwin; then
cd "${DESTDIR}${PREFIX}/bin"
for exe in "${executables[@]}"; do
install_name_tool -add_rpath "@executable_path/../lib/" "$exe"
unset dependencies
while IFS= read -r dep
do dependencies+=("$dep")
done < <(otool -L "$exe" | awk '(NR>1) {print $1}')
for dep in "${dependencies[@]}"; do
if test "$(dirname "$dep")" = "$(dirname "$PREFIX/lib/.")"; then
installname="@rpath/$(basename "$dep")"
install_name_tool -change "$dep" "$installname" "$exe"
fi
done
done
cd "${DESTDIR}${PREFIX}/lib"
for lib in lib*.*.dylib; do
install_name_tool -id "@rpath/$lib" "$lib"
install_name_tool -add_rpath "@loader_path/" "$lib"
while IFS= read -r dep
do dependencies+=("$dep")
done < <(otool -L "$lib" | awk '(NR>1) {print $1}')
for dep in "${dependencies[@]}"; do
if test "$(dirname "$dep")" = "$(dirname "$PREFIX/lib/.")"; then
installname="@rpath/$(basename "$dep")"
install_name_tool -change "$dep" "$installname" "$lib"
fi
done
done
fi
cd "${DESTDIR}${PREFIX}/share/openmpi"
for cmd in mpicc mpic++ mpicxx mpiCC ortecc; do
wrapper_data="$cmd-wrapper-data.txt"
test -e "$wrapper_data" || continue
test ! -L "$wrapper_data" || continue
flags="\(linker_flags=\) *"
rpath="-Wl,-rpath,@{libdir}"
sed -i.orig "s:^$flags$:\1$rpath:" "$wrapper_data"
flags="\(linker_flags=-L\${libdir}\) *"
rpath="-Wl,-rpath,\${libdir}"
sed -i.orig "s:^$flags$:\1 $rpath:" "$wrapper_data"
rm "$wrapper_data".orig
done
cd "${DESTDIR}${PREFIX}/bin"
wrapper_cmd=opal_wrapper
wrapper_src="$PROJECT/cibw-ompi-wrapper.c"
wrapper_bin="$WORKDIR/cibw-ompi-wrapper.exe"
cc -DWRAPPER="$wrapper_cmd" "$wrapper_src" -o "$wrapper_bin"
executables=(mpicc mpic++ mpicxx mpiCC ortecc)
for exe in "${executables[@]}"; do
test -e "$exe" || continue
test -L "$exe" || continue
install "$wrapper_bin" "$exe"
done
cd "${DESTDIR}${PREFIX}/bin"
if test -f prterun; then
executor=mpirun
wrapper=ompirun_wrapper
else
executor=orterun
wrapper=orterun_wrapper
fi
mv "$executor" "$wrapper"
ln -s "$wrapper" "$executor"
wrapper_src="$PROJECT/cibw-ompi-wrapper.c"
wrapper_bin="$WORKDIR/cibw-ompi-wrapper.exe"
cc -DWRAPPER="$wrapper" "$wrapper_src" -o "$wrapper_bin"
executables=(mpirun mpiexec orterun)
for exe in "${executables[@]}"; do
test -e "$exe" || continue
test -L "$exe" || continue
install "$wrapper_bin" "$exe"
done
} # fixup-openmpi()
echo fixing install tree
fixup-"$mpiname"