所以我得扔在一起這個簡單的MPI例子。我在測試boost :: mpi :: request時看到一些奇怪的行爲,我無法解釋。具體來說,如果您刪除了對第二個循環的評論,它將永遠旋轉。在boost :: mpi :: request上測試是否只返回true?如果是這樣,什麼狀態正在更新?我通過Boost的MPI和可選代碼進行了探索,但我無法解釋我所看到的。我對boost :: mpi :: request缺少什麼?測試似乎改變狀態
(當然,對於新手來說,你需要使用mpiexec的兩個節點,以這種自己跑。)
# include "stdafx.h"
# include <boost/serialization/string.hpp>
# include <boost/mpi.hpp>
# include <windows.h>
# include <iostream>
# include <boost/mpi.hpp>
# include <boost/optional.hpp>
int main(int argc, char *argv[]);
int main(int argc, char *argv[])
{
boost::mpi::environment m_env;
boost::mpi::communicator m_world;
if (m_world.rank() == 0)
{
m_world.send(1,0, std::string("hi!"));
}
else
{
std::shared_ptr<std::string> rcv = std::shared_ptr<std::string>(new std::string());
boost::mpi::request x = m_world.irecv(0, 0, *rcv);
while (!x.test())
{
Sleep(10);
}
//while (!x.test())
//{
// Sleep(10);
//}
std::cout << *rcv;
}
}
是的,這就是我最終做的 - 只是書寫我自己的布爾。我沒有考慮底層的MPI_TEST - 謝謝 – Carbon