For example, if I have an 8x8 matrix:
0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0
0 1 1 0 0 0 0 0
1 0 0 0 0 1 1 1
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
And I have 4 processes. Each one will receive data in a matrix of size (HIGH + 2) * (WIDTH + 2) (HIGH = size of the matrix / number of processes and WIDTH = size of the matrix, that is: HIGH = 8/4 and WIDTH = 8). For example, for process 0 it would be like this:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
For process 1, it would be like this:
0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0
0 1 0 0 0 0 1 1 1 0
0 0 0 0 0 0 0 0 0 0
And so on.
I wrote in my code, what follows, and the processes do not receive what I want (which is all I said before):
MPI_Scatter(matriz, (size*size)/np, MPI_INT, matriz_vja+( (1*(ANCHO+2)) +1), (ALTO+2)*(ANCHO+2), MPI_INT, 0, MPI_COMM_WORLD);
* "size" is the size of the 8x8 matrix, "matrix_vja" is the matrix that each process will have, "matrix" is the original 8x8 matrix, "np" is the number of processes.
I also planned to do something like that and it does not work for me either:
MPI_Datatype porcolumnas, newcolumnas;
MPI_Type_vector(ALTO, ANCHO, ANCHO*ALTO, MPI_INT,&porcolumnas);
MPI_Type_create_resized(porcolumnas, 0, ALTO*sizeof(int), &newcolumnas);
MPI_Type_commit(&newcolumnas);
MPI_Scatter(matriz, 1, newcolumnas, matriz_vja+((1*(ANCHO+2))+1), (ALTO+2)*(ANCHO+2), MPI_INT, 0, MPI_COMM_WORLD);
When I run the program, for process 0, your matrix looks like this:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
For process 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0
For process 2:
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
And for process 3:
0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0
0 1 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0
What can I write, then, by code, to be sent to all processes, from process 0, the first two rows for process 0, the other two rows for process 1, and so on?