[petsc-users] ts behavior question

Smith, Barry F. bsmith at mcs.anl.gov
Tue Nov 12 09:43:43 CST 2019


  For any vector you only read you should use the read version.

  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

> On Nov 12, 2019, at 9:26 AM, Gideon Simpson <gideon.simpson at gmail.com> wrote:
> 
> 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.

  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.

   Barry

> 
> On Tue, Nov 12, 2019 at 12:33 AM Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
> 
> 
> > On Nov 11, 2019, at 7:00 PM, Gideon Simpson via petsc-users <petsc-users at mcs.anl.gov> wrote:
> > 
> > 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:
> > 1. I have to explicitly provide the Jacobian
> 
>    Yes
> 
> > 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.
> 
>   Presumably you call VecGetArray() instead? 
> > 
> >  
> > 3.  My code works without declaring const when I'm using an explicit scheme.
> > 
> > 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.
> 
>   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.
> > 
> > Can someone clarify what is expected/preferred?
> 
>   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.
> 
>   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.  https://gitlab.com/petsc/petsc/issues/493
> 
>   Thanks for pointing out the inconsistency
> 
>   Barry
> 
> > 
> > -- 
> > gideon
> 
> 
> 
> -- 
> gideon



More information about the petsc-users mailing list