-
Notifications
You must be signed in to change notification settings - Fork 0
/
modularity.c
69 lines (58 loc) · 1.52 KB
/
modularity.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
#include <stdio.h>
#include "defs.h"
#include "globals.h"
#include <malloc.h>
#if !defined(__MTA__)
#include "compat/xmt-ops.h"
#endif
#include "stinger-atomics.h"
/* Input array *membership indicates the coloring by specifying an
integer "color" for each vertex. numColors indicates the number
of colors where the colors are 0 to (numColors-1). */
double computeModularityValue(graph *G, int64_t *membership, int64_t numColors)
{
int64_t NV = G->numVertices;
int64_t * start = G->edgeStart;
int64_t * eV = G->endVertex;
int64_t i,j;
int64_t comm;
double mod = 0.0;
int64_t degree_u, degree_v;
int64_t posmod = 0;
int64_t negmod = 0;
double modularity = 0.0;
int64_t *sumtable = (int64_t *) xmalloc(numColors * sizeof(int64_t));
OMP("omp parallel for")
for (i = 0; i < numColors; i++)
{
sumtable[i] = 0;
}
OMP("omp parallel for")
MTA("mta assert parallel")
for (i = 0; i < NV; i++)
{
degree_v = start[i+1] - start[i];
stinger_int_fetch_add(sumtable + membership[i], degree_v);
}
OMP("omp parallel for")
MTA("mta assert parallel")
for (i = 0; i < NV; i++)
{
comm = membership[i];
int64_t myStart = start[i];
int64_t myEnd = start[i+1];
degree_u = myEnd - myStart;
for (j = myStart; j < myEnd; j++)
{
if (membership[eV[j]] == comm)
{
stinger_int_fetch_add(&posmod, 1);
}
}
stinger_int_fetch_add(&negmod, -degree_u*sumtable[membership[i]]);
}
mod = posmod + negmod/(2.0*G->numEdges);
printf("Modularity is: %9.6lf\n",mod/(2*G->numEdges));
free(sumtable);
return modularity;
}