<div dir="ltr">Hi Jonathan<div><br></div><div>I've successfully used petsc shell matrices from Python. There is an example of how to do it in demo/poisson2d/poisson2d.py. The example is a little sparse, but it has all the important information. The most important is to define the </div>
<div><br></div><div>def mult(self, mat, x, y):</div><div><br></div><div>routine inside of a Python class that is given in mat.setPythonContext() command. </div><div><br></div><div>Hope that helps. </div><div><br></div><div>
Gaetan</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 30, 2014 at 7:29 PM, Jonathan Tu <span dir="ltr"><<a href="mailto:jonathantu@gmail.com" target="_blank">jonathantu@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">Hi,<div><br></div><div>I would like to solve a large linear system.  I have a linear operator that operates on a "state" vector.  The linear operator does things like take the sum of the state elements, take the cross product of the state with a known vector, and then multiply the state by a large (distributed) matrix.  You could imagine it like this:</div>

<div><br></div><div>[sum of elements, cross product with other vector, multiplication with large matrix] = A * x</div><div><br></div><div>Now, I realize it is possible to implement all of this using a large matrix.  After all, these are all linear operations.  However, I thought it might be faster and less error-prone to use some of numpy's built-in operations, for the sums and cross products, and only use a distributed matrix for the last part of the output.  </div>

<div><br></div><div>From the PETSc documentation, it seems like a matrix shell would be perfect for this.  I could define my own mult operator that does all of these things in steps, using built-in numpy functions when appropriate and direct matrix multiplication when appropriate.  However, I cannot figure out how to do this in petsc4py.  I found somewhere online that perhaps createPython is the way I need to go about this, but I couldn't figure out the details.  </div>

<div><br></div><div>Any ideas?</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br></div><div><br></div><div>Jonathan Tu</div></font></span></div>
</blockquote></div><br></div>