1

I'm beginner at parallel programming so I need some help. I'm multiplying 2D matrices which are 6*6 and the number of processors are 4.I divided it to 4 blocks of 9 elements then I used derived data type and defined a new data type with MPI_TYPE_VECTOR. And then tried to SCATTER each block to one processor. But it does not work. I can do that by point-to-point send and receive but I want to do that by using MPI_SCATTER. Could somebody please help me.

Here is part of my code:

q = (int) sqrt((double) p); // p is number of processors
MPI_Datatype my_block,tmpType;

MPI_Type_vector(n / q, n / q, n, MPI_DOUBLE, &my_block);// n is size of matrics
MPI_Type_commit(&my_block);
MPI_Type_create_resized( my_block, 0, ((n*n)/ p) * sizeof(double), &tmpType ); 
MPI_Type_commit(&tmpType);

MPI_Scatter( Matrix_B, 1, tmpType, &b ,1, tmpType,0, grid_comm );

for (int i=0; i< n*0.5 ;i++){
    for (int j=0; j< n*0.5;j++){
        printf("Processor %d :  %lf ,",my_grid_rank,*(b+(n/q )*i+j));
    }
    printf("\n");
}
Link
  • 11
  • 3
  • 1
    It turns out you need to use `MPI_Scatterv` as described in and for the reasons given in [this answer](http://stackoverflow.com/questions/9269399/sending-blocks-of-2d-array-in-c-using-mpi/9271753#9271753) – Jonathan Dursi Feb 21 '13 at 22:25

0 Answers0