main.cpp
/*main.cpp
*
*The starting point of the network simulator
*-Include all network header files
*-initilize the network
*-initialize the traffic manager and set it to run
*
*
*/
#include <sys/time.h> #include <string>
#include <cstdlib>
#include <iostream>
#include <fstream> #include <sstream>
#include "booksim.hpp"
#include "routefunc.hpp"
#include "traffic.hpp"
#include "booksim_config.hpp"
#include "trafficmanager.hpp"
#include "random_utils.hpp"
#include "network.hpp"
#include "injection.hpp"
#include "power_module.hpp"
///////////////////////////////////////////////////////////////////////////////
//Global declarations
////////////////////// /* the current traffic manager instance */
TrafficManager * trafficManager = NULL; int GetSimTime() {
return trafficManager->getTime();
} class Stats; //数据实体
Stats * GetStats(const std::string & name) {
Stats* test = trafficManager->getStats(name);
if(test == ){
cout<<"warning statistics "<<name<<" not found"<<endl;
}
return test;
} /* printing activity factor*/
bool gPrintActivity; int gK;//radix, the number of routers per dimension
int gN;//dimension, such as 1D, 2D
int gC;//concentration, the number of nodes sharing a single router int gNodes; //generate nocviewer trace
bool gTrace; ostream * gWatchOut;
bool Simulate( BookSimConfig const & config )
{
vector<Network *> net; int subnets = config.GetInt("subnets");
/*To include a new network, must register the network here
*add an else if statement with the name of the network
*/
//resize改变当前使用数据的大小,如果它比当前使用的大,填充默认值
net.resize(subnets);
for (int i = ; i < subnets; ++i) {
/*ostringstream
*通常用于执行C风格的串流的输出操作,
*格式化字符串,避免申请大量的缓冲区,替代sprintf
*该类能够根据内容自动分配内存,对内存的管理也是相当的到位
*取得ostringstream里的内容可以通过str()和str(string&)成员函数
*/
ostringstream name;
name << "network_" << i;
net[i] = Network::New( config, name.str() );
} /*tcc and characterize are legacy
*not sure how to use them
*/
//assert如果它的条件返回错误,则终止程序执行
assert(trafficManager == NULL);
trafficManager = TrafficManager::New( config, net ) ; /*Start the simulation run
*/ double total_time; /* Amount of time we've run */
struct timeval start_time, end_time; /* Time before/after user code */
total_time = 0.0;
//获得当前精确时间
gettimeofday(&start_time, NULL); bool result = trafficManager->Run() ; gettimeofday(&end_time, NULL);
total_time = ((double)(end_time.tv_sec) + (double)(end_time.tv_usec)/1000000.0)
- ((double)(start_time.tv_sec) + (double)(start_time.tv_usec)/1000000.0); cout<<"Total run time "<<total_time<<endl; for (int i=; i<subnets; ++i) { ///Power analysis
if(config.GetInt("sim_power") > ){
Power_Module pnet(net[i], config);
pnet.run();
} delete net[i];
} delete trafficManager;
trafficManager = NULL; return result;
}
int main( int argc, char **argv )
{ BookSimConfig config; if ( !ParseArgs( &config, argc, argv ) ) {
cerr << "Usage: " << argv[] << " configfile... [param=value...]" << endl;
return ;
} /*initialize routing, traffic, injection functions
*/
InitializeRoutingMap( config ); gPrintActivity = (config.GetInt("print_activity") > );
gTrace = (config.GetInt("viewer_trace") > ); string watch_out_file = config.GetStr( "watch_out" );
if(watch_out_file == "") {
gWatchOut = NULL;
} else if(watch_out_file == "-") {
gWatchOut = &cout;
} else {
gWatchOut = new ofstream(watch_out_file.c_str());
} /*configure and run the simulator
*/
bool result = Simulate( config );
return result ? - : ;
}
main.cpp的更多相关文章
- [原创]C/C++语言中,如何在main.c或main.cpp中调用另一个.c文件
C/C++语言中,如何在main.cpp中调用另一个.c文件主要有5种思路: 1.在VS2012 IDE中,将被引用的.c文件后缀名全部修改为.h,然后通过IDE的解决方案资源管理器中鼠标右键单击“头 ...
- Compiling: main.cpp /bin/sh: g++: not found
Kbuntu用codeblocks编写C程序的时候,编译报错如下: Compiling: main.cpp/bin/sh: g++: not found 解决方法: sudo apt-get inst ...
- 【评测机】评测时报错cc1plus: fatal error: /xx/xx/main.cpp: Permission denied compilation terminated.的解决方法
事情是这亚子发生的,原本建立评测机的时候就出现过这个问题,但莫名其妙就解决了. 报错的文件路径是位于docker内的,所以本质上这个错误是docker内的没有权限执行相关文件. 原因是centos7中 ...
- 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码
前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...
- template 不能分别在.h和.cpp中定义模板
先上代码: #ifndef SEQLIST_H #define SEQLIST_H #include <iostream> ; template <typename type> ...
- Nginx + CGI/FastCGI + C/Cpp
接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...
- QWebView在 Qt 5.x中编译出错:File not found: main.obj
错误现象 近日由于项目需要,想要学习一下QWebView的使用.于是简单的建立了一个Qt工程,并编写了如下代码: #include <QApplication> #include < ...
- x01.Game.Main: 从零开始
一切从零开始,一切皆有可能. 浅墨,90后,<逐梦之旅>深入浅出,堪比大师. 1.安装 DXSDK_June10.exe 或更新版本. 2.运行 vs2012,新建 VC Win32 空项 ...
- Cocos2d-x 关于Android.mk 自动读入CPP
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
随机推荐
- stm32 map文件的分析
相信有较大项目开发经验的朋友都曾遇到内存溢出的问题,那么大家都是如何分析这类问题的呢?大家遇到HardFault_Handler 有对map分析过吗? 首先讲述一下关于map在MDK-ARM中的配置. ...
- python的常用库及文档使用
1.requests 官网链接 http://docs.python-requests.org/zh_CN/latest/user/quickstart.html 2.机器学习最热门的tensorfl ...
- 【git】日志提交规范
我自己总结的规范: feature: 功能添加bugfix: bug修复change: 调整,比如配置,某些方法替换等optimize: 优化过程doc: 文档变更refactor: 重构,功能不变t ...
- [剑指Offer]27-二叉树的镜像
题目链接 https://www.nowcoder.com/practice/564f4c26aa584921bc75623e48ca3011?tpId=13&tqId=11171&t ...
- mysql定时删除6个月前的表
查看定时是否开启: 查看event是否开启 : SHOW VARIABLES LIKE '%event_sche%'; 将事件计划开启 : ; 将事件计划关闭 : ; 代码: BEGIN -- 保存表 ...
- To be a better me
2017.4.15 突然成为前端实习生.做了两个周的官网项目,主要是更新官网一些文字图片以及新加一个页面,因为是静态页面,所以熟悉了代码就上手了.幸好没出什么差错. 两周后,实习结束. 2017.7. ...
- c#引用命名空间的作用
System 包含用于定义常用值和引用数据类型.事件和事件处理程序.接口.属性和处理异常的基础类和基类.其他类提供支持下列操作的服务:数据类型转换,方法参数操作,数学计算,远程和本地程序调用,应用程序 ...
- android项目安装报错:INSTALL_FAILED_CONFLICTING_PROVIDER
这主要是由于调试的环境中已有一个同名的Provider存在. 解决方法是修改AndroidManifest.xml中的 <provider android:name="applockP ...
- Android 中 IntentService 的优点
简而言之:可以处理异步请求,任务完成会自动停止自己. IntentService是一个通过Context.startService(Intent)启动可以处理异步请求的Service,使用时你只需要 ...
- config/index.js
// see http://vuejs-templates.github.io/webpack for documentation.var path = require('path') module. ...