[petsc-dev] checking if a vector is ghosted

Jed Brown jedbrown at mcs.anl.gov
Tue Nov 8 14:07:58 CST 2011


On Tue, Nov 8, 2011 at 14:05, Matthew Knepley <knepley at gmail.com> wrote:

> Just want to check that the following is a kosher use of the return error
>> handler
>>
>>    bool _is_ghosted = true;
>>    PetscErrorCode ierr;
>>    PetscPushErrorHandler(PetscReturnErrorHandler,PETSC_NULL);
>>    ierr= VecGhostGetLocalForm(*x, x_ghosted.get());
>>    if (ierr != 0 )
>>      _is_ghosted = false;
>>    PetscPopErrorHandler();
>>
>
> Do you need to mess with the error handler?
>

Yes, otherwise an error message would be printed.

Mark, what you describe is okay. We, or you, could make a VecIsGhosted().
The code shows how it determines whether a Vec is ghosted.

PetscErrorCode  VecGhostGetLocalForm(Vec g,Vec *l)
{
  PetscErrorCode ierr;
  PetscBool      isseq,ismpi;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(g,VEC_CLASSID,1);
  PetscValidPointer(l,2);

  ierr = PetscTypeCompare((PetscObject)g,VECSEQ,&isseq);CHKERRQ(ierr);
  ierr = PetscTypeCompare((PetscObject)g,VECMPI,&ismpi);CHKERRQ(ierr);
  if (ismpi) {
    Vec_MPI *v  = (Vec_MPI*)g->data;
    if (!v->localrep) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Vector
is not ghosted");
    *l = v->localrep;
  } else if (isseq) {
    *l = g;
  } else {
    SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Vector type %s does not
have local representation",((PetscObject)g)->type_name);
  }
  ierr = VecGhostStateSync_Private(g,*l);CHKERRQ(ierr);
  ierr = PetscObjectReference((PetscObject)*l);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20111108/2b23d368/attachment.html>


More information about the petsc-dev mailing list