Skip to content

Commit fc4a1b9

Browse files
committed
Add tests for new parallel=:threads impls
1 parent a7db672 commit fc4a1b9

File tree

3 files changed

+115
-91
lines changed

3 files changed

+115
-91
lines changed

test/parallel/distance.jl

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,43 @@
77
distmx1 = [Inf 2.0 Inf; 2.0 Inf 4.2; Inf 4.2 Inf]
88
distmx2 = [Inf 2.0 Inf; 3.2 Inf 4.2; 5.5 6.1 Inf]
99

10-
for g in testgraphs(a1)
11-
z = @inferred(Graphs.eccentricity(g, distmx1))
12-
y = @inferred(Parallel.eccentricity(g, distmx1))
13-
@test isapprox(y, z)
14-
@test @inferred(Graphs.diameter(y)) ==
15-
@inferred(Parallel.diameter(g, distmx1)) ==
16-
6.2
17-
@test @inferred(Graphs.periphery(y)) ==
18-
@inferred(Parallel.periphery(g, distmx1)) ==
19-
[1, 3]
20-
@test @inferred(Graphs.radius(y)) == @inferred(Parallel.radius(g, distmx1)) == 4.2
21-
@test @inferred(Graphs.center(y)) == @inferred(Parallel.center(g, distmx1)) == [2]
10+
for parallel in [:threads, :distributed]
11+
for g in testgraphs(a1)
12+
z = @inferred(Graphs.eccentricity(g, distmx1))
13+
y = @inferred(Parallel.eccentricity(g, distmx1; parallel))
14+
@test isapprox(y, z)
15+
@test @inferred(Graphs.diameter(y)) ==
16+
@inferred(Parallel.diameter(g, distmx1)) ==
17+
6.2
18+
@test @inferred(Graphs.periphery(y)) ==
19+
@inferred(Parallel.periphery(g, distmx1)) ==
20+
[1, 3]
21+
@test @inferred(Graphs.radius(y)) ==
22+
@inferred(Parallel.radius(g, distmx1)) ==
23+
4.2
24+
@test @inferred(Graphs.center(y)) ==
25+
@inferred(Parallel.center(g, distmx1)) ==
26+
[2]
27+
end
2228
end
2329

24-
for g in testdigraphs(a2)
25-
z = @inferred(Graphs.eccentricity(g, distmx2))
26-
y = @inferred(Parallel.eccentricity(g, distmx2))
27-
@test isapprox(y, z)
28-
@test @inferred(Graphs.diameter(y)) ==
29-
@inferred(Parallel.diameter(g, distmx2)) ==
30-
6.2
31-
@test @inferred(Graphs.periphery(y)) ==
32-
@inferred(Parallel.periphery(g, distmx2)) ==
33-
[1]
34-
@test @inferred(Graphs.radius(y)) == @inferred(Parallel.radius(g, distmx2)) == 4.2
35-
@test @inferred(Graphs.center(y)) == @inferred(Parallel.center(g, distmx2)) == [2]
30+
for parallel in [:threads, :distributed]
31+
for g in testdigraphs(a2)
32+
z = @inferred(Graphs.eccentricity(g, distmx2))
33+
y = @inferred(Parallel.eccentricity(g, distmx2; parallel))
34+
@test isapprox(y, z)
35+
@test @inferred(Graphs.diameter(y)) ==
36+
@inferred(Parallel.diameter(g, distmx2)) ==
37+
6.2
38+
@test @inferred(Graphs.periphery(y)) ==
39+
@inferred(Parallel.periphery(g, distmx2)) ==
40+
[1]
41+
@test @inferred(Graphs.radius(y)) ==
42+
@inferred(Parallel.radius(g, distmx2)) ==
43+
4.2
44+
@test @inferred(Graphs.center(y)) ==
45+
@inferred(Parallel.center(g, distmx2)) ==
46+
[2]
47+
end
3648
end
3749
end

test/parallel/shortestpaths/dijkstra.jl

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,44 @@
66
g3 = path_graph(5)
77
d = [0 1 2 3 4; 1 0 1 0 1; 2 1 0 11 12; 3 0 11 0 5; 4 1 19 5 0]
88

9-
for g in testgraphs(g3)
10-
z = floyd_warshall_shortest_paths(g, d)
11-
zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d))
12-
@test all(isapprox(z.dists, zp.dists))
9+
for parallel in [:threads, :distributed]
10+
for g in testgraphs(g3)
11+
z = floyd_warshall_shortest_paths(g, d)
12+
zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d; parallel))
13+
@test all(isapprox(z.dists, zp.dists))
1314

14-
for i in 1:5
15-
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
16-
for j in 1:5
17-
if zp.parents[i, j] != 0
18-
@test zp.parents[i, j] in state.predecessors[j]
15+
for i in 1:5
16+
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
17+
for j in 1:5
18+
if zp.parents[i, j] != 0
19+
@test zp.parents[i, j] in state.predecessors[j]
20+
end
1921
end
2022
end
21-
end
2223

23-
z = floyd_warshall_shortest_paths(g)
24-
zp = @inferred(Parallel.dijkstra_shortest_paths(g))
25-
@test all(isapprox(z.dists, zp.dists))
24+
z = floyd_warshall_shortest_paths(g)
25+
zp = @inferred(Parallel.dijkstra_shortest_paths(g; parallel))
26+
@test all(isapprox(z.dists, zp.dists))
2627

27-
for i in 1:5
28-
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
29-
for j in 1:5
30-
if zp.parents[i, j] != 0
31-
@test zp.parents[i, j] in state.predecessors[j]
28+
for i in 1:5
29+
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
30+
for j in 1:5
31+
if zp.parents[i, j] != 0
32+
@test zp.parents[i, j] in state.predecessors[j]
33+
end
3234
end
3335
end
34-
end
3536

36-
z = floyd_warshall_shortest_paths(g)
37-
zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2]))
38-
@test all(isapprox(z.dists[1:2, :], zp.dists))
37+
z = floyd_warshall_shortest_paths(g)
38+
zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2]; parallel))
39+
@test all(isapprox(z.dists[1:2, :], zp.dists))
3940

40-
for i in 1:2
41-
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
42-
for j in 1:5
43-
if zp.parents[i, j] != 0
44-
@test zp.parents[i, j] in state.predecessors[j]
41+
for i in 1:2
42+
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
43+
for j in 1:5
44+
if zp.parents[i, j] != 0
45+
@test zp.parents[i, j] in state.predecessors[j]
46+
end
4547
end
4648
end
4749
end
@@ -51,42 +53,44 @@
5153
g3 = path_digraph(5)
5254
d = float([0 1 2 3 4; 5 0 6 7 8; 9 10 0 11 12; 13 14 15 0 16; 17 18 19 20 0])
5355

54-
for g in testdigraphs(g3)
55-
z = floyd_warshall_shortest_paths(g, d)
56-
zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d))
57-
@test all(isapprox(z.dists, zp.dists))
56+
for parallel in [:threads, :distributed]
57+
for g in testdigraphs(g3)
58+
z = floyd_warshall_shortest_paths(g, d)
59+
zp = @inferred(Parallel.dijkstra_shortest_paths(g, collect(1:5), d; parallel))
60+
@test all(isapprox(z.dists, zp.dists))
5861

59-
for i in 1:5
60-
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
61-
for j in 1:5
62-
if z.parents[i, j] != 0
63-
@test zp.parents[i, j] in state.predecessors[j]
62+
for i in 1:5
63+
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
64+
for j in 1:5
65+
if z.parents[i, j] != 0
66+
@test zp.parents[i, j] in state.predecessors[j]
67+
end
6468
end
6569
end
66-
end
6770

68-
z = floyd_warshall_shortest_paths(g)
69-
zp = @inferred(Parallel.dijkstra_shortest_paths(g))
70-
@test all(isapprox(z.dists, zp.dists))
71+
z = floyd_warshall_shortest_paths(g)
72+
zp = @inferred(Parallel.dijkstra_shortest_paths(g; parallel))
73+
@test all(isapprox(z.dists, zp.dists))
7174

72-
for i in 1:5
73-
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
74-
for j in 1:5
75-
if zp.parents[i, j] != 0
76-
@test zp.parents[i, j] in state.predecessors[j]
75+
for i in 1:5
76+
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
77+
for j in 1:5
78+
if zp.parents[i, j] != 0
79+
@test zp.parents[i, j] in state.predecessors[j]
80+
end
7781
end
7882
end
79-
end
8083

81-
z = floyd_warshall_shortest_paths(g)
82-
zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2]))
83-
@test all(isapprox(z.dists[1:2, :], zp.dists))
84+
z = floyd_warshall_shortest_paths(g)
85+
zp = @inferred(Parallel.dijkstra_shortest_paths(g, [1, 2]; parallel))
86+
@test all(isapprox(z.dists[1:2, :], zp.dists))
8487

85-
for i in 1:2
86-
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
87-
for j in 1:5
88-
if zp.parents[i, j] != 0
89-
@test zp.parents[i, j] in state.predecessors[j]
88+
for i in 1:2
89+
state = Graphs.dijkstra_shortest_paths(g, i; allpaths=true)
90+
for j in 1:5
91+
if zp.parents[i, j] != 0
92+
@test zp.parents[i, j] in state.predecessors[j]
93+
end
9094
end
9195
end
9296
end

test/parallel/traversals/greedy_color.jl

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
@testset "Parallel.Greedy Coloring" begin
22
g3 = star_graph(10)
3-
for g in testgraphs(g3)
4-
for op_sort in (true, false)
5-
C = @inferred(Parallel.greedy_color(g, reps=5, sort_degree=op_sort))
6-
@test C.num_colors == 2
3+
for parallel in [:threads, :distributed]
4+
for g in testgraphs(g3)
5+
for op_sort in (true, false)
6+
C = @inferred(
7+
Parallel.greedy_color(g; reps=5, sort_degree=op_sort, parallel)
8+
)
9+
@test C.num_colors == 2
10+
end
711
end
812
end
913

1014
g4 = path_graph(20)
1115
g5 = complete_graph(20)
1216

13-
for graph in [g4, g5]
14-
for g in testgraphs(graph)
15-
for op_sort in (true, false)
16-
C = @inferred(Parallel.greedy_color(g, reps=5, sort_degree=op_sort))
17+
for parallel in [:threads, :distributed]
18+
for graph in [g4, g5]
19+
for g in testgraphs(graph)
20+
for op_sort in (true, false)
21+
C = @inferred(
22+
Parallel.greedy_color(g; reps=5, sort_degree=op_sort, parallel)
23+
)
1724

18-
@test C.num_colors <= maximum(degree(g)) + 1
19-
correct = true
20-
for e in edges(g)
21-
C.colors[src(e)] == C.colors[dst(e)] && (correct = false)
25+
@test C.num_colors <= maximum(degree(g)) + 1
26+
correct = true
27+
for e in edges(g)
28+
C.colors[src(e)] == C.colors[dst(e)] && (correct = false)
29+
end
30+
@test correct
2231
end
23-
@test correct
2432
end
2533
end
2634
end

0 commit comments

Comments
 (0)