## Zero solution with cula sparse

General CULA Sparse support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

### Zero solution with cula sparse

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)
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" ?

gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

If B is zero, then you have a trivial solution where x=0.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Zero solution with cula sparse

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.
gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

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).
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Zero solution with cula sparse

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?
gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

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.

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.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Zero solution with cula sparse

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?
gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

You'll want to initialize outside the loop.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Zero solution with cula sparse

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.
gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

Our strings are ISO-8859-1 - your editor may be expecting UTF8 or some kind of wide character encoding?
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Zero solution with cula sparse

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
gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

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.
john

Posts: 587
Joined: Thu Jul 23, 2009 2:31 pm

### Re: Zero solution with cula sparse

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 OUTPUTWRite(*,*) 'NNZ ELEMENTS',Annzcounterwrite(*,*) culares%iterationsWRITE(*,'(a)') buf`

this is my code

and the output looks like this:
Code: Select all
`NNZ ELEMENTS       119850Solver:      GMRES(5)Precond:     JacobiFlag:        Converged successfully in 21 iterationsResidual:    9.422576e-09Total 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....
gregk

Posts: 9
Joined: Thu Apr 18, 2013 3:28 am

### Re: Zero solution with cula sparse

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.
john