help:taucs_linsolve failed when I tempt to use the factorization!

112 views
Skip to first unread message

dhw

unread,
Dec 16, 2008, 12:22:20 PM12/16/08
to matrixprogramming
If I use the code
int rc= taucs_linsolve(pAtA,NULL,3,X,B,options,NULL);
it success!

But when I want to reuse the factorization for several solve linear
systems with same left side following the guide in the taucs manual,It
failed. The code is as following:
int rc = taucs_linsolve(pAtA,&F,
0,NULL,NULL,options_factor,NULL); //factor
rc= taucs_linsolve(pAtA,&F,3,X,B,NULL,NULL); //solve

The first line works okay,but the second line failed with a return code
( rc = -1). I don't know what's the problem?
Who can tell me the reason?
Thanks,

Evgenii Rudnyi

unread,
Dec 16, 2008, 4:06:10 PM12/16/08
to matrixpr...@googlegroups.com

Could you please make a sample code and upload it with the matrix to
Files of this group?

dhw

unread,
Dec 17, 2008, 10:56:03 AM12/17/08
to matrixprogramming
I test taucs using the code in a message in this group
"[matrixprogramming] Re: Problem running TAUCS in Microsoft Visual C++
6.0".
The code failed when execute the line "i = taucs_linsolve(&A,&F,1, x,
b, NULL,NULL); //solve" .The code is as following :

void taucs_test(){
vector<double> an(10);
vector<int> jn(10);
vector<int> ia(10);
vector<double> f(10); // right-hand size vector object

// create CCS matrix structure using vector class
an[0] = 1.0;
an[1] = 0.5;
an[2] = 1.0;
an[3] = 0.5;
an[4] = 1.0;
an[5] = 0.5;
an[6] = 1.0;

jn[0] = 0;
jn[1] = 1;
jn[2] = 1;
jn[3] = 2;
jn[4] = 2;
jn[5] = 3;
jn[6] = 3;

ia[0] = 0;
ia[1] = 2;
ia[2] = 4;
ia[3] = 6;
ia[4] = 7;

// create right-hand size vector object
f[0] = 1.0;
f[1] = 2.0;
f[2] = 3.0;
f[3] = 4.0;

// resize vectors.
an.resize(7);
jn.resize(7);
ia.resize(5);
f.resize(4);

// create TAUCS matrix from vector objects an, jn and ia
taucs_ccs_matrix A; // a matrix to solve Ax=b in CCS format
A.n = ia.size() - 1;
A.m = ia.size() - 1;
A.flags = (TAUCS_DOUBLE | TAUCS_SYMMETRIC | TAUCS_LOWER);
A.colptr = &ia[0];
A.rowind = &jn[0];
A.values.d = &an[0];

// create TAUCS right-hand size
taucs_double* b = &f[0]; // right hand side vector to solve Ax=b

// allocate TAUCS solution vector
taucs_double* x = new taucs_double[f.size()]; // the unknown vector
to solve Ax=b

// solve the linear system
void* F = NULL;
char* options[] = {"taucs.factor.LLT=true", NULL};
void* opt_arg[] = { NULL };

// int i = taucs_linsolve(&A, &F, 1, x, b, options, opt_arg);

int i = taucs_linsolve(&A,&F,0,NULL,NULL,options,NULL); //factor
i = taucs_linsolve(&A,&F,1, x, b, NULL,NULL); //solve
i = taucs_linsolve(NULL,&F,0,NULL,NULL,NULL,NULL); //free the
factorization

if (i != TAUCS_SUCCESS)
{
cout << "Solution error." << endl;
if (i==TAUCS_ERROR)
cout << "Generic error." << endl;

if (i==TAUCS_ERROR_NOMEM)
cout << "NOMEM error." << endl;

if (i==TAUCS_ERROR_BADARGS)
cout << "BADARGS error." << endl;

if (i==TAUCS_ERROR_MAXDEPTH)
cout << "MAXDEPTH error." << endl;

if (i==TAUCS_ERROR_INDEFINITE)
cout << "NOT POSITIVE DEFINITE error." << endl;
}
else {
cout << "Solution success." << endl;
for (unsigned j = 0; j < f.size(); j++)
cout << x[j] << endl;
}

// deallocate the factorization
taucs_linsolve(NULL, &F, 0, NULL, NULL, NULL, NULL);

// deallocate solution
delete [] x;

Alejandro A. Ortiz Bernardin

unread,
Dec 17, 2008, 1:42:06 PM12/17/08
to matrixpr...@googlegroups.com

I test taucs using the code in a message in this group
"[matrixprogramming] Re: Problem running TAUCS in Microsoft Visual C++
6.0".
The code failed when execute the line "i = taucs_linsolve(&A,&F,1, x,
b, NULL,NULL); //solve" .
----------------------------------------------------------------

I think you don't need to do the following:

int i = taucs_linsolve(&A,&F,0,NULL,NULL,options,NULL); //factor
i = taucs_linsolve(&A,&F,1, x, b, NULL,NULL); //solve
i = taucs_linsolve(NULL,&F,0,NULL,NULL,NULL,NULL); //free the

You can combine the first and second lines in one line given by the "solve"
line using 'options' instead of the first NULL as follows:

i = taucs_linsolve(&A,&F,1, x, b, options,NULL); //solve

But if you still want to do the three lines do it changing NULL to
'options':

