[petsc-dev] PetscBag not a PetscObject?

Barry Smith bsmith at mcs.anl.gov
Fri Apr 8 21:55:35 CDT 2011


   I think originally PetscBag was this small lightweight thing that was not "worthy" of being a full fledged object. 

    It will be slightly tricky (or at least nonstandard) to make PetscBag a PETSc object because of 

 ierr = PetscMalloc(bagsize+sizeof(struct _n_PetscBag)+sizeof(PetscScalar),bag);CHKERRQ(ierr);
  ierr = PetscMemzero(*bag,bagsize+sizeof(struct _n_PetscBag)+sizeof(PetscScalar));CHKERRQ(ierr);
  (*bag)->bagsize        = bagsize+sizeof(struct _n_PetscBag)+sizeof(PetscScalar);
  (*bag)->bagcomm        = comm;
  (*bag)->structlocation = (void*)(((char*)(*bag)) + sizeof(PetscScalar)*(sizeof(struct _n_PetscBag)/sizeof(PetscScalar)) + sizeof(PetscScalar));

while for PETSc objects

PetscErrorCode  PetscObjectCreate(MPI_Comm comm, PetscObject *obj)
{
  GenericObject  o;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  PetscValidPointer(obj,2);
#if !defined(PETSC_USE_DYNAMIC_LIBRARIES)
  ierr = PetscSysInitializePackage(PETSC_NULL);CHKERRQ(ierr);
#endif
  ierr = PetscHeaderCreate(o,_p_GenericObject,-1,PETSC_OBJECT_CLASSID,0,"PetscObject",comm,PetscObjectDestroy_GenericObject,0);CHKERRQ(ierr);

#define PetscHeaderCreate(h,tp,pops,cook,t,class_name,com,des,vie)	\
  (PetscNew(struct tp,&(h)) ||						\
   PetscNew(PetscOps,&(((PetscObject)(h))->bops)) ||			\
   PetscNew(pops,&((h)->ops)) ||					\
   PetscHeaderCreate_Private((PetscObject)h,cook,t,class_name,com,(PetscObjectFunction)des,(PetscObjectViewerFunction)vie) || \
   PetscLogObjectCreate(h) ||						\
   PetscLogObjectMemory(h, sizeof(struct tp) + sizeof(PetscOps) + sizeof(pops)))

The "size" of the malloced space is funky in the PetscBag case so you cannot directly do the PetscHeaderCreate() to create the PetscBag.
 
At this time I vote that you add the PetscBagSetOptionsPrefix() directly for Bags and do not turn the Bag into a real PetscObject.

   Barry

On Apr 8, 2011, at 12:29 PM, Ethan Coon wrote:

> 
> I'm using a couple of bags in an application, and that application is in
> turn being used in a domain-decomposition algorithm with multiple
> domains (each an instance of the application).  So I'd like to set the
> options prefix of the bag, so that each application instance has its own
> prefix and can be used with the same options "database."  Currently
> PetscBag passes PETSC_NULL for the prefix.
> 
> To fix this, it looks like the best option would be to have a
> PetscBagSetOptionsPrefix() in the same mold as everything else.  I added
> this, and then found out that PetscBag isn't a PetscObject, in the sense
> that it has no header or CLASS_ID (so PetscObjectSetOptionsPrefix()
> doesn't work on a bag).
> 
> Is this the best way forward, to make PetscBag a PetscObject, with
> CLASS_ID, etc?  And if so, is there a good example of this that I should
> follow to do so?
> 
> Thanks,
> 
> Ethan
> 
> 
> 
> 
> -- 
> ------------------------------------
> Ethan Coon
> Post-Doctoral Researcher
> Applied Mathematics - T-5
> Los Alamos National Laboratory
> 505-665-8289
> 
> http://www.ldeo.columbia.edu/~ecoon/
> ------------------------------------
> 




More information about the petsc-dev mailing list