forked from CGCL-codes/DGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwcc.cpp
More file actions
88 lines (71 loc) · 2.03 KB
/
wcc.cpp
File metadata and controls
88 lines (71 loc) · 2.03 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
#include "api.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;
template <class App>
class WCCApp : public App
{
public:
WCCApp(string dir, string value_dir): App(dir, string("cc_value.bin"), value_dir){};
int min(int a, int b){return a < b ? a : b;}
void init(ID id, typename App::value_t &value)
{
value = (int)(id);
}
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 val = rvalue[virtual_id];
for (int i = 0; i < in_cnt; i++)
val = min(val, rvalue[inbor[i]]);
for (int i = 0; i < out_cnt; i++)
val = min(val, rvalue[outbor[i]]);
bool is_cvg = (wvalue[virtual_id] == val);
//if(!is_cvg)
// cout << App::map_nto[virtual_id] << ": " << val << "->" << wvalue[virtual_id] << endl;
wvalue[virtual_id] = val;
return is_cvg;
}
void print_wcc()
{
cnt_t cnt = 0;
cout << "WCCs:" << endl;
for(ID i = 0; i < App::vtxs_size; i++)
{
if(App::map_nto[i] == App::value1[i])
{
//cout << "wcc-" << App::map_nto[i] << endl;
cnt++;
}
}
cout << "wcc num: " << cnt << endl;
cout << endl;
}
};
int main(int argc, char *argv[])
{
if (argc != 3 && argc != 4)
{
cout << "Usage ./wcc <data dir> <generate value to dir> <print top(default 10)>" << endl;
return 0;
}
int top_num = (argc == 4 ? top_num = atoi(argv[3]) : 10) ;
string dir(argv[1]), to_dir(argv[2]);
cout << "normal para run" << endl; get_time(false);
WCCApp<UnSccDagApp<int>> ucc(dir, to_dir);
ucc.reset(false);
ucc.para_run();
get_time(); cout << endl;
ucc.print_top(top_num);
ucc.print_wcc();
cout << "undirect para run" << endl; get_time(false);
WCCApp<SccDagApp<int>> cc(dir, to_dir);
cc.reset(false);
cc.undirect_para_run();
get_time(); cout << endl;
cc.print_top(top_num);
cc.print_wcc();
return 0;
}