97. Examples using MPI_SCATTER, MPI_SCATTERV


Up: Scatter Next: Gather-to-all Previous: Scatter

The examples in this section use intracommunicators.
Example The reverse of Example Examples using MPI_GATHER, MPI_GATHERV . Scatter sets of 100 ints from the root to each process in the group. See Figure 9 .


    MPI_Comm comm; 
    int gsize,*sendbuf; 
    int root, rbuf[100]; 
    ... 
    MPI_Comm_size( comm, &gsize); 
    sendbuf = (int *)malloc(gsize*100*sizeof(int)); 
    ... 
    MPI_Scatter( sendbuf, 100, MPI_INT, rbuf, 100, MPI_INT, root, comm); 


Figure 9: The root process scatters sets of 100  ints to each process in the group.


Example The reverse of Example Examples using MPI_GATHER, MPI_GATHERV . The root process scatters sets of 100 ints to the other processes, but the sets of 100 are stride ints apart in the sending buffer. Requires use of MPI_SCATTERV. Assume . See Figure 10 .


    MPI_Comm comm; 
    int gsize,*sendbuf; 
    int root, rbuf[100], i, *displs, *scounts; 
 
    ... 
 
    MPI_Comm_size( comm, &gsize); 
    sendbuf = (int *)malloc(gsize*stride*sizeof(int)); 
    ... 
    displs = (int *)malloc(gsize*sizeof(int)); 
    scounts = (int *)malloc(gsize*sizeof(int)); 
    for (i=0; i<gsize; ++i) { 
        displs[i] = i*stride; 
        scounts[i] = 100; 
    } 
    MPI_Scatterv( sendbuf, scounts, displs, MPI_INT, rbuf, 100, MPI_INT, 
                                                              root, comm); 


Figure 10: The root process scatters sets of 100  ints, moving by  stride ints from send to send in the scatter.


Example The reverse of Example Examples using MPI_GATHER, MPI_GATHERV . We have a varying stride between blocks at sending (root) side, at the receiving side we receive into the i-th column of a 100×150 C array. See Figure 11 .


Figure 11: The root scatters blocks of  100-i ints into column  i of a 100$ x $150 C array. At the sending side, the blocks are  stride[i] ints apart.



Up: Scatter Next: Gather-to-all Previous: Scatter


Return to MPI-2.2 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-2.2 of September 4, 2009
HTML Generated on September 10, 2009