I'm working on an MPI program and I have the following code for each of my processes:
#define CELL(A,X,Y,MX,MY) (*(A+Y*MX+X))
int bs_x = 1;
int bs_y = 1;
int *this_data=calloc((bs_y+2)*(bs_x+2), sizeof(int));
//...
int *recv_top = calloc(bs_x, sizeof(int));
int *recv_left = calloc(bs_x, sizeof(int));
// Now I make some operations and I want to assign
// the value of recv_top and recv_left to this_data
for(i=0; i<bs_x; ++i) CELL(this_data, i+1, 0, bs_x+2, bs_y+2) = recv_top[i]; // Sets both (0,1) and (1,0) to recv_top!!
for(i=0; i<bs_x; ++i) CELL(this_data, 0, i+1, bs_x+2, bs_y+2) = recv_left[i]; // Again sets both (0,1) and (1,0) to recv_left!!
Now the problem comes when I check the value of the element (1,0) and I found out that the first call also saves the value of recv_top in the element (0,1):
for(i=0; i<bs_x; ++i) CELL(this_data, i+1, 0, bs_x+2, bs_y+2) = recv_top[i];
if (rank == 4)
{
printf("Rank 4 value at (%d,0) = %d\n", 1, CELL(this_data,1,0,bs_x+2,bs_y+2));
printf("Rank 4 value at (0,%d) = %d\n", 1, CELL(this_data,0,1,bs_x+2,bs_y+2));
}
//Rank 4 value at (1,0) = 12
//Rank 4 value at (0,1) = 12
And the next:
for(i=0; i<bs_x; ++i) CELL(this_data, 0, i+1, bs_x+2, bs_y+2) = recv_left[i];
if (rank == 4)
{
printf("Rank 4 value at (%d,0) = %d\n", 1, CELL(this_data,1,0,bs_x+2,bs_y+2));
printf("Rank 4 value at (0,%d) = %d\n", 1, CELL(this_data,0,1,bs_x+2,bs_y+2));
}
//Rank 4 value at (1,0) = 1024
//Rank 4 value at (0,1) = 1024
Updates also (1,0).
They shouldn't do that since they are not the same:
CELL(this_data, 0, i+1, bs_x+2, bs_y+2) = (*(this_data+(i+1)*(bs_x+2))
CELL(this_data, i+1, 0, bs_x+2, bs_y+2) = (*(this_data+i+1))
Any ideas what I'm doing wrong?