On Tue, May 8, 2012 at 9:50 AM, Christian Staudt <span dir="ltr"><<a href="mailto:christian.staudt@ira.uka.de" target="_blank">christian.staudt@ira.uka.de</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I am currently getting to know PETSc via petsc4py. Because I am writing a Python offshoot of a project originally in MATLAB, I have to<br>
come up with equivalents of built-in MATLAB functions. I am discovering that numpy already provides many equivalents (this page documents some numpy equivalents for common MATLAB expressions: [1])<br>
<br>
However, the goal is shared-memory parallelism, so numpy is not sufficient. This is where PETSc comes in, and the petsc4py bindings are very convenient. As far as I know, petsc4py is based on numpy.<br>
<br>
My questions to users of petsc4py and numpy:<br>
<br>
a) Is there an easy and efficient way to convert a numpy.ndarray to a PETSc.Vec or PETSc.Mat (and vice-versa)? (A PETSc.Vec.getArray() returns a numpy.ndarray, though I have found no such method for PETSc.Mat yet. )<br>
</blockquote><div><br></div><div>If you are using dense matrices (MATDENSE) then MatGetArray() works.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
b) In MATLAB, arrays are used everywhere, also for small collections, where one would use tuples or lists in Python (e.g. multiple return values from a function). When I encounter an array in the original MATLAB code, I have to decide whether a tuple, a list, a numpy.ndarray or a PETSc.Vec/PETSc.Mat is appropriate. One approach would be to use PETSc wherever the array can be larger than a typical tuple. Is there a performance penalty associated with using PETSc Vec/Mat for rather small arrays?<br>
</blockquote><div><br></div><div>The opposite. However, it is not as flexible because the type is constrained.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Regards & thank you for your answers,<br>
Chris<br>
<br>
[1] <a href="http://www.scipy.org/NumPy_for_Matlab_Users" target="_blank">http://www.scipy.org/NumPy_for_Matlab_Users</a></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>