C++ std::在noxim代码中超出范围

C++ std::在noxim代码中超出范围,c++,systemc,C++,Systemc,我从一些SystemC编码开始,我尝试使用一个叫做“Noxim”的片上网络模拟器,我听说它非常平滑和简单。然而,当我尝试“制作”模拟的某些部分时,我会遇到这个常见错误 terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr Abort 我认为它来自于一个cpp代码,我并不拥有它,而且,真诚地说,我并不完全理解它。代码可以在下面找到,完整的Noxim分布可

我从一些SystemC编码开始,我尝试使用一个叫做“Noxim”的片上网络模拟器,我听说它非常平滑和简单。然而,当我尝试“制作”模拟的某些部分时,我会遇到这个常见错误

terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr
Abort
我认为它来自于一个cpp代码,我并不拥有它,而且,真诚地说,我并不完全理解它。代码可以在下面找到,完整的Noxim分布可以在这里找到:

代码位于Noxim/other/

Noxim_explorer.cpp和sim.cfg与我要做的实验室密切相关

请,如果有人已经解决了这个问题或有任何想法,这将是非常有帮助的

作为记录:我在试图跟踪这个实验室时被绊倒了,因为我在matlab文件中找不到任何信息

#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 values
typedef vector<string> TParameterSpace;

// parameter name, parameter space
typedef map<string, TParameterSpace> TParametersSpace;

// parameter name, parameter value
typedef 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;
}

//---------------------------------------------------------------------------w

string 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;

  string param_suffix;
  getline(iss, param_suffix);

  for (double v=min; v<=max; v+=step)
    {
      ostringstream oss;
      oss << v;
      ps.push_back(oss.str() + param_suffix);
    }

  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")
    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;
  eparams.repetitions = DEF_REPETITIONS;

  for (uint i=0; i<explorer_params.size(); i++)
    {
      istringstream iss(explorer_params[i]);

      string label;
      iss >> label;

      if (label == SIMULATOR_LABEL)
    iss >> eparams.simulator;
      else if (label == REPETITIONS_LABEL)
    iss >> eparams.repetitions;
      else if (label == TMP_DIR_LABEL)
    iss >> eparams.tmp_dir;
      else
    {
      error_msg = "Invalid explorer option '" + label + "'";
      return false;
    }
    }

  return true;
}

//---------------------------------------------------------------------------

bool PrintHeader(const string& fname,
         const TExplorerParams& eparams,
         const string& def_cmd_line, const string& conf_cmd_line, 
         ofstream& fout, 
         string& error_msg)
{
  fout.open(fname.c_str(), ios::out);
  if (!fout)
    {
      error_msg = "Cannot create " + fname;
      return false;
    }

  fout << "% fname: " << fname << endl
       << "% " << eparams.simulator << " "
       << conf_cmd_line << " " << def_cmd_line
       << endl << endl;

  return true;
}

//---------------------------------------------------------------------------

bool PrintMatlabFunction(const string& mfname,
             ofstream& fout, 
             string& error_msg)
{
  fout << "function [max_pir, max_throughput, min_delay] = " << mfname << "(symbol)" << endl
       << endl;

  return true;
}

//---------------------------------------------------------------------------

bool ReadResults(const string& fname, 
         TSimulationResults& sres, 
         string& error_msg)
{
  ifstream fin(fname.c_str(), ios::in);
  if (!fin)
    {
      error_msg = "Cannot read " + fname;
      return false;
    }

  int nread = 0;
  while (!fin.eof())
    {
      string line;
      getline(fin, line);

      uint pos;

      pos = line.find(RPACKETS_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(RPACKETS_LABEL).size()));
      iss >> sres.rpackets;
      continue;
    }

      pos = line.find(RFLITS_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(RFLITS_LABEL).size()));
      iss >> sres.rflits;
      continue;
    }

      pos = line.find(AVG_DELAY_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(AVG_DELAY_LABEL).size()));
      iss >> sres.avg_delay;
      continue;
    }

      pos = line.find(AVG_THROUGHPUT_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(AVG_THROUGHPUT_LABEL).size()));
      iss >> sres.avg_throughput;
      continue;
    }

      pos = line.find(THROUGHPUT_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(THROUGHPUT_LABEL).size()));
      iss >> sres.throughput;
      continue;
    }

      pos = line.find(MAX_DELAY_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(MAX_DELAY_LABEL).size()));
      iss >> sres.max_delay;
      continue;
    }

      pos = line.find(TOTAL_ENERGY_LABEL);
      if (pos != string::npos) 
    {
      nread++;
      istringstream iss(line.substr(pos + string(TOTAL_ENERGY_LABEL).size()));
      iss >> sres.total_energy;
      continue;
    }
    }

  if (nread != 7)
    {
      error_msg = "Output file " + fname + " corrupted";
      return false;
    }

  return true;
}

