如何知道接收器和MPI请求的发送者(How to know the receiver and the

2019-10-21 09:32发布

我不知道是否有知道接收机的过程中,发送进程和提升的MPI通信的标签值的方法。

现在,我有一些过程,其发送/接收大量的信息到/从对方。 而且,我在接收端的boost :: MPI ::请求的集合。 此集合存储已接收到请求的项目。 通信操作完成后,我可以提取谁接收过程和发送过程,从这个集合? (我还需要知道标记值。)或者,我应该改变我的策略是什么? 也许有请求的集合体没有意义?

Answer 1:

这些信息是在状态请求完成之后,而不是在请求本身。

#include <boost/mpi.hpp>
#include <iostream>
#include <string>
#include <boost/serialization/string.hpp>
namespace mpi = boost::mpi;

int main()
{
    mpi::environment env;
    mpi::communicator world;

    if (world.rank() == 0) {
        std::string msg, out_msg = "Hello from rank 0.";
        world.send(1, 17, out_msg);
    } else {
        mpi::request req[1];
        mpi::status stat[1];
        std::string rmsg;

        req[0] = world.irecv(mpi::any_source, mpi::any_tag, rmsg);
        mpi::wait_all(req, req + 1, stat);

        std::cout << "Got " << rmsg << std::endl;
        std::cout << "From   " << stat[0].source() << std::endl;
        std::cout << "Tagged " << stat[0].tag() << std::endl;
    }

    return 0;
}


文章来源: How to know the receiver and the sender of an MPI request