[petsc-users] petsc4py, cython

Lisandro Dalcin dalcinl at gmail.com
Thu Jan 18 10:13:03 CST 2018

In Cython code using C types from petsc4py, you should do:

from petsc4py.PETSc cimport Vec,  PetscVec
from petsc4py.PETSc cimport Mat,  PetscMat
# etcetera

now you can "cdef"  either "PetscVec" (the low-level PETSc C type) and
"Vec" (the higher-level petsc4py Python type)

Or you can just

from petsc4py.PETSc cimport *

to get all definitions, or even

from petsc4py cimport PETSc

then use properly-namespaced definitions "PETSc.PetscVec" (C type) and
"PETSc.Vec" (Python type).

Lisandro Dalcin
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)

4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia

Office Phone: +966 12 808-0459

More information about the petsc-users mailing list