# Sparse eigenvalue

32 views

### Klaus Schüller

Mar 1, 2021, 9:15:22 PMMar 1
to MAGMA User
Hello everyone,

I am trying to use magma for finding smallest eigenvalues of large sparse matrices.

I tried to follow conversation about the same on this group but I am not able to get results

Can someone please guide me?
I get floating point exception as error

### Stanimire Tomov

Mar 1, 2021, 10:47:58 PMMar 1
to MAGMA User, shree...@gmail.com

I assume you are trying to use LOBPCG, which is for SPD matrices.
Example on usage is the following tester, in this case finding smallest 8 eigenvalues
for the Trfethen_2000 matrix:
./testing_dsolver --solver LOBPCG --ev 8 test_matrices/Trefethen_2000.mtx
It is possible you didn't set some parameters.
What is the matrix that you are trying and for how many eigenvalues?
We can try to reproduce if the matrix is available.

### Klaus Schüller

Mar 2, 2021, 9:43:11 AMMar 2
to MAGMA User, to...@icl.utk.edu, Klaus Schüller
Yes it is indeed positive definite matrix.

I have attached matrix in csr format.
three files are matrix values, row_num and column_values
matrix is 66x66 matrix with 1002 nonzero values.
This is low dimension matrix I am starting with as I can keep track of nonzero elements for smaller matrix.
If this is not sparse enough I can give larger matrix with dimension ~4000 x 4000.

I am trying to produce smallest three eigenvalues(algebreically).

Also I am using this on cluster where magma is preinstalled.
Thank you.
matrix_values.txt
row_num.txt
column_values.txt

### Klaus Schüller

Mar 3, 2021, 11:46:11 AMMar 3
to MAGMA User, to...@icl.utk.edu
My  code with preconditioners and solver parameters are as follows
magma_init();
magma_dopts dopts;
magma_queue_t queue;
magma_queue_create( 0, &queue );
magma_d_matrix A={Magma_CSR}, dA={Magma_CSR},dx={Magma_CSR};
magma_d_matrix b;
// Pass the system to MAGMA.
magma_dcsrset( dim, dim, csr_row, sparse_column,sparse_values , &A, queue );
// Choose a solver, preconditioner, etc. - see documentation for options.
dopts.solver_par.solver          = Magma_LOBPCG;
dopts.solver_par.num_eigenvalues = 3;
dopts.solver_par.maxiter         = 1000;
dopts.solver_par.rtol            = 1e-8;
dopts.solver_par.ev_length       = dim;

dopts.precond_par.solver         = Magma_ILU;
dopts.precond_par.levels         = 0;
dopts.precond_par.trisolver      = Magma_CUSOLVE;

//initialize solver
magma_dsolverinfo_init( &dopts.solver_par, &dopts.precond_par, queue );
//preconditioner setup
magma_deigensolverinfo_init(&dopts.solver_par,queue);

printf("eigensolver and solver initialized\n");

// Copy the system to the device (optional, only necessary if using the GPU)
magma_dmtransfer( A, &dA, Magma_CPU, Magma_DEV, queue );
printf("transfer completed\n");

After this: I tried two approaches
1:
magma_d_precondsetup( dA, dx, &dopts.solver_par, &dopts.precond_par, queue );

magma_d_solver(dA,b,&dx,&dopts,queue);

This says sparse RHS not supported yet

2:
magma_dlobpcg(dA,&dopts.solver_par, &dopts.precond_par,queue);
printf("%0.16f \n",dopts.solver_par.eigenvalues[0]);
output:
eigenvalues =0 .0000000000000

Please let me know what is wrong here.

### Stanimire Tomov

Mar 3, 2021, 3:06:55 PMMar 3
to Klaus Schüller, MAGMA User, to...@icl.utk.edu
I am trying to load the example matrix in Matlab to check its properties and eigenvalues,
but looks like the non-zeroes provided are only 900. Also, the last element of the rows file is 66.
I guess this should be 1002, right?

### Klaus Schüller

Mar 3, 2021, 9:45:04 PMMar 3
to MAGMA User, to...@icl.utk.edu, MAGMA User, Klaus Schüller
Hello
I thought last element for csr row is dimension of matrix.
I am sorry for matrix problem.

I have attached matrix values as file again.

Thank you

mat_val.csv

### Stanimire Tomov

Mar 4, 2021, 12:39:10 AMMar 4
to Klaus Schüller, MAGMA User, to...@icl.utk.edu
Hello,

I put the matrix in Matrix Market format (attached) and ran it through the magma tester.
I get the correct eigenvalues, or at least they are the same as what matlab gives me, e.g,
here is the output just running on my laptop:

