Gil Peretz
Gil Peretz

Reputation: 2419

Differences between MPI_Scatter and MPI_Bcast

Can anyone please explain what are the differences between MPI_Scatter and MPI_Bcast? (Beside the fact that any process can broadcast using MPI_Scatter and only root can use MPI_Bcast)

In which cases I should use the first one over the other?

Upvotes: 18

Views: 9701

Answers (2)

almgwary
almgwary

Reputation: 173

MPI_Bcast takes a single data element at the root process (the red box) and copies it to all other processes. MPI_Scatter takes an array of elements and distributes the elements in the order of process rank.

the illustration,

Upvotes: 15

francis
francis

Reputation: 9817

MPI_Bcast() sends the same piece of data to everyone, while MPI_Scatter() sends each process a part of the input array. MPI_Bcast() is the opposite of MPI_Reduce() and MPI_Scatter() is the opposite of MPI_Gather(). A little scheme like this one is self-explanatory.

And both MPI_Scatter() and MPI_Bcast() have an argument named int root to specify the root process.

Upvotes: 29

Related Questions