1
$\begingroup$

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.

$\endgroup$
0

1 Answer 1

3
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.