Sparse Data Patterns
Coordinate Row Sum
Grouping Sparse Entries
Coordinate sparse storage keeps row, column, and value arrays side by side.
Program
Play the program to sum entries from a different sparse row.
coordinate_row_sum.f90
Replay: real traced execution (multi-file project)
program coordinate_row_sum_demo
implicit none
integer :: rows(4)
integer :: cols(4)
integer :: values(4)
integer :: target_row
integer :: i
integer :: count
integer :: total
rows = [1, 2, 2, 3]
cols = [1, 1, 3, 2]
values = [5, 7, 4, 6]
target_row = 2
count = 0
total = 0
do i = 1, 4
if (rows(i) == target_row) then
count = count + 1
total = total + values(i)
end if
end do
print '(I0, 1X, I0, 1X, I0)', target_row, count, total
end program coordinate_row_sum_demo
program coordinate_row_sum_demo
implicit none
integer :: rows(4)
integer :: cols(4)
integer :: values(4)
integer :: target_row
integer :: i
integer :: count
integer :: total
rows = [1, 2, 2, 3]
cols = [1, 1, 3, 2]
values = [5, 7, 4, 6]
target_row = 1
count = 0
total = 0
do i = 1, 4
if (rows(i) == target_row) then
count = count + 1
total = total + values(i)
end if
end do
print '(I0, 1X, I0, 1X, I0)', target_row, count, total
end program coordinate_row_sum_demo
program coordinate_row_sum_demo
implicit none
integer :: rows(4)
integer :: cols(4)
integer :: values(4)
integer :: target_row
integer :: i
integer :: count
integer :: total
rows = [1, 2, 2, 3]
cols = [1, 1, 3, 2]
values = [5, 7, 4, 6]
target_row = 3
count = 0
total = 0
do i = 1, 4
if (rows(i) == target_row) then
count = count + 1
total = total + values(i)
end if
end do
print '(I0, 1X, I0, 1X, I0)', target_row, count, total
end program coordinate_row_sum_demo
rows ← [1, 2, 2, 3]
11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]values this step[1, 2, 2, 3]rowscols ← [1, 1, 3, 2]
11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]values this step[1, 1, 3, 2]colsvalues ← [5, 7, 4, 6]
12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]14target_row = 2values this step[5, 7, 4, 6]valuestarget_row ← 2
13values = [5, 7, 4, 6]14target_row = 215count = 0values this step2target_rowcount ← 0
14target_row = 215count = 016total = 0values this step0counttotal ← 0
15count = 016total = 017do i = 1, 4values this step0totali ← 1
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step1iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(1) == target_rowi ← 2
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step2iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.true.rows(2) == target_rowcount ← 1
18if (rows(i) == target_row) then19 count = count + 120 total = total + values(i)values this step0 → 1counttotal ← 7
19 count = count + 120 total = total + values(i)21end ifvalues this step0 → 7total7values(2)i ← 3
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step3iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.true.rows(3) == target_rowcount ← 2
18if (rows(i) == target_row) then19 count = count + 120 total = total + values(i)values this step1 → 2counttotal ← 11
19 count = count + 120 total = total + values(i)21end ifvalues this step7 → 11total4values(3)i ← 4
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step4iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(4) == target_rowprint '(I0, 1X, I0, 1X, I0)', target_row, count, total
22 end do23 print '(I0, 1X, I0, 1X, I0)', target_row, count, total24end program coordinate_row_sum_demooutput2 2 11values this step2target_row2count11total
rows ← [1, 2, 2, 3]
11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]values this step[1, 2, 2, 3]rowscols ← [1, 1, 3, 2]
11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]values this step[1, 1, 3, 2]colsvalues ← [5, 7, 4, 6]
12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]14target_row = 1values this step[5, 7, 4, 6]valuestarget_row ← 1
13values = [5, 7, 4, 6]14target_row = 115count = 0values this step1target_rowcount ← 0
14target_row = 115count = 016total = 0values this step0counttotal ← 0
15count = 016total = 017do i = 1, 4values this step0totali ← 1
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step1iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.true.rows(1) == target_rowcount ← 1
18if (rows(i) == target_row) then19 count = count + 120 total = total + values(i)values this step0 → 1counttotal ← 5
19 count = count + 120 total = total + values(i)21end ifvalues this step0 → 5total5values(1)i ← 2
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step2iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(2) == target_rowi ← 3
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step3iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(3) == target_rowi ← 4
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step4iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(4) == target_rowprint '(I0, 1X, I0, 1X, I0)', target_row, count, total
22 end do23 print '(I0, 1X, I0, 1X, I0)', target_row, count, total24end program coordinate_row_sum_demooutput1 1 5values this step1target_row1count5total
rows ← [1, 2, 2, 3]
11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]values this step[1, 2, 2, 3]rowscols ← [1, 1, 3, 2]
11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]values this step[1, 1, 3, 2]colsvalues ← [5, 7, 4, 6]
12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]14target_row = 3values this step[5, 7, 4, 6]valuestarget_row ← 3
13values = [5, 7, 4, 6]14target_row = 315count = 0values this step3target_rowcount ← 0
14target_row = 315count = 016total = 0values this step0counttotal ← 0
15count = 016total = 017do i = 1, 4values this step0totali ← 1
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step1iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(1) == target_rowi ← 2
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step2iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(2) == target_rowi ← 3
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step3iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.false.rows(3) == target_rowi ← 4
16total = 017do i = 1, 418 if (rows(i) == target_row) thenvalues this step4iif (rows(i) == target_row) then
17do i = 1, 418 if (rows(i) == target_row) then19 count = count + 1values this step.true.rows(4) == target_rowcount ← 1
18if (rows(i) == target_row) then19 count = count + 120 total = total + values(i)values this step0 → 1counttotal ← 6
19 count = count + 120 total = total + values(i)21end ifvalues this step0 → 6total6values(4)print '(I0, 1X, I0, 1X, I0)', target_row, count, total
22 end do23 print '(I0, 1X, I0, 1X, I0)', target_row, count, total24end program coordinate_row_sum_demooutput3 1 6values this step3target_row1count6total
coordinate arrays
`rows`, `cols`, and `values` describe each stored entry.
row filter
Only entries whose row matches `target_row` contribute to the summary.
sparse row total
`count` and `total` describe the selected sparse row.