user3728774
user3728774

Reputation: 1

MPI_Send is not working correctly

This is the skelton of our program. The MPI_Send function is not working,the printf statement before MPI_Send is working correctly but the control is not going to the printf statement after MPI_Send. And also it is not going to the if(rank>0) condition.

#define MASTER_TO_SLAVE_TAG 1 
#define SLAVE_TO_MASTER_TAG 4

void MPI_Init(int argc,char ***argv);
int MPI_Comm_rank( MPI_Comm comm, int *rank);
int MPI_Comm_size(MPI_Comm comm, int *totalProcess);
if(rank==0)
{
   printf("before send “);
   double  tArray[1];
   tArray[0]=t;
   for(rank=1;rank<totalProcess;rank++)
      MPI_Send(&tArray, 1, MPI_DOUBLE, rank, MASTER_TO_SLAVE_TAG,MPI_COMM_WORLD);
   printf("after send “);
}
if(rank>0)
{
  printf(“inside slave”);
  MPI_Recv(&tArray, 1, MPI_DOUBLE, 0, SLAVE_TO_MASTER_TAG,MPI_COMM_WORLD, &status);
}

Upvotes: 0

Views: 529

Answers (1)

Wesley Bland
Wesley Bland

Reputation: 9062

You're trying to receive from a different tag than you're using to send. The MPI_SEND and MPI_RECV calls match by MPI_Comm, tag, and rank. If you don't match all three, the messages will never be received.

Upvotes: 1

Related Questions