How it works...

The root process of 0 receives data from the other four processes, as represented in the previous diagram.

We set n (= 5) processes sending their data:

    data = (rank+1)**2  

If the rank of the process is 0, then the data is collected in an array:

if rank == 0: 
    for i in range(1,size): 
        value = data[i] 

The gathering of data is given, instead, by the following function:

data = comm.gather(data, root=0) 

Finally, we run the code setting the group of processes equal to 5:

C:>mpiexec -n 5 python gather.py
rank = 0 ...receiving data to other process process 0 receiving 4 from process 1 process 0 receiving 9 from process 2 process 0 receiving 16 from process 3 process 0 receiving 25 from process 4

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

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