我有类似的东西
while(j<nOSlaves)
{
//Iterate through all the slaves.
for(int i=1;i<nOSlaves && j<nOSlaves;i++)
{
//Create a taskMessage which contains length and distance.
MPI_Status st;
MPI_Recv(&buffer, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &st);
if (buffer > 0)
{ //Handle the message.... }
}
}
现在的问题是我必须等待每个人直到消息到达,我希望它更快并尝试异步。
MPI_Irecv(&buffer, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &rq);
int flag = 0;
MPI_Test(&rq, &flag, &st);
//If the asynchronous message has been received advance, else try again later.
if (flag)
{ //Handle the message.... }
但是在 for 的每次迭代之后,我都会丢失请求。有没有办法遍历所有“奴隶”并查看是否有人已经回答?