<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Hello,<br></div><div class="gmail_default" style="font-family:verdana,sans-serif">I just started with PETSc and was trying the KSP Solvers. I was trying for the problem -  <br><br>int main(int argc, char *argv[])<br>{   <br>    /// matrix creation variables.<br>    PetscInt    *idxm = new PetscInt[3];<br>    PetscInt    *idxn = new PetscInt[3];<br>    PetscReal   loc[]  = { 1.0, -2.0, -6.0,<br>                                   2.0,  4.0, 12.0,<br>                                   1.0, -4.0,-12.0};<br>    PetscReal   b_array[] = {  12.0, <br>                              -17.0,<br>                               22.0};<br>    PetscInt i;<br>    KSP      ksp; <br>    <br>    /// Declaring the vectors<br>    Vec     x, b;<br><br>    // Declaring matrices<br>    Mat A;<br><br>    PetscInitialize(&argc,&argv,(char*)0,help);<br>    // Creating vectors<br>    VecCreateSeq(PETSC_COMM_SELF, 3, &x);<br>    VecCreateSeq(PETSC_COMM_SELF, 3, &b);<br>    // Creating matrix<br>    MatCreateSeqAIJ(PETSC_COMM_SELF, 3, 3, 3, NULL, &A);<br>    // Creating the indices<br>    for(i=0; i<3; i++) {<br>        idxm[i] = i;<br>        idxn[i] = i;<br>    }<br>    // Assembling the vector b and x<br>    VecSetValues(b, 3, idxm, b_array, INSERT_VALUES);<br>    VecAssemblyBegin(b);<br>    VecAssemblyEnd(b);<br>    <br>    //Assembling the Matrix    <br>    MatSetValues(A, 3, idxm, 3, idxn, loc, INSERT_VALUES);<br>    MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);<br>    MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);<br><br>    // KSP related operations<br>    KSPCreate(PETSC_COMM_SELF, &ksp);<br>    KSPSetType(ksp, KSPGMRES);<br>    KSPSetOperators(ksp, A, A);<br>    KSPSetFromOptions(ksp);<br>    KSPSolve(ksp,b,x);<br>    KSPDestroy(&ksp);<br><br>    VecView(x, PETSC_VIEWER_STDOUT_SELF);<br><br>    PetscFinalize();<br>    return 0;<br>}<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">But the obtained solution is found out to be- (inf, inf, inf).<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">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).<br><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Thank you. <br clear="all"></div></div>