Skip to content

Commit 6c04af1

Browse files
committed
Add MPI_Allgather for uniform and MPI_Allgatherv for variable length arrays
1 parent 7200970 commit 6c04af1

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pylops_mpi/signalprocessing/Fredholm1.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ def _rmatvec(self, x: DistributedArray) -> DistributedArray:
151151
if hasattr(self, "GT"):
152152
y1 = ncp.matmul(self.GT, x)
153153
else:
154-
y1 = ncp.matmul(self.G.transpose(0, 2, 1).conj(), x)
154+
y1 = (
155+
ncp.matmul(x.transpose(0, 2, 1).conj(), self.G)
156+
.transpose(0, 2, 1)
157+
.conj()
158+
)
155159
else:
156160
y1 = ncp.squeeze(ncp.zeros((self.nsls[self.rank], self.ny, self.nz), dtype=self.dtype))
157161
if hasattr(self, "GT"):

pylops_mpi/utils/_mpi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ def mpi_allgather(base_comm: MPI.Comm,
4747
send_shapes = base_comm.allgather(send_buf.shape)
4848
recvcounts = base_comm.allgather(send_buf.size)
4949
recv_buf = recv_buf if recv_buf else ncp.zeros(sum(recvcounts), dtype=send_buf.dtype)
50+
if len(set(send_shapes)) == 1:
51+
_mpi_calls(base_comm, "Allgather", send_buf.copy(), recv_buf, engine=engine)
52+
return [chunk.reshape(send_shapes[0]) for chunk in ncp.split(recv_buf, base_comm.size)]
5053
displs = [0]
5154
for i in range(1, len(recvcounts)):
5255
displs.append(displs[i - 1] + recvcounts[i - 1])
53-
_mpi_calls(base_comm, "Allgatherv", send_buf,
54-
[recv_buf, recvcounts, list(displs), MPI._typedict[send_buf.dtype.char]], engine=engine)
56+
_mpi_calls(base_comm, "Allgatherv", send_buf.copy(),
57+
[recv_buf, recvcounts, displs, MPI._typedict[send_buf.dtype.char]], engine=engine)
5558
return [
5659
recv_buf[displs[i]:displs[i] + recvcounts[i]].reshape(send_shapes[i])
5760
for i in range(base_comm.size)

0 commit comments

Comments
 (0)