Excellent! <div><br></div><div>It finally runs without segfaulting. Now... to get it actually solve my problem.... :)</div><div><br></div><div>Gaetan<br><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 11:51 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>I think these function pointers should not be copied over, at least not in this way. I think Peter is working on a Fortran example to reproduce, but I think that if you apply the patch below, your calling sequence will work.</div>
<div><br>diff --git a/src/snes/interface/snes.c b/src/snes/interface/snes.c</div><div>--- a/src/snes/interface/snes.c</div><div>+++ b/src/snes/interface/snes.c</div><div>@@ -2463,9 +2463,6 @@</div><div> ierr = SNESSetApplicationContext(snes->pc,appctx);CHKERRQ(ierr);</div>
<div> ierr = VecDestroy(&fpc);CHKERRQ(ierr);</div><div> </div><div>- /* copy the function pointers over */</div><div>- ierr = PetscObjectCopyFortranFunctionPointers((PetscObject)snes,(PetscObject)snes->pc);CHKERRQ(ierr);</div>
<div>-</div><div> /* default to 1 iteration */</div><div> ierr = SNESSetTolerances(snes->pc, 0.0, 0.0, 0.0, 1, snes->pc->max_funcs);CHKERRQ(ierr);</div><div> ierr = SNESSetNormType(snes->pc, SNES_NORM_FINAL_ONLY);CHKERRQ(ierr);</div>
<div class="HOEnZb"><div class="h5">
<div><br></div><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 10:44 PM, Gaetan Kenway <span dir="ltr"><<a href="mailto:kenway@utias.utoronto.ca" target="_blank">kenway@utias.utoronto.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Following your suggestion I changed by calling routines to:<div><div><br></div><div> call SNESCreate(SUMB_COMM_WORLD, outer_snes, ierr)</div><div> call SNESSetType(outer_snes, SNESNGMRES, ierr)</div><div>
<div> call SNESSetFunction(outer_snes, rVec, formFunction_snes, ctx2, ierr)</div>
</div><div> call snessetfromoptions(outer_snes, ierr)</div><div><div><br></div><div> call SNESGetPC(outer_snes, psnes, ierr)</div><div> call SNESSetType(psnes, SNESSHELL, ierr)</div><div> call SNESShellSetSolve(psnes, psnes_func, ierr)</div>
<div><br></div></div><div>And the exact same errors occur. I'm pretty sure it has something to do with combing the two snes objects. Both work just fine by themselves. Do some pointers get accidentally overwritten somehow? I also tried creating the 'psnes' first (with a SNESCreate) , and then using the SNESSetPC() instead but the same error happens. </div>
<span><font color="#888888">
<div><br></div><div>Gaetan</div></font></span><div><div><div><br></div><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 11:21 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div>On Mon, Aug 27, 2012 at 9:52 PM, Gaetan Kenway <span dir="ltr"><<a href="mailto:kenway@utias.utoronto.ca" target="_blank">kenway@utias.utoronto.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I ran it though the debugger and came up with the following output:<div><div>(gdb) backtrace</div><div>#0 0x00000000 in ?? ()</div><div>#1 0xb5fd2832 in oursnesshellsolve (snes=0xbb03d30, x=0xbb2a4f0) at /nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/impls/shell/ftn-custom/zsnesshellf.c:13</div>
</div></blockquote><div><br></div></div><div>How are you calling SNESShellSetSolve(). The usage we expected was that you would<br><br>call SNESSetFromOptions(snes,ierr)<br>call SNESGetPC(snes,snespc,ierr)</div><div>call SNESShellSetSolve(snespc,yourfunction,ierr)</div>
<div><div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div>#2 0xb6017009 in SNESSolve_Shell (snes=0xbb03d30) at /nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/impls/shell/snesshell.c:169</div><div>#3 0xb60032e8 in SNESSolve (snes=0xbb03d30, b=0xb8c0610, x=0xbb2a4f0) at /nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/interface/snes.c:3536</div>
<div>#4 0xb6041547 in SNESSolve_NGMRES (snes=0xb8c1f70) at /nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/impls/ngmres/snesngmres.c:259</div><div>#5 0xb60032e8 in SNESSolve (snes=0xb8c1f70, b=0xb8c0610, x=0xb8ba6f0) at /nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/interface/snes.c:3536</div>
<div>#6 0xb5fd0e73 in snessolve_ (snes=0xb4d75a2c, b=0xb4d75c6c, x=0xb4d75c68, __ierr=0xbfffe338)</div><div> at /nfs/mica/home/kenway/Downloads/petsc-3.3/src/snes/interface/ftn-custom/zsnesf.c:181</div><div>#7 0xb47791f3 in nksolver2 () at NKSolver2.F90:20</div>
<div>#8 0xb46f8f68 in solvestate () at solveState.F90:485</div><div>#9 0xb46f95c2 in solversteady () at solverSteady.f90:27</div><div>#10 0xb46f9257 in solver () at solver.F90:102</div><div>#11 0x0b8ba2c0 in ?? ()</div>
<div>#12 0xb464a222 in f2py_rout_sumb_solver () from /tmp/tmpTaGWsk/sumb.so</div><div>#13 0xb46454e5 in fortran_call () from /tmp/tmpTaGWsk/sumb.so</div><div>#14 0x0805fd6a in PyObject_Call ()</div><div>#15 0x080dd5b0 in PyEval_EvalFrameEx ()</div>
<div>#16 0x080dfbb2 in PyEval_EvalCodeEx ()</div><div>#17 0x08168f1f in ?? ()</div><div>#18 0x0805fd6a in PyObject_Call ()</div><div>#19 0x080dcbeb in PyEval_EvalFrameEx ()</div><div>#20 0x080dfbb2 in PyEval_EvalCodeEx ()</div>
<div>#21 0x08168e3c in ?? ()</div><div>#22 0x0805fd6a in PyObject_Call ()</div><div>#23 0x08067d5c in ?? ()</div><div>#24 0x0805fd6a in PyObject_Call ()</div><div>#25 0x080b3554 in ?? ()</div><div>#26 0x0805fd6a in PyObject_Call ()</div>
<div>#27 0x080dd5b0 in PyEval_EvalFrameEx ()</div><div>#28 0x080dfbb2 in PyEval_EvalCodeEx ()</div><div>#29 0x080dfca7 in PyEval_EvalCode ()</div><div>#30 0x080fd956 in PyRun_FileExFlags ()</div><div>#31 0x080fdbb2 in PyRun_SimpleFileExFlags ()</div>
<div>#32 0x0805b6d3 in Py_Main ()</div><div>#33 0x0805a8ab in main ()</div><div><br></div><div>I'm also 99% certain that the function in set correctly since the shell snes works just fine when it is called directly. (see some of the earlier code snippits). Its only when I'm trying to use it as the preconditioner for the another snes object (ngmres) I have issues. </div>
<span><font color="#888888">
<div><br></div><div>Gaetan</div></font></span><div><div><br><div class="gmail_quote">On Mon, Aug 27, 2012 at 10:34 PM, Jed Brown <span dir="ltr"><<a href="mailto:jedbrown@mcs.anl.gov" target="_blank">jedbrown@mcs.anl.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div>On Mon, Aug 27, 2012 at 7:31 PM, Gaetan Kenway <span dir="ltr"><<a href="mailto:kenway@utias.utoronto.ca" target="_blank">kenway@utias.utoronto.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>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. </div></blockquote><div><br></div></div><div>You can use -start_in_debugger, then type "c" (for "continue") at the gdb prompt.</div>
<div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br></div><div>The petsc4py is initialized with:</div><div><div>import petsc4py</div><div>petsc4py.init(args=sys.argv)</div><div><br></div></div><div>so other options are passed in just fine. </div><div><br></div><div>
I ran it with valgrind and got the following:</div><div><div><br></div><div>==15046== Jump to the invalid address stated on the next line</div><div>==15046== at 0x0: ???</div><div>==15046== by 0x95EF008: SNESSolve_Shell (snesshell.c:169)</div>
<div>==15046== by 0x95DB2E7: SNESSolve (snes.c:3536)</div><div>==15046== by 0x9619546: SNESSolve_NGMRES (snesngmres.c:259)</div><div>==15046== by 0x95DB2E7: SNESSolve (snes.c:3536)</div><div>==15046== by 0x95A8E72: snessolve_ (zsnesf.c:181)</div>
<div>==15046== by 0x9AEA302: nksolver2_ (NKSolver2.F90:20)</div><div>==15046== by 0x9A6A077: solvestate_ (solveState.F90:485)</div><div>==15046== by 0x9A6A6D1: solversteady_ (solverSteady.f90:27)</div><div>==15046== by 0x99BB1C1: f2py_rout_sumb_solver (in /tmp/tmpGQGZda/sumb.so)</div>
<div>==15046== by 0x99B6484: fortran_call (in /tmp/tmpGQGZda/sumb.so)</div><div>==15046== by 0x805FD69: PyObject_Call (in /usr/bin/python2.6)</div><div>==15046== Address 0x0 is not stack'd, malloc'd or (recently) free'd</div>
</div></blockquote></div></div><br><div>This looks like SNESShellSetSolve() did not work. Are you sure that the type was set (e.g. SNESSetType() or SNESSetFromOptions()) before you called SNESShellSetSolve()?</div>
</blockquote></div><br></div></div></div>
</blockquote></div></div></div><br></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br>
</div></div></blockquote></div><br></div>