BSR (Block Compressed Sparse Row) is a sparse matrix storage format that groups nonzeros into fixed-size dense blocks (with zero padding if needed) and stores those blocks in a CSR-like structure. At present AOCL-Sparse only supports square blocks. Each block is of size block_dim, having bM block rows and bN block columns. The elements inside all nonzero blocks are either stored in row-major or column-major order.
The BSR format of a bM x bN block sparse matrix will have bNNZ number of blocks. It uses three arrays as follows:
row_ptr: Array of size
bM+1that contains pointers to the start of each block row in the col_idx and (in strides ofblock_dim * block_dim) val arrays. The last element points to the total number of nonzero blocks.col_idx: Array of size
bNNZcontaining the block column indices of each nonzero blocks.val: Array of size
block_dim * block_dim * bNNZcontaining all the nonzero elements of the matrix stored block by block, padded with zeros to fill the incomplete blocks.
BSR format can either use 0-based indexing or 1-based indexing similar to CSR and CSC formats.
The above diagram shows a BSR matrix of block size 2 x 3 with block_dim = 2 in 0-based indexing.
bM = 2, bN = 3, bNNZ = 4row_ptr[bM + 1] = {0, 1, 4}col_idx[bNNZ] = {1, 0, 1, 2}
Row Major:
val[block_dim * block_dim * bNNZ] = {0, 0, 2.2, 0, 3.0, 3.4, 0, 0, 0, 0, 0, 5.4, 4.2, 0, 6.0, 0}
Column Major:
val[block_dim * block_dim * bNNZ] = {0, 2.2, 0, 0, 3.0, 0, 3.4, 0, 0, 0, 0, 5.4, 4.2, 6.0, 0, 0}
Note
In BSR representation, the actual dimensions of the matrix will have \(bM * block\_dim\) number of rows and \(bN * block\_dim\) number of columns.