<div dir="ltr">I'm updating my Fortran code to petsc 3.8. I have several modules with types, and often when a type is initialized in the code, there are certain Petsc variables that aren't ready to be initialized, so they are set to 0. Later, in several parts of the code, these are checked with and if statments, e.g.:<div><br></div><div>module modmat</div><div>#include <petsc/finclude/petsc.h></div><div>#include <petsc/finclude/petscmat.h><br></div><div>use petsc</div><div>use petscmat</div><div><br></div><div>type mymat</div><div>Mat :: Amat</div><div>end type mymat</div><div><br></div><div>contains </div><div> subroutine mymat_init(this)</div><div> this%Amat = 0</div><div> end subroutine mymat_init</div><div>end module modmat</div><div><br></div><div><div><br></div><div>program main</div><div>use modmat</div><div>implicit none</div><div>type(mymat)::mymat1</div><div><br></div><div>call mymat_init(mymat1)</div><div>call somethingamazing(mymat1)</div><div>end program main</div><div><br></div><div><div>subroutine somethingamazing(this)</div><div>use modmat</div><div>typ(mymat) :: this</div><div>if (this%Amat == 0) then</div><div> print 'Amat not initialized'</div><div>endif<br clear="all"><div>end subroutine somethingamazing</div></div></div><div><br></div><div><br></div><div>However, with Petsc 3.8, if I set Amat to 0, I get the error:</div><div>error #6303: The assignment operation or the binary expression operation is invalid for the data types of the two operands.<br></div><div><br></div><div>I replaced the 0 with PETSC_NULL_MAT, but then the if statement gives an error:</div><div>error #6355: This binary operation is invalid for this data type.<br></div><div><br></div><div>I change the if statement to:</div><div>if (this%Amat == PETSC_NULL_MAT) then</div><div>and it compiles. </div><div><br></div><div>Is this the right way to update Fortran code to v3.8? Is there any alternative? My concern is we will have no backwards compatibility, because I believe the specific PETSC_NULL_XXX objects were only introduced in 3.8. So if we update to 3.8, we would either have to drop support for <3.8 or have a lot of #if PETSC_VERSION statements.</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">R. Michael Churchill</div></div>
</div></div>