./testing_dsolver --solver LOBPCG --precond ILU --ev 3 ~/Documents/MATLAB/matrix.mtx
% MAGMA 2.5.4 svn 32-bit magma_int_t, 64-bit pointer.
Compiled with CUDA support for 3.0
% CUDA runtime 7000, driver 7050. MAGMA not compiled with OpenMP.
% device 0: GeForce GT 750M, 925.5 MHz clock, 2047.6 MiB memory, capability 3.0
% Thu Mar  4 00:19:41 2021
% Usage: ./testing_dsolver [options] [-h|--help]  matrices

% Reading sparse matrix from file (/Users/tomov/Documents/MATLAB/matrix.mtx): done. Converting to CSR: done.

% matrix info: 66-by-66 with 1002 nonzeros

matrixinfo = [
%   size   (m x n)     ||   nonzeros (nnz)   ||   nnz/m   ||   stored nnz
%============================================================================%
66        66            1002               15              1002
%============================================================================%
];
Eigenvalues:
8.919981e-01  9.313147e+00  9.621497e+00

Final residuals:
[    0.0000   0.0146   0.2200 ];

Residuals are stored in file residualNorms
Plot the residuals using: myplot
convergence = [
%   iter   ||   residual-nrm2    ||   runtime    ||   SpMV-count   ||   info
%=================================================================================%
8       8.748103e-08          0.025119                9            0
%=================================================================================%

%=================================================================================%
% LOBPCG iteration solver summary:
%    initial residual: 9.298386e+01
%    preconditioner setup: 0.0137 sec
%    iterations:    8
%    SpMV-count:    9
%    exact final residual: 3.557550e-09
%    runtime: 0.0251 sec
%    preconditioner runtime: 0.0074 sec
%=================================================================================%
];

solverinfo = [
%   iter   ||   residual-nrm2    ||   runtime    ||   SpMV-count   ||   info
%=================================================================================%
8       8.748103e-08          0.025119                9            0
%=================================================================================%

%=================================================================================%
% LOBPCG iteration solver summary:
%    initial residual: 9.298386e+01
%    preconditioner setup: 0.0137 sec
%    iterations:    8
%    SpMV-count:    9
%    exact final residual: 3.557550e-09
%    runtime: 0.0251 sec
%    preconditioner runtime: 0.0074 sec
%=================================================================================%
];

precondinfo = [
%   setup  runtime
0.013676  0.007447
];

I think you are setting everything correct, as far as I can tell without running the code.
The only thing I don’t see is where do you initialize x. I am looking at our example tester,
and there we initialize x to be random.

Stan

matrix.mtx

### Klaus Schüller

Mar 5, 2021, 12:49:01 PMMar 5
to MAGMA User, to...@icl.utk.edu, MAGMA User, Klaus Schüller
Hello,
Thank you for reply.
So should I always use testing dsolver code then produce eigen values.
I was hoping to use it inside c code where matrix is generated.

Thank you

### Stanimire Tomov

Mar 5, 2021, 1:12:11 PMMar 5
to Klaus Schüller, MAGMA User, to...@icl.utk.edu
Hello,

Preferably you will use it from your code.

I have the tester to rule out possible problems within the magma library or the matrix setup.
Now that magma eigensolver works for this problem, we can also use the tester to compare
and see what is getting set different in your code.

I think the only problem was the initial guess that you don’t provide. We don’t start with initial
guess generated in the LOBPCG solver because some users prefer the option to provide
good initial guess; which can be done in various applications.

Did you try setting a random initial guess to see if that would fix your problem?

Also, now I am thinking that actually another possible problem is the matrix setup - I had fixed the
last value in the row matrix to point to the end of column indexes (before you asked if that value
should be the dimension, but actually it should be the number of non-zeroes, i.e., 1002 in this case).

Stan

### Klaus Schüller

Mar 5, 2021, 2:20:22 PMMar 5
to MAGMA User, to...@icl.utk.edu, MAGMA User, Klaus Schüller
Thank you for reply.
I was able to use testing program to generate eigenvalues.
I added random generated "x" in my code. gave segmentation fault.

Also when try to set tolerance I get following error(for testing code)
./testing_dsolver --solver LOBPCG --ev 3 --atol 0.00000000001 matrix.mtx
% Unable to open file 3   ----this is after -ev 3
Segmentation fault

if I remove ev and keep atol only, error goes to number after atol.

But code did give exactly 3 eigenvalues. I am trying to increase accuracy to double prercision for eigenvalues generated.
Thank you