static char help[] = "Demonstrates the use of fast Richardson for SOR. And\n\ also tests the MatSOR() routines. Input parameters are:\n\ -n : problem dimension\n\n"; #include #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]; KSPType kspname; PCType pcname; PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL)); /* 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(MatCreate(PETSC_COMM_SELF,&mat)); PetscCall(MatSetType(mat,MATSEQAIJ)); PetscCall(MatSetSizes(mat,n,n,n,n)); PetscCall(MatSetFromOptions(mat)); PetscCall(MatSeqAIJSetPreallocation(mat,3,NULL)); PetscCall(MatSeqBAIJSetPreallocation(mat,1,3,NULL)); PetscCall(MatSeqSBAIJSetPreallocation(mat,1,3,NULL)); PetscCall(MatSeqSELLSetPreallocation(mat,3,NULL)); value[0] = -1.0; value[1] = 2.0; value[2] = -1.0; for (i=1; i