Skip to content

Instantly share code, notes, and snippets.

@shelling
Created June 15, 2010 09:51
Show Gist options
  • Select an option

  • Save shelling/438924 to your computer and use it in GitHub Desktop.

Select an option

Save shelling/438924 to your computer and use it in GitHub Desktop.
Hello, MPI4Py
#!/usr/bin/env python
from mpi4py import MPI
import os
import numpy
import commands
Comm = MPI.COMM_WORLD
size = Comm.Get_size()
rank = Comm.Get_rank()
host = commands.getoutput("hostname")
print "I am process " + str(rank) + " of " + str(size) + " on " + host
Comm.Barrier()
total = 0
Comm.reduce( rank, total, op=MPI.SUM, root=0 )
if rank == 0:
print "total is " + str(total)
Comm.Barrier()
if rank < size-1:
Comm.send( { "source": rank }, dest=rank+1, tag=0 )
if rank > 0:
data = Comm.recv(source=rank-1, tag=0)
print "my rank is " + str(rank) + " and I've received data from " + str(data["source"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment