forked from yecol/xtrapulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtrapulp.cpp
262 lines (246 loc) · 9.47 KB
/
xtrapulp.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
//@HEADER
// *****************************************************************************
//
// XtraPuLP: Xtreme-Scale Graph Partitioning using Label Propagation
// Copyright (2016) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact George M. Slota ([email protected])
// Siva Rajamanickam ([email protected])
// Kamesh Madduri ([email protected])
//
// *****************************************************************************
//@HEADER
*/
#include <mpi.h>
#include <omp.h>
#include <math.h>
#include <stdio.h>
#include <cstdlib>
#include <stdint.h>
#include <cstring>
#include <sys/time.h>
#include <time.h>
#include "xtrapulp.h"
#include "comms.h"
#include "pulp_data.h"
#include "dist_graph.h"
#include "pulp_init.h"
#include "pulp_v.h"
#include "pulp_ve.h"
#include "pulp_vec.h"
namespace pulp{
int procid, nprocs;
int seed;
bool verbose, debug, verify;
extern MPI_Comm pulp_comm;
extern "C" int xtrapulp_run(dist_graph_t* g, pulp_part_control_t* ppc,
int* parts, int num_parts)
{
mpi_data_t comm;
pulp_data_t pulp;
queue_data_t q;
init_comm_data(&comm);
init_pulp_data(g, &pulp, num_parts);
init_queue_data(g, &q);
if (ppc->do_repart)
memcpy(pulp.local_parts, parts, g->n_local*sizeof(int32_t));
xtrapulp(g, ppc, &comm, &pulp, &q);
memcpy(parts, pulp.local_parts, g->n_local*sizeof(int32_t));
clear_comm_data(&comm);
clear_pulp_data(&pulp);
clear_queue_data(&q);
return 0;
}
extern "C" int xtrapulp(dist_graph_t* g, pulp_part_control_t* ppc,
mpi_data_t* comm, pulp_data_t* pulp, queue_data_t* q)
{
double vert_balance = ppc->vert_balance;
//double vert_balance_lower = 0.25;
double edge_balance = ppc->edge_balance;
double do_label_prop = ppc->do_lp_init;
double do_nonrandom_init = ppc->do_bfs_init;
verbose = ppc->verbose_output;
bool do_vert_balance = true;
bool do_edge_balance = ppc->do_edge_balance;
bool do_maxcut_balance = ppc->do_maxcut_balance;
bool do_repart = ppc->do_repart;
bool has_vert_weights = (g->vertex_weights != NULL);
bool has_edge_weights = (g->edge_weights != NULL);
int balance_outer_iter = 1;
int label_prop_iter = 3;
int vert_outer_iter = 3;
int vert_balance_iter = 5;
int vert_refine_iter = 10;
//int edge_outer_iter = 3;
//int edge_balance_iter = 5;
//int edge_refine_iter = 10;
int num_parts = (int)pulp->num_parts;
seed = ppc->pulp_seed;
double elt, elt2, elt3;
elt = timer();
if (do_label_prop && (has_vert_weights || has_edge_weights))
{
if (procid == 0 && verbose) printf("\tDoing (weighted) lp init stage with %d parts\n", num_parts);
elt2 = timer();
pulp_init_label_prop_weighted(g, comm, q, pulp, label_prop_iter);
elt2 = timer() - elt2;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt2);
}
else if (do_label_prop)
{
if (procid == 0 && verbose) printf("\tDoing lp init stage with %d parts\n", num_parts);
elt2 = timer();
pulp_init_label_prop(g, comm, q, pulp, label_prop_iter);
elt2 = timer() - elt2;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt2);
}
else if (do_nonrandom_init)
{
if (procid == 0 && verbose) printf("\tDoing bfs init stage with %d parts\n", num_parts);
elt2 = timer();
pulp_init_bfs_max(g, comm, q, pulp);
elt2 = timer() - elt2;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt2);
}
else if (!do_repart)
{
if (procid == 0 && verbose) printf("\tDoing block init stage with %d parts\n", num_parts);
elt2 = timer();
pulp_init_block(g, comm, q, pulp);
elt2 = timer() - elt2;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt2);
}
if (procid == 0 && verbose) printf("\tBeginning vertex (and edge) refinement\n");
for (int boi = 0; boi < balance_outer_iter; ++boi)
{
elt2 = timer();
if (do_vert_balance && (has_vert_weights || has_edge_weights))
{
if (procid == 0 && verbose) printf("\t\tDoing (weighted) vert balance and refinement stage\n");
elt3 = timer();
pulp_v_weighted(g, comm, q, pulp,
vert_outer_iter, vert_balance_iter, vert_refine_iter,
vert_balance, edge_balance);
elt3 = timer() - elt3;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt3);
}
else if (do_vert_balance)
{
if (procid == 0 && verbose) printf("\t\tDoing vert balance and refinement stage\n");
elt3 = timer();
pulp_v(g, comm, q, pulp,
vert_outer_iter, vert_balance_iter, vert_refine_iter,
vert_balance, edge_balance);
elt3 = timer() - elt3;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt3);
}
if (do_edge_balance && !do_maxcut_balance &&
(has_vert_weights || has_edge_weights))
{
if (procid == 0 && verbose) printf("\t\tDoing (weighted) edge balance and refinement stage\n");
elt3 = timer();
pulp_ve_weighted(g, comm, q, pulp,
vert_outer_iter, vert_balance_iter, vert_refine_iter,
vert_balance, edge_balance);
elt3 = timer() - elt3;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt3);
}
else if (do_edge_balance && !do_maxcut_balance)
{
if (procid == 0 && verbose) printf("\t\tDoing edge balance and refinement stage\n");
elt3 = timer();
pulp_ve(g, comm, q, pulp,
vert_outer_iter, vert_balance_iter, vert_refine_iter,
vert_balance, edge_balance);
elt3 = timer() - elt3;
if (procid == 0 && verbose) printf("done: %9.6lf(s)\n", elt3);
}
else if (do_edge_balance && do_maxcut_balance &&
(has_vert_weights || has_edge_weights))
{
if (procid == 0 && verbose) printf("\t\tDoing (weighted) maxcut balance and refinement stage\n");
elt3 = timer();
pulp_vec_weighted(g, comm, q, pulp,
vert_outer_iter, vert_balance_iter, vert_refine_iter,
vert_balance, edge_balance);
elt3 = timer() - elt3;
if (procid == 0 && verbose) printf("done: %9.6lfs\n", elt3);
}
else if (do_edge_balance && do_maxcut_balance)
{
if (procid == 0 && verbose) printf("\t\tDoing maxcut balance and refinement stage\n");
elt3 = timer();
pulp_vec(g, comm, q, pulp,
vert_outer_iter, vert_balance_iter, vert_refine_iter,
vert_balance, edge_balance);
elt3 = timer() - elt3;
if (procid == 0 && verbose) printf("done: %9.6lfs\n", elt3);
}
elt2 = timer() - elt2;
if (procid == 0 && verbose) printf("\tFinished outer loop iter %d: %9.6lf(s)\n", (boi+1), elt2);
}
elt = timer() - elt;
if (procid == 0 && verbose) printf("Partitioning finished: %9.6lf(s)\n", elt);
return 0;
}
extern "C" int create_xtrapulp_dist_graph(dist_graph_t* g,
unsigned long n_global, unsigned long m_global,
unsigned long n_local, unsigned long m_local,
unsigned long* local_adjs, unsigned long* local_offsets,
unsigned long* global_ids, unsigned long* vert_dist,
int* vertex_weights, int* edge_weights)
{
MPI_Comm_rank(pulp_comm, &procid);
MPI_Comm_size(pulp_comm, &nprocs);
if (nprocs > 1)
{
create_graph(g, (uint64_t)n_global, (uint64_t)m_global,
(uint64_t)n_local, (uint64_t)m_local,
(uint64_t*)local_offsets, (uint64_t*)local_adjs,
(uint64_t*)global_ids,
(int32_t*)vertex_weights, (int32_t*)edge_weights);
relabel_edges(g, vert_dist);
}
else
{
create_graph_serial(g, (uint64_t)n_global, (uint64_t)m_global,
(uint64_t)n_local, (uint64_t)m_local,
(uint64_t*)local_offsets, (uint64_t*)local_adjs,
(int32_t*)vertex_weights, (int32_t*)edge_weights);
}
get_ghost_degrees(g);
//get_ghost_weights(g);
return 0;
}
}