Skip to content

Commit 5bd4e80

Browse files
committed
Support for Open MPI
1 parent 9fc9988 commit 5bd4e80

10 files changed

+297
-14
lines changed

Diff for: .codespellrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://github.com/codespell-project/codespell #-*- mode: conf -*-
2+
3+
[codespell]
4+
ignore-words-list = pevent

Diff for: .github/workflows/cd-wheel.yml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ on: # yamllint disable-line rule:truthy
3939
type: choice
4040
options:
4141
- mpich
42+
- openmpi
4243
version:
4344
description: 'Version'
4445
default: ''

Diff for: .github/workflows/cd.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on: # yamllint disable-line rule:truthy
1212
type: choice
1313
options:
1414
- mpich
15+
- openmpi
1516
version:
1617
description: 'Version'
1718
default: ''

Diff for: README.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
# mpich-publish
1+
# mpi-publish
22

3-
This repository builds and publishes [MPICH](https://mpich.org)
4-
Python wheels able to run in a variety of
3+
This repository builds and publishes [MPICH](https://www.mpich.org) and
4+
[Open MPI](https://www.open-mpi.org/) Python wheels able to run in
5+
a variety of
56

67
- operating systems: *Linux*, *macOS*;
78
- processor architectures: *AMD64*, *ARM64*, *PPC64*;
89
- Python implementations: *CPython*, *PyPy*.
910

10-
MPICH wheels are uploaded to the [Anaconda.org](https://anaconda.org/mpi4py)
11+
MPI wheels are uploaded to the [Anaconda.org](https://anaconda.org/mpi4py)
1112
package server. These wheels can be installed with `pip` specifying the
1213
alternative index URL:
1314

1415
```sh
1516
python -m pip install mpich -i https://pypi.anaconda.org/mpi4py/simple
1617
```
1718

19+
```sh
20+
python -m pip install openmpi -i https://pypi.anaconda.org/mpi4py/simple
21+
```
22+
1823
> [!CAUTION]
19-
> MPICH wheels are distributed with a focus on ease of use, compatibility,
20-
> and interoperability. The Linux MPICH wheels are built in somewhat
21-
> constrained environments with relatively dated Linux distributions
24+
> MPI wheels are distributed with a focus on ease of use, compatibility, and
25+
> interoperability. The Linux wheels are built in somewhat constrained
26+
> environments with relatively dated Linux distributions
2227
> ([manylinux](https://github.com/pypa/manylinux) container images).
2328
> Therefore, they may lack support for high-performance features like
2429
> cross-memory attach (XPMEM/CMA). In production scenarios, it is recommended
25-
> to use external (either custom-built or system-provided) MPICH
26-
> installations.
30+
> to use external (either custom-built or system-provided) MPI installations.
2731
2832
> [!TIP]
2933
> [Intel MPI](https://software.intel.com/intel-mpi-library) distributes [Linux

Diff for: bootstrap.sh

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,24 @@ set -euo pipefail
33

44
mpiname=${MPINAME:-mpich}
55

6+
PROJECT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
7+
PACKAGE=$PROJECT/package
8+
SOURCE=$PACKAGE/source
9+
610
if test "$mpiname" = "mpich"; then
711
version=${VERSION:-4.2.0}
812
urlbase="https://www.mpich.org/static/downloads/$version"
913
tarball="$mpiname-$version.tar.gz"
1014
license=COPYRIGHT
1115
fi
1216

13-
SOURCE=package/source
17+
if test "$mpiname" = "openmpi"; then
18+
version=${VERSION:-5.0.2}
19+
urlbase=https://download.open-mpi.org/release/open-mpi/v${version%.*}
20+
tarball="$mpiname-$version.tar.gz"
21+
license=LICENSE
22+
fi
23+
1424
if test ! -d "$SOURCE"; then
1525
if test ! -f "$tarball"; then
1626
echo downloading "$urlbase"/"$tarball"...
@@ -21,6 +31,14 @@ if test ! -d "$SOURCE"; then
2131
echo extracting "$tarball" to "$SOURCE"...
2232
tar xf "$tarball"
2333
mv "$mpiname-$version" "$SOURCE"
34+
if test "$mpiname-$(uname)" = "openmpi-Darwin"; then
35+
cd "$SOURCE"/3rd-party
36+
tar xf libevent-*.tar.gz
37+
cd libevent-*
38+
echo running autogen.sh on "$(basename "$(pwd)")"
39+
./autogen.sh
40+
cd "$PROJECT"
41+
fi
2442
else
2543
echo reusing directory "$SOURCE"...
2644
fi

Diff for: check-wheel.sh

+23
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ if test "$mpiname" = "mpich"; then
7474
fi
7575
fi
7676

77+
if test "$mpiname" = "openmpi"; then
78+
headers=(
79+
"$data"/include/mpi.h
80+
)
81+
scripts=(
82+
"$data"/bin/mpicc
83+
"$data"/bin/mpic++
84+
"$data"/bin/mpicxx
85+
"$data"/bin/mpiexec
86+
"$data"/bin/mpirun
87+
)
88+
programs=(
89+
"$data"/bin/ompi_info
90+
"$data"/bin/opal_wrapper
91+
)
92+
libraries=(
93+
"$data"/lib/libmpi.*
94+
"$data"/lib/libopen-*.*
95+
)
96+
runlibs+='|lib(z|util|event.*|hwloc)'$soregex
97+
runlibs+='|lib(open-(pal|rte)|pmix)'$soregex
98+
fi
99+
77100
check-dso() {
78101
local dso=$1 out1="" out2=""
79102
echo checking "$dso"...

Diff for: cibw-build-mpi.sh

+164-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ set -euo pipefail
44
mpiname="${MPINAME:-mpich}"
55
variant="${VARIANT:-}"
66

7-
SOURCE=${SOURCE:-$PWD/package/source}
8-
WORKDIR=${WORKDIR:-$PWD/package/workdir}
9-
DESTDIR=${DESTDIR:-$PWD/package/install}
7+
PROJECT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
8+
PACKAGE=$PROJECT/package
9+
10+
SOURCE=${SOURCE:-$PACKAGE/source}
11+
WORKDIR=${WORKDIR:-$PACKAGE/workdir}
12+
DESTDIR=${DESTDIR:-$PACKAGE/install}
1013
PREFIX=${PREFIX:-"/opt/$mpiname"}
1114

1215
if test "$mpiname" = "mpich"; then
@@ -40,6 +43,30 @@ if test "$mpiname" = "mpich"; then
4043
sed -i.orig "$disable_doc" "$SOURCE"/Makefile.in
4144
fi
4245

46+
if test "$mpiname" = "openmpi"; then
47+
options=(
48+
--enable-debug # FIXME
49+
CC=cc
50+
CXX=c++
51+
--prefix="$PREFIX"
52+
--disable-dlopen
53+
--disable-oshmem
54+
--without-ofi
55+
--without-ucx
56+
--without-psm2
57+
--without-cuda
58+
--without-rocm
59+
--with-pmix=internal
60+
--with-prrte=internal
61+
--with-libevent=internal
62+
--with-hwloc=internal
63+
--disable-static
64+
--disable-sphinx
65+
)
66+
if test "$(uname)" = Darwin; then
67+
options=("${options[@]/--disable-static}") # libevent
68+
fi
69+
fi
4370

4471
if test "$(uname)" = Darwin; then
4572
export MACOSX_DEPLOYMENT_TARGET="11.0"
@@ -170,5 +197,139 @@ fi
170197

171198
} # fixup-mpich()
172199

200+
fixup-openmpi() {
201+
202+
cd "${DESTDIR}${PREFIX}"
203+
rm -fr include/ev*
204+
rm -fr include/hwloc*
205+
rm -fr include/pmix*
206+
rm -fr include/prte*
207+
rm -f include/mpif*.h
208+
rm -f include/*/*/*mpifh.h
209+
rm -f bin/ev*
210+
rm -f bin/hwloc*
211+
rm -f bin/lstopo*
212+
213+
#rm -f bin/pmix_info
214+
rm -f bin/palloc
215+
rm -f bin/pattrs
216+
rm -f bin/pctrl
217+
rm -f bin/pevent
218+
rm -f bin/plookup
219+
rm -f bin/pps
220+
rm -f bin/pquery
221+
222+
#rm -f bin/prte_info
223+
#rm -f bin/prte
224+
#rm -f bin/prted
225+
#rm -f bin/prterun
226+
rm -f bin/prun
227+
rm -f bin/psched
228+
rm -f bin/pterm
229+
230+
rm -fr sbin
231+
rm -f bin/pmixcc
232+
rm -f bin/mpif77
233+
rm -f bin/mpif90
234+
rm -f bin/mpifort
235+
rm -f bin/oshrun
236+
rm -f lib/*.mod
237+
rm -f lib/lib*.a
238+
rm -f lib/lib*.la
239+
rm -f lib/libmpi_mpifh*.*
240+
rm -f lib/libmpi_usempi*.*
241+
rm -f lib/libompitrace.*
242+
rm -fr lib/openmpi
243+
rm -fr lib/pkgconfig
244+
rm -fr share/bash-completion
245+
rm -fr share/doc
246+
rm -fr share/man
247+
rm -fr share/hwloc
248+
rm -fr share/prte/rst
249+
rm -f share/openmpi/mpif77-wrapper-data.txt
250+
rm -f share/openmpi/mpif90-wrapper-data.txt
251+
rm -f share/openmpi/mpifort-wrapper-data.txt
252+
rm -f share/pmix/pmixcc-wrapper-data.txt
253+
rm -f share/*/*.supp
254+
rm -f share/*/*/example.conf
255+
256+
cd "${DESTDIR}${PREFIX}/bin"
257+
unset executables
258+
for exe in 'mpirun' 'ompi*' 'pmix*' 'prte*' 'opal*' 'orte*'; do
259+
while IFS= read -r filename
260+
do executables+=("$(basename "$filename")")
261+
done < <(find . -name "$exe")
262+
done
263+
264+
if test "$(uname)" = Linux; then
265+
cd "${DESTDIR}${PREFIX}/bin"
266+
for exe in "${executables[@]}"; do
267+
patchelf --set-rpath "\$ORIGIN/../lib" "$exe"
268+
done
269+
cd "${DESTDIR}${PREFIX}/lib"
270+
for lib in lib*.so; do
271+
patchelf --set-rpath "\$ORIGIN" "$lib"
272+
soname=$(patchelf --print-soname "$lib")
273+
if test -L "$soname"; then
274+
mv "$(readlink "$soname")" "$soname"
275+
ln -sf "$soname" "$lib"
276+
fi
277+
done
278+
fi
279+
280+
if test "$(uname)" = Darwin; then
281+
cd "${DESTDIR}${PREFIX}/bin"
282+
for exe in "${executables[@]}"; do
283+
install_name_tool --add-rpath "@executable_path/../lib/" "$exe"
284+
unset dependencies
285+
while IFS= read -r dep
286+
do dependencies+=("$dep")
287+
done < <(otool -L "$exe" | sed 1,1d)
288+
for dep in "${dependencies[@]}"; do
289+
if test "$(dirname "$dep")" = "$PREFIX"; then
290+
installname="@rpath/$(basename "$dep")"
291+
install_name_tool --change "$dep" "$installname" "$exe"
292+
fi
293+
done
294+
done
295+
cd "${DESTDIR}${PREFIX}/lib"
296+
for lib in lib*.*.dylib; do
297+
install_name_tool -id "@rpath/$lib" "$lib"
298+
install_name_tool -add_rpath "@loader_path/" "$lib"
299+
while IFS= read -r dep
300+
do dependencies+=("$dep")
301+
done < <(otool -L "$lib" | sed 1,1d)
302+
for dep in "${dependencies[@]}"; do
303+
if test "$(dirname "$dep")" = "$PREFIX"; then
304+
installname="@rpath/$(basename "$dep")"
305+
install_name_tool --change "$dep" "$installname" "$lib"
306+
fi
307+
done
308+
done
309+
fi
310+
311+
cd "${DESTDIR}${PREFIX}/bin"
312+
wrapper_cmd=opal_wrapper
313+
wrapper_bin="$WORKDIR/$wrapper_cmd"
314+
wrapper_src="$PROJECT/cibw-ompi-wrapper.c"
315+
cc -DWRAPPER="$wrapper_cmd" "$wrapper_src" -o "$wrapper_bin"
316+
executables=(mpicc mpicxx mpiCC mpic++)
317+
for exe in "${executables[@]}"; do
318+
install "$wrapper_bin" "$exe"
319+
done
320+
321+
cd "${DESTDIR}${PREFIX}/bin"
322+
wrapper_cmd=orun_wrapper
323+
wrapper_bin="$WORKDIR/$wrapper_cmd"
324+
wrapper_src="$PROJECT/cibw-ompi-wrapper.c"
325+
cc -DWRAPPER="$wrapper_cmd" "$wrapper_src" -o "$wrapper_bin"
326+
cp -a mpirun "$wrapper_cmd"
327+
executables=(mpirun mpiexec)
328+
for exe in "${executables[@]}"; do
329+
install "$wrapper_bin" "$exe"
330+
done
331+
332+
} # fixup-openmpi()
333+
173334
echo fixing install tree
174335
fixup-"$mpiname"

Diff for: cibw-check-mpi.sh

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
mpiname="${MPINAME:-mpich}"
4+
pkgname=$(pip list | awk '/mpich|openmpi/ {print $1}')
5+
mpiname=${pkgname%_*}
56

67
tempdir="$(mktemp -d)"
78
trap 'rm -rf $tempdir' EXIT
@@ -27,6 +28,15 @@ int main(int argc, char *argv[])
2728
EOF
2829
ln -s helloworld.c helloworld.cxx
2930

31+
if test "$mpiname" = "openmpi"; then
32+
export OMPI_ALLOW_RUN_AS_ROOT=1
33+
export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1
34+
export OMPI_MCA_rmaps_base_oversubscribe=true
35+
export OMPI_MCA_rmaps_default_mapping_policy=:oversubscribe
36+
export OMPI_MCA_plm_rsh_agent=false
37+
export OMPI_MCA_plm_ssh_agent=false
38+
fi
39+
3040
RUN() { echo + "$@"; "$@"; }
3141

3242
if test "$mpiname" = "mpich"; then

Diff for: cibw-ompi-wrapper.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <libgen.h>
2+
#include <limits.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
#include <unistd.h>
6+
#if defined(__APPLE__)
7+
#include <mach-o/dyld.h>
8+
#endif
9+
10+
#define STRINGIZE_(arg) #arg
11+
#define STRINGIZE(arg) STRINGIZE_(arg)
12+
13+
#if !defined(WRAPPER)
14+
#define WRAPPER opal_wrapper
15+
#endif
16+
17+
int main(int argc, char *argv[]) {
18+
19+
char exe[PATH_MAX+32];
20+
char path[PATH_MAX+32];
21+
char prefix[PATH_MAX+32];
22+
23+
#if defined(__APPLE__)
24+
int size = PATH_MAX;
25+
(void) _NSGetExecutablePath(path, &size);
26+
(void) realpath(path, exe);
27+
#else
28+
(void) readlink("/proc/self/exe", exe, PATH_MAX);
29+
#endif
30+
31+
(void) strncpy(path, dirname(exe), PATH_MAX);
32+
(void) strncat(path, "/..", PATH_MAX);
33+
(void) realpath(path, prefix);
34+
35+
(void) setenv("OPAL_PREFIX", prefix, 1);
36+
37+
(void) strncpy(exe, prefix, PATH_MAX);
38+
(void) strncat(exe, "/bin/", PATH_MAX);
39+
(void) strncat(exe, STRINGIZE(WRAPPER), PATH_MAX);
40+
41+
return execv(exe, argv);
42+
}

0 commit comments

Comments
 (0)