A triangle counting assignment for A.U.TH Parallel and distributed systems class.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
810 B

  1. /*!
  2. * \file v4.cpp
  3. * \brief vv3 part of the exercise.
  4. *
  5. * \author
  6. * Christos Choutouridis AEM:8997
  7. * <cchoutou@ece.auth.gr>
  8. */
  9. #include <iostream>
  10. #include <random>
  11. #include <v4.h>
  12. namespace v4 {
  13. using index_t = typename matrix::indexType;
  14. using value_t = typename matrix::dataType;
  15. std::vector<value_t> mmacc_v(matrix& A, matrix& B) {
  16. std::vector<value_t> c(A.size());
  17. for (int i=0 ; i<A.size() ; ++i) {
  18. for (auto j = A.getRow(i); j.index() != j.end() ; ++j){
  19. c[i] += A.getRow(i)*B.getCol(j.index());
  20. }
  21. }
  22. return c;
  23. }
  24. value_t sum (std::vector<value_t>& v) {
  25. value_t s =0;
  26. for (auto& it : v)
  27. s += it;
  28. return s;
  29. }
  30. value_t triang_count (matrix& A) {
  31. auto v = mmacc_v(A, A);
  32. return (session.makeSymmetric) ? sum(v)/6 : sum(v);
  33. }
  34. }