Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import random
- from random import seed
- from mpi4py import MPI
- comm = MPI.COMM_WORLD
- size = comm.Get_size()
- rank = comm.Get_rank()
- num = 4
- N = num // size + (num % size > rank)
- position_x = np.zeros(num,dtype=float)
- seed(10059)
- for i in range(num):
- position_x[i] = round(random.uniform(-5,5),3)
- print(position_x)
- if rank == 0:
- share1 = position_x
- else:
- share1 = None
- count = []
- for i in range(size):
- if i <= num%size-1:
- count += [num//size + 1]
- else:
- count += [num//size]
- pos1 = np.zeros(N, dtype='f')
- comm.Scatterv([share1, count, MPI.FLOAT], pos1, root=0)
- print(pos1,'from ',rank)
- [-2.275 4.238 -1.637 0.981]
- [5177.344] from 1
- [-2.275 4.238 -1.637 0.981]
- [ 4.172325e-08 -2.034375e+00] from 0
- [-2.275 4.238 -1.637 0.981]
- [2.264875] from 2
Add Comment
Please, Sign In to add comment