A triangle counting assignment for A.U.TH Parallel and distributed systems class.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*!
  2. * \file utils.cpp
  3. * \brief Utilities to handle matrix files, chrono, etc...
  4. *
  5. * \author
  6. * Christos Choutouridis AEM:8997
  7. * <cchoutou@ece.auth.gr>
  8. */
  9. #include <utils.h>
  10. #include <algorithm>
  11. /*!
  12. * Initialize the matrix as Erdős-Rényi graph
  13. * \param A The matrix to initialize
  14. * \param p The probability of each edge
  15. */
  16. void init_ER_graph (matrix& A, double p) {
  17. std::random_device rd;
  18. std::mt19937 gen(rd());
  19. std::binomial_distribution<> d(1, p);
  20. #if CODE_VERSION == V12
  21. std::transform (A.begin(), A.end(), A.begin(),
  22. [&] (int x) { std::ignore =x; return d(gen); }
  23. #else
  24. A.for_each_in(0, A.size(), [&](auto i) {
  25. A.for_each_in(i+1, A.size(), [&](auto j){
  26. matrix::dataType edge = d(gen);
  27. if (edge) {
  28. A.set(edge, i, j);
  29. A.set(edge, j, i);
  30. }
  31. });
  32. });
  33. #endif
  34. }
  35. /*!
  36. * Utility to print the graph to sdtout
  37. */
  38. void print_graph (matrix& A) {
  39. matrix::indexType N = (A.size() < (matrix::indexType)session.mtx_print_size) ? A.size() : session.mtx_print_size;
  40. A.for_each_in(0, N, [&](auto i){
  41. A.for_each_in(0, N, [&](auto j) {
  42. std::cout << A(i, j) << ' ';
  43. });
  44. std::cout << '\n';
  45. });
  46. }
  47. /*!
  48. * Utility to print to logger thread information
  49. */
  50. void threads_info () {
  51. #if defined CILK
  52. logger << "Running with max threads: " << __cilkrts_get_nworkers() << logger.endl;
  53. logger << "Utilizing " << __cilkrts_get_nworkers() << " threads for calculating vector." << logger.endl;
  54. logger << "Utilizing " << nworkers() << " threads for calculating sum." << logger.endl;
  55. #elif defined OMP
  56. logger << "Running with max threads: " << nworkers() << logger.endl;
  57. #elif defined THREADS
  58. logger << "Running with max threads: " << nworkers() << logger.endl;
  59. #else
  60. logger << "Running the serial version of the algorithm." << logger.endl;
  61. #endif
  62. }