So this is a simple code snippet that doesn’t work for me stating expecting 4 items, got 55. In reality, I want to have a list of strings and split this list between the n_processes to do the computation on them. How is this possible with scatter??
from mpi4py import MPI
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
if rank == 0:
data = [(i+1)**2 for i in range(55)]
comm.Scatter(data, root=0)
print rank, data
Take a look at the underlying Scatter API call:
http://www.open-mpi.org/doc/v1.5/man3/MPI_Scatter.3.php
The Scatter call uses the list argument to send one element of the list to each process. You have hardcoded 55 elements in the list but it sounds like you are only running 4 processes. Either change the
range(55)torange(size)(the more appropriate solution) or run 55 processes so that the existing code is correct.