Created
December 25, 2014 04:04
-
-
Save lebedov/01eed51891464ecae820 to your computer and use it in GitHub Desktop.
How to use mpi4py with msgpack serialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
How to use mpi4py with msgpack serialization | |
""" | |
from mpi4py import MPI | |
import msgpack | |
# mpi4py assumes that the serializer function takes more than one parameter: | |
MPI.pickle.dumps = lambda *x: msgpack.dumps(x[0]) | |
MPI.pickle.loads = msgpack.loads | |
comm = MPI.COMM_WORLD | |
size = comm.Get_size() | |
rank = comm.Get_rank() | |
in_data = str(rank) | |
comm.send(in_data, ((rank+1) % size)) | |
out_data = comm.recv(source=(rank-1) % size) | |
print 'node %s: received %s' % (rank, out_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment