[petsc-users] Memory usage of KSP (or any PETSc object)
Jed Brown
jedbrown at mcs.anl.gov
Wed Sep 28 21:10:02 CDT 2011
On Wed, Sep 28, 2011 at 20:44, Mohamad M. Nasr-Azadani <mmnasr at gmail.com>wrote:
> Thanks Jed,
>
> To get this right, I thought I should get a zero value for the code below:
>
> * PetscLogDouble mem1, mem2;*
>
> * PetscMemoryGetCurrentUsage(&mem1);*
>
> * PetscMemoryGetCurrentUsage(&mem2);*
>
> * printf("mem1:%f mem2:%f memory:%d\n", mem1, mem2, (int)(mem2 - mem1));*
>
> *
>
>
> What I get is not zero!
> *
>
> *
>
> "mem1:3047424.000000 mem2:3076096.000000 memory:28672"
> *
>
>
So it's important to understand what this function means. It reports the
resident set size for the process. This is not the amount of memory malloced
(malloc doesn't allocate memory, it just promises to find it if you
eventually "fault" it) nor the amount of memory your process is using (pages
could be swapped out, thus not resident; read-only segments can be shared
with other processes and are not counted). Calling malloc and faulting the
memory you get back does not necessarily change the resident size for your
application because the malloc implementation might find it already mapped
and not need to allocate.
This is not a PETSc issue at all, it's just the way operating systems work.
I realize that your profiling would be easier if operating systems had the
semantics that you seem to be expecting, but that would cause far more
problems, so they don't work that way. You have to live with this or ask a
different question of the system.
> *
>
>
>
> I ran the code with/without the runtime flag -malloc. Also, PETSc is complied without debugging.
> I am confused. Apparently, even when I allocate some memory using PetscMalloc() or malloc() between the two
>
> PetscMemoryGetCurrentUsage(&mem1);
>
> /* some memory allocation using malloc or PescMalloc()
>
> PetscMemoryGetCurrentUsage(&mem2);
>
>
> I still get the same number.
> *
>
>
Use PetscMallocGetCurrentUsage() in this case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110928/dfc9018b/attachment.htm>
More information about the petsc-users
mailing list