/*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的更多相关文章

  1. [原创]C/C++语言中,如何在main.c或main.cpp中调用另一个.c文件

    C/C++语言中,如何在main.cpp中调用另一个.c文件主要有5种思路: 1.在VS2012 IDE中,将被引用的.c文件后缀名全部修改为.h,然后通过IDE的解决方案资源管理器中鼠标右键单击“头 ...

  2. Compiling: main.cpp /bin/sh: g++: not found

    Kbuntu用codeblocks编写C程序的时候,编译报错如下: Compiling: main.cpp/bin/sh: g++: not found 解决方法: sudo apt-get inst ...

  3. 【评测机】评测时报错cc1plus: fatal error: /xx/xx/main.cpp: Permission denied compilation terminated.的解决方法

    事情是这亚子发生的,原本建立评测机的时候就出现过这个问题,但莫名其妙就解决了. 报错的文件路径是位于docker内的,所以本质上这个错误是docker内的没有权限执行相关文件. 原因是centos7中 ...

  4. 使用“Cocos引擎”创建的cpp工程如何在VS中调试Cocos2d-x源码

    前段时间Cocos2d-x更新了一个Cocos引擎,这是一个集合源码,IDE,Studio这一家老小的整合包,我们可以使用这个Cocos引擎来创建我们的项目. 在Cocos2d-x被整合到Cocos引 ...

  5. template 不能分别在.h和.cpp中定义模板

    先上代码: #ifndef SEQLIST_H #define SEQLIST_H #include <iostream> ; template <typename type> ...

  6. Nginx + CGI/FastCGI + C/Cpp

    接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...

  7. QWebView在 Qt 5.x中编译出错:File not found: main.obj

    错误现象 近日由于项目需要,想要学习一下QWebView的使用.于是简单的建立了一个Qt工程,并编写了如下代码: #include <QApplication> #include < ...

  8. x01.Game.Main: 从零开始

    一切从零开始,一切皆有可能. 浅墨,90后,<逐梦之旅>深入浅出,堪比大师. 1.安装 DXSDK_June10.exe 或更新版本. 2.运行 vs2012,新建 VC Win32 空项 ...

  9. Cocos2d-x 关于Android.mk 自动读入CPP

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

随机推荐

  1. angular小技巧随笔

    1. 重新刷新页面 同页面切换状态: $state.go('tab.index', {inviteId:inviteId}); self.location.reload();

  2. ACM-ICPC 2018 南京赛区网络预赛 G. Lpl and Energy-saving Lamps(二分+线段树区间最小)

    During tea-drinking, princess, amongst other things, asked why has such a good-natured and cute Drag ...

  3. delete[] p与 delete p

    基本类型的对象没有析构函数,所以回收基本类型组成的数组空间用 delete 和 delete[] 都是应该可以的:但是对于类对象数组,只能用 delete[].对于 new 的单个对象,只能用 del ...

  4. HttpClient--使用HttpClient进行Get Post请求访问

    在java后台开发中,我们有时候需要调用其他网站的接口进行数据的获取操作,我们一般会采用 1.java net 包中的URL 类,进行网络的数据获取 2.使用apache提供的HttpClient进行 ...

  5. day 16 包,random,shutil

    包: 函数过多,可以分模块文件去管理函数,模块文件过多,将模块文件分类放在一个个的文件夹中,这个文件夹就叫做包,组织结构更加清晰,合理! 模式就是被别人使用,包既然是一些模块的集合,也是被调用. 文件 ...

  6. Day 04 列表,元祖,range

    列表: why: 1.字符串取值费劲 2.对字符串做任何操作,取出来的都是字符串 3.字符串有长度限制 基于以上原因,python提供了另一个数据类型,list 容器类数据类型. 列表页脚数组,可以存 ...

  7. wampserver 403forbidden问题

    1.c:\wamp\alias\phpmyadmin.conf 打开之后又这么一段源码; <Directory "D:\wamp\apps\phpmyadmin3.4.10.1/&qu ...

  8. Python爬虫项目--爬取猫眼电影Top100榜

    本次抓取猫眼电影Top100榜所用到的知识点: 1. python requests库 2. 正则表达式 3. csv模块 4. 多进程 正文 目标站点分析 通过对目标站点的分析, 来确定网页结构,  ...

  9. linux C程序中获取shell脚本输出(如获取system命令输出)

    转载自 http://blog.csdn.net/hjxhjh/article/details/7909518 1. 前言 Unix 界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些 ...

  10. vue 初识组件

    Vue.component("greeting",{ template: `<p>{{ name }}大家好 <button v-on:click="c ...