Skip to content

Commit df3329f

Browse files
committed
Demo of a non-blocking message chain
1 parent 7f5ea8a commit df3329f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

demos/mpi-msg-chain.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from mpi4py import MPI
2+
import numpy
3+
4+
comm = MPI.COMM_WORLD
5+
rank = comm.Get_rank()
6+
size = comm.Get_size()
7+
8+
data = numpy.arange(10, dtype=float) * (rank + 1) # send buffer
9+
buffer = numpy.zeros(10, dtype=float) # receive buffer
10+
11+
tgt = rank + 1
12+
src = rank - 1
13+
if rank == 0:
14+
src = MPI.PROC_NULL
15+
if rank == size - 1:
16+
tgt = MPI.PROC_NULL
17+
18+
req = []
19+
req.append(comm.Isend(data, dest=tgt))
20+
req.append(comm.Irecv(buffer, source=src))
21+
22+
MPI.Request.waitall(req)
23+
24+
print('[{0:2}] Received: {1}'.format(rank, buffer))

0 commit comments

Comments
 (0)