-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompression_vertex.cc
71 lines (56 loc) · 1.58 KB
/
compression_vertex.cc
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
// Copyright (c) 2019 ETH-Zurich.
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "benchmark.h"
#include "command_line.h"
#include <omp.h>
void SG_low_degree( NodeID u, const Graph &g, bool keep_nodes[] ) {
if( (g.in_degree( u ) + g.out_degree( u )) < 2 ) { // equivalent to (v.deg == 0) || (v.deg == 1)
keep_nodes[u] = false;
} else {
keep_nodes[u] = true;
}
}
int main(int argc, char* argv[]) {
CLApp cli(argc, argv, "single-vertex compression kernel");
if (!cli.ParseArgs()) {
return -1;
}
std::string g_output_file_name = cli.output_filename();
// build graph
Builder b(cli);
Graph g = b.MakeGraph();
int64_t n = g.num_nodes();
bool* keep_nodes = new bool[n];
#pragma omp parallel for
for (NodeID i = 0; i < n; i++) {
SG_low_degree( i, g, keep_nodes );
}
// we need to reassign the IDs of the vertices
size_t num_removed = 0;
NodeID* newNodeID = new NodeID[n];
for (NodeID i = 0; i < n; i++) {
if( keep_nodes[i] ) {
newNodeID[i] = i - num_removed;
} else {
num_removed++;
}
}
// write out the compressed graph
std::ofstream compressed_graph_file(g_output_file_name);
for (NodeID i = 0; i < n; i++) {
if( keep_nodes[i] ) {
for (NodeID j : g.out_neigh(i)) {
if( keep_nodes[j] ) {
compressed_graph_file << newNodeID[i] << " " << newNodeID[j] << std::endl;
}
}
}
}
compressed_graph_file.close();
delete [] keep_nodes;
delete [] newNodeID;
return 0;
}