Reputation: 105
I am trying to send an array to the different processors in the hypercube architecture. The problem is that it either doesn't send to all the processors or it sends to wrong processor. When I try to send a single integer it works correctly.
Here is the code:
void hypercube(int d,int my_id,int X[]){
mask = (int)pow((double)2,d)-1;
for(i = d-1;i>=0;i--){
//printf("before xor mask is %d and power is %d\n",mask,(int)pow((double)2,i));
mask = xor(mask,(int)pow((double)2,i));
//printf("After xor rank is %d and mask is %d\n",rank,mask);
if(and(my_id, mask) == 0){
if(and(my_id,(int) pow((double)2,i)) == 0){
dest = xor(my_id,(int) pow((double)2,i));
printf("rank %d destination %d\n",rank,dest);
MPI_Send(&X,8,MPI_INT,dest,tag,MPI_COMM_WORLD);;
//MPI_Send(&X,1,MPI_INT,dest,tag,MPI_COMM_WORLD);
//printf("After sending from rank %d and destination is %d\n",my_id,dest);
}
else{
//printf("going to receive in a sec...\n");
source = xor(my_id,(int)pow((double)2,i));
MPI_Recv(&X,8,MPI_INT,source,tag,MPI_COMM_WORLD,&status);
//MPI_Recv(&X,1,MPI_INT,source,tag,MPI_COMM_WORLD,&status);
//printf("in rank %d with data %d\n",rank,X);
}
}
}
}
int main(int argc, char **argv){
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&world_size);;
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
if(rank == master){
//a[ARR_SIZE] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
// q = 4;
}
hypercube(3,rank,a);
return 0;
}
Is there anything that I am not taking care of??
Upvotes: 0
Views: 103
Reputation: 8380
Your array is declared as int X[]
, so the buffer you have to pass to MPI_Send()
or MPI_Recv()
is X
instead of &X
.
Note passing &X[0]
is also correct, though i'd rather suggest X
because it is simpler.
Upvotes: 1