27 #include <graphlab.hpp>
31 float RESET_PROB = 0.15;
33 float TOLERANCE = 1.0E-2;
36 typedef float vertex_data_type;
39 typedef graphlab::empty edge_data_type;
78 float gather(icontext_type& context,
const vertex_type& vertex,
79 edge_type& edge)
const {
80 return ((1.0 - RESET_PROB) / edge.source().num_out_edges()) *
85 void apply(icontext_type& context, vertex_type& vertex,
86 const gather_type& total) {
87 const double newval = total + RESET_PROB;
88 last_change = std::fabs(newval - vertex.data());
89 vertex.data() = newval;
94 const vertex_type& vertex)
const {
100 void scatter(icontext_type& context,
const vertex_type& vertex,
101 edge_type& edge)
const {
102 context.signal(edge.target());
111 struct pagerank_writer {
113 std::stringstream strm;
114 strm << v.
id() <<
"\t" << v.
data() <<
"\n";
122 int main(
int argc,
char** argv) {
124 graphlab::mpi_tools::init(argc, argv);
130 std::string graph_dir;
131 std::string format =
"adj";
132 std::string exec_type =
"synchronous";
133 clopts.attach_option(
"graph", graph_dir,
134 "The graph file. Required ");
135 clopts.add_positional(
"graph");
136 clopts.attach_option(
"format", format,
137 "The graph file format");
138 clopts.attach_option(
"engine", exec_type,
139 "The engine type synchronous or asynchronous");
140 clopts.attach_option(
"tol", TOLERANCE,
141 "The permissible change at convergence.");
142 std::string saveprefix;
143 clopts.attach_option(
"saveprefix", saveprefix,
144 "If set, will save the resultant pagerank to a "
145 "sequence of files with prefix saveprefix");
147 if(!clopts.parse(argc, argv)) {
148 dc.
cout() <<
"Error in parsing command line arguments." << std::endl;
152 if (graph_dir ==
"") {
153 dc.
cout() <<
"Graph not specified. Cannot continue";
159 dc.
cout() <<
"Loading graph in format: "<< format << std::endl;
160 graph.load_format(graph_dir, format);
163 dc.
cout() <<
"#vertices: " << graph.num_vertices()
164 <<
" #edges:" << graph.num_edges() << std::endl;
167 graph.transform_vertices(init_vertex);
173 const float runtime = engine.elapsed_seconds();
174 dc.
cout() <<
"Finished Running engine in " << runtime
175 <<
" seconds." << std::endl;
178 if (saveprefix !=
"") {
179 graph.save(saveprefix, pagerank_writer(),
186 graphlab::mpi_tools::finalize();