Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sparse matrix library for C++ [closed]

Is there any sparse matrix library that can do these:

  • solve linear algebraic equations
  • support operations like matrix-matrix/number multiplication/addition/subtraction,matrix transposition, get a row/column of a matrix,and so on
  • matrix size could be 40k*40k or bigger,like 250k*250k
  • fast
  • can be used in Windows

Can someone recommend some libraries for me? If you recommend, please tell me the advantages and disadvantages of it, and the reason why you recommend it.

By the way,I have searched many sparse matrix libraries on the internet and tested some of them. I found that each of them only supported very few operations(many of them can only solve linear algebraic equations and do matrix-vector multiplication) .Finally I found one named SparseLib++. It didn't support many operations, either.So I added a lot of basic matrix operations. Now it works. However, I just heard that SparseLib++ was too old and not fast. But my project is based on SparseLib++ and I have spent a lot of work on SparseLib++. So I am wondering whether to try another sparse matrix library or not.

like image 946
Li Ming Avatar asked Jun 21 '13 17:06

Li Ming


People also ask

What is sparse matrix in C?

CServer Side ProgrammingProgramming. In a given matrix, when most of the elements are zero then, we call it as sparse matrix. Example − 3 x3 matrix 1 1 0 0 0 2 0 0 0. In this matrix, most of the elements are zero, so it is sparse matrix.

How sparse matrix is stored?

A sparse matrix can be stored in full-matrix storage mode or a packed storage mode. When a sparse matrix is stored in full-matrix storage mode, all its elements, including its zero elements, are stored in an array.

What is the issue with sparse matrices?

The problem with representing these sparse matrices as dense matrices is that memory is required and must be allocated for each 32-bit or even 64-bit zero value in the matrix. This is clearly a waste of memory resources as those zero values do not contain any information.

What is the time complexity of sparse matrix?

The computational complexity of sparse matrix multiplication on AP is shown to be an O(nnz) where nnz is the number of nonzero elements. The AP is found to be especially efficient in binary sparse matrix multiplication. AP outperforms conventional solutions in power efficiency.


3 Answers

http://www.mcs.anl.gov/petsc/ has a lot of built in linear algebra and ca distribute matrices over a cluster when your data gets big. There's also an active following on https://scicomp.stackexchange.com/ when you have technical questions. The downside is that the learning curve is a bit steep.

like image 104
dranxo Avatar answered Nov 30 '22 22:11

dranxo


Can someone recommend some libraries for me?

If you recommend, please tell me the advantages and disadvantages of it, and the reason why you recommend it.

When it comes to large-scale sparse stuff, I personally use the Harwell Subroutine library. It's written in Fortran and it is a pain to interface it with C++. Nevertheless, I use it because it is robust and fast.

like image 32
Ali Avatar answered Nov 30 '22 23:11

Ali


Eigen library has good support for spars matrix manipulation, and the most appealing feature is that its style is like Matlab.

like image 32
kevin Avatar answered Nov 30 '22 23:11

kevin