A triangle counting assignment for A.U.TH Parallel and distributed systems class.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

94 linhas
2.7 KiB

  1. /*
  2. * main.cpp
  3. *
  4. * Created on: Dec 4, 2020
  5. * Author: hoo2
  6. */
  7. #include <sstream>
  8. #include <fstream>
  9. #include <iostream>
  10. #include <algorithm>
  11. #define SIZE 20
  12. std::ifstream file;
  13. /*!
  14. * Calculates and return the median of an array of measurements
  15. * \param t Pointer to measurements
  16. * \param n Size of measurements array
  17. * \return The average
  18. */
  19. int median (int *t, int n) {
  20. std::sort (t, &t[n]);
  21. return (n % 2) ? t[n/2] : (t[n/2] + t[n/2 -1]) /2;
  22. }
  23. /*
  24. * A small post processing...
  25. */
  26. int main(int argc, char* argv[]) {
  27. file = std::ifstream(argv[1]);
  28. std::string line, token, exec, mtx, times, dt, units, dyn1, dyn2;
  29. std::string t1, t2, t3, t4;
  30. enum state_en {RUNNING, LOAD, DATA, SUM} state = RUNNING;
  31. int cnt =0, med =0;
  32. int delta_t[SIZE];
  33. while (std::getline (file, line, '\n')) {
  34. std::stringstream ss(line);
  35. switch (state) {
  36. case RUNNING:
  37. ss >> token;
  38. if (token == "running") {
  39. ss >> exec >> t1 >> mtx >> t2 >> times >> t3 >> t4 >> dyn1 >> dyn2;
  40. cnt =0;
  41. state = LOAD;
  42. }
  43. break;
  44. case LOAD: state = DATA; break;
  45. case DATA:
  46. ss >> t1 >> t2 >> t3 >> dt >> units;
  47. if (units == "[usec]") delta_t[cnt] = std::atoi(dt.c_str());
  48. else if (units == "[msec]") delta_t[cnt] = std::atoi(dt.c_str()) * 1000;
  49. else if (units == "[sec]") delta_t[cnt] = std::atoi(dt.c_str()) * 1000000;
  50. if (++cnt == std::atoi(times.c_str())) {
  51. med = median (delta_t, cnt);
  52. cnt =0;
  53. state = SUM;
  54. }
  55. break;
  56. case SUM:
  57. ss >> token;
  58. if (token == "running") {
  59. std::cout << exec << ',' << mtx << ',' << med << ", ," <<
  60. (((dyn1 == "--dynamic") || (dyn2 == "--dynamic")) ? "dyn\n" : " \n");
  61. dyn1 = "";
  62. dyn2 = "";
  63. ss >> exec >> t1 >> mtx >> t2 >> times >> t3 >> t4 >> dyn1 >> dyn2;
  64. cnt =0;
  65. state = LOAD;
  66. }
  67. else if (token == "[Timing]:") {
  68. ss >> t1 >> t2 >> dt >> units;
  69. if (units == "[usec]") med += std::atoi(dt.c_str());
  70. else if (units == "[msec]") med += std::atoi(dt.c_str()) * 1000;
  71. else if (units == "[sec]") med += std::atoi(dt.c_str()) * 1000000;
  72. state = RUNNING;
  73. std::cout << exec << ',' << mtx << ',' << med << ",sum," <<
  74. (((dyn1 == "--dynamic") || (dyn2 == "--dynamic")) ? "dyn\n" : " \n");
  75. dyn1 = "";
  76. dyn2 = "";
  77. }
  78. break;
  79. }
  80. }
  81. return 0;
  82. }