//---------------------------------------------------------------------------

bool RunSimulation(const string& cmd_base,
           const string& tmp_dir,
           TSimulationResults& sres, 
           string& error_msg)
{
  string tmp_fname = tmp_dir + TMP_FILE_NAME;
  //  string cmd = cmd_base + " >& " + tmp_fname; // this works only with csh and bash
  string cmd = cmd_base + " >" + tmp_fname + " 2>&1"; // this works with sh, csh, and bash!

  cout << cmd << endl;
  system(cmd.c_str());
  if (!ReadResults(tmp_fname, sres, error_msg))
    return false;

  string rm_cmd = string("rm -f ") + tmp_fname;
  system(rm_cmd.c_str());

  return true;
}

//---------------------------------------------------------------------------

string ExtractFirstField(const string& s)
{
  istringstream iss(s);

  string sfirst;

  iss >> sfirst;

  return sfirst;
}

//---------------------------------------------------------------------------

bool RunSimulations(double start_time,
            pair<uint,uint>& sim_counter,
            const string& cmd, const string& tmp_dir, const int repetitions,
            const TConfiguration& aggr_conf, 
            ofstream& fout, 
            string& error_msg)
{
  int    h, m, s;

  for (int i=0; i<repetitions; i++)
    {
      cout << "# simulation " << (++sim_counter.first) << " of " << sim_counter.second;
      if (i != 0)
    cout << ", estimated time to finish " << h << "h " << m << "m " << s << "s";
      cout << endl;

      TSimulationResults sres;
      if (!RunSimulation(cmd, tmp_dir, sres, error_msg))
    return false;

      double current_time = GetCurrentTime();
      TimeToFinish(current_time-start_time, sim_counter.first, sim_counter.second, h, m, s);

      // Print aggragated parameters
      fout << "  ";
      for (uint i=0; i<aggr_conf.size(); i++)
    fout << setw(MATRIX_COLUMN_WIDTH) << ExtractFirstField(aggr_conf[i].second); // this fix the problem with pir
      // fout << setw(MATRIX_COLUMN_WIDTH) << aggr_conf[i].second;

      // Print results;
      fout << setw(MATRIX_COLUMN_WIDTH) << sres.avg_delay
       << setw(MATRIX_COLUMN_WIDTH) << sres.throughput
       << setw(MATRIX_COLUMN_WIDTH) << sres.max_delay
       << setw(MATRIX_COLUMN_WIDTH) << sres.total_energy
       << setw(MATRIX_COLUMN_WIDTH) << sres.rpackets
       << setw(MATRIX_COLUMN_WIDTH) << sres.rflits 
       << endl;
    }

  return true;
}

//---------------------------------------------------------------------------

bool PrintMatlabVariableBegin(const TParametersSpace& aggragated_params_space, 
                  ofstream& fout, string& error_msg)
{
  fout << MATLAB_VAR_NAME << " = [" << endl;
  fout << "% ";
  for (TParametersSpace::const_iterator i=aggragated_params_space.begin();
       i!=aggragated_params_space.end(); i++)
    fout << setw(MATRIX_COLUMN_WIDTH) << i->first;

  fout << setw(MATRIX_COLUMN_WIDTH) << "avg_delay"
       << setw(MATRIX_COLUMN_WIDTH) << "throughput"
       << setw(MATRIX_COLUMN_WIDTH) << "max_delay"
       << setw(MATRIX_COLUMN_WIDTH) << "total_energy"
       << setw(MATRIX_COLUMN_WIDTH) << "rpackets"
       << setw(MATRIX_COLUMN_WIDTH) << "rflits";

  fout << endl;

  return true;
}

