On Thu, May 17, 2012 at 12:06 PM, Christian Staudt <span dir="ltr">&lt;<a href="mailto:christian.staudt@ira.uka.de" target="_blank">christian.staudt@ira.uka.de</a>&gt;</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">
Hello petsc4py users,<br>
<br>
I need some advice on petsc4py and how it can coexist with other approaches to get high performance with Python. Here&#39;s the situation:<br>
<br>
- I am working on a reimplementation of a graph laplacian solver that uses a multigrid approach. [1]<br>
- The original sequential implementation is in MATLAB, so Python was a natural choice because it makes it easy to translate concepts from MATLAB. The project is not small and translating everything to C++ would have been difficult and tedious. Numpy/Scipy also provide many equivalents for built-in MATLAB functions.<br>

- Unlike the original implementation, the new version should be parallelized. Here, PETSc (via petsc4py) should provide the parallel data structures and some operations.<br>
- There are probably functions for which pure Python does not deliver the necessary speed (and PETSc probably does not provide the operations needed). I am researching how to rewrite such performance-critical parts in C/C++, and embed them in the Python code - using methods like scipy.weave or ctypes. [2]<br>

- My question: Is it possible to share PETSc objects between the Python code and the embedded C/C++ code? For example, pass a PETSc.Mat via Python, operate on it with C/C++ and return the matrix to Python?<br></blockquote>
<div><br></div><div>Yes, PETSc is just C code, so this works the same way.</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">

In general: Do you think my approach makes sense? I am new to PETSc and have not done high performance Python before, so I hope to learn from your answers, hints and criticism.<br>
<br>
Chris<br>
<br>
<br>
[1] <a href="https://code.google.com/p/lamg/" target="_blank">https://code.google.com/p/lamg/</a><br>
[2] <a href="http://www.scipy.org/PerformancePython#head-cafc55bbf8fd74071b2c2ebcfb6f24ed1989d540" target="_blank">http://www.scipy.org/PerformancePython#head-cafc55bbf8fd74071b2c2ebcfb6f24ed1989d540</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>