<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Calibri" size="2"><span style="font-size:11pt;">
<div>Hi, I’m using the KSP solver as following to solve a linear system Ax=b, where A is a 16767x16767 square matrix, b is a 16767 length vector. </div>
<div> </div>
<div>EXTERN_C_BEGIN</div>
<div>extern PetscErrorCode PCCreate_Jacobi(PC);</div>
<div>EXTERN_C_END</div>
<div> </div>
<div>static PetscErrorCode solvingAxb(Mat A, Vec b, PetscInt nbus, Vec &x, const int me)</div>
<div>{</div>
<div> PetscErrorCode ierr;</div>
<div> </div>
<div> KSP ksp; // linear solver context</div>
<div> Vec u; // exact solution</div>
<div> PetscInt its;</div>
<div> PetscReal norm; // norm of solution error</div>
<div> PetscLogDouble t1, t2;</div>
<div> PetscViewer viewer;</div>
<div> PC pc; // preconditioner context</div>
<div> PetscInt Istart, Iend;</div>
<div> </div>
<div> ierr = VecDuplicate(b, &u); CHKERRQ(ierr);</div>
<div> ierr = VecDuplicate(b, &x); CHKERRQ(ierr);</div>
<div> </div>
<div> ierr = KSPCreate(PETSC_COMM_WORLD, &ksp); CHKERRQ(ierr);</div>
<div> </div>
<div> ierr = KSPSetOperators(ksp, A, A, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr);</div>
<div> </div>
<div> PCRegister("ourjacobi", PCCreate_Jacobi);</div>
<div> </div>
<div> KSPGetPC(ksp, &pc);</div>
<div> PCSetType(pc, "ourjacobi");</div>
<div> </div>
<div> ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);</div>
<div> </div>
<div> ierr = KSPSolve(ksp, b, x); CHKERRQ(ierr);</div>
<div> </div>
<div> ierr = MatMult(A,x,u); CHKERRQ(ierr);</div>
<div> ierr = VecAXPY(u, -1.0, b); CHKERRQ(ierr);</div>
<div> ierr = VecNorm(u, NORM_2, &norm); CHKERRQ(ierr);</div>
<div> ierr = KSPGetIterationNumber(ksp, &its); CHKERRQ(ierr);</div>
<div> </div>
<div> ierr = VecDestroy(&b); CHKERRQ(ierr);</div>
<div> ierr = VecDestroy(&u); CHKERRQ(ierr);</div>
<div> </div>
<div> ierr = KSPDestroy(&ksp);CHKERRQ(ierr);</div>
<div> </div>
<div> PetscFunctionReturn(0);</div>
<div>}</div>
<div><font face="Times New Roman"> </font></div>
<div>I would like to know how to set the solver options at runtime to make it run faster, such as ksp_type, pc_type, and etc? It takes very long time to solve the system if I use no options.</div>
<div> </div>
<div>Thanks,</div>
<div>Shuangshuang</div>
<div><font face="Times New Roman"> </font></div>
</span></font>
</body>
</html>