static char help[] = "Tests PC and KSP on a tridiagonal matrix. Note that most\n\ users should employ the KSP interface instead of using PC directly.\n\n"; #include int main(int argc,char **args) { Mat mat; /* matrix */ Vec b,ustar,u; /* vectors (RHS, exact solution, approx solution) */ PC pc; /* PC context */ KSP ksp; /* KSP context */ PetscInt n = 10,i,its,col[3]; PetscScalar value[3]; PCType pcname; KSPType kspname; PetscReal norm,tol=1000.*PETSC_MACHINE_EPSILON; PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); /* Create and initialize vectors */ PetscCall(VecCreateSeq(PETSC_COMM_SELF,n,&b)); PetscCall(VecCreateSeq(PETSC_COMM_SELF,n,&ustar)); PetscCall(VecCreateSeq(PETSC_COMM_SELF,n,&u)); PetscCall(VecSet(ustar,1.0)); PetscCall(VecSet(u,0.0)); /* Create and assemble matrix */ PetscCall(MatCreateSeqAIJ(PETSC_COMM_SELF,n,n,3,NULL,&mat)); value[0] = -1.0; value[1] = 2.0; value[2] = -1.0; for (i=1; i tol) { PetscCall(PetscPrintf(PETSC_COMM_SELF,"2 norm of error %g Number of iterations %D\n",(double)norm,its)); } /* Free data structures */ PetscCall(KSPDestroy(&ksp)); PetscCall(VecDestroy(&u)); PetscCall(VecDestroy(&ustar)); PetscCall(VecDestroy(&b)); PetscCall(MatDestroy(&mat)); PetscCall(PCDestroy(&pc)); PetscCall(PetscFinalize()); return 0; } /*TEST test: args: -ksp_type cg -ksp_monitor_short TEST*/