<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello,<div><br></div><div>    I am trying to solve a linear problem by using KSPSolve and DM. In the example  /src/ksp/ksp/examples/tutorials/ex45.c, the Matrix and the RHS vector are computed by calling <span style="font-size: 12pt;"> </span><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetComputeRHS.html#KSPSetComputeRHS" style="font-size: 12pt;">KSPSetComputeRHS</a> and  <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetComputeOperators.html#KSPSetComputeOperators" style="font-size: 12pt;">KSPSetComputeOperators</a> in which functions <span style="font-size: 12pt;">ComputeRHS() and </span><span style="font-size: 12pt;">ComputeMatrix() are called and the matrix is assembled in ComputeMatrix().   </span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;">    Since the linear system is solved in an iteration, it will save time to reuse the matrix assembled in ComputeMatrix().  That is the ComputeMatrix() is called only once, but ComputeRHS() is called in each iteration.  Can anyone tell me what should I do to keep the assembled matrix?</span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;">     I am thinking not to use </span><span style="font-size: 12pt;"> </span><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/KSP/KSPSetComputeOperators.html#KSPSetComputeOperators" style="font-size: 12pt;">KSPSetComputeOperators</a> for assembling the matrix, but use <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/DM/DMCreateMatrix.html#DMCreateMatrix" style="font-size: 12pt;">DMCreateMatrix</a><span style="font-size: 12pt;">() alternatively. Am I right?</span></div><div><span style="font-size: 12pt;"><br></span></div><div><span style="font-size: 12pt;">     Any hits would be appreciated very much. Thanks alot.</span></div><div><br></div><div><pre width="80"> </pre></div>                                    </div></body>
</html>