I am trying to send implement master-slave pattern in which master has an array(acts as job queue) and sends data to slave processors. Based on the data obtained from master, slaves compute results and return answers to master. Master on receiving results, find out the slave rank from which msg was received, and then send the next job to that slave.
This is the code skeleton which I have implemented:
if (my_rank != 0)
{
MPI_Recv(&seed, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &status);
//.. some processing
MPI_Send(&message, 100, MPI_FLOAT, 0, my_rank, MPI_COMM_WORLD);
}
else
{
for (i = 1; i < p; i++) {
MPI_Send(&A[i], 1, MPI_FLOAT, i, tag, MPI_COMM_WORLD);
}
for (i = p; i <= S; i++) {
MPI_Recv(&buf, 100, MPI_FLOAT, MPI_ANY_SOURCE, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
//.. processing to find out free slave rank from which above msg was received (y)
MPI_Send(&A[i], 1, MPI_FLOAT, y, tag, MPI_COMM_WORLD);
}
for (i = 1; i < p; i++) {
MPI_Recv(&buf, 100, MPI_FLOAT, MPI_ANY_SOURCE, MPI_ANY_TAG,MPI_COMM_WORLD, &status);
// .. more processing
}
}
If I am using 4 processor; 1 is master and 3 are slaves; the program sends and receives messages for first 3 jobs in job queue but after that the program hangs. What could be the problem?