<div dir="ltr">So this might be a resolution/another question. Part of the reason to use the da is that it provides you with ghost points. If you're only accessing the dependent variables entries with <span class="gmail-im">DMDAVecGetArrayRead, then you can't modify the ghost points. If you can't modify the ghost points here, where would you do so in the context of a problem with, for instance, time dependent boundary conditions?<br></span></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 12, 2019 at 10:43 AM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
For any vector you only read you should use the read version.<br>
<br>
Sometimes the vector may not be locked and hence the other routine can be used but that may change as we add more locks and improve the code. So best to do it right<br>
<br>
> On Nov 12, 2019, at 9:26 AM, Gideon Simpson <<a href="mailto:gideon.simpson@gmail.com" target="_blank">gideon.simpson@gmail.com</a>> wrote:<br>
> <br>
> So, in principle, should we actually be using DMDAVecGetArrayRead in this context? I seem to be able to get away with DMDAVecGetArray with all time steppers.<br>
<br>
I am not sure why DMDAVecGetArray would work if VecGetArray did not work. Internally it calls VecGetArray() that will do the check. If you call it on local ghosted vectors it doesn't check if the vector is locked since the ghosted version is a copy of the true locked vector.<br>
<br>
Barry<br>
<br>
> <br>
> On Tue, Nov 12, 2019 at 12:33 AM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
> <br>
> <br>
> > On Nov 11, 2019, at 7:00 PM, Gideon Simpson via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br>
> > <br>
> > I noticed that when I am solving a problem with the ts and I am *not* using a da, if I want to use an implicit time stepping routine:<br>
> > 1. I have to explicitly provide the Jacobian<br>
> <br>
> Yes<br>
> <br>
> > 2. When I do provide the Jacobian, if I want to access the elements of x(t) to construct f(t,x), I need to use a const PetscScalar and a VecGetArrayRead to get it to work.<br>
> <br>
> Presumably you call VecGetArray() instead? <br>
> > <br>
> > <br>
> > 3. My code works without declaring const when I'm using an explicit scheme.<br>
> > <br>
> > In contrast, if I solve a problem using a da, my code works, I can use implicit schemes without having to provide the Jacobian, and I don't have to use const anywhere.<br>
> <br>
> The use with DMDA provides automatic routines for computing the needed Jacobians using finite differencing of your provided function and coloring of the Jacobian. This results in reasonably efficient computation of Jacobians that work in most (almost all) cases.<br>
> > <br>
> > Can someone clarify what is expected/preferred?<br>
> <br>
> You should always use VecGetArrayRead() for vectors you are accessing but NOT changing the values in. There is no reason not and it provides the potential for higher performance.<br>
> <br>
> The algebraic solvers have additional checks to prevent peopled from inadvertently changing the entries in x (which would produce bugs). Presumably this results in generating an error when you call VecGetArray(). At least some of the TS explicit calls do not have such checks. They could be added and should be added. <a href="https://gitlab.com/petsc/petsc/issues/493" rel="noreferrer" target="_blank">https://gitlab.com/petsc/petsc/issues/493</a><br>
> <br>
> Thanks for pointing out the inconsistency<br>
> <br>
> Barry<br>
> <br>
> > <br>
> > -- <br>
> > gideon<br>
> <br>
> <br>
> <br>
> -- <br>
> gideon<br>
<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">gideon</div>