?? noxim_explorer.cpp.svn-base
字號:
#include <iostream>#include <iomanip>#include <fstream>#include <sstream>#include <vector>#include <map>#include <string>#include <cassert>#include <cstdlib>#include <sys/time.h>using namespace std;//---------------------------------------------------------------------------#define DEFAULT_KEY "default"#define AGGREGATION_KEY "aggregation"#define EXPLORER_KEY "explorer"#define SIMULATOR_LABEL "simulator"#define REPETITIONS_LABEL "repetitions"#define TMP_DIR_LABEL "tmp"#define DEF_SIMULATOR "./noxim"#define DEF_REPETITIONS 5#define DEF_TMP_DIR "./"#define TMP_FILE_NAME ".noxim_explorer.tmp"#define RPACKETS_LABEL "% Total received packets:"#define RFLITS_LABEL "% Total received flits:"#define AVG_DELAY_LABEL "% Global average delay (cycles):"#define AVG_THROUGHPUT_LABEL "% Global average throughput (flits/cycle):"#define THROUGHPUT_LABEL "% Throughput (flits/cycle/IP):"#define MAX_DELAY_LABEL "% Max delay (cycles):"#define TOTAL_ENERGY_LABEL "% Total energy (J):"#define MATLAB_VAR_NAME "data"#define MATRIX_COLUMN_WIDTH 15//---------------------------------------------------------------------------typedef unsigned int uint;// parameter valuestypedef vector<string> TParameterSpace;// parameter name, parameter spacetypedef map<string, TParameterSpace> TParametersSpace;// parameter name, parameter valuetypedef vector<pair<string, string> > TConfiguration;typedef vector<TConfiguration> TConfigurationSpace;struct TExplorerParams{ string simulator; string tmp_dir; int repetitions;};struct TSimulationResults{ double avg_delay; double throughput; double avg_throughput; double max_delay; double total_energy; unsigned int rpackets; unsigned int rflits;};//---------------------------------------------------------------------------double GetCurrentTime(){ struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + (tv.tv_usec * 1.0e-6);}//---------------------------------------------------------------------------void TimeToFinish(double elapsed_sec, int completed, int total, int& hours, int& minutes, int &seconds){ double total_time_sec = (elapsed_sec * total)/completed; double remain_time_sec = total_time_sec - elapsed_sec; seconds = (int)remain_time_sec % 60; minutes = ((int)remain_time_sec / 60) % 60; hours = (int)remain_time_sec / 3600;}//---------------------------------------------------------------------------bool IsComment(const string& s){ return (s == "" || s.at(0) == '%');}//---------------------------------------------------------------------------string TrimLeftAndRight(const string& s){ int len = s.length(); int i, j; for (i=0; i<len && s.at(i) == ' '; i++) ; for (j=len-1; j>=0 && s.at(j) == ' '; j--) ; return s.substr(i,j-i+1);}//---------------------------------------------------------------------------bool ExtractParameter(const string& s, string& parameter){ uint i = s.find("["); if (i != string::npos) { uint j = s.rfind("]"); if (j != string::npos) { parameter = s.substr(i+1, j-i-1); return true; } } return false;}//---------------------------------------------------------------------------bool GetNextParameter(ifstream& fin, string& parameter){ bool found = false; while (!fin.eof() && !found) { string s; getline(fin, s); if (!IsComment(s)) found = ExtractParameter(s, parameter); } return found;}//---------------------------------------------------------------------------wstring MakeStopParameterTag(const string& parameter){ string sparameter = "[/" + parameter + "]"; return sparameter;}//---------------------------------------------------------------------------bool ManagePlainParameterSet(ifstream& fin, const string& parameter, TParametersSpace& params_space, string& error_msg){ string str_stop = MakeStopParameterTag(parameter); bool stop = false; while (!fin.eof() && !stop) { string s; getline(fin, s); if (!IsComment(s)) { if (s.find(str_stop) != string::npos) stop = true; else params_space[parameter].push_back(TrimLeftAndRight(s)); } } return true;}//---------------------------------------------------------------------------bool ExpandInterval(const string& sint, TParameterSpace& ps, string& error_msg){ istringstream iss(sint); double min, max, step; iss >> min; iss >> max; iss >> step; for (double v=min; v<=max; v+=step) { ostringstream oss; oss << v; ps.push_back(oss.str()); } return true;}//---------------------------------------------------------------------------bool ManageCompressedParameterSet(ifstream& fin, const string& parameter, TParametersSpace& params_space, string& error_msg){ string str_stop = MakeStopParameterTag(parameter); bool stop = false; while (!fin.eof() && !stop) { string s; getline(fin, s); if (!IsComment(s)) { if (s.find(str_stop) != string::npos) stop = true; else { if (!ExpandInterval(s, params_space[parameter], error_msg)) return false; } } } return true;}//---------------------------------------------------------------------------bool ManageParameter(ifstream& fin, const string& parameter, TParametersSpace& params_space, string& error_msg){ bool err; if (parameter == "pir" || parameter == "por") err = ManageCompressedParameterSet(fin, parameter, params_space, error_msg); else err = ManagePlainParameterSet(fin, parameter, params_space, error_msg); return err;}//---------------------------------------------------------------------------bool ParseConfigurationFile(const string& fname, TParametersSpace& params_space, string& error_msg){ ifstream fin(fname.c_str(), ios::in); if (!fin) { error_msg = "Cannot open " + fname; return false; } while (!fin.eof()) { string parameter; if ( GetNextParameter(fin, parameter) ) { if (!ManageParameter(fin, parameter, params_space, error_msg)) return false; } } return true;}//---------------------------------------------------------------------------bool LastCombination(const vector<pair<int,int> >& indexes){ for (uint i=0; i<indexes.size(); i++) if (indexes[i].first < indexes[i].second-1) return false; return true;}//---------------------------------------------------------------------------bool IncrementCombinatorialIndexes(vector<pair<int,int> >& indexes){ for (uint i=0; i<indexes.size(); i++) { if (indexes[i].first < indexes[i].second - 1) { indexes[i].first++; return true; } indexes[i].first = 0; } return false;}//---------------------------------------------------------------------------TConfigurationSpace Explore(const TParametersSpace& params_space){ TConfigurationSpace conf_space; vector<pair<int,int> > indexes; // <index, max_index> for (TParametersSpace::const_iterator psi=params_space.begin(); psi!=params_space.end(); psi++) indexes.push_back(pair<int,int>(0, psi->second.size())); do { int i = 0; TConfiguration conf; for (TParametersSpace::const_iterator psi=params_space.begin(); psi!=params_space.end(); psi++) { conf.push_back( pair<string,string>(psi->first, psi->second[indexes[i].first])); i++; } conf_space.push_back(conf); } while (IncrementCombinatorialIndexes(indexes)); return conf_space;}//---------------------------------------------------------------------------bool RemoveParameter(TParametersSpace& params_space, const string& param_name, TParameterSpace& param_space, string& error_msg){ TParametersSpace::iterator i = params_space.find(param_name); if (i == params_space.end()) { error_msg = "Cannot extract parameter '" + param_name + "'"; return false; } param_space = params_space[param_name]; params_space.erase(i); return true;}//---------------------------------------------------------------------------bool RemoveAggregateParameters(TParametersSpace& params_space, TParameterSpace& aggregated_params, TParametersSpace& aggragated_params_space, string& error_msg){ for (uint i=0; i<aggregated_params.size(); i++) { string param_name = aggregated_params[i]; TParameterSpace param_space; if (!RemoveParameter(params_space, param_name, param_space, error_msg)) return false; aggragated_params_space[param_name] = param_space; } return true;}//---------------------------------------------------------------------------string ParamValue2Cmd(const pair<string,string>& pv){ string cmd; if (pv.first == "topology") { istringstream iss(pv.second); int width, height; char times; iss >> width >> times >> height; ostringstream oss; oss << "-dimx " << width << " -dimy " << height; cmd = oss.str(); } else cmd = "-" + pv.first + " " + pv.second; return cmd;}//---------------------------------------------------------------------------string Configuration2CmdLine(const TConfiguration& conf){ string cl; for (uint i=0; i<conf.size(); i++) cl = cl + ParamValue2Cmd(conf[i]) + " "; return cl;}//---------------------------------------------------------------------------string Configuration2FunctionName(const TConfiguration& conf){ string fn; for (uint i=0; i<conf.size(); i++) fn = fn + conf[i].first + "_" + conf[i].second + "__"; // Replace " ", "-", ".", "/" with "_" int len = fn.length(); for (int i=0; i<len; i++) if (fn.at(i) == ' ' || fn.at(i) == '.' || fn.at(i) == '-' || fn.at(i) == '/') fn[i] = '_'; return fn;}//---------------------------------------------------------------------------bool ExtractExplorerParams(const TParameterSpace& explorer_params, TExplorerParams& eparams, string& error_msg){ eparams.simulator = DEF_SIMULATOR; eparams.tmp_dir = DEF_TMP_DIR;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -