[petsc-users] fortran INTENT with petsc object gives segfault after upgrade from 3.8.4 to 3.10.2

Matthew Knepley knepley at gmail.com
Fri Oct 19 13:09:20 CDT 2018


On Fri, Oct 19, 2018 at 10:38 AM Klaij, Christiaan <C.Klaij at marin.nl> wrote:

> As far as I (mis)understand fortran, this is a data protection
> thing: all arguments are passed in from above but the subroutine
> is only allowed to change rr and ierr, not aa and xx (if you try,
> you get a compiler warning). That's why I find it very odd to
> give an intent(in) to rr.


rr is not changed, and it cannot be. You pass in a pointer to the object
and we
fill up the object with values. We cannot change that pointer.

   Matt


> But I've tried your suggestion anyway:
> both intent(in) and intent(inout) for rr do work! Can't say I
> understand though.
>
> Below's a small example of what I was expecting. Change rr to
> intent(in) and the compiler complains.
>
> Chris
>
> $ cat intent.f90
> program intent
>
>   implicit none
>
>   real, allocatable :: aa(:), xx(:), rr(:)
>   integer :: ierr
>
>   allocate(aa(10),xx(10),rr(10))
>
>   aa = 1.0
>   xx = 2.0
>
>   call matmult(aa,xx,rr,ierr)
>
>   print *, rr(1)
>   print *, ierr
>
>   deallocate(aa,xx,rr)
>
>   contains
>
>     subroutine matmult(aa,xx,rr,ierr)
>       real, intent(in) :: aa(:), xx(:)
>       real, intent(out):: rr(:)
>       integer, intent(out) :: ierr
>       rr=aa*xx
>       ierr=0
>     end subroutine matmult
>
> end program intent
> $ ./a.out
>    2.000000
>            0
>
>
>
>
> dr. ir. Christiaan Klaij  | Senior Researcher | Research & Development
> MARIN | T +31 317 49 33 44 | mailto:C.Klaij at marin.nl | http://www.marin.nl
>
> MARIN news:
> http://www.marin.nl/web/News/News-items/Seminar-Scheepsbrandstof-en-de-mondiale-zwavelnorm-2020.htm
>
> ________________________________________
> From: Smith, Barry F. <bsmith at mcs.anl.gov>
> Sent: Friday, October 19, 2018 2:32 PM
> To: Klaij, Christiaan
> Cc: petsc-users at mcs.anl.gov
> Subject: Re: [petsc-users] fortran INTENT with petsc object gives segfault
> after upgrade from 3.8.4 to 3.10.2
>
>    Hmm, the intent of all three first arguments should be in since they
> are passed in from the routine above. Does it work if you replace
>
> >  Vec, INTENT(out) :: rr_system
>
> with
>
> >  Vec, INTENT(in) :: rr_system
>
> ?
>
>     Barry
>
>
> > On Oct 19, 2018, at 3:51 AM, Klaij, Christiaan <C.Klaij at marin.nl> wrote:
> >
> > I've recently upgraded from petsc-3.8.4 to petsc-3.10.2 and was
> > surprised to find a number of segmentation faults in my test
> > cases. These turned out to be related to user-defined MatMult and
> > PCApply for shell matrices. For example:
> >
> > SUBROUTINE systemMatMult(aa_system,xx_system,rr_system,ierr)
> >  Mat, INTENT(in) :: aa_system
> >  Vec, INTENT(in) :: xx_system
> >  Vec, INTENT(out) :: rr_system
> >  PetscErrorCode, INTENT(out) :: ierr
> >  ...
> > END
> >
> > where aa_system is the shell matrix. This code works fine with
> > 3.8.4 and older, but fails with 3.10.2 due to invalid
> > pointers (gdb backtrace shows failure of VecSetValues due to
> > invalid first argument). After replacing by:
> >
> > SUBROUTINE
> mass_momentum_systemMatMult(aa_system,xx_system,rr_system,ierr)
> >  Mat :: aa_system
> >  Vec :: xx_system
> >  Vec :: rr_system
> >  PetscErrorCode :: ierr
> >  ...
> > END
> >
> > everything's fine again. So clearly something has changed since
> > 3.8.4 that now prevents the use of INTENT in Fortran (at least
> > using intel 17.0.1 compilers). Any reason for this?
> >
> > Chris
> >
> >
> > dr. ir. Christiaan Klaij  | Senior Researcher | Research & Development
> > MARIN | T +31 317 49 33 44 | mailto:C.Klaij at marin.nl |
> http://www.marin.nl
> >
> > MARIN news:
> http://www.marin.nl/web/News/News-items/ReFRESCO-successfully-coupled-to-ParaView-Catalyst-for-insitu-analysis-1.htm
> >
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181019/d7370806/attachment.html>


More information about the petsc-users mailing list