Must the Block in MKL sparse BSR format be Square? - sparse-matrix

I am new to the MKL sparse blas, and want to use BSR as my sparse matrix format.
I notice that the block_size is specified by an integer. Does this mean the block must be a square matrix?
Is there a way to specify a non-square block in BSR?
Best,
Zhihao

Related

GSL sparse matrix eigensystems

Does the Gnu Scientific Library (GSL) support finding eigenvectors/values of a sparse matrix (complex or otherwise) directly?
The C library GSL supports sparse matrices (highly compressed matrices, used for whenever you have a matrix which is mostly 0), example a complex matrix:
gsl_spmatrix_complex* H_sparse = gsl_spmatrix_complex_alloc (N_states, N_states);
And GSL has operations for finding eigenvalues/eigenvectors of a dense (not sparse) matrix, so this for instance works if I inflate the matrix H beforehand (skipping any allocations/freeing of workspace, vectors, matrices etc.):
gsl_spmatrix_complex_sp2d(H_dense, H_sparse);
/*...Allocate workspace w, dense matrix evec for eigenvectors, and vector eval for eigenvalues*/
gsl_eigen_hermv(H_dense, eval,evec , w);//hermv = hermitan complex matrix, and get vectors
gsl_eigen_hermv_sort ( eval,evec,GSL_EIGEN_SORT_VAL_ASC);
Inflating the sparse matrix before doing the one operation I need to do largely defeats the purpose of having a sparse matrix in the first place.
But I can't find functions for getting the eigenvalues and eigenvectors of a sparse matrix directly. I have tried looking through the header files gsl_eigen.h, gsl_splinalg.h, and gsl_spmatrix.h and the manuals, but I can't seem to find the functions I am looking for.
So does GSL support finding eigenvectors/values of a sparse matrix directly?

How save memory for a solving a symmetric (or upper traingular) matrix?

I need to solve system of linear algebraic equations A.X = B
The matrix A is double precision with about size of 33000x33000 and I will get an error when I try to allocate it:
Cannot allocate array - overflow on array size calculation.
Since I am using LAPACK dposv with the Intel MKL library, I was wondering if there is a way to somehow pass an smaller matrix to the library function? (because only half of the matrix arrays are needed to solve)
The dposv function only needs an upper or lower triangular matrix for A. Here is more details about dposv.
Update: Please notice that the A matrix is N x N and yet it takes lda: INTEGER as The leading dimension of a; lda ≥ max(1, n). So may be there is a way to parse A as an 1D array?
As the error says (Cannot allocate array - overflow on array size calculation) Your problem seems to be somewhere else: especially the limit of the integer type used to compute the array size internally. And I am afraid that you might not be able to solve that even if you add more memory. You will need to check the internals of the library that your are using for memory management (Possibly MKL, but I don't use MKL so I can not help) or choose another one.
Explanation, some functions use 4 bytes integer to compute the memory size when allocating. That gives you a limit of 2^32 or 4 Gbytes of memory that you can allocate wich is way lower than your 8 Gbytes array. In that I am assuming unsigned integer; with signed integer, that limit is 2 Gbytes.
Hints if you have limited memory:
If you do not have enough memory (about 4 Gbytes for the matrix alone since it is triangular) and you do not know the structure of the matrix, then forget about special solvers and solve your problem yourself. Solving a system with an upper triangular matrix is a backward substitution. Starting with the last row of the solution, you need only one row of the matrix to compute each component of the solution.
Find a way to load your matrix row by row starting with the last row.
Thanks to mecej4
There are several options to pass a huge matrix using less memory:
Using functions that support Matrix Storage Schemes e.g. ?pbsv
Using PARDISO

Will intel mkl sparse BLAS coogemv internally change coo to csr storage?

There is sparse version of BLAS in intel MKL, for example doing multiplication of matrix and vector, we could use
mkl_?coogemv
Computes matrix-vector product of a sparse general matrix stored in
the coordinate format with one-based indexing
But I heard that multiplication is much more efficient when doing in CSR storage.
However to generate CSR storage sparse matrix is a headache, it is much easy and understandable to generate a COO storage sparse matrix.
What I want to know is that: Will MKL change the COO storage to CSR storage internally when using coogemv? The documentation didn't say.

Sparse matrix-matrix multiplication

I'm currently working with sparse matrices, and I have to compare the computation time of sparse matrix-matrix multiplication with full matrix-matrix multiplication. The issue is that sparse matrix computation is waaaaay slower than full matrix computation.
I'm compressing my matrices with the Compressed Row Storage, and multiplicating 2 matrices is very time consuming (quadruple for loop), so I'm wondering if there is a better compression format more suitable for matrix-matrix operation (CRS is very handy with matrix-vector computation).
Thanks in advance!
It's usually referred to as "Compressed Sparse Rows" (CSR), not CRS. The transpose, Compressed Sparse Columns (CSC) is also commonly used, including by the CSparse package that ends up being the backend of quite a lot of systems including MatLAB and SciPy (I think).
There is also a less-common Doubly-Compressed Sparse Columns (DCSC) format used by the Combinatorial BLAS. It compresses the column index again, and is useful for cases where the matrix is hypersparse. A hypersparse matrix has most columns empty, something that happens with 2D matrix decomposition.
That said, yes there is more overhead. However your operations are now dominated by the number of nonzeros, not the dimensions. So your FLOPS might be less but you still get your answer quicker.
You might look at the paper EFFICIENT SPARSE MATRIX-MATRIX PRODUCTS USING COLORINGS http://www.mcs.anl.gov/papers/P5007-0813_1.pdf for a discussion of how to achieve high performance with sparse matrix matrix products.

Eigen Sparse Matrix

I am trying to multiply two large sparse matrices of size 300k * 1000k and 1000k*300k using Eigen. The matrices are highly sparse ~0.01% non zero entries, however there's no block or other structure in their sparsity.
It turns out that Eigen chokes and ends up taking 55-60G of memory. Actually, it makes the final matrix dense which explains why it takes so much memory.
I have tried multiplying matrices of similar sizes when one of the matrix is diagonal and the multiplication works fine, with ~2-3 G of memory.
Any thoughts on whats going wrong?
Even though your matrices are sparse, the result might be completely dense. You can try to remove smallest entries with (A*B).prune(ref,eps); where ref is a reference value for what is not a zero and eps is a tolerance value. Basically, all entries smaller than ref*eps will be removed during the computation of the product, thus reducing both the memory usage and size of the result. A better option would be to find a way to avoid performing this product.

Resources