Skip to content

Commit 8eba943

Browse files
plotting bandedness for 5, 10, 20
1 parent 655c211 commit 8eba943

File tree

1 file changed

+72
-33
lines changed

1 file changed

+72
-33
lines changed

benchmarks/LinearSolve/MatrixDepot.jmd

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,35 @@ cols = [:red, :blue, :green, :magenta, :turqoise] # one color per alg
3030
allmatrices_md = listnames("*/*")
3131

3232
@info "Total number of matrices: $(allmatrices_md.content[1].rows)"
33+
3334
times = fill(NaN, length(allmatrices_md.content[1].rows), length(algs))
3435
percentage_sparsity = fill(NaN, length(allmatrices_md.content[1].rows))
3536
spaced_out_sparsity = fill(NaN, length(allmatrices_md.content[1].rows))
3637
matrix_size = fill(NaN, length(allmatrices_md.content[1].rows))
37-
bandedness = fill(NaN, length(allmatrices_md.content[1].rows))
38+
bandedness_five = fill(NaN, length(allmatrices_md.content[1].rows))
39+
bandedness_ten = fill(NaN, length(allmatrices_md.content[1].rows))
40+
bandedness_twenty = fill(NaN, length(allmatrices_md.content[1].rows))
41+
42+
function compute_bandedness(A, bandwidth)
43+
n = size(A, 1)
44+
total_band_positions = 0
45+
non_zero_in_band = 0
46+
bandwidth = bandwidth
47+
for r in 1:n
48+
for c in 1:n
49+
if abs(r - c) <= bandwidth
50+
total_band_positions += 1 # This position belongs to the band
51+
if A[r, c] != 0
52+
non_zero_in_band += 1 # This element is non-zero in the band
53+
end
54+
end
55+
end
56+
end
57+
58+
percentage_filled = non_zero_in_band / total_band_positions * 100
59+
return percentage_filled
60+
end
61+
3862
```
3963

4064
```julia
@@ -50,18 +74,16 @@ for z in 1:length(allmatrices_md.content[1].rows)
5074
A = convert(SparseMatrixCSC, A)
5175
n = size(A, 1)
5276

53-
5477
mtx_copy = copy(A)
5578

5679
@info "$n × $n"
5780
n > 100 && error("Skipping too large matrices")
5881

59-
82+
## COMPUTING SPACED OUT SPARSITY
6083
rows, cols = size(mtx_copy)
6184
new_rows = div(rows, 2)
6285
new_cols = div(cols, 2)
6386
condensed = zeros(Int, new_rows, new_cols)
64-
6587
while size(mtx_copy, 1) > 32 || size(mtx_copy, 2) > 32
6688

6789
rows, cols = size(mtx_copy)
@@ -74,12 +96,11 @@ for z in 1:length(allmatrices_md.content[1].rows)
7496
block = mtx_copy[r:min(r+1, rows), c:min(c+1, cols)]
7597
condensed[div(r-1, 2) + 1, div(c-1, 2) + 1] = (length(nonzeros(block)) >= 2) ? 1 : 0
7698
end
77-
end
78-
79-
mtx_copy = condensed
80-
99+
end
100+
mtx_copy = condensed
81101
end
82102

103+
## COMPUTING FACTORIZATION TIME
83104
b = rand(rng, n)
84105
u0 = rand(rng, n)
85106

@@ -92,22 +113,13 @@ for z in 1:length(allmatrices_md.content[1].rows)
92113
times[z,j] = bt
93114
end
94115

95-
total_band_positions = 0
96-
non_zero_in_band = 0
97-
bandwidth = 5
98-
for r in 1:n
99-
for c in 1:n
100-
if abs(r - c) <= bandwidth
101-
total_band_positions += 1 # This position belongs to the band
102-
if A[r, c] != 0
103-
non_zero_in_band += 1 # This element is non-zero in the band
104-
end
105-
end
106-
end
107-
end
116+
bandedness_five[z] = compute_bandedness(A, 5)
117+
bandedness_ten[z] = compute_bandedness(A, 10)
118+
bandedness_twenty[z] = compute_bandedness(A, 20)
119+
percentage_sparsity[z] = length(nonzeros(A)) / n^2
120+
spaced_out_sparsity[z] = length(nonzeros(mtx_copy)) * percentage_sparsity[z]
121+
matrix_size[z] = n
108122

109-
percentage_filled = non_zero_in_band / total_band_positions * 100
110-
bandedness[z] = percentage_filled
111123
#=
112124
p = bar(algnames, times[z, :];
113125
ylabel = "Time/s",
@@ -133,6 +145,12 @@ end
133145
percentage_sparsity = percentage_sparsity[.!isnan.(percentage_sparsity)]
134146
spaced_out_sparsity = spaced_out_sparsity[.!isnan.(spaced_out_sparsity)]
135147
spaced_out_sparsity = replace(spaced_out_sparsity, 0 => 1e-10)
148+
bandedness_five = bandedness_five[.!isnan.(bandedness_five)]
149+
bandedness_five = replace(bandedness_five, 0 => 1e-10)
150+
bandedness_ten = bandedness_ten[.!isnan.(bandedness_ten)]
151+
bandedness_ten = replace(bandedness_ten, 0 => 1e-10)
152+
bandedness_twenty = bandedness_twenty[.!isnan.(bandedness_twenty)]
153+
bandedness_twenty = replace(bandedness_twenty, 0 => 1e-10)
136154
matrix_size = matrix_size[.!isnan.(matrix_size)]
137155
nanrows = any(isnan, times; dims=2)
138156
times = times[.!vec(nanrows), :]
@@ -161,41 +179,62 @@ p = scatter(percentage_sparsity, times;
161179
```
162180

163181
```julia
164-
p = scatter(bandedness, times;
182+
p = scatter(matrix_size, times;
165183
ylabel = "Time/s",
166184
yscale = :log10,
167-
xlabel = "Bandedness",
185+
xlabel = "Matrix Size",
168186
xscale = :log10,
169187
label = algnames_transpose,
170-
title = "Factorization Time vs Bandedness",
188+
title = "Factorization Time vs Matrix Size",
171189
fmt = :png,
172190
legend = :outertopright)
173191
```
174192

175193
```julia
176-
p = scatter(matrix_size, times;
194+
p = scatter(spaced_out_sparsity, times;
177195
ylabel = "Time/s",
178196
yscale = :log10,
179-
xlabel = "Matrix Size",
197+
xlabel = "Spaced Out Sparsity",
180198
xscale = :log10,
181199
label = algnames_transpose,
182-
title = "Factorization Time vs Matrix Size",
200+
title = "Factorization Time vs Spaced Out Sparsity",
183201
fmt = :png,
184202
legend = :outertopright)
185203
```
186204

187205
```julia
188-
p = scatter(spaced_out_sparsity, times;
206+
p = scatter(bandedness_five, times;
189207
ylabel = "Time/s",
190208
yscale = :log10,
191-
xlabel = "Spaced Out Sparsity",
209+
xlabel = "Bandedness",
192210
xscale = :log10,
193211
label = algnames_transpose,
194-
title = "Factorization Time vs Spaced Out Sparsity",
212+
title = "Factorization Time vs Bandedness, Bandwidth=5",
213+
fmt = :png,
214+
legend = :outertopright)
215+
```
216+
```julia
217+
p = scatter(bandedness_ten, times;
218+
ylabel = "Time/s",
219+
yscale = :log10,
220+
xlabel = "Bandedness",
221+
xscale = :log10,
222+
label = algnames_transpose,
223+
title = "Factorization Time vs Bandedness, Bandwidth=10",
224+
fmt = :png,
225+
legend = :outertopright)
226+
```
227+
```julia
228+
p = scatter(bandedness_twenty, times;
229+
ylabel = "Time/s",
230+
yscale = :log10,
231+
xlabel = "Bandedness",
232+
xscale = :log10,
233+
label = algnames_transpose,
234+
title = "Factorization Time vs Bandedness, Bandwidth=20",
195235
fmt = :png,
196236
legend = :outertopright)
197237
```
198-
199238

200239
## Appendix
201240

0 commit comments

Comments
 (0)