【发布时间】:2023-03-29 02:45:01
【问题描述】:
我正在用 MPI 库用 C++ 编写程序。发生死锁只有一个节点有效!我没有使用发送或接收集合操作,而只使用了两个集合函数(MPI_Allreduce 和MPI_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();
}
【问题讨论】: