<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hong,<div class=""><br class=""></div><div class="">can you explain what’s the rationale behind calling explicitly the Layout and header destroy for the submit case in the loop here <a href="https://bitbucket.org/petsc/petsc/src/ac3af1b492556bac9856a6aee1c73992bd0b1779/src/mat/impls/aij/seq/aij.c?at=master&fileviewer=file-view-default#aij.c-2531" class="">https://bitbucket.org/petsc/petsc/src/ac3af1b492556bac9856a6aee1c73992bd0b1779/src/mat/impls/aij/seq/aij.c?at=master&fileviewer=file-view-default#aij.c-2531</a></div><div class=""><br class=""></div><div class="">A code like this fails since you don’t take into account reference counting on the submatrices.</div><div class=""><br class=""></div><div class="">MatCreateSubMatrices(A,….&submats)</div><div class="">PetscObjectCompose(B,”_XXXX”,submats[0);</div><div class="">…..</div><div class="">MatDestroySubMatrices(..,submats);</div><div class="">MatDestroy(B); //Error, corrupt argument when trying to destroy composed objects</div><div class=""><br class=""></div><div class="">Here is a representative valgrind stack trace</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133== Invalid read of size 4</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    at 0x100368F63: PetscCheckPointer (/Users/szampini/software/petsc/src/sys/error/checkptr.c:108)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1001ACA9F: PetscObjectDereference (/Users/szampini/software/petsc/src/sys/objects/inherit.c:564)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x10019AC07: PetscObjectListDestroy (/Users/szampini/software/petsc/src/sys/objects/olist.c:154)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1001A8176: PetscHeaderDestroy_Private (/Users/szampini/software/petsc/src/sys/objects/inherit.c:115)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100626CAD: MatDestroy (/Users/szampini/software/petsc/src/mat/interface/matrix.c:1237)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">==90133==  Address 0x106c4c320 is 1,632 bytes inside a block of size 4,420 free'd</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    at 0x10014C9F3: free (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100229B7A: PetscFreeAlign (/Users/szampini/software/petsc/src/sys/memory/mal.c:88)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x10022D771: PetscTrFreeDefault (/Users/szampini/software/petsc/src/sys/memory/mtr.c:309)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100A7034D: MatDestroySubMatrices_SeqAIJ (/Users/szampini/software/petsc/src/mat/impls/aij/seq/aij.c:2549)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1006260BD: MatDestroySubMatrices (/Users/szampini/software/petsc/src/mat/interface/matrix.c:6957)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1006D82EC: _DestroyContainer</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1001AFA31: PetscContainerDestroy (/Users/szampini/software/petsc/src/sys/objects/inherit.c:899)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1001ACBE5: PetscObjectDereference (/Users/szampini/software/petsc/src/sys/objects/inherit.c:566)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x10019AC07: PetscObjectListDestroy (/Users/szampini/software/petsc/src/sys/objects/olist.c:154)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1001A8176: PetscHeaderDestroy_Private (/Users/szampini/software/petsc/src/sys/objects/inherit.c:115)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100626CAD: MatDestroy (/Users/szampini/software/petsc/src/mat/interface/matrix.c:1237)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">==90133==  Block was alloc'd at</div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    at 0x10014C616: malloc (in /usr/local/Cellar/valgrind/3.13.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x1002299AC: PetscMallocAlign (/Users/szampini/software/petsc/src/sys/memory/mal.c:48)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x10022CA73: PetscTrMallocDefault (/Users/szampini/software/petsc/src/sys/memory/mtr.c:183)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x10022B328: PetscMallocA (/Users/szampini/software/petsc/src/sys/memory/mal.c:396)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100C12E05: MatCreate (/Users/szampini/software/petsc/src/mat/utils/gcreate.c:89)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100B839F6: MatCreateSubMatrices_MPIAIJ_Local (/Users/szampini/software/petsc/src/mat/impls/aij/mpi/mpiov.c:2554)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x100B7DEE7: MatCreateSubMatrices_MPIAIJ (/Users/szampini/software/petsc/src/mat/impls/aij/mpi/mpiov.c:2038)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">==90133==    by 0x10066703A: MatCreateSubMatrices (/Users/szampini/software/petsc/src/mat/interface/matrix.c:6806)</span></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div></div></body></html>