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

Mohamad M. Nasr-Azadani mmnasr at gmail.com
Wed Sep 28 21:33:29 CDT 2011


Thanks Jed for your detailed answer. That is more clear now.
So, the most accurate way to find the size of a PETSc object would be to
use

*PetscMallocGetCurrentUsage()*
*
*
before and after the block that creation and/or setting values happens? The
reason that I am asking this is I am interested in finding out the size of
KSP solver with BoomerAMG preconditioner. I assume the hypre package does
not use PetscMalloc() and therefore the returned memory size could be not
the most accurate?
Thanks again,
Mohamad

*
*
*
*
*
*



On Wed, Sep 28, 2011 at 7:10 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:

> 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/5b9ecdf0/attachment-0001.htm>


More information about the petsc-users mailing list