Skip to content

Commit 9b942c0

Browse files
committed
Deal with mpi4py v4.1 no longer having IN_PLACE be an int instance
1 parent 818458a commit 9b942c0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mockmpi/comm.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
# This constant used to be 1 in both MPICH and OpenMPI,
77
# but starting with mpi4py version 4, they switched it to -1.
8+
# Even worse, starting with 4.1, it's not a subtype of int as it had been until then.
9+
# But it does cast to an int if requested.
810
# Use -1 here, but when we check for it allow 1 as well.
9-
# And if we happen to have mpi4py installed, include whatever it actually has as well.
11+
# And if we happen to have mpi4py installed, include whatever it actually has as well
12+
# both for the value and the type.
1013
try:
1114
from mpi4py.MPI import IN_PLACE
15+
ALLOWED_IN_PLACE_TYPES = (int, type(IN_PLACE))
1216
except ImportError:
1317
IN_PLACE = -1
18+
ALLOWED_IN_PLACE_TYPES = (int,)
1419
ALLOWED_IN_PLACE = [IN_PLACE, 1, -1]
1520

1621

@@ -119,7 +124,7 @@ def allreduce(self, sendobj, op=None):
119124
return d
120125

121126
def Reduce(self, sendbuf, recvbuf, op=None, root=0):
122-
if isinstance(sendbuf, int) and (sendbuf in ALLOWED_IN_PLACE):
127+
if isinstance(sendbuf, ALLOWED_IN_PLACE_TYPES) and (sendbuf in ALLOWED_IN_PLACE):
123128
sendbuf = recvbuf.copy()
124129

125130
if not isinstance(sendbuf, np.ndarray):

0 commit comments

Comments
 (0)