SparseLib++ / IML++ / CG iterative solver : What went wrong

Open discussion regarding features, bugs, issues, vendors, etc.

SparseLib++ / IML++ / CG iterative solver : What went wrong

Hi:

I have program in the following (SparseLib++ and IML++) :

-------------------- BEGIN --------------------
#include <iostream>
#include <stdlib.h>

#include "compcol_double.h"
#include "comprow_double.h"
#include "coord_double.h"
#include "diagpre_double.h"
#include "ilupre_double.h"
#include "icpre_double.h"
#include "iohb_double.h"

#include "cg.h"

using namespace std;

int main()
{

CompCol_Mat_double Acol;
CompRow_Mat_double Arow;

double val = {1,2,-1,5,7,9,-3,1,4};
int r = {0,0,0,1,1,1,2,2,2};
int c = {0,1,2,0,1,2,0,1,2};

Coord_Mat_double A(3, 3, 9, val, r, c);

// Coord_Mat_double A(3,3,9,val,r,c);

cout << "A=\n" << A << "\n";

Acol = A;
cout << "Acol=\n" << Acol << "\n";

// cout << "A[0,0]=" << A(0,0) << "\n";
// A.set(0,2) = 9;
// cout << "A[0,0]=" << A(0,0) << "\n";
// cout << A.dim(0) << "\n";

Acol = A;

double tol = 1.e-6;
int maxit = 150;

int m = Acol.dim(0), n = Acol.dim(1);

VECTOR_double b(n), x(m,0.0);
for (int i = 0; i < n; i++) {
b(i) = i+1;
}

cout << "x = \n" << x << "\n";
cout << "b = \n" << b << "\n";

DiagPreconditioner_double D(Acol);

// cout << "D = \n" << D << "\n";

int result = CG(Acol, x, b, D, maxit, tol);

cout << "--- status = " << result << "\n";
cout << "--- iter = " << maxit << "\n";
cout << "--- tol = " << tol << "\n";
cout << "x = \n" << x << "\n";

}

------------------- END -----------------------

The output result:

-------- BEGIN -------------------
A=
1 1 1.000000000000e+00
1 2 2.000000000000e+00
1 3 -1.000000000000e+00
2 1 5.000000000000e+00
2 2 7.000000000000e+00
2 3 9.000000000000e+00
3 1 -3.000000000000e+00
3 2 1.000000000000e+00
3 3 4.000000000000e+00

Acol=
1 1 1.000000000000e+00
2 1 5.000000000000e+00
3 1 -3.000000000000e+00
1 2 2.000000000000e+00
2 2 7.000000000000e+00
3 2 1.000000000000e+00
1 3 -1.000000000000e+00
2 3 9.000000000000e+00
3 3 4.000000000000e+00

x =
0
0
0

b =
1
2
3

--- status = 1
--- iter = 150
--- tol = 186.071
x =
38.6817
-2.54686
57.1055
---END ------------------------------

The x for Acol * x = b is wrong.

Can someoen kindly point out why?

Thanks

-FongYuan
FongYuan

Posts: 2
Joined: Tue Aug 02, 2005 1:17 am

Hello,

I am not sure this is the good place to ask questions about sparse solvers, IML++ and SparseLib++. This forum is intended for Sca/LAPACK supports.

Just one hint. If CG stands for Conjugate Gradient method, then you have to know that CG works only for symmetric positive definite matrix. Your matrix is not symmetric. CG can not solve your problem. You should try to use a nonsymmetric iterative method (GMRES, QMR,....) when the matrix is nonsymmetric.

Julien
Julien Langou

Posts: 834
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Can LAPACK take sparse matrix representation as inputs ?

Thank you Julien!

Sorry to post Sparse++ question in this forum.

Another question,
can LAPACK take sparse matrix representation as inputs?
I have a sparse matrix about 100,000 * 100,000 but only 10% of it have non zero values.
I doubt it beause the engine is written in Fortran.

Thanks

-TCL
FongYuan

Posts: 2
Joined: Tue Aug 02, 2005 1:17 am

can LAPACK take sparse matrix representation as inputs?

nope, LAPACK supports dense, symmetric dense, symmetric packed and band format of matrix. It does not support sparse matrices.
Julien
Julien Langou

Posts: 834
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA 