Created
June 15, 2010 09:51
-
-
Save shelling/438924 to your computer and use it in GitHub Desktop.
Hello, MPI4Py
This file contains hidden or 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 | |
| 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