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 */ PetscErrorCode ierr; PetscInt n = 10,i,its,col[3]; PetscScalar value[3]; KSPType kspname; PCType pcname; ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; ierr = PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);CHKERRQ(ierr); /* Create and initialize vectors */ ierr = VecCreateSeq(PETSC_COMM_SELF,n,&b);CHKERRQ(ierr); ierr = VecCreateSeq(PETSC_COMM_SELF,n,&ustar);CHKERRQ(ierr); ierr = VecCreateSeq(PETSC_COMM_SELF,n,&u);CHKERRQ(ierr); ierr = VecSet(ustar,1.0);CHKERRQ(ierr); ierr = VecSet(u,0.0);CHKERRQ(ierr); /* Create and assemble matrix */ ierr = MatCreate(PETSC_COMM_SELF,&mat);CHKERRQ(ierr); ierr = MatSetType(mat,MATSEQAIJ);CHKERRQ(ierr); ierr = MatSetSizes(mat,n,n,n,n);CHKERRQ(ierr); ierr = MatSetFromOptions(mat);CHKERRQ(ierr); ierr = MatSeqAIJSetPreallocation(mat,3,NULL);CHKERRQ(ierr); ierr = MatSeqBAIJSetPreallocation(mat,1,3,NULL);CHKERRQ(ierr); ierr = MatSeqSBAIJSetPreallocation(mat,1,3,NULL);CHKERRQ(ierr); ierr = MatSeqSELLSetPreallocation(mat,3,NULL);CHKERRQ(ierr); value[0] = -1.0; value[1] = 2.0; value[2] = -1.0; for (i=1; i