[petsc-users] petsc4py and high performance python

Christian Staudt christian.staudt at ira.uka.de
Thu May 17 11:06:35 CDT 2012


Hello petsc4py users,

I need some advice on petsc4py and how it can coexist with other approaches to get high performance with Python. Here's the situation:

- I am working on a reimplementation of a graph laplacian solver that uses a multigrid approach. [1]
- 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.
- Unlike the original implementation, the new version should be parallelized. Here, PETSc (via petsc4py) should provide the parallel data structures and some operations.
- 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]
- 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?

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. 

Chris


[1] https://code.google.com/p/lamg/
[2] http://www.scipy.org/PerformancePython#head-cafc55bbf8fd74071b2c2ebcfb6f24ed1989d540


More information about the petsc-users mailing list