xref: /petsc/src/sys/tests/ex55.py (revision 4a39b367f075d4cbee3be4cb8e973102c7675e4f)
1*b6efb0a5SBarry Smithfrom mpi4py import MPI
2*b6efb0a5SBarry Smithimport numpy
3*b6efb0a5SBarry Smith
4*b6efb0a5SBarry Smithcomm = MPI.COMM_WORLD
5*b6efb0a5SBarry Smithrank = comm.Get_rank()
6*b6efb0a5SBarry Smith
7*b6efb0a5SBarry Smith# passing MPI datatypes explicitly
8*b6efb0a5SBarry Smithif rank == 0:
9*b6efb0a5SBarry Smith    data = numpy.arange(1000, dtype='i')
10*b6efb0a5SBarry Smith    comm.Send([data, MPI.INT], dest=1, tag=77)
11*b6efb0a5SBarry Smithelif rank == 1:
12*b6efb0a5SBarry Smith    data = numpy.empty(1000, dtype='i')
13*b6efb0a5SBarry Smith    comm.Recv([data, MPI.INT], source=0, tag=77)
14*b6efb0a5SBarry Smith
15*b6efb0a5SBarry Smith# automatic MPI datatype discovery
16*b6efb0a5SBarry Smithif rank == 0:
17*b6efb0a5SBarry Smith    data = numpy.arange(100, dtype=numpy.float64)
18*b6efb0a5SBarry Smith    comm.Send(data, dest=1, tag=13)
19*b6efb0a5SBarry Smithelif rank == 1:
20*b6efb0a5SBarry Smith    data = numpy.empty(100, dtype=numpy.float64)
21*b6efb0a5SBarry Smith    comm.Recv(data, source=0, tag=13)
22