changes for PetscMap

Barry Smith bsmith at
Tue Oct 27 16:37:43 CDT 2009

    PetscMap is a strange beast in PETSc.

1) it is not a PetscObject (that is it has no PETSc header)
2) it is used as a PetscMap* instead of PetscMap like most objects
3) it does not have a PetscMapCreate() instead it has a  
PetscMapInitialize() which is like a create except it does not malloc  
its memory
4) It does have a PetscMapDestroy() that DOES free the space.
5) Sometimes a PetscMalloc() is called before PetscMapInitialize() and  
sometimes a PetscMap is declared and a & of the variable is passed in
     In this case it will crash if one calls PetscMapDestroy() is  
called on it. So instead one must call PetscFree(map->range); to free  
the interior space.

   This strange creature evolved over time because I did not want  
PetscMap to be a full heavy weight object, but it pretty much ended up  
being one anyways (for example it has reference counting). For a long  
time I hid PetscMap in the less public part of PETSc didn't want most  
people to have to deal with it.

    I still don't want it to be something most PETSc users need ever  
see, but it is time to fix it up and make it more consistent with  
other objects. So I propose to make a PetscMap just like other PETSc  
objects, with create(), destroy(), opaque definition except I will  
still not make it have a PETSc header. This will not require much  
change in the code but will simplify its usage.

   Any comments.


More information about the petsc-dev mailing list