Sending a Column
Since C stores matrices in row-major order it’s easy to send rows
{MPI_Send(&A[2][0], 10, MPI_DOUBLE, 1, 0, MPI_COMM_WORLD);}
{MPI_Recv(&A[2][0], 10, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, &status);}
But what if I want to send a column?
MPI_Type_vector(10, 1, 10, MPI_DOUBLE, &col_t);
{MPI_Send(&A[0][2], 1, col_t, 1, 0, MPI_COMM_WORLD);}
{MPI_Recv(&A[0][2], 1, col_t, 0, 0, MPI_COMM_WORLD, &status);}
Note that since the address isn’t bound with the derived datatype we can use col_t
to send any column of any 10x10 matix of doubles!
Reuse is important since it’s fairly expensive to construct a derived datatype