<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Stefano:</div><div class="gmail_quote">Sorry, I do not understand your question. Where comes matrix B?</div><div class="gmail_quote">Can you give me an example of this error?</div><div class="gmail_quote">Hong</div><div class="gmail_quote"><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hong,<div><br></div><div>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" target="_blank">https://bitbucket.org/<wbr>petsc/petsc/src/<wbr>ac3af1b492556bac9856a6aee1c739<wbr>92bd0b1779/src/mat/impls/aij/<wbr>seq/aij.c?at=master&<wbr>fileviewer=file-view-default#<wbr>aij.c-2531</a></div><div><br></div><div>A code like this fails since you don’t take into account reference counting on the submatrices.</div><div><br></div><div>MatCreateSubMatrices(A,….&<wbr>submats)</div><div>PetscObjectCompose(B,”_XXXX”,<wbr>submats[0);</div><div>…..</div><div>MatDestroySubMatrices(..,<wbr>submats);</div><div>MatDestroy(B); //Error, corrupt argument when trying to destroy composed objects</div><div><br></div><div>Here is a representative valgrind stack trace</div><div><br></div><div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    at 0x100368F63: PetscCheckPointer (/Users/szampini/software/<wbr>petsc/src/sys/error/checkptr.<wbr>c:108)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1001ACA9F: PetscObjectDereference (/Users/szampini/software/<wbr>petsc/src/sys/objects/inherit.<wbr>c:564)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x10019AC07: PetscObjectListDestroy (/Users/szampini/software/<wbr>petsc/src/sys/objects/olist.c:<wbr>154)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1001A8176: PetscHeaderDestroy_Private (/Users/szampini/software/<wbr>petsc/src/sys/objects/inherit.<wbr>c:115)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100626CAD: MatDestroy (/Users/szampini/software/<wbr>petsc/src/mat/interface/<wbr>matrix.c:1237)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">==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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    at 0x10014C9F3: free (in /usr/local/Cellar/valgrind/3.<wbr>13.0/lib/valgrind/vgpreload_<wbr>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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100229B7A: PetscFreeAlign (/Users/szampini/software/<wbr>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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x10022D771: PetscTrFreeDefault (/Users/szampini/software/<wbr>petsc/src/sys/memory/mtr.c:<wbr>309)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100A7034D: MatDestroySubMatrices_SeqAIJ (/Users/szampini/software/<wbr>petsc/src/mat/impls/aij/seq/<wbr>aij.c:2549)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1006260BD: MatDestroySubMatrices (/Users/szampini/software/<wbr>petsc/src/mat/interface/<wbr>matrix.c:6957)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1001AFA31: PetscContainerDestroy (/Users/szampini/software/<wbr>petsc/src/sys/objects/inherit.<wbr>c:899)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1001ACBE5: PetscObjectDereference (/Users/szampini/software/<wbr>petsc/src/sys/objects/inherit.<wbr>c:566)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x10019AC07: PetscObjectListDestroy (/Users/szampini/software/<wbr>petsc/src/sys/objects/olist.c:<wbr>154)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1001A8176: PetscHeaderDestroy_Private (/Users/szampini/software/<wbr>petsc/src/sys/objects/inherit.<wbr>c:115)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100626CAD: MatDestroy (/Users/szampini/software/<wbr>petsc/src/mat/interface/<wbr>matrix.c:1237)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)">==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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    at 0x10014C616: malloc (in /usr/local/Cellar/valgrind/3.<wbr>13.0/lib/valgrind/vgpreload_<wbr>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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x1002299AC: PetscMallocAlign (/Users/szampini/software/<wbr>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)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x10022CA73: PetscTrMallocDefault (/Users/szampini/software/<wbr>petsc/src/sys/memory/mtr.c:<wbr>183)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x10022B328: PetscMallocA (/Users/szampini/software/<wbr>petsc/src/sys/memory/mal.c:<wbr>396)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100C12E05: MatCreate (/Users/szampini/software/<wbr>petsc/src/mat/utils/gcreate.c:<wbr>89)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100B839F6: MatCreateSubMatrices_MPIAIJ_<wbr>Local (/Users/szampini/software/<wbr>petsc/src/mat/impls/aij/mpi/<wbr>mpiov.c:2554)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x100B7DEE7: MatCreateSubMatrices_MPIAIJ (/Users/szampini/software/<wbr>petsc/src/mat/impls/aij/mpi/<wbr>mpiov.c:2038)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><span style="font-variant-ligatures:no-common-ligatures">==90133==    by 0x10066703A: MatCreateSubMatrices (/Users/szampini/software/<wbr>petsc/src/mat/interface/<wbr>matrix.c:6806)</span></div><div style="margin:0px;font-size:14px;line-height:normal;font-family:Menlo;background-color:rgb(255,255,255)"><br></div></div></div></blockquote></div><br></div></div>