예제 #1
0
int main()
{
    try
    {
        // use non-randomized striping to avoid side effects on random generator
        typedef stxxl::VECTOR_GENERATOR<element, 2, 2, (2 * 1024 * 1024), stxxl::striping>::result vector_type;
        vector_type v(64 * 1024 * 1024 / sizeof(element));

        // test assignment const_iterator = iterator
        vector_type::const_iterator c_it = v.begin();
        STXXL_UNUSED(c_it);

        unsigned int big_size = 1024 * 1024 * 2 * 16 * 16;
        typedef stxxl::vector<double> vec_big;
        vec_big my_vec(big_size);

        vec_big::iterator big_it = my_vec.begin();
        big_it += 6;

        test_const_iterator(v);

        stxxl::random_number32 rnd;
        int offset = rnd();

        STXXL_MSG("write " << v.size() << " elements");

        stxxl::ran32State = 0xdeadbeef;
        vector_type::size_type i;

        // fill the vector with increasing sequence of integer numbers
        for (i = 0; i < v.size(); ++i)
        {
            v[i].key = i + offset;
            assert(v[i].key == stxxl::int64(i + offset));
        }


        // fill the vector with random numbers
        stxxl::generate(v.begin(), v.end(), stxxl::random_number32(), 4);
        v.flush();

        STXXL_MSG("seq read of " << v.size() << " elements");

        stxxl::ran32State = 0xdeadbeef;

        // testing swap
        vector_type a;
        std::swap(v, a);
        std::swap(v, a);

        for (i = 0; i < v.size(); i++)
            assert(v[i].key == rnd());

        // check again
        STXXL_MSG("clear");

        v.clear();

        stxxl::ran32State = 0xdeadbeef + 10;

        v.resize(64 * 1024 * 1024 / sizeof(element));

        STXXL_MSG("write " << v.size() << " elements");
        stxxl::generate(v.begin(), v.end(), stxxl::random_number32(), 4);

        stxxl::ran32State = 0xdeadbeef + 10;

        STXXL_MSG("seq read of " << v.size() << " elements");

        for (i = 0; i < v.size(); i++)
            assert(v[i].key == rnd());

        STXXL_MSG("copy vector of " << v.size() << " elements");

        vector_type v_copy0(v);
        assert(v == v_copy0);

        vector_type v_copy1;
        v_copy1 = v;
        assert(v == v_copy1);
    }
    catch (const std::exception & ex)
    {
        STXXL_MSG("Caught exception: " << ex.what());
    }
    catch (...)
    {
        STXXL_MSG("Caught unknown exception.");
    }

    return 0;
}
void concurrency_handler::output_samples(int node_id) {
  //cout << _states.size() << " samples seen:" << endl;
  ofstream myfile;
  stringstream datname;
  datname << "concurrency." << node_id << ".dat";
  myfile.open(datname.str().c_str());
  _function_mutex.lock();
  // limit ourselves to N functions.
  map<task_identifier, int> func_count;
  // initialize the map
  for (set<task_identifier>::iterator it=_functions.begin(); it!=_functions.end(); ++it) {
    func_count[*it] = 0;
  }
  // count all function instances
  for (unsigned int i = 0 ; i < _states.size() ; i++) {
    for (set<task_identifier>::iterator it=_functions.begin(); it!=_functions.end(); ++it) {
      if (_states[i]->find(*it) == _states[i]->end()) {
        continue;
      } else {
        func_count[*it] = func_count[*it] + (*(_states[i]))[*it];
      }
    }
  }
  // sort the map
  vector<pair<task_identifier,int> > my_vec(func_count.begin(), func_count.end());
  sort(my_vec.begin(),my_vec.end(),&sort_functions);
  set<task_identifier> top_x;
  for (vector<pair<task_identifier, int> >::iterator it=my_vec.begin(); it!=my_vec.end(); ++it) {
    //if (top_x.size() < 15 && (*it).first != "APEX THREAD MAIN")
    if (top_x.size() < MAX_FUNCTIONS_IN_CHART)
      top_x.insert((*it).first);
  }

  // output the header
  myfile << "\"period\"\t\"thread cap\"\t\"power\"\t";
  // output tunable parameter names
  for(auto param : _tunable_param_samples) {
    myfile << "\"" << param.first << "\"\t";
  }
  for (set<task_identifier>::iterator it=_functions.begin(); it!=_functions.end(); ++it) {
    if (top_x.find(*it) != top_x.end()) {
      //string* tmp = demangle(*it);
      task_identifier tmp_id = *it;
      string tmp = tmp_id.get_name();
#ifdef APEX_HAVE_BFD
      std::size_t pos = tmp.find("UNRESOLVED ADDR ");
      if (pos != string::npos) {
        string trimmed = tmp.substr(pos+16);
        uintptr_t function_address = std::stoul(trimmed, nullptr, 16);
        string * tmp2 = lookup_address(function_address, true);
        pos = tmp2->find(" [{");
        if (pos != string::npos) {
            trimmed = tmp2->substr(0, pos);
            myfile << "\"" << trimmed << "\"\t";
        } else {
            myfile << "\"" << *tmp2 << "\"\t";
        }
        delete (tmp2);
      } else {
        myfile << "\"" << tmp << "\"\t";
      }
#else
      myfile << "\"" << tmp << "\"\t";
#endif
    }
  }
  myfile << "\"other\"" << endl;

  size_t max_Y = 0;
  double max_Power = 0.0;
  size_t max_X = _states.size();
  int num_params = _tunable_param_samples.size();
  for (size_t i = 0 ; i < max_X ; i++) {
    myfile << i << "\t";
    myfile << _thread_cap_samples[i] << "\t";
    myfile << _power_samples[i] << "\t";
    for(auto param : _tunable_param_samples) {
      myfile << param.second[i] << "\t";
      if(param.second[i] > max_Power) max_Power = param.second[i];
    }
    unsigned int tmp_max = 0;
    int other = 0;
    for (set<task_identifier>::iterator it=_functions.begin(); it!=_functions.end(); ++it) {
      // this is the idle event.
      //if (*it == "APEX THREAD MAIN")
        //continue;
      int value = 0;
      // did we see this timer during this sample?
      if (_states[i]->find(*it) != _states[i]->end()) {
        value = (*(_states[i]))[*it];
      }
      // is this timer in the top X?
      if (top_x.find(*it) == top_x.end()) {
        other = other + value;
      } else {
        myfile << (*(_states[i]))[*it] << "\t";
        tmp_max += (*(_states[i]))[*it];
      }
    }
    myfile << other << "\t" << endl;
    tmp_max += other;
    if (tmp_max > max_Y) max_Y = tmp_max;
    if ((size_t)(_thread_cap_samples[i]) > max_Y) max_Y = _thread_cap_samples[i];
    if (_power_samples[i] > max_Power) max_Power = _power_samples[i];
  }
  _function_mutex.unlock();
  myfile.close();

  if (max_Power == 0.0) max_Power = 100;
  stringstream plotname;
  plotname << "concurrency." << node_id << ".gnuplot";
  myfile.open(plotname.str().c_str());
  myfile << "everyNth(col) = (int(column(col))%" << (int)(max_X/10) << "==0)?stringcolumn(1):\"\";" << endl;
  myfile << "set key outside bottom center invert box" << endl;
  myfile << "set xtics auto" << endl;
  myfile << "set ytics 4" << endl;
  myfile << "set y2tics auto" << endl;
  myfile << "set xrange[0:" << max_X << "]" << endl;
  myfile << "set yrange[0:" << max_Y << "]" << endl;
  myfile << "set y2range[0:" << max_Power << "]" << endl;
  myfile << "set xlabel \"Time\"" << endl;
  myfile << "set ylabel \"Concurrency\"" << endl;
  myfile << "set y2label \"Power\"" << endl;
  myfile << "# Select histogram data" << endl;
  myfile << "set style data histogram" << endl;
  myfile << "# Give the bars a plain fill pattern, and draw a solid line around them." << endl;
  myfile << "set style fill solid border" << endl;
  myfile << "set style histogram rowstacked" << endl;
  myfile << "set boxwidth 1.0 relative" << endl;
  myfile << "set palette rgb 33,13,10" << endl;
  myfile << "unset colorbox" << endl;
  myfile << "set key noenhanced" << endl; // this allows underscores in names
  myfile << "plot for [COL=" << (4+num_params) << ":" << top_x.size()+num_params+4;
  myfile << "] '" << datname.str().c_str();
  myfile << "' using COL:xticlabel(everyNth(1)) palette frac (COL-" << (3+num_params) << ")/" << top_x.size()+1;
  myfile << ". title columnheader axes x1y1, '"  << datname.str().c_str();
  myfile << "' using 2 with lines linecolor rgb \"red\" axes x1y1 title columnheader, '" << datname.str().c_str();
  myfile << "' using 3 with lines linecolor rgb \"black\" axes x1y2 title columnheader,";
  for(int p = 0; p < num_params; ++p) {
    myfile << "'" << datname.str().c_str() << "' using " << (4+p) << " with linespoints axes x1y2 title columnheader,";
  }
  myfile << endl;
  myfile.close();
}