を使用して多くのメッセージを送信する予定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
ます。
少数のメッセージでこれをテストしましたが、うまくいくように見えますが、常にうまくいくのか、それとも運が良かっただけなのかはわかりません。