Undefined symbol error during importing dolfinx

Hi,

I installed all the libraries(basix, ffcx, ufl, petsc and slepc) and they are working very well. But when I want to import dolfinx, it is giving this error;

Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dolfinx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/__init__.py", line 31, in <module>
    from dolfinx.cpp import __version__
ImportError: /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/cpp.cpython-38-x86_64-
linux-gnu.so: undefined symbol: 
_ZN7dolfinx3fem18create_matrix_nestERKSt6vectorIS1_IPKNS0_4FormIdEESaIS5_EESaIS7_EERKS1_IS1_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISH_EESaISJ_EE

I am using ubuntu 20.04. I checked this question but it didn’t help. I have installed last version of libraries.

Can you please guide me about how to fix this error?

It says you’re using a local installation of dolfinx from /home/ekrem/Development/Fenicsx/dolfinx-complex, not the ubuntu package. I guess you’ve made your own local build? In that case you’ll need to make sure your local path is included in your python path, PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages. You’ll probably need to do something similar with LD_LIBRARY_PATH so the linker can find your libdolfinx.so libraries.

1 Like

Thanks for your reply. I have built dolfinx from source. The real build works fine. But, I need complex build. Here is the script I am using for environment variables;

export PKG_CONFIG_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-complex-32
export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:$LD_LIBRARY_PATH

By the way, do we have complex build in conda environment for Ubuntu 20.04?

You’ve got PETSC_ARCH set there. Have you tried setting PETSC_DIR instead?

I’m not sure about conda. I assume you don’t have admin access so as to just install the Ubuntu packages?

I have tried the PETSC_DIR and it still persists the same error. I have upgraded my cmake during PETSc installation. Does that effect the complex dolfinx? Very interesting that the real build works like a charm…

If real build is working then it’s almost certainly something to do with PETSC_DIR. What value did you use?

1 Like

I am not specifying the PETSC_DIR? I have installed dolfinx to virtual environment. First, I am activating venv by just sourcing;

source /home/ekrem/Development/Fenicsx/dolfinx/bin/activate 

Then activating complex-mode;

export PKG_CONFIG_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-complex-32
export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:$LD_LIBRARY_PATH

My real mode script has exact same procedure with the one above;

export PKG_CONFIG_PATH=/home/ekrem/Development/Fenicsx/dolfinx-real/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-real-32
export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-real/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/home/ekrem/Development/Fenicsx/dolfinx-real/lib:$LD_LIBRARY_PATH

What to do with PETSC_DIR?

Could you produce the output of echo $PYTHONPATH and echo $LD_LIBRARY_PATH when you try to run this in your complex mode?

Most likely you will find that both the real and complex mode is present in these paths.

My python path is;

/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:

And LD_LIBRARY_PATH is;

/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:

If you’re building dolfinx from source, then you need to set PETSC_DIR to the directory containing the petsc installation that you want to use. If you don’t set it, then the dolfinx config scripts will find the default petsc, which evidently is petsc-real. You’ll need to set it to the location of your petsc-complex installation to get dolfinx building with complex numbers.

1 Like

My complex PETSC is working perfectly fine without setting PETSC_DIR directly;

>>> from petsc4py import PETSc
>>> print(PETSc.ScalarType)
<class 'numpy.complex128'>
>>> from slepc4py import SLEPc
>>> print(SLEPc.ScalarType)
<class 'numpy.complex128'>

That’s using python. dolfinx does not use python or petsc4py to configure its build.

I was wrong, thanks. I was exporting all the environment variables in a script.And script has PETSC_DIR as;

export GMSH_VERSION=4_8_4
export HDF5_SERIES=1.12
export HDF5_PATCH=1
export PYBIND11_VERSION=2.8.1
export PETSC_VERSION=3.16.1
export SLEPC_VERSION=3.16.0
export ADIOS2_VERSION=2.7.1
export PYVISTA_VERSION=0.32.1
export NUMPY_VERSION=1.20.3
export KAHIP_VERSION=3.12
export XTENSOR_VERSION=0.24.0
export XTL_VERSION=0.7.3

export MPICH_VERSION=3.4.2
export OPENMPI_SERIES=4.1
export OPENMPI_PATCH=1

export PETSC_SLEPC_OPTFLAGS="-O2"
# PETSc and SLEPc number of make processes (--with-make-np)
export PETSC_SLEPC_MAKE_NP=2
# Turn on PETSc and SLEPc debugging. "yes" or "no".
export PETSC_SLEPC_DEBUGGING="no"

