NVIDIA / AMGX

Distributed multigrid linear solver library on GPU
502 stars 143 forks source link

Extract eigenvalues and eigenvectors from AMGX_eigensolver_handle #37

Open maguilo11 opened 6 years ago

maguilo11 commented 6 years ago

Hello, I can't sort how to extract the eigenvalues and eigenvectors from the AMGX_eigensolver_handle. I tried following the eigen_example; however it is not clear how to get this information form the example.

Thank you, Miguel

marsaev commented 6 years ago

Hi maguilo,

Looks like there is not C-API method for grabbing actual values, but you can skip using C-API and use AMGX classes directly.

Our eigensolvers interface is not very user friendly and exists mainly as an auxiliary feature - to get eigenvalues estimates for other algorithms, etc. Unfortunately it's not well documented and what exact eigensolvers do need to be understood from the code. Solvers for eigenvalues and eigenvectors are awkwardly merged into single EigenSolver class, see here: https://github.com/NVIDIA/AMGX/blob/master/base/include/eigensolvers/eigensolver.h This interface has methods get_eigenvalues() and get_eigenvectors() which will return what you want. There is also EigenVectorSolver class, but as you can see in it's implementation (https://github.com/NVIDIA/AMGX/blob/master/base/src/eigensolvers/eigenvector_solver.cu) - it's just a wrapper for EigenSolver functionality. Note that eigenvalues/eigenpairs produced depend on the type and parameters of those solvers.

maguilo11 commented 6 years ago

Hello marsaev,

Thank you for replying to my email.

I am trying to follow your instructions; however, it is not clear to me what to pass as the template parameter type TConfig used in EigenSolver. I tried following your examples and unit tests without any luck. Is it the AMGX_Mode?

Thank you, maguilo

marsaev commented 6 years ago

AMGX Mode is mode of operations for structures and algorithms that controls following parameters 1) memoryspace for data (for data structures) or for execution (for algorithms) 2) matrix precision 3) vector precision 4) index precision

Those are defined in: https://github.com/NVIDIA/AMGX/blob/master/base/include/amgx_config.h For example mode that will perform on device, works on fp64 matrix values, fp64 vector values and int32 index values is defined like:

AMGX_mode_dDDI = AMGX_ASSEMBLE_MODE(AMGX_device, AMGX_vecDouble, AMGX_matDouble, AMGX_indInt), // mode == 8193

In order to map between C-type defines for AMGX mode to C++ style type TConfig we have TemplateMode type In the file https://github.com/NVIDIA/AMGX/blob/master/base/include/basic_types.h So to get template parameter for algorithms for the mode i described above you use:

TemplateMode<AMGX_mode_dDDI>

, or, i.e. for Lanczos_EigenSolver, :

typedef Lanczos_EigenSolver< TemplateMode<AMGX_mode_dDDI>::Type > LanczosSolver;
LanczosSolver mysolver;
mysolver.setup();
...
maguilo11 commented 6 years ago

Thank you for your feedback. I'll give this a try and keep you posted.

Thanks.

maguilo11 commented 6 years ago

Thank you! I was able to figure things out after going carefully through the source code. Here is my solution using amgx::CWrapHandle

const AMGX_Mode tAMGX_Mode = AMGX_mode_dDDI; typedef amgx::AMG_EigenSolver< typename amgx::TemplateMode::Type > SolverLetterT; typedef amgx::CWrapHandle<AMGX_eigensolver_handle, SolverLetterT> SolverW; SolverW tWrapSolver(aEigensolver); SolverLetterT &tMySolver = *tWrapSolver.wrapped();

const size_t tNumEigenvalues = tMySolver.getSolverObject()->get_eigenvalues().size(); for(size_t tIndex = 0; tIndex < tNumEigenvalues; tIndex++) {
tHostEntries[tIndex] = tMySolver.getSolverObject()->get_eigenvalues()[tIndex]; }


Now, my next question is: Which eigensolver do you recommend if I want to extract multiple eigenvalues and eigenvectors? The example that I have working right now uses the following three options: POWER_ITERATION and INVERSE_GMRES. I tried using LANCZOS to get multiple eigen-pairs and it did not worked since it was looking for the MAGMA library.

Any suggestions?

Thank you.

K4liber commented 5 years ago

Hello guys. I try to figure out how to get multiple eigenvalues using your example 'eigen_examples/eigensolver.c'. Can it be done by using specific config file or I have to modify the code? I suppose that this algorithm works like this: starting from random vector and by modifying (through iteration) this vector getting closer to eigenvector? Then i have to start from different random vectors to receive multiple eigenvalues, but this will not give me all of the eigenvalues every time for sure. Is there any info I can read about this eigensolvers algorithms or I have to get this info by reading all the code? Cheers.