This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using SuperLU with Eigen?

Tags: None
(comma "," separated)
Phraides
Registered Member
Posts
7
Karma
0

Using SuperLU with Eigen?

Mon Jan 04, 2010 4:56 pm
Hello everyone,

First of all I would like to say that I am using Eigen for my project and it's a great library, very convenient especially for the SVD solvers :)

I am struggling now to solve a linear problem (Ax=b) using sparse matrices (well only A is sparse, x and b are dense). I have read on the forum that the solution is to use SuperLU since it's not built-in in Eigen.

So here is what I do (I realise that I might do something very dumb, so please tell me if it's the case!), in a very simplified way (I fill a part of A with random values, and b with random values).

Code: Select all
void PoissonBlending::computeTest()
{
   int w = m_foreground.width();
   int h = m_foreground.height();

   // Create x
   VectorXf x(w*h);
   x.setZero();

   // Create b
   VectorXf b(w*h);
   b.setRandom();

   // Create A
   Eigen::SparseMatrix<float> A(w*h,w*h);
   {
      Eigen::RandomSetter<Eigen::SparseMatrix<float>> setter(A);

      // Set random values in A (only a small part, to keep it sparse)
      for(int i=0; i<w*h; ++i)
         setter(std::max(0,std::min(rand(),w*h-1)), std::max(0,std::min(rand(),w*h-1))) = rand();

   }

   A.finalize();

   // Create solver
   Eigen::SparseLU<Eigen::SparseMatrix<float>,Eigen::SuperLU> slu(A);

   if(slu.succeeded())
      std::cout << "SUCCEDED!" << std::endl;
   else
      std::cout << "FAILED!" << std::endl;

   bool ok = slu.solve(b,&x);

   if(ok)
      std::cout << "SUCCEDED!" << std::endl;
   else
      std::cout << "FAILED!" << std::endl;
}


It doesn't work, x is filled with zeros, and the output is:

Code: Select all
SUCCEDED!
FAILED!


So the succeded() method works, but the solve() fails, and I don't know why.

I use the setter since I want later to fill A in a random order. I am using the latest dev version of Eigen, but the problem is the same with the 2.10.

Am I doing anything wrong? Also that might seem stupid but do I have to build anything? I am using Eigen by including the .h in my project, so far it was working perfectly. What about SuperLU? Is there a special thing to do for it to work with Eigen? I tried to build it (I am using VS2008) and add the paths of the .lib and the headers to my project, but it's the same. I don't even have an error when I don't explicitely add SuperLU to my project, is it included in Eigen in some way?

Any idea?
Sorry for the zillion questions!

Cheers!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Using SuperLU with Eigen?

Mon Jan 04, 2010 5:17 pm
First of all you have to #define EIGEN_SUPERLU_SUPPORT before including Eigen. Without that it uses the default implementation which is empty (it even does not set m_succeed to false, that is not nice, I know, though in debug mode it triggers an assert telling you this is not implemented). Again I agree this current state is not ideal, you should get a compilation error, I'll try to improve that (and the doc!).

Then you should get a linkage error if you don't link your stuff to SuperLU.

Finally, you should make sure that you have a at least one non zero per row of your matrix, otherwise the solver will likely complain...
Phraides
Registered Member
Posts
7
Karma
0

Re: Using SuperLU with Eigen?

Tue Jan 05, 2010 11:19 am
Thank you very much for this explanation :)

I tried what you said, and after struggling for several hours to compile SuperLU and BLAS on my windows machine, it works!

Well the setter crashed after setting about 200 000 values, but I will think about a more efficient way to fill the matrix.

BTW, my matrix will eventually be 1000000 x 1000000, filled with about 5*1000000 elements. Do you recommend any particular method to create an d fill the sparse matrix? About the solver, do you think that SuperLU & blas (ATLAS) are fine for that?

Cheers!
kaloter
Registered Member
Posts
6
Karma
0

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 5:10 am
ggael wrote:First of all you have to #define EIGEN_SUPERLU_SUPPORT before including Eigen. Without that it uses the default implementation which is empty (it even does not set m_succeed to false, that is not nice, I know, though in debug mode it triggers an assert telling you this is not implemented). Again I agree this current state is not ideal, you should get a compilation error, I'll try to improve that (and the doc!).

