Fenics Installation problem using source

Hello
I am using WSL ubuntu 20.04.4 LTS (focal) to use FEniCS. I am following this github instruction page: (GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment) to install FEniCS in my Ubuntu sub-system. I pass these commands in ubuntu command prompt:

  1. (base) fenics@DESKTOP-CVH2BNB:~$ git clone GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment
  2. (base) fenics@DESKTOP-CVH2BNB:~/dolfinx/cpp$ cmake …

In the no.2 command output I get this error:

– The C compiler identification is GNU 9.4.0
– The CXX compiler identification is GNU 9.4.0
– Check for working C compiler: /usr/bin/cc
– Check for working C compiler: /usr/bin/cc – works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /usr/bin/c++
– Check for working CXX compiler: /usr/bin/c++ – works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Could NOT find MPI_C (missing: MPI_C_LIB_NAMES MPI_C_HEADER_DIR MPI_C_WORKS) (Required is at least version “3”)
– Could NOT find MPI_CXX (missing: MPI_CXX_LIB_NAMES MPI_CXX_HEADER_DIR MPI_CXX_WORKS) (Required is at least version “3”)
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find MPI (missing: MPI_C_FOUND MPI_CXX_FOUND) (Required is at
least version “3”)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindMPI.cmake:1688 (find_package_handle_standard_args)
CMakeLists.txt:86 (find_package)

– Configuring incomplete, errors occurred!
See also “/home/fenics/dolfinx/cpp/CMakeFiles/CMakeOutput.log”.
See also “/home/fenics/dolfinx/cpp/CMakeFiles/CMakeError.log”.

I am attaching the CMakeError.log and CMakeOutput.log file.

Please help me to solve my issue!
Thanks

Note that DOLFINx has dependencies: Installation — DOLFINx 0.4.2.0 documentation

You could either: install these or use docker, spack or conda

Have I to install each and every components of C++ and python interface individually before running the above commands?

Yes, to compile from source, you need to have every dependency installed on your system.
Since you are using Ubuntu, you can install most of them with apt.
However, do not install basix, ffcx, and ufl from apt, they are old versions that are not compatible for compiling the main branch of dolfinx. I recommend you to also build these from source, and install C++ and python interface to your system before attempting to compile dolfinx.

