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.
 
 
 
 
 
 

54 linhas
1.2 KiB

  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_ER_graph (matrix& A) {
  39. matrix::indexType N = (A.size() < (matrix::indexType)session.print_size) ? A.size() : session.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. }