How it works...

The process of rank equal to 0 distributes the array_to_share data structure to other processes:

array_to_share = [1, 2, 3, 4 ,5 ,6 ,7, 8 ,9 ,10] 

The recvbuf parameter indicates the value of the ith variable that will be sent to the process through the comm.scatter statement:

recvbuf = comm.scatter(array_to_share, root=0)

The output is as follows:

C:>mpiexec -n 10 python scatter.py 
process = 0 variable shared  = 1 
process = 4 variable shared  = 5 
process = 6 variable shared  = 7 
process = 2 variable shared  = 3 
process = 5 variable shared  = 6 
process = 3 variable shared  = 4 
process = 7 variable shared  = 8 
process = 1 variable shared  = 2 
process = 8 variable shared  = 9 
process = 9 variable shared  = 10 

We also remark that one of the restrictions to comm.scatter is that you can scatter as many elements as the processors you specify in the execution statement. In fact, if you attempt to scatter more elements than the processors specified (three, in this example), then you will get an error similar to the following:

C:> mpiexec -n 3 python scatter.py 
Traceback (most recent call last): 
  File "scatter.py", line 13, in <module> 
    recvbuf = comm.scatter(array_to_share, root=0) 
  File "Comm.pyx", line 874, in mpi4py.MPI.Comm.scatter 
(c:usersutenteappdatalocal emppip-build-h14iajmpi4py
srcmpi4py.MPI.c:73400) File "pickled.pxi", line 658, in mpi4py.MPI.PyMPI_scatter
(c:usersutenteappdatalocal emppip-build-h14iajmpi4pysrc
mpi4py.MPI.c:34035) File "pickled.pxi", line 129, in mpi4py.MPI._p_Pickle.dumpv
(c:usersutenteappdatalocal emppip-build-h14iajmpi4py
srcmpi4py.MPI.c:28325)
ValueError: expecting 3 items, got 10 mpiexec aborting job... job aborted: rank: node: exit code[: error message] 0: Utente-PC: 123: mpiexec aborting job 1: Utente-PC: 123 2: Utente-PC: 123

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.34.146