<div dir="ltr">OK so I just ran the example under valgrind, and if I use two VecViews, it complains about following leak:<div><br></div><div><div><font face="monospace, monospace">==66838== 24,802 (544 direct, 24,258 indirect) bytes in 1 blocks are definitely lost in loss record 924 of 926</font></div><div><font face="monospace, monospace">==66838==    at 0x100009EBB: malloc (in /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)</font></div><div><font face="monospace, monospace">==66838==    by 0x10005E638: PetscMallocAlign (in /usr/local/Cellar/petsc/3.7.2/real/lib/libpetsc.3.7.2.dylib)</font></div><div><font face="monospace, monospace">==66838==    by 0x100405F00: DMCreate_DA (in /usr/local/Cellar/petsc/3.7.2/real/lib/libpetsc.3.7.2.dylib)</font></div><div><font face="monospace, monospace">==66838==    by 0x1003CFFA4: DMSetType (in /usr/local/Cellar/petsc/3.7.2/real/lib/libpetsc.3.7.2.dylib)</font></div><div><font face="monospace, monospace">==66838==    by 0x100405B7F: DMDACreate (in /usr/local/Cellar/petsc/3.7.2/real/lib/libpetsc.3.7.2.dylib)</font></div><div><font face="monospace, monospace">==66838==    by 0x1003F825F: DMDACreate2d (in /usr/local/Cellar/petsc/3.7.2/real/lib/libpetsc.3.7.2.dylib)</font></div><div><font face="monospace, monospace">==66838==    by 0x100001D89: main (main_test.cpp:7)</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">By I am destroying the dm ... also I dont get this when using a single VecView. As a bonus info, PETSC_VIEWER_STDOUT_WORLD is just fine, so this looks like it is definitely vtk related.</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 3, 2016 at 2:05 PM, Mohammad Mirzadeh <span dir="ltr"><<a href="mailto:mirzadeh@gmail.com" target="_blank">mirzadeh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On Wed, Aug 3, 2016 at 10:59 AM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span>On Tue, Aug 2, 2016 at 12:40 PM, Mohammad Mirzadeh <span dir="ltr"><<a href="mailto:mirzadeh@gmail.com" target="_blank">mirzadeh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>I often use the memory usage information in log_view as a way to check on memory leaks and so far it has worked perfect. However, I had long noticed a false-positive report in memory leak for Viewers, i.e. destruction count is always one less than creation.</div></div></blockquote><div><br></div></span><div>Yes, I believe that is the Viewer being used to print this information.</div></div></div></div></blockquote><div><br></div></span><div>That makes sense. </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Today, I noticed what seems to be a second one. If you use VecView to write the same DA to vtk, i.e. call VecView(A, vtk); twice, it also report a memory leak for vectors, vecscatters, dm, etc. I am calling this a false-positive since the code is valgrind-clean.</div><div><br></div><div>Is this known/expected?</div></div></blockquote><div><br></div></span><div>The VTK viewers have to hold everything they output until they are destroyed since the format does not allow immediate writing.</div><div>I think the VTK viewer is not destroyed at the time of this output. Can you make a small example that does this?</div></div></div></div></blockquote><div><br></div></span><div>Here's a small example that illustrates the issues</div><div><br></div>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)"><petsc.h></span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">main</span><span style="color:rgb(0,0,0)">(</span><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">argc</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">char</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">*</span><span style="color:rgb(0,0,0)">argv</span><span style="color:rgb(0,0,0)">[])</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">{</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,0,0)">PetscInitialize</span><span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">argc</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">argv</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">DM</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">dm</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,0,0)">DMDACreate2d</span><span style="color:rgb(0,0,0)">(</span>PETSC_COMM_WORLD<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">DM_BOUNDARY_NONE</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">DM_BOUNDARY_NONE</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">DMDA_STENCIL_BOX</span><span style="color:rgb(0,0,0)">,</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">               </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(0,0,128)">10</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">-</span><span style="color:rgb(0,0,128)">10</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">PETSC_DECIDE</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">PETSC_DECIDE</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">1</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">NULL</span><span style="color:rgb(0,0,0)">,</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">               </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">dm</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,128,0)">DMDASetUniformCoordinates(dm,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">-1,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">1,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">-1,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">1,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">0,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">0);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">Vec</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">sol</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>DMCreateGlobalVector<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">dm</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">sol</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>VecSet<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">sol</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">PetscViewer</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">vtk</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,0,0)">PetscViewerVTKOpen</span><span style="color:rgb(0,0,0)">(</span>PETSC_COMM_WORLD<span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">"test.vts"</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">FILE_MODE_WRITE</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">&</span><span style="color:rgb(0,0,0)">vtk</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>VecView<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(0,0,0)">sol</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,0)">vtk</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,128,0)">//</span><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,128,0)">VecView(sol,</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">vtk);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>PetscViewerDestroy<span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">vtk</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>DMDestroy<span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">dm</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>VecDestroy<span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(0,0,0)">sol</span><span style="color:rgb(0,0,0)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,0,0)">PetscFinalize</span><span style="color:rgb(0,0,0)">();</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span><span style="color:rgb(0,0,0)">;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,0)">}</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><div>If you uncomment the second VecView you get reports for leaks in VecScatter and dm. If you also uncomment the DMDASetUniformCoordinates, and use both VecViews, you also get a leak report for Vecs ... its quite bizarre ...</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>I have switched to HDF5 and XDMF due to the limitations of VTK format.</div><div><br></div></div></div></div></blockquote><div><br></div></span><div>I had used XDMF + raw binary in the past and was satisfied with the result. Do you write a single XDMF as a "post-processing" step when the simulation is finished? If I remember correctly preview could not open xmf files as time-series.</div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div>  Thanks,</div><div><br></div><div>     Matt</div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Here's the relevant bit from log_view:</div><div><br></div><div><div><font face="monospace, monospace">--- Event Stage 0: Main Stage</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">              Vector     8              7       250992     0.</font></div><div><font face="monospace, monospace">      Vector Scatter     2              0            0     0.</font></div><div><font face="monospace, monospace">    Distributed Mesh     2              0            0     0.</font></div><div><font face="monospace, monospace">Star Forest Bipartite Graph     4              0            0     0.</font></div><div><font face="monospace, monospace">     Discrete System     2              0            0     0.</font></div><div><font face="monospace, monospace">           Index Set     4              4        83136     0.</font></div><div><font face="monospace, monospace">   IS L to G Mapping     2              0            0     0.</font></div><div><font face="monospace, monospace">              Viewer     2              1          784     0.</font></div><div><font face="monospace, monospace">========================================================================================================================</font></div></div><div><br></div></div>
</blockquote></span></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</font></span></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div>