[petsc-users] KSP Solver giving inf's

Kaushik Kulkarni kaushikggg at gmail.com
Sat Apr 8 06:54:56 CDT 2017


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];
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170408/ec57459f/attachment.html>


More information about the petsc-users mailing list