[petsc-users] PetscFunctionBegin, -malloc_dump and C++ classes with PETSc objects
Miguel Angel Salazar de Troya
salazardetroya at gmail.com
Tue Nov 18 11:19:41 CST 2014
Hi
I'm implementing a problem using the TS. Most of my functions are methods
inside of a class, except for the callbacks (to form the RHS and the TS
monitor), which are outside of the class, although in the same .C file
where the class methods are implemented. For these callbacks I followed the
network example:
https://bitbucket.org/petsc/petsc/src/a614f7369d93d476173b8fc6bf2463276dcbdb3a/src/snes/examples/tutorials/network/pflow/pf.c?at=master
Therefore, the callbacks have the PetscFunctionBegin at the beginning
and PetscFunctionReturn(0) at the end. My problems come when I run the
program with -malloc_dump and I get a lot of unfreed memory. Inspecting the
output I see that the line of my code where the memory is allocated
corresponds with the line when PetscFunctionBegin is called. Later in the
file, I see that the function DMGetLocalVector() is called within a petsc
internal routine (at the file dmget.c). I also call this routine in my
callback methods few lines after PetscFunctionBegin. The procedure that I
follow to use the local vectors is as the one in the network example. For
vectors that I want to modify this is:
ierr = DMGetLocalVector(networkdm,&localX);CHKERRQ(ierr);
ierr =
DMGlobalToLocalBegin(networkdm,X,INSERT_VALUES,localX);CHKERRQ(ierr);
ierr = DMGlobalToLocalEnd(networkdm,X,INSERT_VALUES,localX);CHKERRQ(ierr);
ierr = VecGetArray(localX,&xarr);CHKERRQ(ierr);
Modify values in xarr
ierr = VecRestoreArray(localX,&xarr);CHKERRQ(ierr);
ierr =
DMLocalToGlobalBegin(networkdm,localX,INSERT_VALUES,X);CHKERRQ(ierr);
ierr = DMLocalToGlobalEnd(networkdm,localX,INSERT_VALUES,X);CHKERRQ(ierr);
ierr = DMRestoreLocalVector(networkdm,&localX);CHKERRQ(ierr);
One last thing that I think it might be a issue here is how I destroy the
petsc objects. I create the petsc objects within a class. For instance, the
class has a petsc vector that later passes to the TS object to get the
solution. To destroy the petsc objects, I use the class destructor, where
at the end I call PetscFinalize() Inside the class I pass the callbacks to
the TS routines that need them (e.g. TSSetRHSFunction() ) I can compile the
code and run it, but many memory allocations are not freed. What can be the
issue here? Do you know of an example using C++ classes to implement PETSc
methods? Thanks in advance.
Miguel
--
*Miguel Angel Salazar de Troya*
Graduate Research Assistant
Department of Mechanical Science and Engineering
University of Illinois at Urbana-Champaign
(217) 550-2360
salaza11 at illinois.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141118/33c8334b/attachment.html>
More information about the petsc-users
mailing list