MPI_Irecv
和MPI_Isend
操作返回一个MPI_Request
,以后可以使用MPI_Cancel
将其标记为已取消。是否有类似的机制来阻止MPI_Probe
和MPI_Mprobe
?
问题的上下文是Boost.MPI request handlers使用Probe的最新实现。
编辑-这是一个如何使用假设的MPI_Probecancel
的示例:
#include <mpi.h>
#include <chrono>
#include <future>
using namespace std::literals::chrono_literals;
// Executed in a thread
void async_cancel(MPI_Probe *probe)
{
std::this_thread::sleep_for(1s);
int res = MPI_Probecancel(probe);
}
int main(int argc,char* argv[])
{
int provided;
MPI_Init_thread(&argc,&argv,MPI_THREAD_MULTIPLE,&provided);
if (rank == 0)
{
// A handle to the probe (similar to a request)
MPI_Probe probe;
// Start a thread
// `probe` will be filled with the next call,pretty ugly
// Ideally,this should be done in two steps like MPI_Irecv,MPI_Wait
auto res = std::async(std::launch::async,&async_cancel,&probe);
MPI_Message message;
MPI_Status status;
MPI_MProbe(1,123,MPI_COMM_WORLD,&message,&status,&probe);
if (!probe.cancelled)
{
int buffer;
MPI_Mrecv(&buffer,1,MPI_INT,&status);
}
}
else
std::this_thread::sleep_for(2s);
MPI_Finalize();
return 0;
}