If you want to install DOLFINx from source, you need to make sure that your system has all these requirements.
As I mentioned, there are many other ways to install dolfinx (which does not require alot of manual installations, see: Installation — DOLFINx 0.4.2.0 documentation
and
Create conda packages · Issue #1505 · FEniCS/dolfinx · GitHub

I am following this webpage to install from source: [Installation — DOLFINx 0.4.2.0 documentation]. At the time of installing Basix, using this webpage: [basix/INSTALL.md at main · FEniCS/basix · GitHub], (Advanced installation), I am getting this error:

(base) fenics@DESKTOP-CVH2BNB:~/basix/cpp$ cmake -DCMAKE_BUILD_TYPE=Release -B build-dir -S .
– The CXX compiler identification is GNU 9.4.0
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Performing Test arch_native_supported
– Performing Test arch_native_supported - Success
– Looking for sgemm_
– Looking for sgemm_ - not found
– Looking for C++ include pthread.h
– Looking for C++ include pthread.h - found
– Performing Test CMAKE_HAVE_LIBC_PTHREAD
– Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
– Looking for pthread_create in pthreads
– Looking for pthread_create in pthreads - not found
– Looking for pthread_create in pthread
– Looking for pthread_create in pthread - found
– Found Threads: TRUE
CMake Error at /home/fenics/.spack/Spack/opt/spack/linux-ubuntu20.04-skylake/gcc-9.4.0/cmake-3.23.2-i6y3jvftz2gzsttrd5tmqdpa77rj5cs5/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find BLAS (missing: BLAS_LIBRARIES)
Call Stack (most recent call first):
/home/fenics/.spack/Spack/opt/spack/linux-ubuntu20.04-skylake/gcc-9.4.0/cmake-3.23.2-i6y3jvftz2gzsttrd5tmqdpa77rj5cs5/share/cmake-3.23/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/home/fenics/.spack/Spack/opt/spack/linux-ubuntu20.04-skylake/gcc-9.4.0/cmake-3.23.2-i6y3jvftz2gzsttrd5tmqdpa77rj5cs5/share/cmake-3.23/Modules/FindBLAS.cmake:1337 (find_package_handle_standard_args)
CMakeLists.txt:66 (find_package)

– Configuring incomplete, errors occurred!
See also “/home/fenics/basix/cpp/build-dir/CMakeFiles/CMakeOutput.log”.
See also “/home/fenics/basix/cpp/build-dir/CMakeFiles/CMakeError.log”.

Any idea how to solve it?

I have used the link you shared ([dolfinx/README.md at main · FEniCS/dolfinx · GitHub]) to install dolfinx using SPACK installation. The commands that I have used are (with output):

(base) fenics@DESKTOP-CVH2BNB:~$ cd spack/

(base) fenics@DESKTOP-CVH2BNB:~/spack$ ls
CHANGELOG.md COPYRIGHT LICENSE-MIT README.md bin lib pyproject.toml share
CITATION.cff LICENSE-APACHE NOTICE SECURITY.md etc opt pytest.ini var
(base) fenics@DESKTOP-CVH2BNB:~/spack$ cd share/
(base) fenics@DESKTOP-CVH2BNB:~/spack/share$ ls
spack
(base) fenics@DESKTOP-CVH2BNB:~/spack/share$ cd spack/
(base) fenics@DESKTOP-CVH2BNB:~/spack/share/spack$ ls
bash csh docs keys qa setup-env.fish setup-env.sh spack-completion.bash
bootstrap docker gitlab logo setup-env.csh setup-env.ps1 setup-tutorial-env.sh templates
(base) fenics@DESKTOP-CVH2BNB:~/spack/share/spack$ bash setup-env.sh
(base) fenics@DESKTOP-CVH2BNB:~/spack/share/spack$ spack env create fenicsx-env
(base) fenics@DESKTOP-CVH2BNB:~/spack/share/spack$ spack env activate fenicsx-env
(base) fenics@DESKTOP-CVH2BNB:~/spack/share/spack$ spack add py-fenics-dolfinx cflags="-O3" fflags="-O3"
==> Adding py-fenics-dolfinx cflags="-O3" fflags="-O3" to environment fenicsx-env
(base) fenics@DESKTOP-CVH2BNB:~/spack/share/spack$ spack install

(I am posting the last error output. I am not posting the intermediate outputs)

==> Error: py-fenics-dolfinx-0.4.1-qfej72m2pmkr7mznswteim3hk7qydmsz: Package was not installed
==> Updating view at /home/fenics/.spack/Spack/var/spack/environments/fenicsx-env/.spack-env/view
==> Error: Installation request failed. Refer to reported errors for failing package(s).

Please help!

As the error says, you do not have BLAS installed.

We would need more of the stack trace than this, as this does not tell us what went wrong.

Install a BLAS implementation. On Ubuntu make sure to use a -dev package, e.g.

sudo apt install libopenblas-dev

I have installed BLAS using $sudo apt install libopenblas-dev and I have also installed GCC and gfortran compiler.

fenics@DESKTOP-CVH2BNB:~$ gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

fenics@DESKTOP-CVH2BNB:~$ gfortran --version
GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

When I run $ spack install, I get below stack details with error:

I am unable to post the output here (because of the word limit). So I am attaching the output in a jpeg image format. I am allowed to attach 5 images with this message. So I am attaching the output image in jpeg (only the error portions of the output) in a chronological order.



It looks like spack is not aware of your gfortran installation. Maybe you installed gfortran after creating the spack environment?
Can you try running the following command

spack compiler find

this will force a scan of all available compilers.
After that, if the same error occurs, please post the output of

spack compiler info gcc

fenics@DESKTOP-CVH2BNB:~$ spack compiler find
==> Found no new compilers
==> Compilers are defined in the following files:
/home/fenics/.spack/linux/compilers.yaml

fenics@DESKTOP-CVH2BNB:~$ spack compiler info gcc
gcc@9.4.0:
paths:
cc = /usr/bin/gcc
cxx = /usr/bin/g++
f77 = None
fc = None
modules =
operating system = ubuntu20.04

That’s weird. Not sure why spack is unable to find your fortran compiler.
Not 100% sure it’s gonna help, but you can try editing the /home/fenics/.spack/linux/compilers.yaml file manually into something like this:

spec: gcc@9.4.0:
paths:
    cc = /usr/bin/gcc
    cxx = /usr/bin/g++
    f77 = /usr/bin/gfortran
    fc = /usr/bin/gfortran

After updating /home/fenics/.spack/linux/compilers.yaml file manually as you said, the finding compilers error has been solved. Now the new error comes. I have attached the screenshot showing error with this mail. Please help.


Not sure about this one. Looks like a download error to me but I do not know how to fix it.
Maybe somebody else has an idea.

There is a good news I guess. I have run $spack install again and it is installed (I guess) with no error. Now, can you tell me how to run a test case e.g. poisson_demo.py after installing spack?

simply download the python file and call python3 demo_poisson.py.

fenics@DESKTOP-CVH2BNB:~$ ls
Pipfile basix dolfinx parmetis spack
Pipfile.lock boost_1_79_0 ffcx petsc ufl
Untitled.ipynb boost_1_79_0_rc1.tar.gz install_fenics_And_running_poisson.py slepc-3.17.1.tar.gz
anaconda3 demo_poisson.py mamba-framework slepc4py-3.12.0.tar.gz

fenics@DESKTOP-CVH2BNB:~$ python3 demo_poisson.py
Traceback (most recent call last):
File “demo_poisson.py”, line 73, in
from dolfinx import fem, io, mesh, plot
ImportError: cannot import name ‘fem’ from ‘dolfinx’ (unknown location)

What happens if you call
spack load py-fenics-dolfinx

I think spack is not installed properly. Should I run $spack install again and show you the outcome?

fenics@DESKTOP-CVH2BNB:~$ spack load py-fenics-dolfinx

Command ‘spack’ not found, did you mean:

command ‘fpack’ from deb libcfitsio-bin (3.470-3)
command ‘mpack’ from deb mpack (1.6-8.2)
command ‘stack’ from deb haskell-stack (1.9.3.1-1)
command ‘cpack’ from deb cmake (3.16.3-1ubuntu1)
command ‘ipack’ from deb exult-studio (1.2-18build1)
command ‘slack’ from deb slack (1:0.15.2-9)
command ‘apack’ from deb atool (0.39.0-10)
command ‘hpack’ from deb hpack (0.31.2-1)
command ‘spock’ from deb python3-sardana (3.0.2a0+34.9f6895-1)
command ‘pack’ from deb liballegro4-dev (2:4.4.3.1-1)

Try: sudo apt install