发布
社区首页 >问答首页 >基于NS3和std::线程的并行仿真

基于NS3和std::线程的并行仿真
EN

Stack Overflow用户
提问于 2016-02-22 00:21:17
回答 2查看 2K关注 0票数 3

我正在使用NS3框架运行不同配置的with模拟。我想使用std::线程在一个进程中同时运行许多(数百)模拟。

下面是我的代码,并修改了一些配置:

代码语言:javascript
代码运行次数:0
复制
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;
}

当我只为作业中的一个作业运行这段代码时,它工作得很好,但是对于任何更大的数字(例如两个),我得到的输出如下:

代码语言:javascript
代码运行次数: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>").

实际上,在瓦伦丁运行它会带来数百个问题。

两个问题:

  • 我是否可能做错了什么,而NS3应该支持这一点?
  • 知道NS3不能并行运行多个模拟吗?
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-02-23 07:14:41

简短的回答是:你不能用ns-3来完成这个任务。

长篇大论的答案是:使用多个进程而不是多个线程( ns-3库维护不受多线程一致保护的全局状态)。

我建议使用ns-3 python包装器轻松设置并行多处理作业。如果您想在默认的跟踪设置之外执行跟踪,这可能并不简单(在本例中,您可能需要在C++中执行自己的跟踪,在python中进行拓扑设置)

票数 1
EN

Stack Overflow用户

发布于 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问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35543906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档