# Fastest way to diagonalize square matrices with c++

I am currently writing software in c++ which solves the eigenvalue problem of sparse hermitian matrices. The size of the matrix depends on the user input, but as an estimation it will roughly be 1000x1000. I will have to solve about 300 (again relies on the user input) of them for different initial conditions. What is the fastest way to do it? More specifically, I would like to know if it makes sense to do the calculations on the GPU or would it be faster to do it on the CPU and use openMP for the 300 initial conditions? What c++ library would you suggest to use and why (maybe one has some easy build-in support for GPU)? Currently I am using eigen3 for dense matrices.

• Do you want all the eigenvalues? If not, just a few percent or most of them? Do you want the corresponding eigenvectors as well? Jan 18 '16 at 12:17
• I want just a few eigenvalues and the corresponding eigenvectors. But I need to specify what eigenvalues to take, e.g. the first few >0 and the first few <0. Jan 18 '16 at 13:49
• For dense matrices, LAPACK will be fastest regardless of how many eigenvalues you need (because that's not the bottleneck). These matrices are likely not large enough to offload to GPU if your CPU doesn't suck. For sparse, it's even less likely that offload pays off, unless your Krylov method needs a huge number of matrix-vector products and these run much faster on the GPU than the CPU. Jan 19 '16 at 6:56
• @Jeff In the end I have sparse matrices. I only mentioned dense matrices to state that I am familiar with eigen3. In the case there is a way to use eigen for this... But you basically say do not use GPU for a sparse matrix of size 1e3x1e3. Is there a way to state some kind of border size? How big must a sparse matrix be so that it is beneficial to put it on a GPU? Jan 20 '16 at 8:43