int i = taucs_linsolve(&A,&F,0,NULL,NULL,options,NULL); //factor

i = taucs_linsolve(&A,&F,1, x, b, options,NULL); //solve


i = taucs_linsolve(NULL,&F,0,NULL,NULL,NULL,NULL); //free the


Alejandro.

Evgenii Rudnyi

unread,
Dec 17, 2008, 2:20:07 PM12/17/08
to matrixpr...@googlegroups.com
dhw schrieb:

> I test taucs using the code in a message in this group
> "[matrixprogramming] Re: Problem running TAUCS in Microsoft Visual C++
> 6.0".
> The code failed when execute the line "i = taucs_linsolve(&A,&F,1, x,
> b, NULL,NULL); //solve" .The code is as following :

I have missed it from the beginning. Sorry. Well, note that you try to
deallocate the factor two times but this has nothing to do with the problem.

I could confirm your observations. There is some error in taucs_linsolve
indeed. You can see it if you add

taucs_logfile("stdout");

at the beginnig of your function. Then you see some output from TAUCS.
taucs_linsolve complaints that there is no preconditioner - it uses a
wrong method for the solve phase.

I have looked in the taucs_linsolve code. Actually it is written there

/* (Experimental, unstable interface)

so, you cannot expect too much from it. My guess is that

int opt_factor = 1;

this line is wrong. It forces taucs_linsolve to go to the factorization
if both times. Try to change it to

int opt_factor = 0;

recompile TAUCS and see what happens. If this will not help, I will show
you how to use low-level TAUCS routines. This what I actually do in my
practice, I do not use taucs_linsolve in my work.

Evgenii Rudnyi

unread,
Dec 17, 2008, 2:34:05 PM12/17/08
to matrixpr...@googlegroups.com
> But if you still want to do the three lines do it changing NULL to
> 'options':
>
> int i = taucs_linsolve(&A,&F,0,NULL,NULL,options,NULL); //factor
> i = taucs_linsolve(&A,&F,1, x, b, options,NULL); //solve
> i = taucs_linsolve(NULL,&F,0,NULL,NULL,NULL,NULL); //free the
>

This works indeed but this is not what he wants. Unfortunately
taucs_linsolve makes the factorization again in this case in the second
line - you see it when you use taucs_logfile("stdout"). And the goal is
first factorization and then only back substitution. It can be easily
done at with the low-level routines but taucs_linsolve has just some bug.

Alejandro A. Ortiz Bernardin

unread,
Dec 17, 2008, 10:19:33 PM12/17/08
to matrixpr...@googlegroups.com
Evgenii,

I can imagine what *low-level* routines means, but I am curious to know
them. Could you point me out something in this matter?

Thanks,
Alejandro.


-----Mensaje original-----
De: matrixpr...@googlegroups.com
[mailto:matrixpr...@googlegroups.com] En nombre de Evgenii Rudnyi
Enviado el: Wednesday, December 17, 2008 11:20 AM
Para: matrixpr...@googlegroups.com
Asunto: [matrixprogramming] Re: help:taucs_linsolve failed when I tempt to
use the factorization!

Evgenii Rudnyi

unread,
Dec 18, 2008, 3:47:07 AM12/18/08
to matrixpr...@googlegroups.com
Alejandro A. Ortiz Bernardin schrieb:

> Evgenii,
>
> I can imagine what *low-level* routines means, but I am curious to know
> them. Could you point me out something in this matter?

Alejandro,

Please find a sample code below. You have to make some more effort to
reorder matrix and RHS and then to reorder the solution back but I guess
it is much simpler than to fix taucs_linsolve. METIS is the best
ordering and taucs_supernodal_solve_llt is the fastest solve, so it is
not much sense to try other routines.

I should confess that I have forgotten who and when should delete the
permutations. But this is, after all, not to important.

Evgenii

------- Code starts
#include <iostream>
#include <vector>
extern "C" {
#include <taucs.h>
}

using namespace::std;

int main(){
taucs_logfile("stdout");

int dim = 4;
// we need solution and RHS twice: original and reordered


// create TAUCS right-hand size
taucs_double* b = &f[0]; // right hand side vector to solve Ax=b

vector <double> bodv(dim);
taucs_double* bod = &*bodv.begin();

// allocate TAUCS solution vector

vector <double> xv(dim);
taucs_double* x = &*xv.begin();
vector <double> xodv(dim);
taucs_double* xod = &*xodv.begin();

//Using TAUCS low-level routines
int* perm;
int* invperm;
taucs_ccs_matrix* Aod;
void* F;

// 1) Reordering
taucs_ccs_order(&A, &perm, &invperm, "metis");
Aod = taucs_ccs_permute_symmetrically(&A, perm, invperm);
taucs_vec_permute(dim, TAUCS_DOUBLE, b, bod, perm);

// 2) Factoring
F = taucs_ccs_factor_llt_mf(Aod);

// 3) Back substitution and reodering the solution back
taucs_supernodal_solve_llt(F, xod, bod);
taucs_vec_ipermute(dim, TAUCS_DOUBLE, xod, x, perm);

// 4) Clean-up
taucs_supernodal_factor_free(F);
taucs_ccs_free(Aod);

cout << "Solution" << endl;
for (unsigned j = 0; j < dim; j++)
cout << x[j] << endl;
}
------- Code ends

Reply all
Reply to author
Forward
0 new messages