I'm learning MPI and I don't know if it is OK to send or receive multiple messages using the same array.
Every processor needs to send different chunks of its local data to the other processors (and receive their data, too).
Say I have four processors. I use this:
MPI_Request sendReqs[4];
MPI_Status sendStats[4];
MPI_Request recReqs[4];
MPI_Status recStats[4];
// locData is an array of integers. I need to distribute chunks of it
// assume I have four processors
for( i = 0 ; i < 4; i++) {
send = locData + indices[2*i]; // location at buffer to start ith send
count = indices[2*i+1] - indices[2*i] + 1; // how many we send to i
MPI_Isend(send, count, MPI_INT, i, rank, MPI_COMM_WORLD, sendReqs[i] );
}
similarly, would this be OK?
// gatheredData is where each processor stores data it gets form others
// assume I have four processors
for( i = 0 ; i < 4; i++) {
start = gatheredData + gatheredIndices[2*i];
count = gatheredIndices[2*i+1] - gatheredIndices[2*i] + 1;
MPI_Irecv(start, count, MPI_INT, i, i, MPI_COMM_WORLD, &recReqs[i]);
}
I finish with this this call, to make sure everybody got the data
MPI_Waitall(4, sendReqs, sendStats);
MPI_Waitall(4, recReqs , recStats );
This does not work - the processors show they have some junk values inside of gatheredData (as well as some good values).
MPI_Alltoall
andMPI_Alltoallv
instead. See here: mpich.org/static/docs/v3.1/www3/MPI_Alltoall.html and mpich.org/static/docs/v3.1/www3/MPI_Alltoallv.html - Patrick