<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>  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 </div><div>an object without initializing it from Fortran.</div><div><br class=""></div><div>  It could be changing </div><div><span style="font-family: Menlo; font-size: 14px; font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div><span style="font-family: Menlo; font-size: 14px; font-variant-ligatures: no-common-ligatures;" class="">config/BuildSystem/config/compilersFortran.py</span><span style="font-family: Menlo; font-size: 14px; font-variant-ligatures: no-common-ligatures; color: rgb(46, 174, 187);" class="">:</span><span style="font-family: Menlo; font-size: 14px; font-variant-ligatures: no-common-ligatures;" class="">      self.addDefine('</span><span style="font-family: Menlo; font-size: 14px; font-variant-ligatures: no-common-ligatures; color: rgb(180, 36, 25);" class=""><b class="">FORTRAN_TYPE_INITIALIZE</b></span><span style="font-family: Menlo; font-size: 14px; font-variant-ligatures: no-common-ligatures;" class="">', ' = -2') </span></div><div><font face="Menlo" class=""><span style="font-size: 14px;" class=""><br class=""></span></font></div><div>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.</div><div><br class=""></div><div>Would that be a better model?</div><div><br class=""></div><div>  Barry</div><div><br class=""></div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On Feb 2, 2021, at 2:34 PM, 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="">Thanks Randy, that makes sense.<div class="">Mark</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 2, 2021 at 3:27 PM Randall Mackie <<a href="mailto:rlmackie862@gmail.com" class="">rlmackie862@gmail.com</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">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>> 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="">
</blockquote></div>
</div></blockquote></div><br class=""></body></html>