[petsc-users] a line of code is weird

Fande Kong fdkong.jd at gmail.com
Sat Mar 7 18:35:47 CST 2015


Thanks, Barry.

I understood now.



On Sat, Mar 7, 2015 at 11:11 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
>  Note the lines immediately above it.
>
>  ierr = VecGetOwnershipRange(x1,&start,&end);CHKERRQ(ierr);
> .....
> for (j=start; j<end; j++) {
>        if (PetscAbsScalar(y[j-start]) > amax || j == i) {
>         ierr =
> MatSetValues(B,1,&j,1,&i,y+j-start,INSERT_VALUES);CHKERRQ(ierr);
>
>  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.
>
> 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.
>
> Barry
>
>
> > On Mar 7, 2015, at 11:53 AM, Fande Kong <fdkong.jd at gmail.com> wrote:
> >
> > Hi all,
> >
> > 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.
> >
> > Thanks,
> >
> > Fande,
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150307/82a6d7c0/attachment.html>


More information about the petsc-users mailing list