我正在使用NS3框架运行不同配置的with模拟。我想使用std::线程在一个进程中同时运行许多(数百)模拟。
下面是我的代码,并修改了一些配置:
void simulation(RateAdaptation rate_adaptation,
const bool channel_fading,
// In meters, between AP and station.
const uint32_t distance)
{
ns3::SeedManager::SetSeed(++seed);
ns3::NodeContainer station_node, ap_node;
station_node.Create(1);
ap_node.Create(1);
ns3::YansWifiChannelHelper channel;
channel.SetPropagationDelay("ns3::ConstantSpeedPropagationDelayModel");
channel.AddPropagationLoss( "ns3::LogDistancePropagationLossModel");
// About 130 lines of more configuration for the simulation and
// function parameters.
ns3::Simulator::Stop(ns3::Seconds(10.0));
ns3::Ptr<ns3::FlowMonitor> flowmon;
ns3::FlowMonitorHelper *flowmonHelper = new ns3::FlowMonitorHelper();
flowmon = flowmonHelper->InstallAll();
ns3::Simulator::Run();
ns3::Simulator::Destroy();
flow_output(flowmon, flowmonHelper);
}
int main(int argc, char *argv[])
{
std::vector<std::thread> jobs;
for (uint32_t i = 0; i < 20; ++i)
{
uint32_t varying_distance = 5*(i+1);
jobs.push_back(std::thread(simulation,
RateAdaptation::Aarf,
false,
varying_distance));
}
for (auto it = jobs.begin(); it < jobs.end(); ++it)
{
it.join();
}
return 0;
}
当我只为作业中的一个作业运行这段代码时,它工作得很好,但是对于任何更大的数字(例如两个),我得到的输出如下:
assert failed. cond="SystemThread::Equals (m_main)", msg="Simulator::ScheduleDestroy Thread-unsafe invocation!", file=../src/core/model/default-simulator-impl.cc, line=289
terminate called without an active exception
Command ['[redacted]'] terminated with signal SIGIOT. Run it under a debugger to get more information (./waf --run <program> --comm and-template="gdb --args %s <args>").
实际上,在瓦伦丁运行它会带来数百个问题。
两个问题:
发布于 2016-02-23 07:14:41
简短的回答是:你不能用ns-3来完成这个任务。
长篇大论的答案是:使用多个进程而不是多个线程( ns-3库维护不受多线程一致保护的全局状态)。
我建议使用ns-3 python包装器轻松设置并行多处理作业。如果您想在默认的跟踪设置之外执行跟踪,这可能并不简单(在本例中,您可能需要在C++中执行自己的跟踪,在python中进行拓扑设置)
发布于 2016-02-26 04:17:50
我在这方面的工作是注释掉默认的2断言检查,然后新线程运行良好:
DefaultSimulatorImpl::调度(时间控制与延迟,EventImpl *事件){
// NS_ASSERT_MSG (SystemThread::Equals (m_main),“模拟器:调度线程-不安全调用!”);//第231行.}
DefaultSimulatorImpl::ScheduleNow {
// NS_ASSERT_MSG (SystemThread::Equals (m_main),“模拟器:ScheduleNow线程-不安全调用!”);//第284行.}
然后运行与valgring,以验证潜在的种族/mem问题。
https://stackoverflow.com/questions/35543906
复制相似问题