def parallel_transform(comm, image_data): rank = comm.Get_rank() size = comm.Get_size() print "transforming for rank i = ", rank # We assume number of processes is a power of 2 # start and end are row indices start = rank * int(IMAGE_SIZE / size) end = ((rank+1) * int(IMAGE_SIZE / size)) # Load partial data b = data_transformer(SAMPLE_SIZE, IMAGE_SIZE) data = np.zeros((IMAGE_SIZE, IMAGE_SIZE)) print "about to transform for rank ",rank for i in xrange(start, end): print "working on row = ",i data += b.transform(image_data[i-start], -np.pi/2048*i) print "transformed image for rank ",rank if not (rank == 0): print "sending transformed data for rank ",rank comm.Send([data, MPI.FLOAT], dest=0) print "sent transformed data for rank ",rank return data
def parallel_transform(comm, image_data): rank = comm.Get_rank() size = comm.Get_size() print "transforming for rank i = ", rank # We assume number of processes is a power of 2 # start and end are row indices start = rank * int(IMAGE_SIZE / size) end = ((rank + 1) * int(IMAGE_SIZE / size)) # Load partial data b = data_transformer(SAMPLE_SIZE, IMAGE_SIZE) data = np.zeros((IMAGE_SIZE, IMAGE_SIZE)) print "about to transform for rank ", rank for i in xrange(start, end): print "working on row = ", i data += b.transform(image_data[i - start], -np.pi / 2048 * i) print "transformed image for rank ", rank if not (rank == 0): print "sending transformed data for rank ", rank comm.Send([data, MPI.FLOAT], dest=0) print "sent transformed data for rank ", rank return data
# Compute partial transformation for i in xrange(start, end): print 'transforming for row ', i print 'process = ', rank data += data_trans.transform(image_data[i - start], -np.pi / IMAGE_SIZE * i) # Reduce to root process result = comm.reduce(data, op=MPI.SUM, root=p_root) return result if __name__ == '__main__': dt = np.dtype('d') data_trans = data_transformer(SAMPLE_SIZE, IMAGE_SIZE) comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() im_data = [] result = np.zeros((IMAGE_SIZE, IMAGE_SIZE)) start_end = {} for i in xrange(size): start = i * int(IMAGE_SIZE / size) end = ((i + 1) * int(IMAGE_SIZE / size)) start_end[i] = (start, end) print start_end
# Compute partial transformation for i in xrange(start, end): print 'transforming for row ',i print 'process = ',rank data += data_trans.transform(image_data[i-start], -np.pi/IMAGE_SIZE*i) # Reduce to root process result = comm.reduce(data, op=MPI.SUM, root=p_root) return result if __name__ == '__main__': dt = np.dtype('d') data_trans = data_transformer(SAMPLE_SIZE, IMAGE_SIZE) comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() im_data = [] result = np.zeros((IMAGE_SIZE, IMAGE_SIZE)) start_end = {} for i in xrange(size): start = i * int(IMAGE_SIZE / size) end = ((i+1) * int(IMAGE_SIZE / size)) start_end[i] = (start, end) print start_end