<div dir="ltr">Thanks, Barry.<div><br></div><div>I understood now.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 7, 2015 at 11:11 AM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
 Note the lines immediately above it.<br>
<br>
 ierr = VecGetOwnershipRange(x1,&start,&end);CHKERRQ(ierr);<br>
.....<br>
for (j=start; j<end; j++) {<br>
       if (PetscAbsScalar(y[j-start]) > amax || j == i) {<br>
        ierr = MatSetValues(B,1,&j,1,&i,y+j-start,INSERT_VALUES);CHKERRQ(ierr);<br>
<br>
 j is looping over the global rows of the vector. The -start is to convert to the local row inside the array y[] since y only contains the local part of the vector.<br>
<br>
Note that y+j-start is equivalent to &y[j-start] so this is inserting into the jth global row the jth global row value in the vector which is the j-start local entry in the vector.<br>
<span class="HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
> On Mar 7, 2015, at 11:53 AM, Fande Kong <<a href="mailto:fdkong.jd@gmail.com">fdkong.jd@gmail.com</a>> wrote:<br>
><br>
> Hi all,<br>
><br>
> I am trying to understand how to compute Jacobian using finite difference methods. There is a function called SNESComputeJacobianDefault, where a line of code at 120th line, MatSetValues(B,1,&j,1,&i,y+j-start,INSERT_VALUES), is difficult to understand for me. Because I think inserting  'y' is enough, but there is two extra values 'j-start'. Any explanation is welcome.<br>
><br>
> Thanks,<br>
><br>
> Fande,<br>
<br>
</div></div></blockquote></div><br></div>