c++ - 具有集体功能的 MPI 死锁

标签 c++ mpi

我正在使用 MPI 库用 C++ 编写程序。只有一个节点工作时发生死锁!我没有使用发送或接收集合操作,而只使用了两个集合函数(MPI_AllreduceMPI_Bcast)。 如果有节点等待其他节点发送或接收内容,我实际上不明白是什么导致了这个死锁。

void ParaStochSimulator::first_reacsimulator() {
    SimulateSingleRun();
}

double ParaStochSimulator::deterMinTau() {
    //calcualte minimum tau for this process
    l_nLocalMinTau = calc_tau(); //min tau for each node
    MPI_Allreduce(&l_nLocalMinTau, &l_nGlobalMinTau, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);    
    //min tau for all nodes
    //check if I have the min value
    if (l_nLocalMinTau <= l_nGlobalMinTau && m_nCurrentTime < m_nOutputEndPoint) {
        FireTransition(m_nMinTransPos);
        CalculateAllHazardValues(); 
    }
    return l_nGlobalMinTau;
}

void ParaStochSimulator::SimulateSingleRun() {
    //prepare a run
    PrepareRun();
    while ((m_nCurrentTime < m_nOutputEndPoint) && IsSimulationRunning()) {
        deterMinTau();
        if (mnprocess_id == 0) { //master
            SimulateSingleStep();
            std::cout << "current time:*****" << m_nCurrentTime << std::endl;
            broad_casting(m_nMinTransPos);
            MPI_Bcast(&l_anMarking, l_nMinplacesPos.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
            //std::cout << "size of mani place :" << l_nMinplacesPos.size() << std::endl;
        }
    }
    MPI_Bcast(&l_anMarking, l_nMinplacesPos.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
    PostProcessRun();
}

最佳答案

当您的“主”进程正在执行 A MPI_Bcast 时,所有其他进程仍在运行您的循环,然后进入 deterMinTau,然后执行 MPI_Allreduce。

这是一个死锁,因为您的主节点正在等待所有节点执行 Brodcast,而所有其他节点都在等待主节点执行 Reduce。

我相信您正在寻找的是:

void ParaStochSimulator::SimulateSingleRun() {
    //prepare a run
    PrepareRun();
    while ((m_nCurrentTime < m_nOutputEndPoint) && IsSimulationRunning()) {
        //All the nodes reduce tau at the same time
        deterMinTau();
        if (mnprocess_id == 0) { //master
            SimulateSingleStep();
            std::cout << "current time:*****" << m_nCurrentTime << std::endl;
            broad_casting(m_nMinTransPos);
            //Removed bordcast for master here
        }
        //All the nodes broadcast at every loop iteration
        MPI_Bcast(&l_anMarking, l_nMinplacesPos.size(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
    }
    PostProcessRun();
}

关于c++ - 具有集体功能的 MPI 死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43807532/

相关文章:

c++ - boost::mpi 的 irecv() 返回未初始化的状态对象

file-io - MPI-FORTRAN 的文件 IO

c++ - struct 旁边的 < > 是做什么的?

c++ - 如何在 std::function 上创建一个钩子(Hook)?

c++ - 对类的 undefined reference

C++ "vector iterator not decrementable"?

c - Mpi_Send 和 Mpi_Recv 用于发送矩阵的分区而不是分散

python - 运行 MPI 脚本时 -n 和 -np 之间的区别?

c++ - 在多个节点上运行时 MPI_Reduce() 中的死锁

c++ - Qt5:如何在本地文件系统中读取/写入文件