<br><br>On Friday, 26 August 2016, Steven Dargaville <<a href="mailto:dargaville.steven@gmail.com">dargaville.steven@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi Dave<br><br></div>Thanks for the response. I'm actually using fortran and I wasn't sure that  PetscObjectComposeFunction would be accessible, and if so, what sort of fortran magic I might need to call this function (possibly an interface, with or without c_opt).<br><br></div>Do you know if it is possible to call that routine directly from fortran?</div></div></div></blockquote><div><br></div><div> I don't know. I'll have appeal to the other petsc users for an answer to these questions.</div><div><br></div><div>Thanks,</div><div>  Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thanks<br></div>Steven<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 26, 2016 at 1:35 PM, Dave May <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','dave.mayhem23@gmail.com');" target="_blank">dave.mayhem23@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On 26 August 2016 at 14:34, Dave May <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','dave.mayhem23@gmail.com');" target="_blank">dave.mayhem23@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On 26 August 2016 at 14:14, Steven Dargaville <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','dargaville.steven@gmail.com');" target="_blank">dargaville.steven@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>Hi all<br><br></div>I'm just wondering if there is any plans in the future for MatGetDiagonalBlock to support shell matrices by registering a user-implemented MATOP? MatGetDiagonal supports MATOP, but the block version of this does not. <br><br></div>I found a previous query on the user list which touched on this and mentioned that it would be easy to add:<br><div><div><div><br><a href="http://lists.mcs.anl.gov/pipermail/petsc-users/2011-May/008700.html" target="_blank">http://lists.mcs.anl.gov/piper<wbr>mail/petsc-users/2011-May/0087<wbr>00.html</a><br><br></div><div>I have implemented a matrix-free multigrid algorithm using shell operations in PETSc, and it would be very convenient to be able to provide a local shell Mat so I could apply local GMRES (or other matvec-based solvers) as a local block smoother. <br></div></div></div></div></blockquote><div><br></div></span><div>It looks like the thing you need to do is use PetscObjectComposeFunction() and not MatShellSetOperation()<br><br><a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectComposeFunction.html#PetscObjectComposeFunction" target="_blank">http://www.mcs.anl.gov/petsc/p<wbr>etsc-current/docs/manualpages/<wbr>Sys/PetscObjectComposeFunction<wbr>.html#PetscObjectComposeFuncti<wbr>on</a><br><br></div><div>with your MatShell object. <br><br>That is, instead of calling MatShellSetOperation(), call<br></div><div>ierr = PetscObjectComposeFunction(mys<wbr>hell,"<font color="#666666">MatGetDiagonalBlock_C"</font>, MatGetDiagonalBlock_MyShell);C<wbr>HKERRQ(ierr);</div></div></div></div></blockquote><div><br></div></span><div>Oops - I forgot the cast, the above should be<br><br>ierr = PetscObjectComposeFunction((Pe<wbr>tscObject)myshell,"<font color="#666666">MatGetDiago<wbr>nalBlock_C"</font>, MatGetDiagonalBlock_MyShell);C<wbr>HKERRQ(ierr);<br></div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>where MatGetDiagonalBlock_MyShell is a function pointer to your method to get the diagonal block. <br><br>Important detail is that you don't change the string "MatGetDiagonalBlock_C". The method MatGetDiagonalBlock() does a function pointer query using this string. See<br><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/mat/interface/matrix.c.html#MatGetDiagonalBlock" target="_blank">http://www.mcs.anl.gov/petsc/p<wbr>etsc-current/src/mat/interface<wbr>/matrix.c.html#MatGetDiagonalB<wbr>lock</a><br><br><br></div><div>Thanks <br></div><div>Dave<br></div><div><br><br><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div><div><br></div><div>Thanks!<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div>Steven<br></div><div><br><br></div></font></span></div></div></div>
</blockquote></div><br></div></div>
</blockquote></span></div><br></div></div>
</blockquote></div><br></div>
</blockquote>