Try moving your print statement in ComputeMatrix2 to be after PetscFunctionBeginUser;<br><br>You should really use a debugger to see if these functions are being called or not - don't use print statements. <br><br>On Tuesday, 3 March 2015, Sun, Hui <<a href="mailto:hus003@ucsd.edu">hus003@ucsd.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div>
<div style="direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt">I set up 2 KSPs through KSPSetComputeOperators, <span style="font-size:10pt">with separate compute matrix functions. </span>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    </p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ierr = KSPSetComputeOperators(ksp1,ComputeMatrix1,<span style="color:#bb2ca2">NULL</span>);CHKERRQ(ierr);</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ierr = KSPSetComputeOperators(ksp2,ComputeMatrix2,<span style="color:#bb2ca2">NULL</span>);CHKERRQ(ierr);</p>
<div><span style="font-size:10pt"><br>
</span></div>
<div>Within each computeMatrix function, I define the matrix, and I also print something to the screen. So</div>
<div><br>
</div>
<div>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
PetscErrorCode ComputeMatrix1(KSP ksp, Mat J,Mat jac, <span style="color:#bb2ca2">
void</span> *ctx)</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
{</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ......</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ierr    = PetscPrintf(PETSC_COMM_WORLD,<span style="color:rgb(209,47,27)">"1\n"</span>);CHKERRQ(ierr);</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ......</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
}</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
<br>
</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
PetscErrorCode ComputeMatrix2(KSP ksp, Mat J,Mat jac, <span style="color:rgb(187,44,162)">void</span> *ctx)</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
{</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ......</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ierr    = PetscPrintf(PETSC_COMM_WORLD,<span style="color:rgb(209,47,27)">"2\n"</span>);CHKERRQ(ierr);</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
    ......</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
}</p>
<p style="margin-right:0px;margin-left:0px;font-size:11px;font-family:Menlo">
<br>
</p>
</div>
<div>Now if I compile and execute the code, it only print 2, completely ignoring 1, which is not expected, since I have setup ksp1 to use ComputeMatrix1. </div>
<div><br>
</div>
<div>Does anyone know what might be wrong? Thank you. I have attached the short code here in this email as well. </div>
<div><br>
</div>
<div>Hui</div>
</div>
</div>

</blockquote>