[petsc-users] SNES Shell Problems
Gaetan Kenway
kenway at utias.utoronto.ca
Mon Aug 27 19:31:46 CDT 2012
Hi Peter
I changed by initialization to:
! ----------- 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__)
call snessetfromoptions(outer_snes, ierr)
call EChk(ierr, __FILE__, __LINE__)
! ----------- Create Shell snes context -----------------
!call SNESCreate(SUMB_COMM_WORLD, psnes, ierr)
!call EChk(ierr, __FILE__, __LINE__)
! Set the above create psnes context to the 'pc' of the one just
created
call SNESGetPC(outer_snes, 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__)
Unfortunately that didn't do anything to help. The output is still the same:
[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
Unfortunately I can run backtraces since the code is running from python
and the -on_error_attach_debugger option has no effect when you're running
from python.
The petsc4py is initialized with:
import petsc4py
petsc4py.init(args=sys.argv)
so other options are passed in just fine.
I ran it with valgrind and got the following:
==15046== Jump to the invalid address stated on the next line
==15046== at 0x0: ???
==15046== by 0x95EF008: SNESSolve_Shell (snesshell.c:169)
==15046== by 0x95DB2E7: SNESSolve (snes.c:3536)
==15046== by 0x9619546: SNESSolve_NGMRES (snesngmres.c:259)
==15046== by 0x95DB2E7: SNESSolve (snes.c:3536)
==15046== by 0x95A8E72: snessolve_ (zsnesf.c:181)
==15046== by 0x9AEA302: nksolver2_ (NKSolver2.F90:20)
==15046== by 0x9A6A077: solvestate_ (solveState.F90:485)
==15046== by 0x9A6A6D1: solversteady_ (solverSteady.f90:27)
==15046== by 0x99BB1C1: f2py_rout_sumb_solver (in /tmp/tmpGQGZda/sumb.so)
==15046== by 0x99B6484: fortran_call (in /tmp/tmpGQGZda/sumb.so)
==15046== by 0x805FD69: PyObject_Call (in /usr/bin/python2.6)
==15046== Address 0x0 is not stack'd, malloc'd or (recently) free'd
which I'm not sure is of much additional use.
Any thoughts?
Gaetan
On Mon, Aug 27, 2012 at 8:00 PM, Peter Brune <brune at mcs.anl.gov> wrote:
> I suspect that you could get past your problem by using SNESGetPC to
> create the initial psnes context from the outer solver context and then
> setting its type as you've done here.
>
> A more complete backtrace from the debugger might give me a better notion
> of exactly what is going wrong. You can get this output conveniently using
> the -on_error_attach_debugger.
>
> Thanks,
>
> - Peter
>
>
> On Mon, Aug 27, 2012 at 6:51 PM, Gaetan Kenway <kenway at utias.utoronto.ca>wrote:
>
>> 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]PETSCERROR: 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/70847e5c/attachment-0001.html>
More information about the petsc-users
mailing list