MPI_Bcast死锁 [英] MPI_Bcast deadlock

查看:378
本文介绍了MPI_Bcast死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,主服务器将初始数据发送给他的从计算机.它使用MPI_Bcast(广播)功能,但是当调用Broadcast时,主机继续,但从机陷入死锁.

I have this code, where master sends initial data to his slaves. It uses MPI_Bcast (broadcast) function but when the Broadcast is called, the master continues but the slaves are stuck in deadlock.

代码片段如下:

Master {
    run() {
        ...
        MPI_Pack(&offset, 1, MPI_INT, buffer, BUFFERSIZE, &position, MPI_COMM_WORLD);
        MPI_Pack(&dataSize, 1, MPI_INT, buffer, BUFFERSIZE, &position, MPI_COMM_WORLD);
        MPI_Pack(dataLoader.getData(), dataSize*dataSize, MPI_CHAR, buffer, BUFFERSIZE, &position, MPI_COMM_WORLD);
        MPI_Bcast(buffer, position, MPI_PACKED, 0, MPI_COMM_WORLD);
        printf("master ok");
    }
}

Slave {
    run() {
        MPI_Bcast(buffer, BUFFERSIZE, MPI_PACKED, 0, MPI_COMM_WORLD);
        printf("Slave OK");
        //unpack
        MPI_Unpack(buffer, BUFFERSIZE, &position, &offset, 1, MPI_INT, MPI_COMM_WORLD);
        MPI_Unpack(buffer, BUFFERSIZE, &position, &dataSize, 1, MPI_INT, MPI_COMM_WORLD);
        data = new char[dataSize * dataSize];
        MPI_Unpack(buffer, BUFFERSIZE, &position, data, dataSize*dataSize, MPI_CHAR, MPI_COMM_WORLD);

    }
}

输出为: 好吧

The output would be: Master ok

,从站将停止响应. 感谢您的帮助

and the slave would stop responding. Thanks for help

推荐答案

mpi_bcast应该由通信器中的所有进程调用,并且它们都应该在代码中的同一点都遇到该调用.编写(伪)代码后,根进程将发出广播,而工作进程则不会广播,而工作进程则发出根不会广播的调用.

mpi_bcast should be called by all processes in the communicator and they should all encounter the call at the same point in the code. As you have written your (pseudo-)code the root process makes a call to broadcast which the worker processes do not, and the worker processes make a call which the root does not.

mpi_bcast是MPI的 collective 例程之一,该库负责根据传递给它的参数确定正确的消息发送模式.在mpi_bcast的情况下,第四个参数是广播源的ID(尽管它经常是通信者的根进程,但它常常是).通信器中的所有其他进程将是接收器.

mpi_bcast is one of MPI's collective routines, the library takes care of determining the correct pattern of message sending based on the arguments you pass to it. In the case of mpi_bcast the 4th argument is the id of the source of the broadcast (it doesn't need to be the root process of the communicator though it often is); all the other processes in the communicator will be receivers.

这篇关于MPI_Bcast死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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