I am trying to do some MPI, and here is a simple program using MPI_Send, MPI_Recv (yes, blocking). Rank 0 sends messages to all other processes and the others receive it. However, my MPI_Send never returns. Am I missing something here? Thanks!
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include"mpi.h"
int main(int argc, char **argv)
{
int rank, size, i;
MPI_Status status;
char message[20];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
strcpy(message, "Hello, world");
if (rank==0){
for(i=1;i<size;i++){
printf("I am sending %s\n", message);
MPI_Send(message, 23, MPI_BYTE, 0, 7, MPI_COMM_WORLD);
printf("Sending node=%d, message=%s\n", rank, message);
}
}
else{
MPI_Recv(message, 23, MPI_BYTE, MPI_ANY_SOURCE, 7, MPI_COMM_WORLD,&status);
printf("Receiving node=%d, message=%s\n", rank, message);
}
MPI_Finalize();
return 0;
}