1

It seems common practice to store only the upper or lower triangular part of a sparse symmetric matrix to save memory. Now I am wondering how, e.g. the SpMV kernel in CSR format is designed and how the matrix elements are accessed which are not stored explicitly when only the upper triangular part is given (typical matrix market cases).
The basic CSR SpMV kernel is defined as:

for each row i
  for k=ptr[i] to ptr[i+1] do
    y[i] = y[i] + val[k]*x[ind[k]]

Where ptr defines the row pointer, ind defines the column index, val defines the value and y defines the vector.

Wolfgang Bangerth
  • 55,373
  • 59
  • 119
vydesaster
  • 840
  • 4
  • 11

1 Answers1

3

The important part is that if the matrix stores an entry $(i,j)$ then there is also the entry $(j,i)$. Furthermore, if $i\neq j$, then these two are separate.

As a consequence, the kernel should log as follows:

for each row i
  for k=ptr[i] to ptr[i+1] do
    y[i] = y[i] + val[k]*x[ind[k]]
    if (i != ind[k])
      y[ind[k]] = y[ind[k]] + val[k]*x[i]
Wolfgang Bangerth
  • 55,373
  • 59
  • 119