MPI - 异步广播/收集

xxf*_*8xx 6 c++ process mpi

我有一个项目需要'n'个进程才能解决问题.每个从属进程执行相同的代码.当出现某种情况时,该过程需要以非阻塞方式通知所有其他进程.其他进程还需要以非阻塞方式接收此消息.

有没有办法没有线程单独的循环?

Geo*_*tee 4

我已经有一段时间没有使用 MPI 了。但I函数是非阻塞的。也许是这样的:

int comm_size = comm.Get_size();
int comm_rank = comm.Get_rank();

int* data = new int[comm_size];

while (some_condition)
{
    //During each iteration, check for messages from other nodes
    for (int node = 0; node < comm_size; node++)
    {
        if (node != comm_rank)
        {
            if (comm.Iprobe(node, TAG_NUM))
            {
                comm.Irecv(data[node], 1, MPI_INT, node, TAG_NUM);
            }
        }
    }

    if (some_other_condition)
    {
        //Send the message to every node
        for (int node = 0; node < comm_size; node++)
        {
            if (node != comm_rank)
            {
                comm.Isend(data[node], 1, MPI_INT, node, TAG_NUM);
            }
        }
    }

    //do normal work here.
}

delete [] data;
Run Code Online (Sandbox Code Playgroud)