Coordinate sparse storage keeps row, column, and value arrays side by side.

Program

Play the program to sum entries from a different sparse row.

target_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
  1. rows ← [1, 2, 2, 3]

    11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]
    values this step[1, 2, 2, 3]rows
  2. cols ← [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]cols
  3. values ← [5, 7, 4, 6]

    12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]14target_row = 2
    values this step[5, 7, 4, 6]values
  4. target_row ← 2

    13values = [5, 7, 4, 6]14target_row = 215count = 0
    values this step2target_row
  5. count ← 0

    14target_row = 215count = 016total = 0
    values this step0count
  6. total ← 0

    15count = 016total = 017do i = 1, 4
    values this step0total
  7. i ← 1

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step1i
  8. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(1) == target_row
  9. i ← 2

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step2i
  10. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.true.rows(2) == target_row
  11. count ← 1

    18if (rows(i) == target_row) then19    count = count + 120    total = total + values(i)
    values this step0 1count
  12. total ← 7

    19    count = count + 120    total = total + values(i)21end if
    values this step0 7total7values(2)
  13. i ← 3

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step3i
  14. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.true.rows(3) == target_row
  15. count ← 2

    18if (rows(i) == target_row) then19    count = count + 120    total = total + values(i)
    values this step1 2count
  16. total ← 11

    19    count = count + 120    total = total + values(i)21end if
    values this step7 11total4values(3)
  17. i ← 4

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step4i
  18. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(4) == target_row
  19. 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_demo
    output2 2 11
    values this step2target_row2count11total
  1. rows ← [1, 2, 2, 3]

    11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]
    values this step[1, 2, 2, 3]rows
  2. cols ← [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]cols
  3. values ← [5, 7, 4, 6]

    12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]14target_row = 1
    values this step[5, 7, 4, 6]values
  4. target_row ← 1

    13values = [5, 7, 4, 6]14target_row = 115count = 0
    values this step1target_row
  5. count ← 0

    14target_row = 115count = 016total = 0
    values this step0count
  6. total ← 0

    15count = 016total = 017do i = 1, 4
    values this step0total
  7. i ← 1

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step1i
  8. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.true.rows(1) == target_row
  9. count ← 1

    18if (rows(i) == target_row) then19    count = count + 120    total = total + values(i)
    values this step0 1count
  10. total ← 5

    19    count = count + 120    total = total + values(i)21end if
    values this step0 5total5values(1)
  11. i ← 2

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step2i
  12. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(2) == target_row
  13. i ← 3

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step3i
  14. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(3) == target_row
  15. i ← 4

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step4i
  16. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(4) == target_row
  17. 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_demo
    output1 1 5
    values this step1target_row1count5total
  1. rows ← [1, 2, 2, 3]

    11rows = [1, 2, 2, 3]12cols = [1, 1, 3, 2]
    values this step[1, 2, 2, 3]rows
  2. cols ← [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]cols
  3. values ← [5, 7, 4, 6]

    12cols = [1, 1, 3, 2]13values = [5, 7, 4, 6]14target_row = 3
    values this step[5, 7, 4, 6]values
  4. target_row ← 3

    13values = [5, 7, 4, 6]14target_row = 315count = 0
    values this step3target_row
  5. count ← 0

    14target_row = 315count = 016total = 0
    values this step0count
  6. total ← 0

    15count = 016total = 017do i = 1, 4
    values this step0total
  7. i ← 1

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step1i
  8. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(1) == target_row
  9. i ← 2

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step2i
  10. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(2) == target_row
  11. i ← 3

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step3i
  12. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.false.rows(3) == target_row
  13. i ← 4

    16total = 017do i = 1, 418    if (rows(i) == target_row) then
    values this step4i
  14. if (rows(i) == target_row) then

    17do i = 1, 418    if (rows(i) == target_row) then19        count = count + 1
    values this step.true.rows(4) == target_row
  15. count ← 1

    18if (rows(i) == target_row) then19    count = count + 120    total = total + values(i)
    values this step0 1count
  16. total ← 6

    19    count = count + 120    total = total + values(i)21end if
    values this step0 6total6values(4)
  17. 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_demo
    output3 1 6
    values 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.