Then you should get a linkage error if you don't link your stuff to SuperLU.

Finally, you should make sure that you have a at least one non zero per row of your matrix, otherwise the solver will likely complain...


I downloaded the Eigen dev branch from this site:https://bitbucket.org/eigen/eigen/get/default.zip and used SuperLU as backend, but there's still a "not implemented" assertion.The SuperLU lib is correctedly compiled and linked. I wonder where did I do wrong?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 7:16 am
Make sure you did not used deprecated stuff:

SuperLU<SparseMatrix<double> > slu;
slu.compute(A);
x = slu.solve(b);

With the default branch you can also use the iterative, built-in BiCGSTAB solver:

#include <Eigen/IterativeSolvers>
BiCGSTAB<SparseMatrix<T>, DiagonalPreconditioner<T> > solver;
// solver.setMaxIterations(....);
// solver.setTolerance(...);
x = solver.compute(A).solve(b);
kaloter
Registered Member
Posts
6
Karma
0

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 7:28 am
ggael wrote:Make sure you did not used deprecated stuff:

SuperLU<SparseMatrix<double> > slu;
slu.compute(A);
x = slu.solve(b);

With the default branch you can also use the iterative, built-in BiCGSTAB solver:

#include <Eigen/IterativeSolvers>
BiCGSTAB<SparseMatrix<T>, DiagonalPreconditioner<T> > solver;
// solver.setMaxIterations(....);
// solver.setTolerance(...);
x = solver.compute(A).solve(b);

Thanks for reply! I didn't use the deprecated stuff you mentioned,the code snippet that I use is as follows,
SparseLU<SparseMatrix<double,RowMajor>,SuperLU<SparseMatrix<double,RowMajor>>> lu(lhs);
I tried to use
SparseLU<SparseMatrix<double,RowMajor>,SuperLU> lu(lhs);as mentioned in the tutorial,but it can't compile correctedly.
I don't know what's wrong and really get stuck here. Hope you could help me. Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 7:51 am
SparseLU is deprecated, use the SuperLU class as mentioned above.
kaloter
Registered Member
Posts
6
Karma
0

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 7:53 am
ggael wrote:SparseLU is deprecated, use the SuperLU class as mentioned above.

Thanks,ggael! I get your idea now :)
kaloter
Registered Member
Posts
6
Karma
0

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 8:23 am
ggael wrote:SparseLU is deprecated, use the SuperLU class as mentioned above.

Hi,ggael. I used the SuperLU as you mentioned above:
Code: Select all
SuperLU<SparseMatrix<double,RowMajor>> slu;
      slu.compute(lhs);
      deltaLamda=slu.solve(rhs);

This time I get linking errors:
"unresolved external symbol _dgssvx"
"unresolved external symbol _Destroy_CompCol_Matrix"
"unresolved external symbol _StatFree"
"unresolved external symbol _Destroy_SuperNode_Matrix"
"unresolved external symbol _set_default_options"
"unresolved external symbol _StatInit"

Is it that I didn't compile SuperLU correctly? Thanks.
kaloter
Registered Member
Posts
6
Karma
0

Re: Using SuperLU with Eigen?

Wed Oct 19, 2011 8:59 am
ggael wrote:SparseLU is deprecated, use the SuperLU class as mentioned above.

I've found the reason, it's problem of the libs that I use. Thanks anyway!
algisd
Registered Member
Posts
1
Karma
0

Re: Using SuperLU with Eigen?

Fri May 17, 2013 1:11 pm
kaloter wrote:
ggael wrote:SparseLU is deprecated, use the SuperLU class as mentioned above.

Hi,ggael. I used the SuperLU as you mentioned above:
Code: Select all
SuperLU<SparseMatrix<double,RowMajor>> slu;
      slu.compute(lhs);
      deltaLamda=slu.solve(rhs);

This time I get linking errors:
"unresolved external symbol _dgssvx"
"unresolved external symbol _Destroy_CompCol_Matrix"
"unresolved external symbol _StatFree"
"unresolved external symbol _Destroy_SuperNode_Matrix"
"unresolved external symbol _set_default_options"
"unresolved external symbol _StatInit"

Is it that I didn't compile SuperLU correctly? Thanks.


How did you manage this problem?


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan, sandyvee