[petsc-users] Fortran initialization and XXXDestroy

Barry Smith bsmith at petsc.dev
Wed Feb 3 11:01:16 CST 2021



> On Feb 3, 2021, at 6:07 AM, Mark Adams <mfadams at lbl.gov> wrote:
> 
> Perhaps a custom Fortran interface that checks for FORTRAN_TYPE_INITIALIZE. 
> That was the first thing that I looked for.

   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.

    Note we can still have a check if not initialized and a check if initialized for users (not that they should use them much).

Barry

> 
> On Tue, Feb 2, 2021 at 11:31 PM Satish Balay <balay at mcs.anl.gov <mailto:balay at mcs.anl.gov>> wrote:
> I think the current code is to support:
> 
> if (var not initialized): crate(var).
> 
> And there might be some mapping of 0 to NULL or some other state (hence the choice of -2)
> 
> Satish
> 
> On Tue, 2 Feb 2021, Barry Smith wrote:
> 
> > 
> >   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 
> > an object without initializing it from Fortran.
> > 
> >   It could be changing 
> > 
> > config/BuildSystem/config/compilersFortran.py:      self.addDefine('FORTRAN_TYPE_INITIALIZE', ' = -2') 
> > 
> > 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.
> > 
> > Would that be a better model?
> > 
> >   Barry
> > 
> > 
> > 
> > > On Feb 2, 2021, at 2:34 PM, Mark Adams <mfadams at lbl.gov <mailto:mfadams at lbl.gov>> wrote:
> > > 
> > > Thanks Randy, that makes sense.
> > > Mark
> > > 
> > > On Tue, Feb 2, 2021 at 3:27 PM Randall Mackie <rlmackie862 at gmail.com <mailto:rlmackie862 at gmail.com> <mailto:rlmackie862 at gmail.com <mailto:rlmackie862 at gmail.com>>> wrote:
> > > Hi Mark,
> > > 
> > > 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:
> > > 
> > > mat11=PETSC_NULL_MAT
> > > vec1=PETSC_NULL_VEC
> > > 
> > > etc
> > > 
> > > Then I check and destroy like:
> > > 
> > > if (mat11 /= PETSC_NULL_MAT) call MatDestroy(mat11, ierr)
> > > 
> > > etc.
> > > 
> > > Hope this helps,
> > > 
> > > Randy
> > > 
> > > 
> > > > On Feb 2, 2021, at 12:17 PM, Mark Adams <mfadams at lbl.gov <mailto:mfadams at lbl.gov> <mailto:mfadams at lbl.gov <mailto:mfadams at lbl.gov>>> wrote:
> > > > 
> > > > Satish, a few years ago you helped us transition the XGC Fortran code from v3.7.7 and we seemed to have regressed.
> > > > 
> > > > 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.
> > > > 
> > > > What is the correct way to delete with initializing Fortran objects?
> > > > 
> > > > Thanks,
> > > > Mark
> > > > 
> > > > 
> > > 
> > 
> > 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210203/2aa83e85/attachment-0001.html>


More information about the petsc-users mailing list