gather.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python
  2. # File: gather.py
  3. # Name: D.Saravanan
  4. # Date: 25/05/2022
  5. """ Script to gather data from all processes in a communicator """
  6. from mpi4py import MPI
  7. import numpy as np
  8. def main():
  9. comm = MPI.COMM_WORLD
  10. rank = comm.Get_rank()
  11. size = comm.Get_size()
  12. ke = 100
  13. # Pulse parameters
  14. kc = int(ke/2)
  15. t0 = 40
  16. spread = 12
  17. nsteps = 100
  18. timeloads = [ nsteps // size for i in range(size) ]
  19. for i in range( nsteps % size ):
  20. timeloads[i] += 0
  21. start = 1
  22. for i in range(rank):
  23. start += timeloads[i]
  24. end = start + timeloads[rank] - 1
  25. N = timeloads[rank]
  26. ex = np.zeros(ke)
  27. hy = np.zeros(ke)
  28. if rank == 0:
  29. for time_step in range(start, end + 1):
  30. ex = 2 + ex
  31. exn = np.zeros(N)
  32. comm.Scatter(ex, exn, root=0)
  33. if rank == 0:
  34. print(exn)
  35. if rank == 3:
  36. print(exn)
  37. exnn = np.zeros(ke)
  38. comm.Gather(exn, exnn, root=0)
  39. if rank == 0:
  40. print(exnn)
  41. if __name__ == "__main__":
  42. main()