//---------------------------------------------------------------------------

bool GenMatlabCode(const string& var_name,
           const int fig_no,
           const int repetitions, const int column,
           ofstream& fout, string& error_msg)
{
  fout << var_name << " = [];" << endl
       << "for i = 1:rows/" << repetitions << "," << endl
       << "   ifirst = (i - 1) * " << repetitions << " + 1;" << endl
       << "   ilast  = ifirst + " << repetitions << " - 1;" << endl
       << "   tmp = " << MATLAB_VAR_NAME << "(ifirst:ilast, cols-6+" << column << ");" << endl
       << "   avg = mean(tmp);" << endl
       << "   [h sig ci] = ttest(tmp, 0.1);" << endl
       << "   ci = (ci(2)-ci(1))/2;" << endl
       << "   " << var_name << " = [" << var_name << "; " << MATLAB_VAR_NAME << "(ifirst, 1:cols-6), avg ci];" << endl
       << "end" << endl
       << endl;

  fout << "figure(" << fig_no << ");" << endl
       << "hold on;" << endl
       << "plot(" << var_name << "(:,1), " << var_name << "(:,2), symbol);" << endl
       << endl;

  return true;
}

//---------------------------------------------------------------------------

bool GenMatlabCodeSaturationAnalysis(const string& var_name,
                     ofstream& fout, string& error_msg)
{

  fout << endl 
       << "%-------- Saturation Analysis -----------" << endl
       << "slope=[];"  << endl
       << "for i=2:size(" << var_name << "_throughput,1),"  << endl
       << "    slope(i-1) = (" << var_name << "_throughput(i,2)-" << var_name << "_throughput(i-1,2))/(" << var_name << "_throughput(i,1)-" << var_name << "_throughput(i-1,1));"  << endl
       << "end"  << endl
       << endl
       << "for i=2:size(slope,2),"  << endl
       << "    if slope(i) < (0.95*mean(slope(1:i)))"  << endl
       << "        max_pir = " << var_name << "_throughput(i, 1);"  << endl
       << "        max_throughput = " << var_name << "_throughput(i, 2);"  << endl
       << "        min_delay = " << var_name << "_delay(i, 2);"  << endl
       << "        break;"  << endl
       << "    end"  << endl
       << "end"  << endl;

  return true;
}

//---------------------------------------------------------------------------

bool PrintMatlabVariableEnd(const int repetitions,
                ofstream& fout, string& error_msg)
{
  fout << "];" << endl << endl;

  fout << "rows = size(" << MATLAB_VAR_NAME << ", 1);" << endl
       << "cols = size(" << MATLAB_VAR_NAME << ", 2);" << endl
       << endl;

  if (!GenMatlabCode(string(MATLAB_VAR_NAME) + "_delay", 1,
             repetitions, 1, fout, error_msg))
    return false;

  if (!GenMatlabCode(string(MATLAB_VAR_NAME) + "_throughput", 2,
             repetitions, 2, fout, error_msg))
    return false;

  if (!GenMatlabCode(string(MATLAB_VAR_NAME) + "_maxdelay", 3,
             repetitions, 3, fout, error_msg))
    return false;

  if (!GenMatlabCode(string(MATLAB_VAR_NAME) + "_totalenergy", 4,
             repetitions, 4, fout, error_msg))
    return false;

  if (!GenMatlabCodeSaturationAnalysis(string(MATLAB_VAR_NAME), fout, error_msg))
    return false;

  return true;
}

//---------------------------------------------------------------------------

