[petsc-users] SNESSetFunction

Barry Smith bsmith at mcs.anl.gov
Tue Aug 18 20:29:17 CDT 2015


  We would have to have full details of what happens in the debugger during those crashes. 

  Barry

> On Aug 18, 2015, at 7:25 PM, Reza Yaghmaie <reza.yaghmaie2 at gmail.com> wrote:
> 
> 
> Thank you very much for the insight. It helped.
> 
> I am trying to solve the system using snes routines. Let's say the I execute the below command in Fortran
> 
> 	call SNESSolve(snes,PETSC_NULL_OBJECT,xvec,ierr)
> 
> In the residual calculation and Jacobian update routines I need to finalize the vectors and matrix assemblies using the commands as following otherwise SNESSolve will crash:
> 
> 	call VecAssemblyBegin (FVEC, ierr)
> 	call VecAssemblyEnd   (FVEC, ierr)
> 
>         call MatAssemblyBegin(jac_prec,MAT_FINAL_ASSEMBLY,ierr)
>         call MatAssemblyEnd(jac_prec,MAT_FINAL_ASSEMBLY,ierr)
> 
> I face the issue that my debugger crashes at the locations of theses final vector and matrix assemblies. It worked for the sequential version of the code but for the parallel version it stops there. I am sure all processors in the mpi framework reach to these pointers simultaneously. Any insights?
> 
> Thanks,
> Reza 
> 
> 
> 
> On Mon, Aug 17, 2015 at 2:25 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
> 
>   Reza,
> 
>     See src/snes/examples/tutorials/ex5f90.F for how this may be easily done using a Fortran user defined type
> 
>   Barry
> 
> > On Aug 17, 2015, at 12:39 PM, Matthew Knepley <knepley at gmail.com> wrote:
> >
> > On Mon, Aug 17, 2015 at 11:46 AM, Reza Yaghmaie <reza.yaghmaie2 at gmail.com> wrote:
> >
> > Hi,
> >
> > I have problems with passing variables through  SNESSetFunction in my code. basically I have the following subroutines in the main body of the Fortran code. Could you provide some insight on how to transfer variables into the residual calculation routine (FormFunction1)?
> >
> > Extra arguments to your FormFunction are meant to be passed in a context, through the context variable.
> >
> > This is difficult in Fortran, but you can use a PetscObject as a container. You can attach other
> > PetscObjects using PetscObjectCompose() in Fortran.
> >
> >    Matt
> >
> > Thanks,
> > Reza
> > ------------------------------------------------------------------------------------------------------------------
> > main code
> >
> >       SNES      snes
> >       Vec          xvec,rvec
> >       external   FormFunction1
> >       real*8       variable1(10),variable2(20,20),variable3(30),variable4(40,40)
> >
> >
> >       call SNESSetFunction(snes,rvec,FormFunction1,
> >      &                PETSC_NULL_OBJECT,
> >      &                variable1,variable2,variable3,variable4,
> >      &                ierr)
> >
> >       end
> >
> >       subroutine FormFunction1(snes,XVEC,FVEC,
> >      &                dummy,
> >      &                varable1,varable2,varable3,varable4,
> >      &                ierr)
> >
> >       SNES                      snes
> >       Vec                         XVEC,FVEC
> >       PetscFortranAddr    dummy
> >       real*8                       variable1(10),variable2(20,20),variable3(30),variable4(40,40)
> >
> >
> >       return
> >       end
> > --------------------------------------------------------------------------------------------------------------
> >
> >
> >
> >
> >
> >
> >
> >
> > --
> > 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
> 
> 



More information about the petsc-users mailing list