# MPI variant. "mpich" or "openmpi".
export MPI="mpich"
export MPICH_CONFIGURE_OPTIONS="--with-device=ch3"

# Number of build threads to use with make
export BUILD_NP=2

export OPENBLAS_NUM_THREADS=1 
export OPENBLAS_VERBOSE=0

export PETSC_DIR=/home/ekrem/Development/Fenicsx/petsc 
export DOLFINX_CMAKE_BUILD_TYPE="RelWithDebInfo"

export SLEPC_DIR=/home/ekrem/Development/Fenicsx/slepc
export ADIOS2_DIR=/home/ekrem/Development/Fenicsx/adios2-v2.7.1/cmake
#export DOLFINX_DIR=/home/ekrem/Development/Fenicsx/dolfinx-real/lib/cmake/dolfinx
export COMPLEX_PREFIX=/home/ekrem/Development/Fenicsx/dolfinx-complex

For building it I am using;

mkdir -p build-complex
cd build-complex
PETSC_ARCH=linux-gnu-complex-32 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$COMPLEX_PREFIX -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS=${DOLFIN_CMAKE_CXX_FLAGS} ../cpp
ninja install
source /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/dolfinx/dolfinx.conf
cd ../python
CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-complex-32 pip3 install --target /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages --no-dependencies .

I am still having the same error.

/home/ekrem/Development/Fenicsx/petsc is the location of your petsc-real installation, is that correct?

Yes it is the location of my petsc installation. In that folder, I have;

ekrem@ekrem-TP501UB:~/Development/Fenicsx/petsc$ ls 
CODE_OF_CONDUCT.md  gmakefile             linux-gnu-complex-64  setup.py
config              gmakefile.test        linux-gnu-real-32     share
configtest.mod      GNUmakefile           linux-gnu-real-64     src
configure           include               makefile              systems
configure.log       interfaces            make.log              TAGS
configure.log.bkp   lib                   petscdir.mk
CONTRIBUTING        LICENSE               PKG-INFO
CTAGS               linux-gnu-complex-32  RDict.log

Not exactly. ~/Development/Fenicsx/petsc is a PETSc source dir, not an installation as such. You’ve got 4 builds there, the linux-gnu-* variants. You need PETSC_DIR to point to one of them.

To be fair, your combination of PETSC_DIR and PETSC_ARCH ought to work. But since it’s not, you have to try other permutations (like setting PETSC_DIR and not setting PETSC_ARCH). What is inside the linux-gnu-* dirs? Does the linux-gnu-complex-32 subdir contain a full build of petsc-complex? What is returned by

grep PETSC_SCALAR ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables

or by

grep PETSC_SCALAR ${PETSC_DIR}/lib/petsc/conf/petscvariables

with PETSC_DIR set as needed (with or without PETSC_ARCH)

What did cmake report during the configuration step with respect to PETSc?

2 Likes

Thanks for your responses. Actually I followed all the steps in here.

The first command gives;

(dolfinx) ekrem@ekrem-TP501UB:~/Development/Fenicsx/petsc$ grep PETSC_SCALAR ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables
PETSC_SCALAR = complex
PETSC_SCALAR_SIZE = 64

I think these installations are seperate installations for PETSC variables. By setting PETSC_ARCH and PETSC_DIR, they are just flagging which scalars will be used during petsc use.

I’m not so good with cmake commands, builds and outputs. Can you recommend and other way of installing dolfinx with complex scalars other than the above link that I have provided?

Focusing on the original error, python seems to be finding the complex module. What it’s missing is the libdolfinx.so library that contains the missing symbol. What is your current value of LD_LIBRARY_PATH when you run python? Your undefined symbol does not contain “complex” which is odd since it does on my system. Again, what did cmake report when you ran it?

Do you have admin rights to your machine? Can you install ubuntu packages?

The LD_LIBRARY_PATH returns;

(dolfinx) ekrem@ekrem-TP501UB:~/Development/Fenicsx$ echo $LD_LIBRARY_PATH 
/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:

What cmake report does? Where should I run it?

I can install ubuntu packages, but for some packages, I need additional features which are not exist in v0.3.0. So I need to upgrade them to dev-version for each library (basix, dolfinx…)

When you ran cmake, what did it output?

The next thing for you to check is your lib dir,

$ ls -l /home/ekrem/Development/Fenicsx/dolfinx-complex/lib
$ nm -D /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/libdolfinx*.so | grep create_matrix_nest