[petsc-users] Fortran initialization and XXXDestroy

Randall Mackie rlmackie862 at gmail.com
Tue Feb 2 14:27:51 CST 2021


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> 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
> 
> 



More information about the petsc-users mailing list