[petsc-users] petsc4py KSP Question

Jed Brown jedbrown at mcs.anl.gov
Wed Mar 7 09:14:13 CST 2012


On Wed, Mar 7, 2012 at 08:49, Gaetan Kenway <kenway at utias.utoronto.ca>wrote:

> What is the 'with block' option. I don'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?


with X as x:
    print(numpy.sin(x)) # x is a Numpy array


> 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've got them confused as well.


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 "gotten" array falls out of scope.) I recommend using the
'with' statement, it's much clearer and more explicit about resource
management.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120307/8dd0df50/attachment.htm>


More information about the petsc-users mailing list