bool RunSimulations(const TConfigurationSpace& conf_space,
            const TParameterSpace&     default_params,
            const TParametersSpace&    aggragated_params_space,
            const TParameterSpace&     explorer_params,
            string&                    error_msg)
{
  TExplorerParams eparams;
  if (!ExtractExplorerParams(explorer_params, eparams, error_msg))
    return false;

  // Make dafault parameters string
  string def_cmd_line;
  for (uint i=0; i<default_params.size(); i++)
    def_cmd_line = def_cmd_line + default_params[i] + " ";

  // Explore configuration space
  TConfigurationSpace aggr_conf_space = Explore(aggragated_params_space);

  pair<uint,uint> sim_counter(0, conf_space.size() * aggr_conf_space.size() * eparams.repetitions);

  double start_time = GetCurrentTime();
  for (uint i=0; i<conf_space.size(); i++)
    {
      string conf_cmd_line = Configuration2CmdLine(conf_space[i]);

      string   mfname = Configuration2FunctionName(conf_space[i]);
      string   fname  = mfname + ".m";
      ofstream fout;
      if (!PrintHeader(fname, eparams, 
               def_cmd_line, conf_cmd_line, fout, error_msg))
    return false;

      if (!PrintMatlabFunction(mfname, fout, error_msg))
    return false;

      if (!PrintMatlabVariableBegin(aggragated_params_space, fout, error_msg))
    return false;

      for (uint j=0; j<aggr_conf_space.size(); j++)
    {
      string aggr_cmd_line = Configuration2CmdLine(aggr_conf_space[j]);
      /*
      string cmd = eparams.simulator + " "
        + def_cmd_line + " "
        + conf_cmd_line + " "
        + aggr_cmd_line;
      */
      string cmd = eparams.simulator + " "
            + aggr_cmd_line + " "
        + def_cmd_line + " "
        + conf_cmd_line;

      if (!RunSimulations(start_time,
                  sim_counter, cmd, eparams.tmp_dir, eparams.repetitions,
                  aggr_conf_space[j], fout, error_msg))
        return false;
    }

      if (!PrintMatlabVariableEnd(eparams.repetitions, fout, error_msg))
    return false;
    }

  return true;
}

//---------------------------------------------------------------------------

bool RunSimulations(const string& script_fname,
            string&       error_msg)
{
  TParametersSpace ps;

  if (!ParseConfigurationFile(script_fname, ps, error_msg))
    return false;


  TParameterSpace default_params;
  if (!RemoveParameter(ps, DEFAULT_KEY, default_params, error_msg))
    cout << "Warning: " << error_msg << endl;


  TParameterSpace  aggregated_params;
  TParametersSpace aggragated_params_space;
  if (!RemoveParameter(ps, AGGREGATION_KEY, aggregated_params, error_msg))
    cout << "Warning: " << error_msg << endl;
  else
    if (!RemoveAggregateParameters(ps, aggregated_params, 
                  aggragated_params_space, error_msg))
      return false;

  TParameterSpace explorer_params;
  if (!RemoveParameter(ps, EXPLORER_KEY, explorer_params, error_msg))
    cout << "Warning: " << error_msg << endl;

  TConfigurationSpace conf_space = Explore(ps);

  if (!RunSimulations(conf_space, default_params, 
              aggragated_params_space, explorer_params, error_msg))
    return false;


  return true;
}


//---------------------------------------------------------------------------

int main(int argc, char **argv)
{
  if (argc < 2)
    {
      cout << "Usage: " << argv[0] << " <cfg file> [<cfg file>]" << endl;
      return -1;
    }

  for (int i=1; i<argc; i++)
    {
      string fname(argv[i]);
      cout << "# Exploring configuration space " << fname << endl;

      string error_msg;

      if (!RunSimulations(fname, error_msg))
    cout << "Error: " << error_msg << endl;

      cout << endl;
    }

  return 0;
}

