-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathcomponents_read.daphne
46 lines (34 loc) · 1013 Bytes
/
components_read.daphne
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
// Connected components.
// Arguments:
// - f ... filename of the adjacency matrix (provide as `--args f=\"foo.csv\"`)
t0 = now();
// Read adjacency matrix.
G = readMatrix($f);
// Initialization.
// TODO Don't forget to set this back to something high (e.g. 1000) later.
maxi = 5;
c = seq(1.0, as.f64(nrow(G)), 1.0); // init w/ vertex IDs
diff = inf;
iter = 1;
t1 = now();
// Iterative computation of connected components (decisive part).
while(as.si64(diff > 0.0) && iter <= maxi) {
ti0 = now();
u = max(aggMax(G * t(c), 0), c);
diff = sum(u != c);
c = u;
ti1 = now();
print("iteration ", 0, 1);
print(iter, 0, 1);
print(" took [ns]: ", 0, 1);
print(ti1 - ti0);
iter = iter + 1;
}
t2 = now();
// Print elapsed times in nano seconds.
print(t1 - t0); // initialization
print(t2 - t1); // core algorithm
// Note that, for distributed execution, (t2 - t1) includes reading the input
// files due to some reordering done by the compiler.
// Result output.
print(c);