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************************** ...
随机推荐
- 创建文件指针数组c++
#include<fstream>using namespace std; void main(){ for (int i=0; i<=1; i++) { char szName[1 ...
- mysql系列(3)之 DML语句
DML操作指的是对数据库中表记录的操作,主要包括表记录的插入(insert).更新(update).删除(delete)和查询(select). 1.插入
- eclipse下创建maven项目并部署到tomcat服务器(转)
maven项目部署到服务器有很多方法,可以利用jetty-maven-plugin或者tomcat-maven-plugin,这属于maven的知识点. 通常开发中,需要将项目放在服务器上借助开发工具 ...
- springboot 日志2
SpringBoot关于日志的官方文档 1.简述 SpringBoot官方文档关于日志的整体说明 本博客基于SpringBoot_1.3.6大家请先简单看下这篇英文的官方文档,文中有说 Sprin ...
- SAP请求号的传输
SAP传输目的: SAP传输目的是把开发机中的程序或对象传输到对应的测试机或生成机中,保持各系统的同步性,方便测试和最后的部署! SAP求情号传输的步骤: 1.创建一个请求号 2.用SE10进入如下界 ...
- bootstrap 折叠collapse失效
手动点击折叠,然后调用折叠全部以后,在手动点击折叠项,折叠失效. 方法,折叠项是通过添加或删除".in"来实现,实现如下 $(".collapse.in").c ...
- log4net引用了Mysql.Data.dll,但是就是不能写到mysql数据库的解决办法
这两天遇到log4net写日志到mysql数据库中,有时候在A项目中可以,有时候B项目就有问题,有时候测试环境没问题,到正式部署环境又出问题,经过两天的煎熬,终于理清楚了其中的头绪. 1.配置现状 c ...
- Java运算符号,对象赋值,别名
生活发生的一切,才会促使着我继续前行,今天继续更新哦,看书中的代码练习. 例子1 引入net.mindview.util.Print.* ,方便打印结果. package com.date0529; ...
- Vue filter-v-for 使用
var app5 = new Vue({ el: '#app5', data: { shoppingList: [ "Milk", "Donuts", &quo ...
- (转)Eclipse中需要查看某个类的源码,直接按住Ctrl 然后点击想要查看的类或则方法
文章转自:http://blog.sina.com.cn/s/blog_52f623240102vpcr.html 在Eclipse中需要查看某个类的源码,直接按住Ctrl 然后点击想要查看的 ...