|
- /*!
- * \file utils.cpp
- * \brief Utilities to handle matrix files, chrono, etc...
- *
- * \author
- * Christos Choutouridis AEM:8997
- * <cchoutou@ece.auth.gr>
- */
-
- #include <utils.h>
- #include <algorithm>
-
- /*!
- * Initialize the matrix as Erdős-Rényi graph
- * \param A The matrix to initialize
- * \param p The probability of each edge
- */
- void init_ER_graph (matrix& A, double p) {
- std::random_device rd;
- std::mt19937 gen(rd());
- std::binomial_distribution<> d(1, p);
-
- #if CODE_VERSION == V12
- std::transform (A.begin(), A.end(), A.begin(),
- [&] (int x) { std::ignore =x; return d(gen); }
- #else
- A.for_each_in(0, A.size(), [&](auto i) {
- A.for_each_in(i+1, A.size(), [&](auto j){
- matrix::dataType edge = d(gen);
- if (edge) {
- A.set(edge, i, j);
- A.set(edge, j, i);
- }
- });
- });
- #endif
-
- }
-
- /*!
- * Utility to print the graph to sdtout
- */
- void print_graph (matrix& A) {
- matrix::indexType N = (A.size() < (matrix::indexType)session.mtx_print_size) ? A.size() : session.mtx_print_size;
-
- A.for_each_in(0, N, [&](auto i){
- A.for_each_in(0, N, [&](auto j) {
- std::cout << A(i, j) << ' ';
- });
- std::cout << '\n';
- });
- }
-
- /*!
- * Utility to print to logger thread information
- */
- void threads_info () {
- #if defined CILK
- logger << "Running with max threads: " << __cilkrts_get_nworkers() << logger.endl;
- logger << "Utilizing " << __cilkrts_get_nworkers() << " threads for calculating vector." << logger.endl;
- logger << "Utilizing " << nworkers() << " threads for calculating sum." << logger.endl;
- #elif defined OMP
- logger << "Running with max threads: " << nworkers() << logger.endl;
- #elif defined THREADS
- logger << "Running with max threads: " << nworkers() << logger.endl;
- #else
- logger << "Running the serial version of the algorithm." << logger.endl;
- #endif
- }
|