[petsc-users] Updating Fortran code to petsc 3.8
Smith, Barry F.
bsmith at mcs.anl.gov
Mon Oct 30 12:43:16 CDT 2017
Please clarify.
1) You can successfully update to 3.8 and compile and run the code?
2) You do not have a way to support both 3.7 and 3.8 except by putting a large number of #ifdef in the code?
Yes, 3.8 is a dramatic shift in API (to one we feel is much better), it is not simple to write code that works with both versions. We recommend just using a 3.8 version once you verify it behaves as the previous version. Note that on any computer including those at NERSc if 3.8 is not installed by default you may install it yourself.
Barry
> On Oct 30, 2017, at 12:18 PM, Randy Michael Churchill <rchurchi at pppl.gov> wrote:
>
> 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
More information about the petsc-users
mailing list