[petsc-users] Updating Fortran code to petsc 3.8
Randy Michael Churchill
rchurchi at pppl.gov
Mon Oct 30 12:18:21 CDT 2017
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.:
module modmat
#include <petsc/finclude/petsc.h>
#include <petsc/finclude/petscmat.h>
use petsc
use petscmat
type mymat
Mat :: Amat
end type mymat
contains
subroutine mymat_init(this)
this%Amat = 0
end subroutine mymat_init
end module modmat
program main
use modmat
implicit none
type(mymat)::mymat1
call mymat_init(mymat1)
call somethingamazing(mymat1)
end program main
subroutine somethingamazing(this)
use modmat
typ(mymat) :: this
if (this%Amat == 0) then
print 'Amat not initialized'
endif
end subroutine somethingamazing
However, with Petsc 3.8, if I set Amat to 0, I get the error:
error #6303: The assignment operation or the binary expression operation is
invalid for the data types of the two operands.
I replaced the 0 with PETSC_NULL_MAT, but then the if statement gives an
error:
error #6355: This binary operation is invalid for this data type.
I change the if statement to:
if (this%Amat == PETSC_NULL_MAT) then
and it compiles.
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.
--
R. Michael Churchill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20171030/5f31006f/attachment.html>
More information about the petsc-users
mailing list