<div dir="ltr">Hong,<div><br></div><div>I think  what you wrote is conceptually wrong, being in the interface part of the library.</div><div>The extra allocation is not done consistently throughout all the specific implementations that MatCreateSubMatrices can use.</div><div>Here is an excerpt of a valgrind error I'm getting</div><div><br></div><div><div>==37303== Conditional jump or move depends on uninitialised value(s)</div><div>==37303==    at 0xA94B0D7: MatDestroySubMatrices (/home/szampini/src/petsc/src/mat/interface/matrix.c:6890)</div><div>==37303==    by 0xAFA0400: PCBDDCSubSchursSetUp (/home/szampini/src/petsc/src/ksp/pc/impls/bddc/bddcschurs.c:1545)</div></div><div><div>.....</div><div>==37303==  Uninitialised value was created by a heap allocation</div><div>==37303==    at 0x4C2FF83: memalign (/builddir/build/BUILD/valgrind-3.12.0/coregrind/m_replacemalloc/vg_replace_malloc.c:858)</div><div>==37303==    by 0x9FA172C: PetscMallocAlign (/home/szampini/src/petsc/src/sys/memory/mal.c:39)</div><div>==37303==    by 0x9FA4044: PetscTrMallocDefault (/home/szampini/src/petsc/src/sys/memory/mtr.c:183)</div><div>==37303==    by 0xA87BE20: MatCreateSubMatrix_MPIAIJ_All (/home/szampini/src/petsc/src/mat/impls/aij/mpi/mpiov.c:1082)</div><div>==37303==    by 0xA8852F1: MatCreateSubMatrices_MPIAIJ (/home/szampini/src/petsc/src/mat/impls/aij/mpi/mpiov.c:2024)</div><div>==37303==    by 0xA9490C3: MatCreateSubMatrices (/home/szampini/src/petsc/src/mat/interface/matrix.c:6742)</div><div>==37303==    by 0xAF9F401: PCBDDCSubSchursSetUp (/home/szampini/src/petsc/src/ksp/pc/impls/bddc/bddcschurs.c:1506)</div></div><div><br></div><div>You can see the calling sequence, so that maybe I'm doing something wrong in bddcschurs.c.</div><div><br></div><div>Thanks,</div><div>Stefano</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-12 22:20 GMT+03:00 Hong <span dir="ltr"><<a href="mailto:hzhang@mcs.anl.gov" target="_blank">hzhang@mcs.anl.gov</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">MatCreateSubMatrices_xxx() calloc an array of size n+1, n=ismax and submat[n]=null as default.<div><br><div>For MatCreateSubMatrices_<wbr>MPIAIJ(), I calloc ismax+nstages and use </div><div>submat[n] ... to store some datastructures for reuse.</div><div><br></div><div>When submat[n] != null, these data structures are destroyed.</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888">Hong</font></span><div><div class="h5"><br><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 12, 2017 at 11:29 AM, Stefano Zampini <span dir="ltr"><<a href="mailto:stefano.zampini@gmail.com" target="_blank">stefano.zampini@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Is line number 6890 of matrix.c correct???<div><br></div><div><a href="https://bitbucket.org/petsc/petsc/src/b02a13eda23b9fabea7dbfcadcfb98e3258ee49d/src/mat/interface/matrix.c?at=master&fileviewer=file-view-default#matrix.c-6890" target="_blank">https://bitbucket.org/petsc/pe<wbr>tsc/src/b02a13eda23b9fabea7dbf<wbr>cadcfb98e3258ee49d/src/mat/<wbr>interface/matrix.c?at=master&<wbr>fileviewer=file-view-default#<wbr>matrix.c-6890</a><span class="m_-9002348180672752337gmail-HOEnZb"><font color="#888888"><br clear="all"><div><br></div>-- <br><div class="m_-9002348180672752337gmail-m_4119919259534487923gmail_signature">Stefano</div>
</font></span></div></div>
</blockquote></div><br></div></div></div></div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Stefano</div>
</div>