Thanks Jed for your detailed answer. That is more clear now. <div>So, the most accurate way to find the size of a PETSc object would be to use </div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><b><font class="Apple-style-span" size="4">PetscMallocGetCurrentUsage()</font></b></span></div>
<div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><b><br></b></span></div><div>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?</div>
<div>Thanks again, </div><div>Mohamad</div><div><br></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><b><br></b></span></font></div><div><span class="Apple-style-span" style="font-family: monospace; white-space: pre; "><b><br>
</b></span></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><b><br></b></span></font></div><meta name="qrichtext" content="1"><style type="text/css">
p, li { white-space: pre-wrap; }
</style>
<div><br></div><div><div><br><br><div class="gmail_quote">On Wed, Sep 28, 2011 at 7:10 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im">On Wed, Sep 28, 2011 at 20:44, Mohamad M. Nasr-Azadani <span dir="ltr"><<a href="mailto:mmnasr@gmail.com" target="_blank">mmnasr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks Jed, <div><br></div><div>To get this right, I thought I should get a zero value for the code below: </div><div><br></div><div>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> PetscLogDouble mem1, mem2;</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"></pre><pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> PetscMemoryGetCurrentUsage(&mem1);</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> PetscMemoryGetCurrentUsage(&mem2);</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> printf("mem1:%f mem2:%f memory:%d\n", mem1, mem2, (int)(mem2 - mem1));</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b><span style="font-family:arial;font-weight:normal;white-space:normal"><div>
<br></div><div>What I get is not zero! </div><div></div></span></b></pre><pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b><div style="font-family:arial;font-weight:normal;white-space:normal">
<div>"mem1:3047424.000000 mem2:3076096.000000 memory:28672"</div></div></b></pre></div></blockquote><div><br></div></div><div>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.</div>
<div><br></div><div>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.</div>
<div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b><div style="font-family:arial;font-weight:normal;white-space:normal">
<br></div><div style="font-family:arial;font-weight:normal;white-space:normal">
I ran the code with/without the runtime flag -malloc. Also, PETSc is complied without debugging. </div><div style="font-family:arial;font-weight:normal;white-space:normal">I am confused. Apparently, even when I allocate some memory using PetscMalloc() or malloc() between the two </div>
<div><span style="font-family:arial;font-weight:normal;white-space:normal"><pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> PetscMemoryGetCurrentUsage(&mem1);</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> /* some memory allocation using malloc or PescMalloc()</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b> PetscMemoryGetCurrentUsage(&mem2);</b></pre></span></div><div style="font-family:arial;font-weight:normal;white-space:normal">
<br></div><div style="font-family:arial;font-weight:normal;white-space:normal">I still get the same number. </div></b></pre></div></blockquote><div><br></div></div><div>Use PetscMallocGetCurrentUsage() in this case.</div>
</div>
</blockquote></div><br></div></div>