As Gilles said in his comment, look at MPI_Alltoall(), MPI_Alltoallv, MPI_Alltoallw, etc.
MPI_Alltoallv allows for each process to send different amounts of data to each other, and MPI_Alltoallw is even more generalized exchange (per the MPI Standard documentation)