PETScMatrix(petsc4py.PETSc.Mat) getting wired into the wrong constructor of PETScMatrix
PETScMatrix is supposed to be able to take a Mat as a constructor. (Analogously, PETScVector can take a Vec as a constructor.) The latter works in Python, but the former does not:
diff --git demo/undocumented/petsc4py/python/demo_petsc4py.py demo/undocumented/petsc4py/python/demo_petsc4py.py
index 4449f7c..d45ff78 100644
--- demo/undocumented/petsc4py/python/demo_petsc4py.py
+++ demo/undocumented/petsc4py/python/demo_petsc4py.py
@@ -82,6 +82,9 @@ A_petsc = as_backend_type(A).mat()
b_petsc = as_backend_type(b).vec()
x_petsc = as_backend_type(u.vector()).vec()
+x_again = PETScVector(x_petsc)
+A_again = PETScMatrix(A_petsc)
+
# Create solver, apply preconditioner and solve system
ksp = PETSc.KSP().create()
ksp.setOperators(A_petsc)
crashes with
Traceback (most recent call last):
File "demo_petsc4py.py", line 86, in <module>
A_again = PETScMatrix(A_petsc)
File "/home/pef/src/dolfin/git/local.pefarrell.snes-split-solve-and-init/lib/python2.7/site-packages/dolfin/cpp/la.py", line 1875, in __init__
_la.PETScMatrix_swiginit(self,_la.new_PETScMatrix(*args))
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics@fenicsproject.org
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to create GPU matrix.
*** Reason: PETSc not compiled with Cusp support.
*** Where: This error was encountered inside PETScMatrix.cpp.
*** Process: unknown
***
*** DOLFIN version: 1.3.0+
*** Git changeset: a846a5677af85623582b381a737ca4a2d2256859
*** -------------------------------------------------------------------------
i.e. it's getting into the first constructor of PETScMatrix(use_gpu=false), not the PETScMatrix(Mat) constructor.
Comments (6)
-
-
reporter That's what I did to work around this -- changing the
PETScMatrix(bool use_gpu=false);
constructor to
PETScMatrix();
fixes the problem.
Shall I make a pull request?
-
Issue
#247was marked as a duplicate of this issue. -
reporter No one has objected, so I'll make a pull request.
-
I have pushed a fix for this. It was due to SWIG being confused when a flag used to reducing wrapper code size caused confusion in the dynamic dispatch for the different constructors. The petsc4py matrix was always passed to the constructor taking a bool, which passed it further down the C++ layer as bool(mat) in python works perfectly fine.
I simply turned of the flag. So now the wrapper code is slightly larger for some SWIG modules.
-
- changed status to resolved
A fix commited in: 3fe73a7e437178aa46ad021ff56f12f668acddf9
- Log in to comment
I don't even know if the DOLFIN interface to PETSc + GPU works - I don't think it gets any testing. Maybe we could just remove the gpu option.