Ryan
Ryan

Reputation: 21

Conjugate gradient with incomplete cholesky preconditioner returns unexpected errors for the Eigen library

I am new to stack overflow, so posting a question for the first time. I am aiming to solve the linear equation Ax =b using the conjugate gradient technique with an incomplete cholesky preconditioner, leveraging the Eigen library. So what I am basically looking at is the ICCG algorithm. The Eigen library as I understand allows integration of the preconditioner to the conjugate gradient solver. I have a simple dummy code which fails to execute.

#include <iostream>
#include <Eigen>
using namespace std;
int main()
{
    int n = 10;
    SparseMatrix<double> A = MatrixXd::Random(n,n).sparseView(0.5,1);
    VectorXd b(n),x(n);
    /* Eigen::ConjugateGradient<SparseMatrix<double>, Eigen::Lower|Eigen::Upper, IdentityPreconditioner> cg;  */
    Eigen::ConjugateGradient<SparseMatrix<double>, Eigen::Lower, IncompleteCholesky> cg;
    cg.compute(A);
    x = cg.solve(b);
    x = cg.solve(b);
    return 0;
}

On compilation with g++ with maximum optimization (-O3) the following error gets thrown:

../PracTemplates.cpp:62:94: error: type/value mismatch at argument 3 in template parameter list for 'template<class _MatrixType, int _UpLo, class _Preconditioner> class Eigen::ConjugateGradient'

I also get errors related to .compute() and .solve() but I believe those are related to the issue with the above mentioned error.

The conjugate gradient technique however works with the Identity Preconditioner.

Judging by the error I am clearly missing something from object declaration. Any help will be greatly appreciated. Thanks.

PS: I am using Eclipse IDE, so all I have done is included the path to my eigen library "D:\C++ Development\Eigen" in the "Paths and Symbols" tab.

Compilation Commands:

g++ -I$PATH -O3 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"PracTemplates.d" -MT"PracTemplates.o" -o "PracTemplates.o" "../PracTemplates.cpp"

where "PracTemplates.cpp is the name of my file and $PATH is my path to the eigen library as specified above.

Upvotes: 2

Views: 1940

Answers (1)

ggael
ggael

Reputation: 29205

IncompleteCholesky is a template class with 3 template parameters. The last two are optionals, but you need to specify to the first one, which is the scalar type:

typedef ConjugateGradient<SparseMatrix<double>,Lower, IncompleteCholesky<double> > ICCG;

Upvotes: 4

Related Questions