//---------------------------------------------------------------------------
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
//---------------------------------------------------------------------------
#定义默认值\u键“默认值”
#定义聚合\u键“聚合”
#定义资源管理器\u键“资源管理器”
#定义模拟器标签“模拟器”
#定义重复\u标签“重复”
#定义TMP_目录标签“TMP”
#定义DEF_模拟器“/noxim”
#定义定义重复5次
#定义定义TMP目录“/”
#定义TMP_文件名“.noxim_explorer.TMP”
#定义RPACKETS_标签“%Total received packets:”
#定义RFLITS\U标签“%Total received flits:”
#定义平均延迟标签“%全局平均延迟(周期)”
#定义平均吞吐量标签“%Global average through(flits/cycle):”
#定义吞吐量\u标签“%吞吐量(flits/cycle/IP)”
#定义最大延迟标签“%MAX DELAY(cycles)”
#定义总能量标签“%总能量(J)”
#定义MATLAB_变量_名称“数据”
#定义矩阵\u列\u宽度15
//---------------------------------------------------------------------------
typedef无符号整数单元;
//参数值
typedef向量t参数空间;
//参数名称,参数空间
typedef映射参数空间;
//参数名称、参数值
typedef向量配置;
typedef向量t配置空间;
结构TExplorerParams
{
字符串模拟器;
字符串tmp_dir;
重复;
};
结构t模拟结果
{
双平均延迟;
双吞吐量;
双平均吞吐量;
双最大延迟;
总能量加倍;
无符号整数rpackets;
无符号整数rflits;
};
//---------------------------------------------------------------------------
双GetCurrentTime()
{
结构时间值电视;
gettimeofday(&tv,NULL);
返回tv.tv_sec+(tv.tv_usec*1.0e-6);
}
//---------------------------------------------------------------------------
无效时间完成(双倍时间秒,
完成整数,总计整数,
整数和小时、整数和分钟、整数和秒)
{
双倍总时间秒=(已用秒*总)/已完成;
双剩余时间秒=总时间秒-已用秒;
秒=(整数)剩余时间秒%60;
分钟=((整数)剩余时间秒/60)%60;
小时=(整数)剩余时间秒/3600;
}
//---------------------------------------------------------------------------
布尔值(常量字符串和s)
{
返回值(s=“”| | s.at(0)='%');
}
//---------------------------------------------------------------------------
字符串TrimLeftAndRight(常量字符串&s)
{
int len=s.length();
int i,j;
对于(i=0;i=0&&s.at(j)='';j--);
返回s.substr(i,j-i+1);
}
//---------------------------------------------------------------------------
布尔提取参数(常量字符串和s、字符串和参数)
{
uint i=s.find(“[”);
if(i!=string::npos)
{
uint j=s.rfind(“]”);
if(j!=string::npos)
{
参数=s.substr(i+1,j-i-1);
返回true;
}
}
返回false;
}
//---------------------------------------------------------------------------
bool GetNextParameter(ifstream和fin、字符串和参数)
{
bool-found=false;
而(!fin.eof()&&!found)
{
字符串s;
(财务,s);;
如果(!是常见的)
found=提取参数(s,参数);
}
发现退货;
}
//---------------------------------------------------------------------------w
字符串MakeStopParameterTag(常量字符串和参数)
{
字符串参数=“[/”+参数+“]”;
返回分光计;
}
//---------------------------------------------------------------------------
布尔管理器参数集(ifstream和fin,
常量字符串和参数,
t参数空间和参数空间,
字符串和错误(msg)
{
字符串str_stop=MakeStopParameterTag(参数);
bool-stop=false;
而(!fin.eof()&&!stop)
{
字符串s;
(财务,s);;
如果(!是常见的)
{
如果(s.find(str_stop)!=string::npos)
停止=真;
其他的
参数空间[parameter]。向后推(TrimLeftAndRight(s));
}
}
返回true;
}
//---------------------------------------------------------------------------
bool ExpandInterval(常数串和常数串),
t参数空间和ps,
字符串和错误(msg)
{
istringstream iss(sint);
双最小值、最大值、步长;
国际空间站>>分钟;
iss>>最大值;
iss>>步骤;
字符串参数后缀;
getline(iss,参数后缀);
对于(双v=最小值;v宽度>>乘以>>高度;
ostringstream oss;
oss eparams.tmp_dir;
其他的
{
错误_msg=“无效的资源管理器选项”“+标签”“”;
返回false;
}
}
返回true;
}
//---------------------------------------------------------------------------
布尔打印头(常量字符串和fname,
const-TExplorerParams&eparams,
常量字符串和定义命令行,常量字符串和配置命令行,
流与流,
字符串和错误(msg)
{
fout.open(fname.c_str(),ios::out);
如果(!fout)
{
错误\u msg=“无法创建”+fname;
返回false;
}
四个U是