-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChacoInterface.cs
More file actions
270 lines (246 loc) · 9.32 KB
/
ChacoInterface.cs
File metadata and controls
270 lines (246 loc) · 9.32 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
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
263
264
265
266
267
268
269
270
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using static ChacoSharp.StaticConstants;
using static ChacoSharp.Utilities.Timer;
using static ChacoSharp.Graph.FreeGraph;
using static ChacoSharp.Graph.Reformat;
using static ChacoSharp.SubMain.SubMainHelper;
namespace ChacoSharp
{
public static unsafe class ChacoInterface
{
/// <summary>
///
/// </summary>
/// <param name="nvtxs">number of vertices in full graph</param>
/// <param name="start">start of edge list for each vertex</param>
/// <param name="adjacency">edge list data</param>
/// <param name="vwgts">weights for all vertices</param>
/// <param name="ewgts">weights for all edges</param>
/// <param name="x">coordinates for inertial method</param>
/// <param name="y">coordinates for inertial method</param>
/// <param name="z">coordinates for inertial method</param>
/// <param name="assignment">set number of each vtx (length n)</param>
/// <param name="architecture">0 => hypercube, d => d-dimensional mesh</param>
/// <param name="ndims_tot">total number of cube dimensions to divide</param>
/// <param name="mesh_dims">dimensions of mesh of processors</param>
/// <param name="goal">desired set sizes for each set</param>
/// <param name="globalMethod">global partitioning algorithm</param>
/// <param name="localMethod">local partitioning algorithm</param>
/// <param name="rqi_flag">should I use RQI/Symmlq eigensolver?</param>
/// <param name="vmax">how many vertices to coarsen down to?</param>
/// <param name="ndims">number of eigenvectors (2^d sets)</param>
/// <param name="eigtol">tolerance on eigenvectors</param>
/// <param name="seed">for random graph mutations</param>
/// <returns>A flag indicating if an error occured.</returns>
public static bool INTERFACE(int nvtxs,
int* start,
int* adjacency,
int* vwgts,
float* ewgts,
float* x, float* y, float* z,
int* assignment,
int architecture,
int ndims_tot,
int[] mesh_dims/*[3]*/,
double[] goal,
PartitioningStrategy globalMethod,
LocalPartitioningStrategy localMethod,
bool rqi_flag,
int vmax,
int ndims,
double eigtol,
int seed
)
{
vtx_data** graph = null; /* graph data structure */
float** coords = null; /* coordinates for vertices if used */
bool flag; /* return code from balance */
int nedges; /* number of edges in graph */
var totalSetsCreated = 0; /* total number of sets being created */
int igeom; /* geometric dimension for inertial method */
bool defaultGoal; /* using default goals? */
if (DEBUG_TRACE)
{
Trace.WriteLine("<Entering INTERFACE>");
}
if (goal == null)
{
/* If not passed in, default goals have equal set sizes. */
defaultGoal = true;
if (architecture == 0)
{
totalSetsCreated = 1 << ndims_tot;
}
else if (architecture == 1)
{
totalSetsCreated = mesh_dims[0];
}
else if (architecture == 2)
{
totalSetsCreated = mesh_dims[0] * mesh_dims[1];
}
else if (architecture > 2)
{
totalSetsCreated = mesh_dims[0] * mesh_dims[1] * mesh_dims[2];
}
double vwgt_sum; /* sum of vertex weights */
if (MAKE_VWGTS && start != null)
{
vwgt_sum = start[nvtxs] - start[0] + nvtxs;
}
else if (vwgts == null)
{
vwgt_sum = nvtxs;
}
else
{
vwgt_sum = 0;
var vptr = vwgts; /* loops through vertex weights */
for (var i = nvtxs; i != 0; i--)
{
vwgt_sum += *(vptr++);
}
}
if (totalSetsCreated > 0)
{
vwgt_sum /= totalSetsCreated;
}
goal = new double[totalSetsCreated];
if (goal == null)
{
Trace.WriteLine("\nERROR: No room to make goals.");
flag = true;
goto skip;
}
for (var i = 0; i < totalSetsCreated; i++)
{
goal[i] = vwgt_sum;
}
}
else
{
defaultGoal = false;
}
if (MAKE_VWGTS)
{
/* Generate vertex weights equal to degree of node. */
if (vwgts != null)
{
Trace.WriteLine("WARNING: Vertex weights being overwritten by vertex degrees.");
}
vwgts = (int*) Marshal.AllocHGlobal(nvtxs * sizeof(int));
if (vwgts == null)
{
Trace.WriteLine("\nERROR: No room to make vertex weights.");
flag = true;
goto skip;
}
if (start != null)
{
for (var i = 0; i < nvtxs; i++)
{
vwgts[i] = 1 + start[i + 1] - start[i];
}
}
else
{
for (var i = 0; i < nvtxs; i++)
{
vwgts[i] = 1;
}
}
}
var using_vwgts = (vwgts != null);
var useEdgeWeights = (ewgts != null);
if (start != null || vwgts != null)
{
/* Reformat into our data structure. */
double time = seconds(); /* timing variable */
flag = reformat(start, adjacency, nvtxs, &nedges, vwgts, ewgts, &graph);
if (flag)
{
Trace.WriteLine("\nERROR: No room to reformat graph.");
goto skip;
}
reformat_time += seconds() - time;
}
else
{
nedges = 0;
}
if (FREE_GRAPH)
{
/* Free old graph data structures. */
Marshal.FreeHGlobal((IntPtr) start);
start = null;
Marshal.FreeHGlobal((IntPtr) adjacency);
adjacency = null;
Marshal.FreeHGlobal((IntPtr) vwgts);
vwgts = null;
Marshal.FreeHGlobal((IntPtr) ewgts);
ewgts = null;
}
if (globalMethod == PartitioningStrategy.Inertial ||
(MATCH_TYPE == MatchingRoutine.maxmatch5_geometric && (globalMethod == PartitioningStrategy.Multilevel_KL || (globalMethod == PartitioningStrategy.Spectral && rqi_flag))))
{
if (x == null)
{
igeom = 0;
}
else
{
/* Set up coordinate data structure. */
coords = (float**) Marshal.AllocHGlobal(3 * sizeof(float*));
if (coords == null)
{
Trace.WriteLine("\nERROR: No room to make coordinate array.");
flag = true;
goto skip;
}
/* Minus 1's are to allow remainder of program to index with 1. */
coords[0] = x - 1;
igeom = 1;
if (y != null)
{
coords[1] = y - 1;
igeom = 2;
if (z != null)
{
coords[2] = z - 1;
igeom = 3;
}
}
}
}
else
{
igeom = 0;
}
/* Subtract from assignment to allow code to index from 1. */
assignment = assignment - 1;
flag = submain(graph, nvtxs, nedges, using_vwgts, useEdgeWeights, igeom, coords,
assignment, goal, architecture, ndims_tot, mesh_dims, globalMethod,
localMethod, rqi_flag, vmax, ndims, eigtol, seed);
skip:
Marshal.FreeHGlobal((IntPtr) coords);
if (defaultGoal)
{
goal = null;
}
if (graph != null)
{
free_graph(graph);
}
if (flag && FREE_GRAPH)
{
Marshal.FreeHGlobal((IntPtr) start);
Marshal.FreeHGlobal((IntPtr) adjacency);
Marshal.FreeHGlobal((IntPtr) vwgts);
Marshal.FreeHGlobal((IntPtr) ewgts);
}
return (flag);
}
}
}