Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MATLAB's EIGS vs PRIMME_EIGS #35

Open
Mbakhov opened this issue Jul 28, 2020 · 10 comments
Open

MATLAB's EIGS vs PRIMME_EIGS #35

Mbakhov opened this issue Jul 28, 2020 · 10 comments

Comments

@Mbakhov
Copy link

Mbakhov commented Jul 28, 2020

Dear developers,

I'm planning to use PRIMME to calculate 10 interior eigenvalues and eigenvectors of large sparse matrices (~ 810^5 x 810^5) in Matlab. However, I found that PRIMME is ~ 15 times slower in moderately small matrices ( 3K x 3K) with respect to standard eigs function; Eigs is performing the task in ~ 0.05 sec, while for GD_Olsen_plusK it takes 14 seconds (in 8 cores, 3Ghz each).

So, is it possible to speed up the calculation process?

load H.mat;

[~,Emin]=eigs(H,1,'sa');   
[~,Emax]=eigs(H,1,'la');

 e=(Emax-Emin)/2+Emin;
 
tic
  opts = struct();
D = primme_eigs(H,10,e,opts,'JD_Olsen_plusK' );  
toc
%%
tic
[XX EE]=eigs(H,10,e);
toc

Thank you,

Best regards,

Murod

@Mbakhov
Copy link
Author

Mbakhov commented Jul 28, 2020

H.zip

@stathopoulos
Copy link
Collaborator

stathopoulos commented Jul 28, 2020 via email

@eromero-vlc
Copy link
Collaborator

Thanks for providing a matrix, that always helps! As Andreas said, eigs relays on doing the LU factorization of (H-e*eye(size(H))). For cases where finding interior eigenvalues takes many iterations, doing LU and using eigs may be the fastest choice if you can afford to do the factorization.

I played a little bit with the matrix that you provided. It seems that using refined extraction helps. Also, for many applications, it is sufficient to set the accuracy of the solver to 3-4 order of magnitudes below the average distance of the target eigenvalues. For H, the minimum distance between nearby eigenvalues is 1e-4 around e, and the norm of H is around 8.4, so a tol=avg_eig_dist/norm(H)*1e-3=1e-8 should be ok.

l=primme_eigs(H,10,e,struct('projection','primme_proj_refined','tol',1e-8),'DEFAULT_MIN_TIME')

@Mbakhov
Copy link
Author

Mbakhov commented Jul 28, 2020

Dear Andreas,

Thanks for your quick respond.

I understood the point.

The matrices which I consider are real, hermitian and sparse. The dimension is very large ~ 850 000 x 850 000. Please, find the link to the example matrix.

I need :
10-20 eigenvalues and eigenvectors from the mid-spectrum.

So, my question is what would be the expected cpu memory requirements and number of cores to solve the problem in a reasonable timescale ? and whether it is practical to use PRIMME for such large matrices?

Thank you,

Best regards,

Murod

@Mbakhov
Copy link
Author

Mbakhov commented Jul 28, 2020

Thanks for providing a matrix, that always helps! As Andreas said, eigs relays on doing the LU factorization of (H-e*eye(size(H))). For cases where finding interior eigenvalues takes many iterations, doing LU and using eigs may be the fastest choice if you can afford to do the factorization.

I played a little bit with the matrix that you provided. It seems that using refined extraction helps. Also, for many applications, it is sufficient to set the accuracy of the solver to 3-4 order of magnitudes below the average distance of the target eigenvalues. For H, the minimum distance between nearby eigenvalues is 1e-4 around e, and the norm of H is around 8.4, so a tol=avg_eig_dist/norm(H)*1e-3=1e-8 should be ok.

l=primme_eigs(H,10,e,struct('projection','primme_proj_refined','tol',1e-8),'DEFAULT_MIN_TIME')

Thank you!
Indeed, it helps. However, as I addressed in the previous post, it will take enormous time to perform the same for the matrix of ~ 850 000 x 850 000.

Best regards,

Murod

@stathopoulos
Copy link
Collaborator

stathopoulos commented Jul 28, 2020 via email

@tanlin2013
Copy link

tanlin2013 commented Sep 14, 2021

Hi,

A related question concerning about extracting interior eigenvalues and eigenvectors from a large (Hermition) matrix. I found a rather old paper about this kind of problem. But as an end user, I'm not really certain the efficiency between this modified Rayleigh-Ritz method and Jacobi-Davison-like algorithms. The number of interrior eigenpairs I need is in general around few hundreds, while the size of matrix is about (10^7 * 10^7) also.

I'm still on early planing to see whether this problem is feasible with numerical methods. Hopefully there're some answers in this kind of problem already. Thanks!

best,
Tan

@stathopoulos
Copy link
Collaborator

stathopoulos commented Sep 14, 2021 via email

@tanlin2013
Copy link

Thank you Andreas! I will give it a try.

Then how exactly I could switch to Rayleigh-Ritz in PRIMME? I do find it in the documentation. But if there some some examples that will be helpful. Thanks!

p.s. I'm using python actually.

Best,
Tan

@eromero-vlc
Copy link
Collaborator

eromero-vlc commented Sep 16, 2021

PRIMME by default uses Rayleigh-Ritz. You can change the extraction method with the option projection_projection. The documentation of the option is here as you pointed out. Refined and harmonic only works when finding the eigenvalues closest to a target, which is passed in the option which. These are some examples:

>>> # Rayleigh-Ritz extraction (default)
>>> evals, evecs,stats = primme.eigsh(A, 3, tol=1e-6, which=50.1, projection_projection='primme_proj_RR', return_stats=True); stats['numMatvecs']
212
>>> # Refine extraction
>>> evals, evecs,stats = primme.eigsh(A, 3, tol=1e-6, which=50.1, projection_projection='primme_proj_refined', return_stats=True); stats['numMatvecs']
235
>>> # Harmonic-Ritz extraction
>>> evals, evecs,stats = primme.eigsh(A, 3, tol=1e-6, which=50.1, projection_projection='primme_proj_harmonic', return_stats=True); stats['numMatvecs']
191

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants