[petsc-users] Segmentation fault due to TSDestroy

Barry Smith bsmith at mcs.anl.gov
Tue Mar 21 19:25:52 CDT 2017


  Thanks for letting us know, I added some additional error checking (soon to be) in master that will flag the use of incorrect NULL types for function pointers and thus prevent such crashes.

   Barry

> On Mar 20, 2017, at 7:46 AM, Praveen C <cpraveen at gmail.com> wrote:
> 
> It turns out the problem was with this
> 
>    call TSMonitorSet(ts, Monitor, ctx, PETSC_NULL_OBJECT, ierr); CHKERRQ(ierr)
> 
> The correct way is
> 
>    call TSMonitorSet(ts, Monitor, ctx, PETSC_NULL_FUNCTION, ierr); CHKERRQ(ierr)
> 
> Thanks
> praveen
> 
> On Sat, Mar 18, 2017 at 9:30 PM, Satish Balay <balay at mcs.anl.gov> wrote:
> Perhaps there is some memory corruption - you can try runnng the code with valgrind.
> 
> Satish
> 
> On Sat, 18 Mar 2017, Praveen C wrote:
> 
> > Dear all
> >
> > I get a segmentation fault when I call TSDestroy. Without TSDestroy the
> > code runs fine. I have included portion of my code below.
> >
> > subroutine runts(ctx)
> >    use userdata
> >    use comdata
> >    use mtsdata
> >    implicit none
> > #include <petsc/finclude/petsc.h90>
> >    type(tsdata) :: ctx
> >    ! Local variables
> >    integer,parameter :: h = 100 ! File id for history file
> >    TS                :: ts
> >    Vec               :: u
> >    PetscErrorCode    :: ierr
> >    external          :: RHSFunction, Monitor
> >
> >    call VecDuplicate(ctx%p%v_res, u, ierr); CHKERRQ(ierr)
> >
> >    ! Copy initial condition into u
> >    call VecCopy(ctx%p%v_u, u, ierr); CHKERRQ(ierr)
> >
> >    call TSCreate(PETSC_COMM_WORLD, ts, ierr); CHKERRQ(ierr)
> >    call TSSetProblemType(ts, TS_NONLINEAR, ierr); CHKERRQ(ierr)
> >    call TSSetRHSFunction(ts, PETSC_NULL_OBJECT, RHSFunction, ctx, ierr);
> > CHKERRQ(ierr)
> >    call TSSetInitialTimeStep(ts, 0.0, dtg, ierr); CHKERRQ(ierr)
> >    call TSSetType(ts, TSRK, ierr); CHKERRQ(ierr);
> >    call TSSetDuration(ts, itmax, tfinal, ierr); CHKERRQ(ierr);
> >    call TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP, ierr);
> > CHKERRQ(ierr);
> >    call TSMonitorSet(ts, Monitor, ctx, PETSC_NULL_OBJECT, ierr);
> > CHKERRQ(ierr)
> >    call TSSetSolution(ts, u, ierr); CHKERRQ(ierr)
> >    call TSSetFromOptions(ts, ierr); CHKERRQ(ierr)
> >    call TSSetUp(ts, ierr); CHKERRQ(ierr)
> >
> >    call TSSolve(ts, u, ierr); CHKERRQ(ierr)
> >
> >    call VecCopy(u, ctx%p%v_u, ierr); CHKERRQ(ierr)
> >    call VecDestroy(u, ierr); CHKERRQ(ierr)
> >    call TSDestroy(ts, ierr); CHKERRQ(ierr)
> >
> > end subroutine runts
> >
> > Thanks
> > praveen
> >
> 
> 



More information about the petsc-users mailing list