Error building on OS X 10.10 with complex PETSc/SLEPc

Issue #12 resolved
Johannes Feist created an issue

I was trying to build slepc4py on OS X Yosemite, with PETSc and SLEPc versions from MacPorts built with support for complex numbers and kept getting an error about PyFloat_FromDouble being called on a PetscScalar:

/opt/local/bin/mpicxx-openmpi-gcc49 -pipe -Os -Os -fPIC -I/opt/local/include -Wno-unused-result -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -DPETSC_DIR=/opt/local/lib/petsc -DSLEPC_DIR=/opt/local/lib/slepc -I/opt/local/lib/slepc/include -I/opt/local/include/openmpi-gcc49 -I/opt/local/include -I/opt/local/lib/petsc/include -Isrc/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/petsc4py/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m -c src/SLEPc.c -o build/temp.macosx-10.10-x86_64-3.4/src/SLEPc.o

In file included from src/SLEPc.c:3:0:

src/slepc4py.SLEPc.c: In function 'int __pyx_f_8slepc4py_5SLEPc_NEP_Function(NEP, PetscScalar, Mat, Mat, void*)':

src/slepc4py.SLEPc.c:4587:44: error: cannot convert 'PetscScalar {aka std::complex<double>}' to 'double' for argument '1' to 'PyObject* PyFloat_FromDouble(double)'

   __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

                                            ^

src/slepc4py.SLEPc.c: In function 'int __pyx_f_8slepc4py_5SLEPc_NEP_Jacobian(NEP, PetscScalar, Mat, void*)':

src/slepc4py.SLEPc.c:4840:44: error: cannot convert 'PetscScalar {aka std::complex<double>}' to 'double' for argument '1' to 'PyObject* PyFloat_FromDouble(double)'

   __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

                                            ^

error: command '/opt/local/bin/mpicxx-openmpi-gcc49' failed with exit status 1

I got the same error using the source code tarball for version 3.5, using the sources from git tag 3.5, and using the git maint branch. I can be fixed by manually changing the two PyFloat_FromDouble calls to __pyx_f_8slepc4py_5SLEPc_toScalar in slepc4py.SLEPc.c, but since that is an autogenerated file, that's not really a fix. I noticed that it also works if I manually add two "toScalar" calls in slepcnep.pxi, like so:

diff --git a/src/SLEPc/slepcnep.pxi b/src/SLEPc/slepcnep.pxi
index 150131e..fb488c3 100644
--- a/src/SLEPc/slepcnep.pxi
+++ b/src/SLEPc/slepcnep.pxi
@@ -128,7 +128,7 @@ cdef int NEP_Function(
     cdef Mat Amat = ref_Mat(A)
     cdef Mat Bmat = ref_Mat(B)
     (function, args, kargs) = Nep.get_attr('__function__')
-    retv = function(Nep, mu, Amat, Bmat, *args, **kargs)
+    retv = function(Nep, toScalar(mu), Amat, Bmat, *args, **kargs)
     cdef PetscMat Atmp = NULL, Btmp = NULL
     Atmp = A; A = Amat.mat; Amat.mat = Atmp
     Btmp = B; B = Bmat.mat; Bmat.mat = Btmp
@@ -145,7 +145,7 @@ cdef int NEP_Jacobian(
     cdef NEP Nep  = ref_NEP(nep)
     cdef Mat Jmat = ref_Mat(J)
     (jacobian, args, kargs) = Nep.get_attr('__jacobian__')
-    retv = jacobian(Nep, mu, Jmat, *args, **kargs)
+    retv = jacobian(Nep, toScalar(mu), Jmat, *args, **kargs)
     cdef PetscMat Jtmp = NULL
     Jtmp = J; J = Jmat.mat; Jmat.mat = Jtmp
     return 0

However, I'm not sure exactly what's going on, or if the error is just on my system, so I'm not submitting this as a pull request, but as an issue. I'm using python 3.4 from MacPorts (sys.version: 3.4.2 (default, Nov 4 2014, 16:59:21) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)]), and cython as well from macports, version 0.21.1.

Comments (3)

  1. Log in to comment