Could any help how to use MPI_Scatter to send the following matrix
float **u, **u_local;
if (rank == 0){
u = (float**) malloc(N * size * sizeof(float*));
for(i = 0; i < N * size; i++){
u[i] = (float*) malloc(M * sizeof(float));
memset(u[i], 0, M * sizeof(float));
}
}
I wanna send u[N][M] matrix to all processes equally (u_local)
N number of rows
M number of columns
Thanks
The easiest solution is to allocate memory in a linear way:
Instead of allocating each row of
useparately, this code allocates a chunk of memory as big as the whole matrix and then assigns tou[i]a pointer to the start of thei-th row inu_stor. Now rows are laid continuously in memory and a simple scatter can be used: