如何释放boost :: mpi :: request? [英] How do I free a boost::mpi::request?

查看:207
本文介绍了如何释放boost :: mpi :: request?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使MPI断开通信器的连接,这是一项艰巨的任务-我在下面整理了一个演示.我有相同想法的两个版本,一个int,一个使用MPI_IRecv,一个使用boost :: mpi :: request.

I'm trying to get MPI to disconnect a communicator, which is a tetchy business - I've put together a demo below. I've got two versions of the same idea, listening for an int, one using MPI_IRecv, and one using a boost::mpi::request.

您会注意到,在此程序上使用mpiexec -n 2时,版本A会很高兴地断开连接并退出,而版本B不会.有什么技巧可以使MPI_Request_free-ing boost :: mpi :: request吗?这似乎是这里的区别.如果有关系,我将使用MSVC和MSMPI,以及Boost 1.62.

You'll note when using mpiexec -n 2 on this program that version A will happily disconnect and exit, but version B will not. Is there some trick to MPI_Request_free-ing a boost::mpi::request? That seems to be the difference here. If it matters, I'm using MSVC and MSMPI, and Boost 1.62.

#include "boost/mpi.hpp"
#include "mpi.h"

int main()
{
    MPI_Init(NULL, NULL);
    MPI_Comm regional;
    MPI_Comm_dup(MPI_COMM_WORLD, &regional);
    boost::mpi::communicator comm = boost::mpi::communicator(regional, boost::mpi::comm_attach);
    if (comm.rank() == 1)
    {
        int q;

        //VERSION A:
//      MPI_Request n;
//      int j = MPI_Irecv(&q, 1, MPI_INT, 1, 0, regional, &n);
//      MPI_Cancel(&n);
//      MPI_Request_free(&n);

        //VERSION B:

//      boost::mpi::request z = comm.irecv<int>(1, 0, q);
//      z.cancel();

    }
    MPI_Comm_disconnect(&regional);
    MPI_Finalize();
    return 0;
}

我找到错误了吗?我怀疑我是否在代码中很深.

Did I find a bug? I doubt I'm deep in the code.

推荐答案

好吧,如果有记录的话,它不是一个错误:

Well, it guess it's not a bug if it's documented: MPI_Request_free is unsupported by Boost.MPI.

现在回到MPI本身:

MPI_CANCEL的调用将取消未完成的无阻塞通信操作(发送或接收)标记为取消.取消呼叫是本地电话.立即返回,可能在实际取消通讯之前.仍然有必要使用已取消的请求调用MPI_REQUEST_FREEMPI_WAITMPI_TEST(或任何派生的操作),如下所示: 调用MPI_CANCEL之后的参数. 如果某个通信被标记为取消,那么无论其他进程的活动如何,都保证会返回对该通信的MPI_WAIT调用(即MPI_WAIT充当本地函数);

A call to MPI_CANCEL marks for cancellation a pending, nonblocking communication operation (send or receive). The cancel call is local. It returns immediately, possibly before the communication is actually cancelled. It is still necessary to call MPI_REQUEST_FREE, MPI_WAIT or MPI_TEST (or any of the derived operations) with the cancelled request as argument after the call to MPI_CANCEL. If a communication is marked for cancellation, then a MPI_WAIT call for that communication is guaranteed to return, irrespective of the activities of other processes (i.e., MPI_WAIT behaves as a local function);

这就是说,

z.cancel();
z.wait();

你应该没事.

现在,恕我直言,这是Boost.MPI对适当的RAII的严重浪费.

Now, IMHO this is a bad waste of proper RAII by Boost.MPI.

这篇关于如何释放boost :: mpi :: request?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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