-
Notifications
You must be signed in to change notification settings - Fork 0
/
kcore.cpp
103 lines (85 loc) · 2.5 KB
/
kcore.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <graphlab.hpp>
using namespace graphlab;
#include <mpi.h>
#include <sstream>
#include <string>
using namespace std;
#include <unistd.h>
#define KCORE_DEGREE 10
struct vertex {
bool in_core;
int changed;
vertex() : in_core(true), changed(0) { }
void save(oarchive& oarc) const { }
void load(iarchive& iarc) { }
};
typedef distributed_graph<vertex, empty> graph_type;
class kcore_program : public ivertex_program<graph_type, int>, public IS_POD_TYPE {
public:
edge_dir_type gather_edges(icontext_type& context, const vertex_type& vertex) const {
return IN_EDGES;
}
int gather(icontext_type& context, const vertex_type& vertex, edge_type& edge) const {
return ( edge.source().data().in_core ? 1 : 0 );
}
void apply(icontext_type& context, vertex_type& vertex, const gather_type& total) {
if( total < KCORE_DEGREE ) {
vertex.data().in_core = false;
vertex.data().changed += 1;
}
}
edge_dir_type scatter_edges(icontext_type& context, const vertex_type& vertex) const {
if( vertex.data().changed == 1 ) {
return OUT_EDGES;
}
else {
return NO_EDGES;
}
}
void scatter(icontext_type& context, const vertex_type& vertex, edge_type& edge) const {
if( edge.target().data().in_core ) {
context.signal(edge.target());
}
}
};
class graph_writer
{
public:
std::string save_vertex(graph_type::vertex_type v)
{
stringstream strm;
//strm << "Process id: " << dc.procid() << " : " << mpi_tools::rank() << " / " << mpi_tools::size() << "\n";
/*char name[81];
gethostname(name, 80);
name[80] = 0;*/
if( v.data().in_core ) {
return string("1\n");
}
else {
return string();
}
}
std::string save_edge(graph_type::edge_type e)
{
return "";
}
};
int main(int argc, char* argv[])
{
mpi_tools::init(argc, argv);
distributed_control dc;
graph_type graph(dc);
//char hostname[80];
//gethostname(hostname, 80);
//graph.load_format("hdfs://ip-10-149-6-179/data/M87141220.tsv", "tsv");
graph.load_format("/home/ubuntu/M87141220.tsv", "tsv");
//dc.cout() << "Hello World from " << dc.procid() << "( " << mpi_tools::rank() << ") / " << mpi_tools::size() << "!\n";
omni_engine<kcore_program> engine(dc, graph, "sync");
engine.signal_all();
engine.start();
//graph.save("hdfs://ip-10-149-6-179/paul/output.txt", graph_writer(), false, true, false);
//graph.save("/home/ubuntu/paul/output.txt", graph_writer(), false, true, false);
dc.cout() << "Did " << engine.num_updates() << " updates in " << engine.iteration() << " iterations\n";
mpi_tools::finalize();
return 0;
}