Thanks for the info. I&#39;ve recoded the functions using the &#39;with&#39; statements and I agree is makes it more explicit the scope of the temporary numpy array.  Would the following snippet of code be the preferred way to use the petsc vectors in python?<div>
<br></div><div>Thanks,</div><div>Gaetan</div><div><br></div><div><div>class ASPC(object):</div><div>    def apply(self, pc, X, Y):</div><div>        &quot;&quot;&quot;y &lt;-- M^-1 * x&quot;&quot;&quot;</div><div><br></div>
<div>        # Extract Vector Pointers</div><div>        with X as x:</div><div>            with Y as y:</div><div><br></div><div>                # Apply preconditioners in parallel</div><div>                if self.AS.isAero:</div>
<div>                    y = self.AS.solver.globalNKPreCon(x, y)</div><div><br></div><div>                if self.AS.isStruct:</div><div>                    y = self.AS.solver.globalNKPreCon(x, y)</div><div> </div><div> </div>
</div><div><br><div class="gmail_quote">On Wed, Mar 7, 2012 at 10:14 AM, Jed Brown <span dir="ltr">&lt;<a href="mailto:jedbrown@mcs.anl.gov">jedbrown@mcs.anl.gov</a>&gt;</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 class="im">On Wed, Mar 7, 2012 at 08:49, Gaetan Kenway <span dir="ltr">&lt;<a href="mailto:kenway@utias.utoronto.ca" target="_blank">kenway@utias.utoronto.ca</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

What is the &#39;with block&#39; option. I don&#39;t see anything related to that when I run help(PETSc.Vec()). Does it return a (N/bs,bs) array instead of an (N) array? </blockquote><div><br></div></div><div>with X as x:</div>

<div>    print(numpy.sin(x)) # x is a Numpy array</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Also in petsc4py the call for resetting the pointer from getArray() is actually resetArray() which is different from C/Fortran where it is restoreArray(). I&#39;ve got them confused as well. </blockquote>

</div></div><br><div>No, resetArray() is VecResetArray() which is a different thing, getArray() in Python does not need an explicit restore. (I believe the restore is called when the &quot;gotten&quot; array falls out of scope.) I recommend using the &#39;with&#39; statement, it&#39;s much clearer and more explicit about resource management.</div>

</blockquote></div><br></div>