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
|
# mpiexec -n 2 python ex-2.34.py
# Use of ready-mode and synchronous-mode
# --------------------------------------------------------------------
from mpi4py import MPI
try:
import numpy
except ImportError:
raise SystemExit from None
if MPI.COMM_WORLD.Get_size() < 2:
raise SystemExit from None
# --------------------------------------------------------------------
comm = MPI.COMM_WORLD
buff = numpy.empty((1000, 2), dtype="f", order="f")
rank = comm.Get_rank()
if rank == 0:
req1 = comm.Irecv([buff[:, 0], MPI.FLOAT], 1, 1)
req2 = comm.Irecv([buff[:, 1], MPI.FLOAT], 1, 2)
status = [MPI.Status(), MPI.Status()]
MPI.Request.Waitall([req1, req2], status)
elif rank == 1:
buff[:, 0] = 5
buff[:, 1] = 7
comm.Ssend([buff[:, 1], MPI.FLOAT], 0, 2)
comm.Rsend([buff[:, 0], MPI.FLOAT], 0, 1)
# --------------------------------------------------------------------
if rank == 0:
assert numpy.all(buff[:, 0] == 5)
assert numpy.all(buff[:, 1] == 7)
assert status[0].source == 1
assert status[0].tag == 1
assert status[1].source == 1
assert status[1].tag == 2
# --------------------------------------------------------------------
|