/* file: partial_move.c compile: cc -64 partia_move.c -lmpi run: mpirun -np 2 ./a.out rank = 0 11 12 13 14 15 16 21 22 23 24 25 26 31 32 33 34 35 36 rank = 1 31 32 33 34 35 36 0 0 0 0 0 0 0 0 0 0 0 0 */ #include "mpi.h" main(int argc, char* argv[]){ int myrank; int nprocs; int i,j; int buf[3][6]; MPI_Status status; MPI_Datatype newtype; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); if(myrank==0){ 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{ 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[2][0],6,MPI_INT,1,100,MPI_COMM_WORLD); } else{ MPI_Recv(&buf[0][0],6,MPI_INT,0,100,MPI_COMM_WORLD,&status); 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(); }