[petsc-dev] [petsc4py] news & comments

Lisandro Dalcin dalcinl at gmail.com
Thu Sep 23 10:27:48 CDT 2010


1) Thanks to Barry's pressure and code, the pip install support is
mostly working. Once next petsc 3.1 patch release is out, I'll make a
new petsc4py release with support for "pip install petsc4py". The
rules basically are:

a) If $PETSC_DIR is in your environment, then petsc4py will be built
with that PETSc.
b) If $PETSC_DIR is NOT in your environment, pip will download and
install core PETSc (using the petsc-lite tarball).
c) If latest mpi4py is installed, step (b) will use config stuff from
mpi4py to build PETSc with MPI.
d) if mpi4py is not installed but 'mpicc' can be found on your $PATH,
pip will download and install mpi4py, then back to b()
e) if no mpi4py nor mpicc could be found, PETSc is configured --with-mpi=0

SLEPc still needs a bit more of work and review, Jose Roman and me are
working on it.

2) I've reimplemented the whole business of buffer sharing for Vec
(also for IS, but this is far less important). The former
implementation used NumPy-specific mechanisms (a.k.a "array
interface"). The new implementation uses the legacy core Python buffer
interface for older Python versions (2.x), and the new PEP 3118 buffer
interface in newer Python versions (3.x)

3) As discussed here a few weeks ago, now Vec has support for the with
statement:

with X as x, F as f: # X is a vec, x is the NumPy array sharing memory
with the local buffer of X
    f[0] = x[0]
    f[1:-1] = x[:-1] - 2*x[1:-1] + x[1:]
    f[-1] = x[-1]
    # more code using x...

In this case, you are guaranteed that VecRestoreArray() is called when
the with block finishes. But NEVER EVER access the leaked 'x' array
after the block!! You were warned!!

4) Now you can x = da.getVecArray(X). You get a "x" object with
working getitem/setitem, including slices, and it handles the DA array
lower bounds (aka corners in PETSc terminology) basically by
subtracting them from indices. The type this object does NOT inherit
from NumPy. When you index this object you get a regular numpy array.
The code is here:
http://code.google.com/p/petsc4py/source/browse/src/PETSc/petscda.pxi#141
. Any suggestion on how to improve the API to make it more useful or
easy to use will be very welcome.

2) Because of (2), working with petsc4py-dev requires Cython 0.13
(perhaps 0.12.x works, I do not remember right now).

6) Now petsc4py works on Python 3.


-- 
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169



More information about the petsc-dev mailing list