Skip to content

Instantly share code, notes, and snippets.

@lebedov
Created December 25, 2014 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lebedov/01eed51891464ecae820 to your computer and use it in GitHub Desktop.
Save lebedov/01eed51891464ecae820 to your computer and use it in GitHub Desktop.
How to use mpi4py with msgpack serialization
#!/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