我将使用 发送许多消息MPI_Isend
,但我不确定如何确保我的数据在收到之前是安全的,同时,不要用完所有可用的内存。
目前,我正在做这样的事情:
vector<int*> outbox;
vector<MPI_Request> stats;
void run()
{
while (!done())
{
//some magic
//...
sendMsg(rand(), getRecipRank());
}
}
void sendMsg(int n, int recipRank)
{
//Need to gen n random integers and send it to proc with rank recipRank
//Can't block until the numbers are reveived.
//So how do I make sure these numbers are safe until then?
int* data = (int*)malloc(sizeof(int) * n);
//fill the data array with random numbers here
MPI_Request req;
MPI_Isend(data, n, MPI_INT, recipRank, 0, MPI_COMM_WORLD, &req);
//Keeping the pointer to the array to free it later
outbox.push_back(data); //Does this help keep the data safe until they're received?
stats.push_back(req);
}
然后我有另一个函数偶尔会通过stats
向量来检查发送的状态。如果完成,则该函数释放请求和outbox
.
我已经用少量消息对此进行了测试,它似乎有效,但我不确定它是否总是有效,或者我只是很幸运。