Algorithms: Sequential, Parallel and Distributed 1-19
worker_state = (int*)calloc(p, sizeof(int));
for(i=1; i < p; i++)
worker_state[i] = W;
{
int SourceWorker = 0;
MPI_Recv(message, MSG_LEN, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG,
MPI_COMM_WORLD, &status);
SourceWorker = status.MPI_SOURCE;
// extract next unsent initial task tasknext
change_worker_state(SourceWorker, W);
MPI_Bsend((void*)(task+cur_task*MSG_LEN), MSG_LEN, MPI_INT,
SourceWorker, T, MPI_COMM_WORLD);
cur_task++;
}
else
{
{
j++;
}
*message = SourceWorker;
change_worker_state(SourceWorker, S);
MPI_Bsend(message, MSG_LEN, MPI_INT, j, H, MPI_COMM_WORLD);
}
else
{
change_worker_state(SourceWorker, I);
}
}
break;