#include "petscksp.h" #undef __FUNCT__ #define __FUNCT__ "main" int main(int argc, char* argv[]) { PetscErrorCode ierr; ierr = PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); CHKERRQ(ierr); Mat A; ierr = MatCreateSeqAIJ(PETSC_COMM_SELF, 3, 3, 1, PETSC_NULL, &A); CHKERRQ(ierr); ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY); ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY); ierr = MatShift(A, 1000); CHKERRQ(ierr); Vec x, b; ierr = VecCreateSeq(PETSC_COMM_SELF, 3, &x); CHKERRQ(ierr); ierr = VecShift(x, -10); CHKERRQ(ierr); ierr = VecCreateSeq(PETSC_COMM_SELF, 3, &b); CHKERRQ(ierr); ierr = VecShift(b, 200); CHKERRQ(ierr); KSP ksp; ierr = KSPCreate(PETSC_COMM_SELF, &ksp); CHKERRQ(ierr); //ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr); printf("x before solve\n"); ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); printf("b before solve\n"); ierr = VecView(b, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); ierr = KSPSetOperators(ksp, A, A, SAME_NONZERO_PATTERN); CHKERRQ(ierr); ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr); ierr = KSPSolve(ksp, b, x); CHKERRQ(ierr); printf("x after solve\n"); ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); printf("b after solve\n"); ierr = VecView(b, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); ierr = VecDestroy(x); ierr = VecDestroy(b); ierr = MatDestroy(A); ierr = KSPDestroy(ksp); ierr = PetscFinalize(); CHKERRQ(ierr); }