[petsc-users] Memory usage of KSP (or any PETSc object)

Mohamad M. Nasr-Azadani mmnasr at gmail.com
Wed Sep 28 20:44:37 CDT 2011


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"


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.

Thanks for your help,
Mohamad

*

On Wed, Sep 28, 2011 at 3:26 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> On Tue, Sep 27, 2011 at 23:29, Mohamad M. Nasr-Azadani <mmnasr at gmail.com>wrote:
>
>> I am a bit puzzled by how this function works.
>> I was trying it on this simple example:
>>
>> PetscMemoryGetMaximumUsage(&mem1);
>>
>>     PetscMalloc(1*sizeof(double), &aa);
>>
>>     PetscMemoryGetMaximumUsage(&mem2);
>>
>>
>> The difference I get for (mem2-mem1) is zero.
>>
>
> The maximum usage is actually only updated when objects are destroyed. You
> can call PetscMemoryGetCurrentUsage() to see how much is used by everything
> used by the application (not just PETSc). When using tracing malloc (default
> in debug mode or when run with -malloc). You can use
> PetscMallocGetCurrentUsage() and PetscMallocGetMaximumUsage() at any time
> and it should be a current measure of what PETSc has allocated (not just
> after destroying objects), but does not measure anything allocated directly
> by the application (e.g. by calling malloc directly, C++ new, Fortran
> arrays).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110928/d0eab10a/attachment.htm>


More information about the petsc-users mailing list