-
Notifications
You must be signed in to change notification settings - Fork 0
/
kcore.c
191 lines (162 loc) · 3.36 KB
/
kcore.c
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
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include "defs.h"
#include "globals.h"
#ifdef __MTA__
#include <sys/mta_task.h>
#include <machine/runtime.h>
#else
#include "compat/xmt-ops.h"
#endif
#include <math.h>
#include "stinger-atomics.h"
graph * genSubGraph(graph * G, int64_t NV, int64_t color)
{
int64_t i;
int64_t * mask = G->marks;
int64_t remain = NV;
// Calculates 'remain' if NV is passed as 0 (most applications)
if (remain == 0) {
remain = 0;
for (i = 0; i < G->numVertices; i++) {
if (mask[i] == color)
remain += mask[i];
}
}
NV = G->numVertices;
int64_t * start = G->edgeStart;
int64_t * eV = G->endVertex;
int64_t * weight = G->intWeight;
graph * G2 = xmalloc(sizeof(graph));
int64_t NE2 = 0;
int64_t * mapper = xmalloc(sizeof(int64_t)*remain);
int64_t * backmap = xmalloc(sizeof(int64_t)*NV);
int64_t id = 0;
OMP("omp parallel for")
for (i = 0; i < NV; ++i)
{
if (mask[i] == color) {
const int64_t begin = start[i];
const int64_t end = start[i+1];
int64_t v = stinger_int_fetch_add (&id, 1);
mapper[v] = i;
backmap[i] = v;
for (int64_t j = begin; j < end; ++j)
if(mask[eV[j]] == color)
stinger_int_fetch_add(&NE2, 1);
}
}
alloc_graph (G2, remain, NE2);
int64_t * start2 = G2->edgeStart;
OMP("omp parallel for")
for (i = 0; i < remain+2; i++)
{
start2[i] = 0;
}
OMP("omp parallel for")
MTA("mta assert nodep")
for (i = 0; i < NV; i++)
{
if (mask[i] == color)
{
int64_t begin = start[i];
int64_t end = start[i+1];
int64_t j;
for (j = begin; j < end; j++)
{
if (mask[eV[j]] == color)
{
stinger_int_fetch_add(&start2[mapper[i]+2], 1);
}
}
}
}
for (i = 1; i < remain; i++)
{
start2[i+2] += start2[i+1];
}
int64_t * weight2 = G2->intWeight;
int64_t * eV2 = G2->endVertex;
MTA("mta assert nodep")
for (i = 0; i < remain; i++)
{
int64_t v = mapper[i];
int64_t begin = start[v];
int64_t end = start[v+1];
int64_t j;
for(j = begin; j < end; j++)
{
if(mask[eV[j]] == color)
{
weight2[start2[i+1]] = weight[j];
eV2[start2[i+1]++] = backmap[eV[j]];
}
}
G2->marks[i] = 0;
}
free(backmap);
free(mapper);
return G2;
}
graph * kcore(graph * G, int64_t k)
{
int64_t NV = G->numVertices;
int64_t NE = G->numEdges;
int64_t * start = G->edgeStart;
int64_t * eV = G->endVertex;
int64_t * mask = G->marks;
graph * G2;
int64_t i;
OMP("omp parallel for")
for(i = 0; i < NV; i++)
{
mask[i] = 0;
}
int64_t * degree = (int64_t *) xmalloc(sizeof(int64_t)*NV);
OMP("omp parallel for")
for(i = 0; i < NV; i++)
{
degree[i] = start[i+1] - start[i];
}
OMP("omp parallel for")
for(i = 0; i < NE; i++)
{
// degree[eV[i]]++;
stinger_int_fetch_add(°ree[eV[i]], 1);
}
int64_t remain = NV;
int64_t iter = 0;
while (1)
{
iter++;
int64_t count = 0;
OMP("omp parallel for")
MTA("mta assert nodep")
for (i = 0; i < NV; i++)
{
if ((!mask[i]) && degree[i] < k)
{
mask[i] = iter;
stinger_int_fetch_add(&count, 1);
}
}
if (count==0) break;
remain -= count;
OMP("omp parallel for")
MTA("mta interleave schedule")
for (i = 0; i < NV; i++)
{
int64_t begin = start[i];
int64_t end = start[i+1];
int64_t j;
for(j = begin; j < end; j++)
{
if (mask[eV[j]] == iter)
stinger_int_fetch_add(°ree[i], -1);
}
}
}
G2 = genSubGraph(G, remain, 0);
return G2;
}