I am trying to implement a workpool here. I am supposed to send 100 differnt to numbers in total to slave processes. Each slave process then returns something to master process and another different number is sent to the slave by the master. This continues until all the 100 iterations are over.
My program gets kind of stuck in an infinite loop which I think is due to incorrect mapping of MPI_Send and MPI_Recv. I can't figure out what I am doing wrong. I have spent quite a few hours looking into this but to no avail. I am new to MPI and programming in general. The code is given below:
if(rank == 0) {
int i,iteration = 0, a=0,inside=0,temp=0;
for(i = 1; i < slaves; i++) {
MPI_Send(&iteration,1,MPI_INT,i,0,MPI_COMM_WORLD);
MPI_Send(&a,1,MPI_INT,i,1,MPI_COMM_WORLD);
iteration++;
}
while(iteration < 100+slaves){
MPI_Recv(&temp,1,MPI_INT,MPI_ANY_SOURCE,0, MPI_COMM_WORLD, &status);
if(iteration < 100) {
MPI_Send(&iteration,1,MPI_INT,status.MPI_SOURCE,0,MPI_COMM_WORLD);
MPI_Send(&a,1,MPI_INT,status.MPI_SOURCE,1,MPI_COMM_WORLD);
}
iteration++;
inside = inside + temp;
}
}
else {
int iteration=0,count=0;
if(iteration < 100) {
MPI_Recv(&iteration,1,MPI_INT,0,0,MPI_COMM_WORLD,&status);
MPI_Recv(&count,1,MPI_INT,0,1,MPI_COMM_WORLD,&status);
MPI_Send(&count,1,MPI_INT,0,0,MPI_COMM_WORLD);
}
}
for(i = 1; i < slaves; i++) {
? – Anto Jurković