<div class="gmail_quote">On Wed, Sep 28, 2011 at 20:44, Mohamad M. Nasr-Azadani <span dir="ltr">&lt;<a href="mailto:mmnasr@gmail.com">mmnasr@gmail.com</a>&gt;</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(&amp;mem1);</b></pre>

<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b>    PetscMemoryGetCurrentUsage(&amp;mem2);</b></pre>
<pre style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><b>    printf(&quot;mem1:%f mem2:%f memory:%d\n&quot;, 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>&quot;mem1:3047424.000000 mem2:3076096.000000 memory:28672&quot;</div></div></b></pre></div></blockquote><div><br></div><div>So it&#39;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&#39;t allocate memory, it just promises to find it if you eventually &quot;fault&quot; 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&#39;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&#39;t work that way. You have to live with this or ask a different question of the system.</div>
<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(&amp;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(&amp;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>Use PetscMallocGetCurrentUsage() in this case.</div></div>