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************************** ...
随机推荐
- 微信小程序接入百度统计
一. 百度统计添加应用,获取appkey和微信小程序统计sdk: 1. 百度统计首页,点击“我的全部应用”右侧的添加按钮: 2. “应用类型”选择小程序统计,选择微信小程序,填写应用名称信息,选择内容 ...
- Wannafly挑战赛14 C.可达性(tarjan缩点)
题目描述 给出一个 0 ≤ N ≤ 105 点数.0 ≤ M ≤ 105 边数的有向图, 输出一个尽可能小的点集,使得从这些点出发能够到达任意一点,如果有多个这样的集合,输出这些集合升序排序后字典序最 ...
- Springboot学习01- 配置文件加载优先顺序和本地配置加载
Springboot学习01-配置文件加载优先顺序和本地配置加载 1-项目内部配置文件加载优先顺序 spring boot 启动会扫描以下位置的application.properties或者appl ...
- 高盛昂赛 算法题先写corner case
[方法] 字写大点,先注释框架 链表:指针走就行了,最多是两个同时一起走. 两个链表求交点 //corner case if (headA == null || headB == null) { re ...
- 31-java中知识总结:list, set, map, stack, queue
import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Lin ...
- Python 安装pyautogui
在Python中使用PyAutoGui模拟键盘和鼠标操作 一.系统环境 操作系统:win10 64位 Python版本:Python 3.7.0 二.安装参考 1.使用pip进行安装,pip inst ...
- golang语言中os/exec包的学习与使用
package main; import ( "os/exec" "fmt" "io/ioutil" "bytes" ) ...
- HTML day48
前端知识之HTML内容 HTML介绍 Web服务本质 import socket#引入套接字模块 sk = socket.socket()#实例化一个套接字对象 sk.bind(("12 ...
- css 边距等常用设置
前端知识 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- hdu 1175(BFS&DFS) 连连看
题目在这里:http://acm.hdu.edu.cn/showproblem.php?pid=1175 大家都很熟悉的连连看,原理基本就是这个,典型的搜索.这里用的是广搜.深搜的在下面 与普通的搜索 ...