[petsc-users] Checking for NULL Objects in Fortran
Smith, Barry F.
bsmith at mcs.anl.gov
Mon Sep 10 16:30:31 CDT 2018
Sorry for your difficulties
The recent branch barry/change-fortran-null was intended to simplify the handling of NULL slightly in Fortran and make it more consistent with the handling in C. It essentially changed %v to be equal to 0 for NULL objects rather than -1. This allows easier passing objects directly to C code also.
We did not intend to change the user API; we intended that comparisons with PETSC_NULL_DM would behave exactly as before.
Unfortunately it looks like some places in the code had -1 hardwired, for example,
/* Definitions of Fortran Wrapper routines */
PETSC_EXTERN void PETSC_STDCALL dmplexdistribute_(DM *dm, PetscInt *overlap, PetscSF *sf, DM *dmParallel, int *ierr)
{
CHKFORTRANNULLOBJECT(sf);
CHKFORTRANNULLOBJECT(dmParallel);
*ierr = DMPlexDistribute(*dm, *overlap, sf, dmParallel);
if (dmParallel && !*dmParallel) *dmParallel = (DM)-1;
}
I did not know about this hardwiring and thus did not update them while making the new branch.
The branch barry/change-fortran-null-fixup fixes the two bad uses of -1 that you pointed out. Please try it and let us know other problems that come up since we are planning a release very shortly.
> On Sep 10, 2018, at 4:02 PM, Fabian.Jakub <Fabian.Jakub at physik.uni-muenchen.de> wrote:
>
> Greetings my dear PETSc list.
>
> In my Fortran Code, I usually checked against PETSC_NULL_DM or
> PETSC_NULL_IS after calling methods such as DMPlexDistribute or
> DMGetStratumIS.
>
> Recently this fails me.
>
> I saw the DMPlexDistribute example in
> dm/label/examples/tutorials/ex1f90.F90
>
> where the value of dm_distributed%v is compared against -1
We do not recommend the usage of dm_distributed%v /= 0 and instead recommend comparing with the appropriate PETSC_NULL_XXX as you have done. (the %v business will work, we just don't recommend it).
>
> Now, after the recent change of PETSC_NULL_DM (tDM(1) -> tDM(0) in
> 3d1df95b1) I am not 100% percent sure how to deal with it.
>
> Could you please clarify if testing against ``-1`` is the intended way
> to do it or may this change again soonish?
Definitely not. Your code should remain the same and we simply need to fix the stray -1 to change them to 0.
Barry
>
> Many Thanks,
>
> Fabian
>
>
> Here some code snippets to clarify what lead me to put up this question...
>
> This used to validate:
>
> call DMGetStratumIS(dm, 'DomainBoundary', SIDEFACE, bc_idx, ierr)
> if (bc_ids.eq.PETSC_NULL_IS) then ! dont have domain boundary points
> ...
> endif
>
> or
>
> call DMPlexDistribute(dm, i0, PETSC_NULL_SF, dmdist, ierr)
> if (dmdist.eq.PETSC_NULL_DM) then ! DM was not distributed
> endif
>
>
> Now I could do something like:
>
> if(bc_ids%v.eq.-1)
>
> of (dmdist%v.eq.-1)
>
> ...
>
More information about the petsc-users
mailing list