static char help[] = "Tests MatNorm(), MatLUFactor(), MatSolve() and MatSolveAdd().\n\n"; #include int main(int argc,char **args) { Mat C; PetscInt i,j,m = 3,n = 3,Ii,J; PetscBool flg; PetscScalar v; IS perm,iperm; Vec x,u,b,y; PetscReal norm,tol=PETSC_SMALL; MatFactorInfo info; PetscMPIInt size; PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size)); PetscCheck(size == 1,PETSC_COMM_WORLD,PETSC_ERR_WRONG_MPI_SIZE,"This is a uniprocessor example only!"); PetscCall(MatCreate(PETSC_COMM_WORLD,&C)); PetscCall(MatSetSizes(C,PETSC_DECIDE,PETSC_DECIDE,m*n,m*n)); PetscCall(MatSetFromOptions(C)); PetscCall(MatSetUp(C)); PetscCall(PetscOptionsHasName(NULL,NULL,"-symmetric",&flg)); if (flg) { /* Treat matrix as symmetric only if we set this flag */ PetscCall(MatSetOption(C,MAT_SYMMETRIC,PETSC_TRUE)); PetscCall(MatSetOption(C,MAT_SYMMETRY_ETERNAL,PETSC_TRUE)); } /* Create the matrix for the five point stencil, YET AGAIN */ for (i=0; i0) {J = Ii - n; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} if (i0) {J = Ii - 1; PetscCall(MatSetValues(C,1,&Ii,1,&J,&v,INSERT_VALUES));} if (j tol) { PetscCall(PetscPrintf(PETSC_COMM_SELF,"MatSolve: Norm of error %g\n",(double)norm)); } /* Test MatSolveAdd */ PetscCall(MatSolveAdd(C,b,y,x)); PetscCall(VecAXPY(x,-1.0,y)); PetscCall(VecAXPY(x,-1.0,u)); PetscCall(VecNorm(x,NORM_2,&norm)); if (norm > tol) { PetscCall(PetscPrintf(PETSC_COMM_SELF,"MatSolveAdd(): Norm of error %g\n",(double)norm)); } PetscCall(ISDestroy(&perm)); PetscCall(ISDestroy(&iperm)); PetscCall(VecDestroy(&u)); PetscCall(VecDestroy(&y)); PetscCall(VecDestroy(&b)); PetscCall(VecDestroy(&x)); PetscCall(MatDestroy(&C)); PetscCall(PetscFinalize()); return 0; } /*TEST test: TEST*/