Hi all. The following code (which I am typing in, excuse my typos please) is not working as expected.
Code:
#include <stdlib.h>
#include <mpi.h>
#include <stdio.h>
int main(int argc, char **argv){
double u[4][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
double *recv_buff;
int size, rank;
MPI_Datatype matrix;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Type_vector(4,2,4, MPI_DOUBLE, &matrix);
if(rank ==0){
for (i = 0; i < 4; i++){
for (j = 0; j<4; j++){
printf("u[%i][%j]=%4.3f\n", u[i][j]);
}
}
MPI_Send(u[0][0],1,matrix, 1,0, MPI_COMM_WORD);
}
if (rank == 1){
recv_buff = malloc(sizeof(double *) * 2);
for (i = 0; i<2; i++)
recv_buff[i] = malloc(sizeof(double) * 2);
MPI_Recv(recv_buff[0][0], 1, matrix, 0,0,MPI_COMM_WORLD, &status);
for (i = 0; i < 2; i++){
for (j = 0; j<2; j++){
printf("recv_buff[%i][%j]=%4.3f\n", recv_buff[i][j]);
}
}
}
}
I was expecting the recv_buffer to contain the 4 top-left entries in the original grid, that is the values 1, 2, 5, 6
This code doesnt seem to be working for me. I can't seem to figure out the values for the stride, or the allocations, or something, that will give me those values. Am I forgetting something? It had occured to me maybe i am declaring the arrays wrong, or something, but I am out of ideas. Thanks