Last active
August 29, 2016 22:09
-
-
Save swerwath/8108369623e54f0f21306fa8342029e1 to your computer and use it in GitHub Desktop.
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
from mpi4py import MPI | |
comm = MPI.COMM_WORLD # All our nodes in this cluster | |
rank = comm.Get_rank() # Our node's "ID" | |
if rank == 0: # If we're the root/base node, we'll be the one distributing the data | |
data = [1,2,3,4,5] | |
else: | |
data = [] | |
#Scatter our list elements evenly across the node in comm | |
data = comm.scatter(data, root=0) | |
print "rank", rank, "recieved", data | |
data = data + 2 # Perform our mapping function | |
#Gather | |
data = comm.gather(data, root=0) # Send all the mapped data back to our root node | |
comm.Barrier() # Wait until all processes reach this point | |
if rank == 0: # Only our root node had the data gathered to it | |
print data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment