Page 1 of 1

Zero solution with cula sparse

PostPosted: Tue May 07, 2013 5:23 am
by gregk
First of all greetings to everyone, and thank you very much for this great piece of software.

Now to the point of the topic. The title is abstract but i can't think of a more suitable title now.

I am working on a project for my university and what i am supposed to do is to replace a serial program (written in fortran) that solves a Ax=b specified problem using gauss elimination. A is a sparse matrix and so what would be the best way to solve this problem other than using CULA Sparse.
I've kept the initial code because it contains some subroutines that would cost me a lot of time to rewrite in C, and as soon as CULA Sparse has modules for fortran, i continued to write my code in fortran.

I think i've called CULA correctly because i get no runtime or data error. But the output of CULA is this:

Solver: Cg
Flag: Converged successfully in 1 iterations
Residual: nan

Total Time: 0.005367s (overhead + solve)
Overhead: 0.001329s
Solve: 0.004035s


b matrix is initially zero and after the "solution" x is also zero...

Can i somehow indicate the cause of this "failure" ?

Thanks in advance.

Re: Zero solution with cula sparse

PostPosted: Tue May 07, 2013 5:48 am
by john
If B is zero, then you have a trivial solution where x=0.

Re: Zero solution with cula sparse

PostPosted: Tue May 07, 2013 6:25 am
by gregk
Unfortunatelly that is indeed true. but can't i search for a solution other than this profinite one? I know there is another solution, because GELIM gives me one with the initial code.

Re: Zero solution with cula sparse

PostPosted: Tue May 07, 2013 6:50 am
by john
A full-rank linear system has only a single solution. Are you certain that your gaussian elimination code is producing a correct result? I ask, because sparse gaussian is non-trivial because it will create new non-zeroes (potentially to the point of making your matrix dense).

Re: Zero solution with cula sparse

PostPosted: Tue May 07, 2013 7:33 am
by gregk
The gelim code is surely correct and I think i should take the same solution in the first place. Maybe i've malformed the matrix during the convertion to CSR.

I think i need to check it out again.
Thanks for the help

Btw, i am trying now to trigger a data error when the solver is called, but i can't xD

I am changing the n and nnz arguments but i still get the same output.
How can i indicate that the data i am passing are not correct?

Re: Zero solution with cula sparse

PostPosted: Tue May 07, 2013 11:44 am
by john
You should consider calculating the residual of your gelim code to see how accurate it is: || A*x-b || should be a very small number.

But really, if your B is all zeroes then your answer should be zero.

CULA doesn't do a lot of error checking on your data unless you enable the debug option. You're hitting a short circuit path where your initial residual is calculated and then no iterations occur, because the answer can be trivially calculated.

Re: Zero solution with cula sparse

PostPosted: Thu May 09, 2013 12:40 am
by gregk
I changed solver, tweaked my code a bit and now i get a proper solution.

But i've come up with another problem. I need to call CULA inside a loop, what should i do with the initialize and the shutdown functions??? should they be inside or outside the loop?

I've seed that cula takes some time to initialize, but when i tried to put the initialize inside the loop it did that only the first time. All the next ones, i think where bypassed, with the results being garbage(maybe its the solvers fault here i am not sure, i'll test it again asap) Is this normal?

Re: Zero solution with cula sparse

PostPosted: Thu May 09, 2013 6:10 am
by john
You'll want to initialize outside the loop.

Re: Zero solution with cula sparse

PostPosted: Sun May 12, 2013 1:53 pm
by gregk
john wrote:You'll want to initialize outside the loop.

Thats what i did and worked perfectly.

Now another issue that i have and i wanted to discuss. My workspace is on linux (i don't know if that is the problem but i think i should mention it. Cula returns a result string. When i am trying to print it inside a file, i get en error from any text editor that the encoding is unrecognisable. The same thing happens when i am trying to echo the output of the program inside a file.

Is there any workaround for that? It would be very convenient if i could post cula output inside a file instead of copying and pasting.

Re: Zero solution with cula sparse

PostPosted: Mon May 13, 2013 6:01 am
by john
Our strings are ISO-8859-1 - your editor may be expecting UTF8 or some kind of wide character encoding?

Re: Zero solution with cula sparse

PostPosted: Mon May 13, 2013 10:26 am
by gregk
john wrote:Our strings are ISO-8859-1 - your editor may be expecting UTF8 or some kind of wide character encoding?


my editor can't recognize an encoding for the output file.... Pretty weird because it supports pretty much all encodings... anyways i changed editor and i can see it ok now :)



I have another problem now, i can't manage to print separately the number of iterations of the solver. When i try to print res%iterations it prints 0 :?

Re: Zero solution with cula sparse

PostPosted: Mon May 13, 2013 1:29 pm
by john
If you're solving against zeros, that's what you should expect. "0" basically means the solver terminated before even getting to the first iteration.

Re: Zero solution with cula sparse

PostPosted: Tue May 14, 2013 1:37 am
by gregk
A couple of posts ago, i said that i am getting proper solutions, i changed solver i fixed a wrong cula calling and everything solves fine now (solution is the same with the gelim one).

Code: Select all
STATUS=CULA_DCSR_GMRES_JACOBI(config,solverOpts,precondOpts,np,Annzcounter,ao,jao,iao,du,b,culares)

STATUS= CULA_GET_ERROR_INFO()
CALL CULA_CHECK_STATUS(STATUS)

STATUS=CULA_ITERATIVE_RESULT_STRING(culares,buf,bufsize)

CALL CULA_CHECK_STATUS(STATUS)


! CULA OUTPUT
WRite(*,*) 'NNZ ELEMENTS',Annzcounter
write(*,*) culares%iterations
WRITE(*,'(a)') buf


this is my code

and the output looks like this:
Code: Select all
NNZ ELEMENTS       11985
0
Solver:      GMRES(5)
Precond:     Jacobi
Flag:        Converged successfully in 21 iterations
Residual:    9.422576e-09

Total Time:  0.03573s (overhead + precond + solve)
   Overhead: 0.001077s
   Precond:  0.000111s
   Solve:    0.03454s


And i want to print (actually to save...) that particular 21 there. But when i try to write it it returns 0....

Re: Zero solution with cula sparse

PostPosted: Tue May 14, 2013 7:07 am
by john
IT could be that there's a bug there. The Fortran support has improved quite a bit in S5, so you might want to try that out as well. (Check cula_sparse_legacy.f90)

I'd also note that GMRES is one of our less preferred solvers, so you may also wish to try some of the others. The "solver selection flowchart" in the manual may be of assistance to you.