<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=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 3, 2021, at 6:07 AM, Mark Adams <<a href="mailto:mfadams@lbl.gov" class="">mfadams@lbl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Perhaps a custom Fortran interface that checks for FORTRAN_TYPE_INITIALIZE. <div class="">That was the first thing that I looked for.</div></div></div></blockquote><div><br class=""></div>   This would mean tons more custom interfaces which are a pain to write and often forgotten. I think someone should just try changing to 0.</div><div><br class=""></div><div>    Note we can still have a check if not initialized and a check if initialized for users (not that they should use them much).</div><div><br class=""></div><div>Barry</div><div><br class=""><blockquote type="cite" class=""><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 2, 2021 at 11:31 PM Satish Balay <<a href="mailto:balay@mcs.anl.gov" class="">balay@mcs.anl.gov</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I think the current code is to support:<br class="">
<br class="">
if (var not initialized): crate(var).<br class="">
<br class="">
And there might be some mapping of 0 to NULL or some other state (hence the choice of -2)<br class="">
<br class="">
Satish<br class="">
<br class="">
On Tue, 2 Feb 2021, Barry Smith wrote:<br class="">
<br class="">
> <br class="">
>   I cannot remember why I selected -2 as the initial value for PETSc objects in Fortran. Probably because it would ensure a dramatic crash if you used <br class="">
> an object without initializing it from Fortran.<br class="">
> <br class="">
>   It could be changing <br class="">
> <br class="">
> config/BuildSystem/config/compilersFortran.py:      self.addDefine('FORTRAN_TYPE_INITIALIZE', ' = -2') <br class="">
> <br class="">
> to 0 would mean that if you called destroy on the object and never created it everything would be fine; so you would not need to use any special code to check.<br class="">
> <br class="">
> Would that be a better model?<br class="">
> <br class="">
>   Barry<br class="">
> <br class="">
> <br class="">
> <br class="">
> > On Feb 2, 2021, at 2:34 PM, Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank" class="">mfadams@lbl.gov</a>> wrote:<br class="">
> > <br class="">
> > Thanks Randy, that makes sense.<br class="">
> > Mark<br class="">
> > <br class="">
> > On Tue, Feb 2, 2021 at 3:27 PM Randall Mackie <<a href="mailto:rlmackie862@gmail.com" target="_blank" class="">rlmackie862@gmail.com</a> <mailto:<a href="mailto:rlmackie862@gmail.com" target="_blank" class="">rlmackie862@gmail.com</a>>> wrote:<br class="">
> > Hi Mark,<br class="">
> > <br class="">
> > I don’t know what the XGC code is, but the way I do this in my Fortran code is that I initialize all objects I later want to destroy, for example:<br class="">
> > <br class="">
> > mat11=PETSC_NULL_MAT<br class="">
> > vec1=PETSC_NULL_VEC<br class="">
> > <br class="">
> > etc<br class="">
> > <br class="">
> > Then I check and destroy like:<br class="">
> > <br class="">
> > if (mat11 /= PETSC_NULL_MAT) call MatDestroy(mat11, ierr)<br class="">
> > <br class="">
> > etc.<br class="">
> > <br class="">
> > Hope this helps,<br class="">
> > <br class="">
> > Randy<br class="">
> > <br class="">
> > <br class="">
> > > On Feb 2, 2021, at 12:17 PM, Mark Adams <<a href="mailto:mfadams@lbl.gov" target="_blank" class="">mfadams@lbl.gov</a> <mailto:<a href="mailto:mfadams@lbl.gov" target="_blank" class="">mfadams@lbl.gov</a>>> wrote:<br class="">
> > > <br class="">
> > > Satish, a few years ago you helped us transition the XGC Fortran code from v3.7.7 and we seemed to have regressed.<br class="">
> > > <br class="">
> > > As I recall we removed the initialization of Mats (for example) in XGC. PETSc seems to initialize them with -2 in Fortran (Albert, cc'ed, verified this today) and I recall that from our previous conversation. As I look at the code now Fortran MatDestroy just goes straight to C, which would explain our crashes when we MatDestroy an uninitialized (-2) Mat.<br class="">
> > > <br class="">
> > > What is the correct way to delete with initializing Fortran objects?<br class="">
> > > <br class="">
> > > Thanks,<br class="">
> > > Mark<br class="">
> > > <br class="">
> > > <br class="">
> > <br class="">
> <br class="">
> <br class="">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>