Compressed Row Storage

The compressed row and column (in the next section) storage formats are the most general: they make absolutely no assumptions about the sparsity structure of the matrix, and they don't store any unnecessary elements. On the other hand, they are not very efficient, needing an indirect addressing step for every single scalar operation in a matrix-vector product or preconditioner solve.

The compressed row storage (CRS) format puts the subsequent nonzeros of the matrix rows in contiguous memory locations. Assuming we have a nonsymmetric sparse matrix $A$, we create three vectors: one for floating point numbers (val) and the other two for integers (col_indrow_ptr). The val vector stores the values of the nonzero elements of the matrix $A$ as they are traversed in a row-wise fashion. The col_ind vector stores the column indexes of the elements in the val vector. That is, if ${\tt val(k)}=a_{i,j}$, then${\tt col\_ind(k)}=j$. The row_ptr vector stores the locations in the val vector that start a row; that is, if ${\tt val(k)}=a_{i,j}$, then${\tt row\_ptr(i)}\leq k<{\tt row\_ptr(i+1)}$. By convention, we define ${\tt row\_ptr(n+1)} = nnz+1$, where $nnz$ is the number of nonzeros in the matrix $A$. The storage savings for this approach is significant. Instead of storing $n^2$ elements, we need only $2nnz+n+1$storage locations.

As an example, consider the nonsymmetric matrix $A$ defined by 

\begin{displaymath}A =\left[\begin{array}{rrrrrr}10 & 0 & 0 & 0 &-2 & 0 \\...... 9 & 9 & 13 \\0 & 4 & 0 & 0 & 2 & -1\end{array}\right] ~.\end{displaymath}(269)

The CRS format for this matrix is then specified by the arrays {valcol_indrow_ptr} given below:

val10-2393787$\cdots$ 91342-1  
col_ind15126234$\cdots$ 56256  


row_ptr1369131720

If the matrix  $A$  is symmetric, we need only store the upper (or lower) triangular portion of the matrix. The tradeoff is a more complicated algorithm with a somewhat different pattern of data access.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值