/* static char help[] = "Solves a linear system in parallel with KSP.\n\ Input parameters include:\n\ -random_exact_sol : use a random exact solution vector\n\ -view_exact_sol : write exact solution vector to stdout\n\ -m : number of mesh points in x-direction\n\ -n : number of mesh points in y-direction\n\n"; */ /* Input parameters include:\n\ -random_exact_sol : use a random exact solution vector\n\ -view_exact_sol : write exact solution vector to stdout\n\ -m : number of mesh points in x-direction\n\ -n : number of mesh points in y-direction\n\n"; */ /*T Concepts: KSP^basic parallel example; Concepts: KSP^Laplacian, 2d Concepts: Laplacian, 2d Processors: n T*/ /* Include "petscksp.h" so that we can use KSP solvers. Note that this file automatically includes: petscsys.h - base PETSc routines petscvec.h - vectors petscmat.h - matrices petscis.h - index sets petscksp.h - Krylov subspace methods petscviewer.h - viewers petscpc.h - preconditioners */ #include #include #undef __FUNCT__ #define __FUNCT__ "main" int main(int argc,char **args) { Vec x,b; /* approx solution, RHS, exact solution */ Mat A; /* linear system matrix */ KSP ksp; /* linear solver context */ // PetscRandom rctx; /* random number generator context */ // PetscReal norm; /* norm of solution error */ PetscInt i,j,m = 3,n = 3,its; PetscErrorCode ierr; // PetscBool flg = PETSC_FALSE; PetscScalar v; //#if defined(PETSC_USE_LOG) // PetscLogStage stage; //#endif PetscInitialize(&argc,&args,(char*)0,NULL); // print value of an option const char* pre = NULL; const char name[] = "-ksp_pc_side"; const size_t len = 256; char str[len]; PetscBool isset; ierr = PetscOptionsGetString(pre, name, str, len, &isset); CHKERRQ(ierr); if (isset) { std::cout << "option " << name << " was found" << std::endl; std::cout << "returned string is: " << str << std::endl; } else { std::cout << "option " << name << " not found" << std::endl; } ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr); ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,m,n);CHKERRQ(ierr); ierr = MatSetFromOptions(A);CHKERRQ(ierr); ierr = MatMPIAIJSetPreallocation(A,5,NULL,5,NULL);CHKERRQ(ierr); ierr = MatSeqAIJSetPreallocation(A,5,NULL);CHKERRQ(ierr); // ierr = MatGetOwnershipRange(A,&Istart,&Iend);CHKERRQ(ierr); // ierr = PetscLogStageRegister("Assembly", &stage);CHKERRQ(ierr); // ierr = PetscLogStagePush(stage);CHKERRQ(ierr); for (i=0; i