-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
177 lines (151 loc) · 4.49 KB
/
main.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <cstdlib>
#include <iostream>
#include <string>
#include <omp.h>
#include "graph.hpp"
#include "graph_gpu.hpp"
#include "louvain_gpu.hpp"
#include "types.hpp"
#include "cuda_wrapper.hpp"
#include <unistd.h>
#include <fstream>
#include <sstream>
int main(int argc, char** argv)
{
using namespace std;
Int nv;
Graph* graph = nullptr;
std::string inputFileName, outFileName, randGraphArgs, partArgs;
int part_on_device = 1;
int part_on_batch = 1;
bool part_select = false;
bool is_colored = false;
bool rand_graph = false;
bool bin_graph = false;
bool output_communities = false;
int nbatches = DEFAULT_BATCHES;
Int maxLoops = DEFAULT_ITERATIONS;
Float tau = DEFAULT_THRESHOLD;
int ret;
optind = 1;
bool help_text = false;
while ((ret = getopt(argc, argv, "f:p:r:cb:i:t:ho:")) != -1)
{
switch (ret)
{
case 'f':
bin_graph = true;
inputFileName.assign(optarg);
break;
case 'p':
part_select = true;
partArgs.assign(optarg);
break;
case 'r':
rand_graph = true;
randGraphArgs.assign(optarg);
break;
case 'o':
output_communities = true;
outFileName.assign(optarg);
break;
case 't':
tau = (Float)atof(optarg);
break;
case 'i':
maxLoops = (Int)atoll(optarg);
break;
case 'b':
nbatches = (Int)atoi(optarg);
break;
case 'c':
is_colored = true;
break;
case 'h':
std::cout << "Sample usage [1] (use real-world file): ./run_<NGPU>_<GPU_ARCH> [-f /path/to/binary/file.bin] (see README)" << std::endl;
std::cout << "Sample usage [2] (use synthetic graph): ./run_<NGPU>_<GPU_ARCH> [-r <#vertices> <edge-factor>" << std::endl;
help_text = true;
break;
default:
std::cout << "Reached default -- please check the passed options." << std::endl;
break;
}
}
if (help_text)
std::exit(EXIT_SUCCESS);
if(rand_graph)
{
std::stringstream ss(randGraphArgs);
std::string s;
std::vector<std::string> args;
while (std::getline(ss, s, ' '))
args.push_back(s);
if (args.size() != 2)
{
std::cerr << "For random graphs, expecting (in this order): <#vertices> <edge-factor>"
<< std::endl;
exit(EXIT_FAILURE);
}
nv = std::stoi(args[0]);
Int m0 = std::stoi(args[1]);
graph = new Graph(nv, m0);
args.clear();
}
else if(bin_graph)
graph = new Graph(inputFileName);
else
{
std::cerr << "Input graph arguments missing. Use -f or -r options." << std::endl;
std::exit(-1);
}
// this is for influencing the way we
// compute partitions - default is set,
// do not change unless you know what you
// are doing...
if(part_select)
{
std::stringstream ss(partArgs);
std::string s;
std::vector<std::string> args;
while (std::getline(ss, s, ' '))
args.push_back(s);
if (args.size() != 2)
{
std::cerr << "Expecting 0/1 (in this order): <part-on-device?> <part-on-batch?>"
<< std::endl;
exit(EXIT_FAILURE);
}
part_on_device = std::stoi(args[0]);
part_on_batch = std::stoi(args[1]);
args.clear();
}
std::cout << "#Batches: " << nbatches << std::endl;
std::cout << "#Threshold: " << tau << std::endl;
std::cout << "Max #iterations: " << maxLoops << std::endl;
std::cout << "#NGPUs: " << NGPU << std::endl;
std::cout << "--------------------------------------" << std::endl;
GraphElem* new_orders = nullptr;
if(is_colored)
{
double color_start = omp_get_wtime();
new_orders = graph->coloring();
double color_end = omp_get_wtime();
std::cout << "Coloring Time: " << color_end-color_start << " s\n";
}
GraphGPU* graph_gpu = new GraphGPU(graph, nbatches, part_on_device, part_on_batch);
LouvainGPU* louvain = new LouvainGPU(maxLoops, tau, nbatches);
louvain->run(graph_gpu);
if (output_communities)
graph_gpu->dump_partition(outFileName, new_orders);
if(is_colored)
delete [] new_orders;
delete louvain;
delete graph_gpu;
delete graph;
for(int i = 0; i < NGPU; ++i)
{
CudaSetDevice(i);
CudaCall(cudaDeviceReset());
}
return 0;
}