MPI-异步广播/聚集 [英] MPI - Asynchronous Broadcast/Gather

查看:120
本文介绍了MPI-异步广播/聚集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a project which requires 'n' number of processes to work until the problem is solved. Each slave process executes the same code. When a certain condition arises, the process needs to notify all of the other processes in a non-blocking way. The other processes also need to receive this message in a non-blocking way.

有没有一种方法可以在不使用单独的循环的情况下进行处理?

Is there a way to do with without threading a separate loop?

推荐答案

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

It's been a while since I've used MPI. But the I functions are non-blocking. Maybe something like this:

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;

这篇关于MPI-异步广播/聚集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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