<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><br class=""></div> Ahh, this makes perfect sense.<div class=""><br class=""></div><div class=""> The code for PetscObjectRegisterDestroy() and the actual destruction (called in PetscFinalize()) is very simply and can be found in src/sys/objects/destroy.c PetscObjectRegisterDestroy(), PetscObjectRegisterDestroyAll(). </div><div class=""><br class=""></div><div class=""> You could easily maintain a new array like PetscObjectRegisterGCDestroy_Objects[] and add objects with PetscObjectRegisterGCDestroy() and then destroy them with PetscObjectRegisterDestroyGCAll(). The only tricky part is that you have to have, in the context of your Julia MPI, make sure that PetscObjectRegisterDestroyGCAll() is called collectively over all the MPI ranks (that is it has to be called where all the ranks have made the same progress on MPI communication) that have registered objects to destroy, generally PETSC_COMM_ALL. We would be happy to incorporate such a system into the PETSc source with a merge request.</div><div class=""><br class=""></div><div class=""> Barry<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 23, 2021, at 10:40 PM, Alberto F. Martín <<a href="mailto:amartin@cimne.upc.edu" class="">amartin@cimne.upc.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
<div class=""><p class="">Thanks all for your very insightful answers. <br class="">
</p><p class="">We are leveraging PETSc from Julia in a parallel distributed
memory context (several MPI tasks running the Julia REPL each).</p><p class="">Julia uses Garbage Collection (GC), and we would like to destroy
the PETSc objects automatically when the GC decides so along the
simulation.<br class="">
</p><p class="">In this context, we cannot guarantee deterministic destruction on
all MPI tasks as the GC decisions are local to each task, no
global semantics guaranteed.</p><p class=""> As far as I understand from your answers, there seems to be the
possibility to defer the destruction of objects till points in the
parallel program in which you can guarantee collective semantics,
correct? If yes I guess that this may occur at any point in the
simulation, not necessarily at shut down via PetscFinalize(),
right? <br class="">
</p><p class="">Best regards,</p><p class=""> Alberto.<br class="">
</p><p class=""> <br class="">
</p>
<div class="moz-cite-prefix">On 24/10/21 1:10 am, Jacob
Faibussowitsch wrote:<br class="">
</div>
<blockquote type="cite" cite="mid:171199C7-42C9-4D5C-96FD-83F08CFA33A8@gmail.com" class="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
Depending on the use-case you may also find
PetscObjectRegisterDestroy() useful. If you can’t guarantee your
PetscObjectDestroy() calls are collective, but have some other
collective section you may call it then to punt the destruction of
your object to PetscFinalize() which is guaranteed to be
collective.
<div class=""><br class="">
</div>
<div class=""><a href="https://petsc.org/main/docs/manualpages/Sys/PetscObjectRegisterDestroy.html" class="" moz-do-not-send="true">https://petsc.org/main/docs/manualpages/Sys/PetscObjectRegisterDestroy.html</a></div>
<div class=""><br class="">
<div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">Best regards,<br class="">
<br class="">
Jacob Faibussowitsch<br class="">
(Jacob Fai - booss - oh - vitch)<br class="">
</div>
</div>
</div>
</div>
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On Oct 22, 2021, at 23:33, Jed Brown <<a href="mailto:jed@jedbrown.org" class="" moz-do-not-send="true">jed@jedbrown.org</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<meta charset="UTF-8" class="">
<span style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;" class="">Junchao Zhang <</span><a href="mailto:junchao.zhang@gmail.com" style="font-family: Menlo-Regular; font-size: 11px;
font-style: normal; font-variant-caps: normal;
font-weight: normal; letter-spacing: normal; orphans:
auto; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-size-adjust: auto;
-webkit-text-stroke-width: 0px;" class="" moz-do-not-send="true">junchao.zhang@gmail.com</a><span style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;" class="">> writes:</span><br style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;" class="">
<br style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;" class="">
<blockquote type="cite" style="font-family: Menlo-Regular;
font-size: 11px; font-style: normal; font-variant-caps:
normal; font-weight: normal; letter-spacing: normal;
orphans: auto; text-align: start; text-indent: 0px;
text-transform: none; white-space: normal; widows: auto;
word-spacing: 0px; -webkit-text-size-adjust: auto;
-webkit-text-stroke-width: 0px; text-decoration: none;" class="">On Fri, Oct 22, 2021 at 9:13 PM Barry Smith
<<a href="mailto:bsmith@petsc.dev" class="" moz-do-not-send="true">bsmith@petsc.dev</a>> wrote:<br class="">
<br class="">
<blockquote type="cite" class=""><br class="">
One technical reason is that
PetscHeaderDestroy_Private() may call<br class="">
PetscCommDestroy() which may call MPI_Comm_free()
which is defined by the<br class="">
standard to be collective. Though PETSc tries to limit
its use of new MPI<br class="">
communicators (for example generally many objects
shared the same<br class="">
communicator) if we did not free those we no longer
need when destroying<br class="">
objects we could run out.<br class="">
<br class="">
</blockquote>
PetscCommDestroy() might call MPI_Comm_free() , but it
is very unlikely.<br class="">
Petsc uses reference counting on communicators, so in
PetscCommDestroy(),<br class="">
it likely just decreases the count. In other words,
PetscCommDestroy() is<br class="">
cheap and in effect not collective.<br class="">
</blockquote>
<br style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;" class="">Unless it's the last reference to
a given communicator, which is a risky/difficult thing
for a user to guarantee and the consequences are
potentially dire (deadlock being way worse than a crash)
when the user's intent is to relax ordering for
destruction.</span><br style="caret-color: rgb(0, 0, 0);
font-family: Menlo-Regular; font-size: 11px; font-style:
normal; font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;" class="">
<br style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family:
Menlo-Regular; font-size: 11px; font-style: normal;
font-variant-caps: normal; font-weight: normal;
letter-spacing: normal; text-align: start; text-indent:
0px; text-transform: none; white-space: normal;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration: none; float: none; display: inline
!important;" class="">Alberto, what is the use case in
which deterministic destruction is problematic? If you
relax it for individual objects, is there a place you
can be collective to collect any stale communicators?</span></div>
</blockquote>
</div>
<br class="">
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
Alberto F. Martín-Huertas
Senior Researcher, PhD. Computational Science
Centre Internacional de Mètodes Numèrics a l'Enginyeria (CIMNE)
Parc Mediterrani de la Tecnologia, UPC
Esteve Terradas 5, Building C3, Office 215,
08860 Castelldefels (Barcelona, Spain)
Tel.: (+34) 9341 34223
<a class="moz-txt-link-abbreviated" href="mailto:e-mail:amartin@cimne.upc.edu">e-mail:amartin@cimne.upc.edu</a>
FEMPAR project co-founder
web: <a class="moz-txt-link-freetext" href="http://www.fempar.org/">http://www.fempar.org</a>
**********************
IMPORTANT ANNOUNCEMENT
The information contained in this message and / or attached file (s), sent from CENTRO INTERNACIONAL DE METODES NUMERICS EN ENGINYERIA-CIMNE,
is confidential / privileged and is intended to be read only by the person (s) to the one (s) that is directed. Your data has been incorporated
into the treatment system of CENTRO INTERNACIONAL DE METODES NUMERICS EN ENGINYERIA-CIMNE by virtue of its status as client, user of the website,
provider and / or collaborator in order to contact you and send you information that may be of your interest and resolve your queries.
You can exercise your rights of access, rectification, limitation of treatment, deletion, and opposition / revocation, in the terms established
by the current regulations on data protection, directing your request to the postal address C / Gran Capitá, s / n Building C1 - 2nd Floor -
Office C15 -Campus Nord - UPC 08034 Barcelona or via email to <a class="moz-txt-link-abbreviated" href="mailto:dpo@cimne.upc.edu">dpo@cimne.upc.edu</a>
If you read this message and it is not the designated recipient, or you have received this communication in error, we inform you that it is
totally prohibited, and may be illegal, any disclosure, distribution or reproduction of this communication, and please notify us immediately.
and return the original message to the address mentioned above.</pre>
</div>
</div></blockquote></div><br class=""></div></body></html>