[petsc-users] SNES Shell Problems

Gaetan Kenway kenway at utias.utoronto.ca
Mon Aug 27 18:51:38 CDT 2012


Hi Again

I've pulled the most recent 3.3 branch code, compiled and tried running
with the shell solver. When I run just the snessolve() on the shell solver
everything works just fine. However, when I try to combine it with NGMRES I
get issues. Here's how I setup the solvers:

     ! ----------- Create Shell snes context -----------------


     call SNESCreate(SUMB_COMM_WORLD, psnes, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     ! Set the type to "shell"


     call SNESSetType(psnes, SNESSHELL, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     ! Set the user-defined function for psnes to our funtion


     call SNESShellSetSolve(psnes, psnes_func, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     ! ----------- Create main snes solver object ------------


     call SNESCreate(SUMB_COMM_WORLD, outer_snes, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     ! Set the type to the nonlinear ngmres


     call SNESSetType(outer_snes, SNESNGMRES, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     call SNESSetFunction(outer_snes, rVec, formFunction_snes, ctx2, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     ! Set the above create psnes context to the 'pc' of the one just
created

     call SNESSetPC(outer_snes, psnes, ierr)
     call EChk(ierr, __FILE__, __LINE__)

     call snessetfromoptions(outer_snes, ierr)
     call EChk(ierr, __FILE__, __LINE__)


The actual commands I'm running are:
  call SNESSolve(outer_snes, rhs, wVec, ierr) ! this works when
'outer_snes' is replaced with 'psnes'
  call EChk(ierr,__FILE__,__LINE__) !


I'm pretty sure the function is correct since it runs through when just the
shell solver is called. the "formFunction_snes" also seems to work ok by
itself. The traceback I get is below:

[0]PETSC ERROR:
------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation,
probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see
http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind[0]PETSC ERROR:
or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory
corruption errors
[0]PETSC ERROR: likely location of problem given in stack below
[0]PETSC ERROR: ---------------------  Stack Frames
------------------------------------
[0]PETSC ERROR: Note: The EXACT line numbers in the stack are not available,
[0]PETSC ERROR:       INSTEAD the line number of the start of the function
[0]PETSC ERROR:       is given.
[0]PETSC ERROR: [0] SNESSolve_Shell line 166
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/impls/shell/snesshell.c
[0]PETSC ERROR: [0] SNESSolve line 3491
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/interface/snes.c
[0]PETSC ERROR: [0] SNESSolve_NGMRES line 189
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/impls/ngmres/snesngmres.c
[0]PETSC ERROR: [0] SNESSolve line 3491
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/interface/snes.c
[0]PETSC ERROR: [0] VecCreateMPIWithArray line 313
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/vec/vec/impls/mpi/pbvec.c
[0]PETSC ERROR: [0] VecCreateMPIWithArray line 313
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/vec/vec/impls/mpi/pbvec.c
[0]PETSC ERROR: [0] VecCreateMPIWithArray line 313
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/vec/vec/impls/mpi/pbvec.c
[0]PETSC ERROR: [0] VecCreateMPIWithArray line 313
/nfs/mica/home/kenway/Downloads/petsc-3.3/src/vec/vec/impls/mpi/pbvec.c

I can tell from the output it first calls the supplied 'formFunction'
correctly and then has made its way to the SNESSolve_Shell command as
expected. However, my guess is it actually dies at the following line:

 ierr = (*shell->solve)(snes,snes->vec_sol);CHKERRQ(ierr);

I'm not quite sure what's going on.  Something fishy with the vec_sol
pointer or the solve command pointer?

Do you have any examples of using NGMRES?

Thanks,

Gaetan

On Mon, Aug 27, 2012 at 5:06 PM, Gaetan Kenway <kenway at utias.utoronto.ca>wrote:

> Thanks very much for the very quick response.
>
> I will pull the change from the mercurial repository and give it a try in
> the next couple of days.
>
> Gaetan
>
>
> On Mon, Aug 27, 2012 at 3:59 PM, Peter Brune <brune at mcs.anl.gov> wrote:
>
>> I've tested and pushed a fix to petsc-3.3.  If there are any problems,
>> let me know.
>>
>> On Mon, Aug 27, 2012 at 12:24 PM, Gaetan Kenway <kenway at utias.utoronto.ca
>> > wrote:
>>
>>> Excellent. Thanks.
>>>
>>> The reason for using the snes shell solver is I would like to try out
>>> the ngmres snes. solver. The code I'm working with already has a has a
>>> non-linear multi-grid method, coded directly in the fortran source. My plan
>>> was to setup the the ngmres snes solver, then create a snes shell as the
>>> preconditioner that wraps the nonlienear multigrid solver already in place.
>>>
>>> Does this make sense? Is this the sort of usage you had in mind?
>>>
>>>
>> This is very much the usage we were intending for this.
>>
>> - Peter
>>
>>
>>> Thanks,
>>>
>>> Gaetan
>>>
>>>
>>> On Mon, Aug 27, 2012 at 1:10 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>>>
>>>> On Mon, Aug 27, 2012 at 12:09 PM, Gaetan Kenway <
>>>> kenway at utias.utoronto.ca> wrote:
>>>>
>>>>> That's what I had deduced. I tried modifying the source code taking
>>>>> out the 'C', but it still didn't seem to generate the required wrapper.
>>>>> Does the functions that get passed function pointer handle's require
>>>>> special handling?
>>>>
>>>>
>>>> It needs custom handling. Peter is working on it.
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120827/85dcb00d/attachment-0001.html>


More information about the petsc-users mailing list