[petsc-dev] Better DMDestroy()

Lisandro Dalcin dalcinl at gmail.com
Sun Nov 10 04:05:10 CST 2013


In this branch https://bitbucket.org/petsc/petsc/branch/dalcinl/dm-destroy
you will find my attempts to "fix" DMDestroy() by breaking reference
cycles with the vectors stored in the unnamed/named global/local
vector caches.

This work is preliminary, I have a few more things I would like to
change, and currently there is a test (snes ex5) that  leaks memory.

* I'm not sure why the lines below were introduced in DMDestroy(), but
this is certainly not the right way to do it:

  for (f = 0; f < (*dm)->numFields; ++f) {
    PetscObjectCompose((*dm)->fields[f], "pmat", NULL);
    PetscObjectCompose((*dm)->fields[f], "nullspace", NULL);
    PetscObjectCompose((*dm)->fields[f], "nearnullspace", NULL);
  }

* I removed  some lines from PCMG, but Jed told me privately there is
a better way to do it, so I will need help here.

* After reviewing carefully DMCreate[Global|Local]Vector() and some
discussion with Jed, I really believe that the call to
VecSetDM(newvec,dm) should be moved from implementation code to
interface code, i.e. :

@@ -702,6 +702,7 @@ PetscErrorCode  DMCreateGlobalVector(DM dm,Vec *vec)
   PetscFunctionBegin;
   PetscValidHeaderSpecific(dm,DM_CLASSID,1);
   ierr = (*dm->ops->createglobalvector)(dm,vec);CHKERRQ(ierr);
+  ierr = VecSetDM(*vec,dm);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }

Before continuing with this work, I would like your opinions about the
approach. If it is accepted, then I'll proceed to ask for comments on
what remains to be done.



-- 
Lisandro Dalcin
---------------
CIMEC (UNL/CONICET)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1016)
Tel/Fax: +54-342-4511169



More information about the petsc-dev mailing list