forked from CGCL-codes/DGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathk-core.cpp
More file actions
94 lines (84 loc) · 2.21 KB
/
k-core.cpp
File metadata and controls
94 lines (84 loc) · 2.21 KB
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
#include "api.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
template <class App>
class KCore : public App
{
private:
int K;
public:
KCore(string dir, string value_dir, int K): App(dir, string("k_core_value.bin"), value_dir), K(K){};
void init(ID id, typename App::value_t &value)
{
value = true;
}
bool update(ID virtual_id, typename App::bor_t inbor, typename App::bor_t outbor,
bor_cnt_t in_cnt, bor_cnt_t out_cnt, const typename App::values_t rvalue, typename App::values_t wvalue)
{
int cnt = 0;
/*
for(int i = 0; i < in_cnt; i++)
cnt += rvalue[inbor[i]];
//*/
//*
ID idval = 0;
PG_Foreach(inbor, idval)
cnt += rvalue[idval];
//*/
bool is_cvg = !(wvalue[virtual_id] ^ (cnt >= K));
wvalue[virtual_id] = (cnt >= K);
return is_cvg;
}
void print_top(int top_num)
{
cnt_t core_vtx_num = 0;
for(int i = 0; i < App::vtxs_size; i++)
core_vtx_num += App::value2[i];
cout << "K-Core vtxs num: " << core_vtx_num << endl;
App::print_top(top_num);
}
};
int main(int argc, char *argv[])
{
if (argc != 3 && argc != 4 && argc != 5)
{
cout << "Usage ./k-core <data dir> <generate value to dir> <K(default 5)> <kc.nt top(default 10)>" << endl;
return 0;
}
int top_num = (argc == 5 ? top_num = atoi(argv[4]) : 10),
K = (argc >= 4 ? atoi(argv[3]) : 5);
string dir(argv[1]), to_dir(argv[2]);
/*
cout << "normal para run" << endl; get_time(false);
KCore<UnSccDagApp<bool>> ukc(dir, to_dir, K);
ukc.reset(false);
ukc.para_run();
get_time(); cout << endl;
ukc.kc.nt_top(top_num);
//*/
cout << "para run" << endl; get_time(false);
KCore<SccDagApp<bool>> kc(dir, to_dir, K);
#if defined(SD_NORMAL_SYNC)
cout << "normal sync para run" << endl; get_time(false);
kc.reset();
kc.normal_para_run();
#elif defined(SD_SYNC)
cout << "sync para run" << endl; get_time(false);
kc.reset();
kc.para_run();
#elif defined(SD_NORMAL_ASYNC)
cout << "normal asyn para run" << endl; get_time(false);
kc.reset(false);
kc.normal_para_run();
#else
cout << "asyn para run" << endl; get_time(false);
kc.reset(false);
kc.para_run();
#endif
get_time(); cout << endl;
kc.print_top(top_num);
return 0;
}