[petsc-dev] checking if a vector is ghosted
mspieg
mspieg at ldeo.columbia.edu
Tue Nov 8 14:49:35 CST 2011
Thanks everyone for getting back so fast (as usual).
VecIsGhosted would be nice…
I assume that would go into dev…
In the meantime, I think the error handler trick will work in 3.2…
thanks
marc
On Nov 8, 2011, at 3:41 PM, Barry Smith wrote:
>
> We should add a VecIsGhosted()
>
> Barry
>
> On Nov 8, 2011, at 12:07 PM, Jed Brown wrote:
>
>> 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);
>> }
>
----------------------------------------------------
Marc Spiegelman
Lamont-Doherty Earth Observatory
Dept. of Applied Physics/Applied Math
Columbia University
http://www.ldeo.columbia.edu/~mspieg
tel: 845 704 2323 (SkypeIn)
----------------------------------------------------
More information about the petsc-dev
mailing list