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[12] = {1,2,-1,5,7,9,-3,1,4};

int r[12] = {0,0,0,1,1,1,2,2,2};

int c[12] = {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