如何释放boost :: mpi :: request? [英] How do I free a 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, ®ional);
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(®ional);
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_FREE
,MPI_WAIT
或MPI_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 callMPI_REQUEST_FREE
,MPI_WAIT
orMPI_TEST
(or any of the derived operations) with the cancelled request as argument after the call toMPI_CANCEL
. If a communication is marked for cancellation, then aMPI_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屋!