forked from cmuparlay/parlaylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagerank.cpp
50 lines (43 loc) · 1.33 KB
/
pagerank.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
#include <utility>
#include <parlay/primitives.h>
#include <parlay/sequence.h>
#include "pagerank.h"
#include "helper/graph_utils.h"
// **************************************************************
// Driver
// **************************************************************
int main(int argc, char* argv[]) {
using vertex = int;
using graph = parlay::sequence<parlay::sequence<vertex>>;
using element = std::pair<vertex,float>;
using row = parlay::sequence<element>;
using sparse_matrix = parlay::sequence<row>;
using vector = parlay::sequence<double>;
using utils = graph_utils<vertex>;
auto usage = "Usage: pagerank <n> || pagerank <filename>";
if (argc != 2) std::cout << usage << std::endl;
else {
long n = 0;
graph G;
try { n = std::stol(argv[1]); }
catch (...) {}
if (n == 0) {
G = utils::read_symmetric_graph_from_file(argv[1]);
n = G.size();
} else {
G = utils::rmat_graph(n, 20*n);
}
utils::print_graph_stats(G);
sparse_matrix M = utils::to_normalized_matrix(G);
vector v;
parlay::internal::timer t("Time");
for (int i=0; i < 5; i++) {
v = pagerank(M, 10);
t.next("10 iters of pagerank");
}
double maxv = *parlay::max_element(v);
std::cout << "maximum rank = " << maxv * n << std::endl;
}
}