[petsc-users] KSP Solver giving inf's

Matthew Knepley knepley at gmail.com
Sat Apr 8 08:22:41 CDT 2017


On Sat, Apr 8, 2017 at 6:54 AM, Kaushik Kulkarni <kaushikggg at gmail.com>
wrote:

> Hello,
> I just started with PETSc and was trying the KSP Solvers. I was trying for
> the problem -
>
> int main(int argc, char *argv[])
> {
>     /// matrix creation variables.
>     PetscInt    *idxm = new PetscInt[3];
>     PetscInt    *idxn = new PetscInt[3];
>

Note that the problem below is rank deficient (2 * row 1 + row 2 = 0). Its
not clear to me whether b is
in the range space of the operator.

  Thanks,

    Matt


>     PetscReal   loc[]  = { 1.0, -2.0, -6.0,
>                                    2.0,  4.0, 12.0,
>                                    1.0, -4.0,-12.0};
>     PetscReal   b_array[] = {  12.0,
>                               -17.0,
>                                22.0};
>     PetscInt i;
>     KSP      ksp;
>
>     /// Declaring the vectors
>     Vec     x, b;
>
>     // Declaring matrices
>     Mat A;
>
>     PetscInitialize(&argc,&argv,(char*)0,help);
>     // Creating vectors
>     VecCreateSeq(PETSC_COMM_SELF, 3, &x);
>     VecCreateSeq(PETSC_COMM_SELF, 3, &b);
>     // Creating matrix
>     MatCreateSeqAIJ(PETSC_COMM_SELF, 3, 3, 3, NULL, &A);
>     // Creating the indices
>     for(i=0; i<3; i++) {
>         idxm[i] = i;
>         idxn[i] = i;
>     }
>     // Assembling the vector b and x
>     VecSetValues(b, 3, idxm, b_array, INSERT_VALUES);
>     VecAssemblyBegin(b);
>     VecAssemblyEnd(b);
>
>     //Assembling the Matrix
>     MatSetValues(A, 3, idxm, 3, idxn, loc, INSERT_VALUES);
>     MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
>     MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
>
>     // KSP related operations
>     KSPCreate(PETSC_COMM_SELF, &ksp);
>     KSPSetType(ksp, KSPGMRES);
>     KSPSetOperators(ksp, A, A);
>     KSPSetFromOptions(ksp);
>     KSPSolve(ksp,b,x);
>     KSPDestroy(&ksp);
>
>     VecView(x, PETSC_VIEWER_STDOUT_SELF);
>
>     PetscFinalize();
>     return 0;
> }
>
> But the obtained solution is found out to be- (inf, inf, inf).
>
> I wanted to know whether I am doing something wrong or is the problem
> inherently not solvable using GMRES. Currently I am running the code in a
> sequential manner(no parallelism intended).
>
> Thank you.
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170408/05c96d0e/attachment.html>


More information about the petsc-users mailing list