/* file: column_move.c compile: cc column_move.c -lmpi run: mpirun -np 2 ./a.out */ #include "mpi.h" main(int argc, char* argv[]){ int myrank; int i,j; int dest=1; int source=0; int buf[3][6]; MPI_Status status; MPI_Datatype newtype; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); if(myrank==0){ /* Processor0 rank = 0 11 12 13 14 15 16 21 22 23 24 25 26 31 32 33 34 35 36 */ for(i=0; i<3; i++){ for(j=0; j<6; j++){ buf[i][j]=10*(i+1)+(j+1); } } printf("rank = %d\n",myrank); for(i=0; i<3; i++){ for(j=0; j<6; j++){ printf("%d ", buf[i][j]); } printf("\n"); } } else{ /* Processor1 rank = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */ for(i=0; i<3; i++){ for(j=0; j<6; j++){ buf[i][j]=0; } } } MPI_Type_vector(3,1,6,MPI_INTEGER,&newtype); MPI_Type_commit(&newtype); if(myrank==0){ MPI_Send(&buf[0][5],1,newtype,dest,100,MPI_COMM_WORLD); } else{ MPI_Recv(&buf[0][0],1,newtype,source,100,MPI_COMM_WORLD,&status); /* rank = 1 16 0 0 0 0 0 26 0 0 0 0 0 36 0 0 0 0 0 */ printf("rank = %d\n", myrank); for(i=0; i<3; i++){ for(j=0; j<6; j++){ printf("%2d ", buf[i][j]); } printf("\n"); } } MPI_Finalize(); }