如何知道MPI请求的接收者和发送者 [英] How to know the receiver and the sender of an MPI request

查看:174
本文介绍了如何知道MPI请求的接收者和发送者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以知道接收器进程,发送者进程和MPI通信在boost中的标签值。

I wonder if there is a way to know the receiver process, the sender process and tag values of an MPI communication in boost.

现在,我有一些进程其彼此发送/接收大量消息。而且,我在接收器端有一个boost :: mpi :: request的集合。此集合存储已接收的请求项目。在通信操作完成后,我可以从这个集合中提取接收者进程和发送者进程是谁吗? (我还需要知道标签的值。)或者,我应该改变我的策略?

Now, I have some processes which send/receive a lot of messages to/from each other. And, I have a collection of boost::mpi::request in the receiver side. This collection stores the request items that have been received. After the communication operations are completed, can I extract who the receiver process and the sender process are, from this collection? (I also need to know the tag value.) Or, should I change my strategy? Maybe having a collection of requests does not make sense?

推荐答案

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

That information is in the status after the request is completed, not in the request itself.

#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;
}

这篇关于如何知道MPI请求的接收者和发送者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