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************************** ...
随机推荐
- 微信小程序开发——前端如何区分小程序运行环境
前言: 之前用vue做h5项目,对于接口请求,都是根据前端访问域名来判断运行环境,然后自动适配对应的服务器地址的.这样的好处就是在开发.测试及发布上线全程都不需要手动去改接口请求地址,只要提前配置好就 ...
- xadmin系列之单实例模式
先看下单实例的定义 python的模块实现单例模式是python语言特有的,python的模块天然就是单例的,因为python有个pyc文件,导入一次后,第二次导入直接从pyc中取数据了 这里我们主要 ...
- webpack(一) 安装使用 之css使用注意
在webpackDemo 文件夹中新建 style.css,index.html style.css 中将背景色设为红色. body{ background-color: red; } he'llWo ...
- linux命令学习之:read
read命令从键盘读取变量的值,通常用在shell脚本中与用户进行交互的场合.该命令可以一次读取多个变量的值,变量和输入的值都需要使用空格隔开.在read命令后面,如果没有指定变量名,读取的数据将被自 ...
- 5.Mysql常用函数
5.常用函数函数可以进行字符串的处理.数值计算和日期计算等,mysql可以用在SQL(DML)中以增加SQL的功能.5.1 数值函数1. abs(x) 返回x的绝对值select abs(5),abs ...
- laravel框架数据迁移
迁移就像数据库的版本控制,允许团队简单轻松的编辑并共享应用的数据库表结构,迁移通常和Laravel 的 schema 构建器结对从而可以很容易地构建应用的数据库表结构.如果你曾经告知小组成员需要手动添 ...
- python添加fluent日志记录-aop
python添加fluent日志,aop实现 1.配置fluent相关信息 fluent_config.ini fluent_config.ini [fluent.aop] #is support f ...
- 为什么CNN能自动提取图像特征
1.介绍 在大部分传统机器学习场景里,我们先经过特征工程等方法得到特征表示,然后选用一个机器学习算法进行训练.在训练过程中,表示事物的特征是固定的. 后来嘛,后来深度学习就崛起了.深度学习对外推荐自己 ...
- 常用的TCP Option
当前,TCP常用的Option如下所示———— Kind (Type) Length Name Reference 描述 & 用途 0 1 EOL RFC 793 选项列表结束 1 1 NOP ...
- N! (大数,优化)
Problem Description 输出N的阶乘.(注意时间限制150ms&&注意不能打表后输出) 打表的定义:在本地主机预先计算出了每个值对应的答案,并把输入和输出的映射直接写入 ...