Could you please make a sample code and upload it with the matrix to
Files of this group?
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.
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.
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,
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