I am building a Docker image with fenicsx as part of it. During the basix config, it reports BLAS_LIBRARIES not found error.
I already have built the BLAS and LAPACK with MPI while building PETSc. Can those be used at all? or do I have to install libopenblas-dev, boost-dev etc for compiling fenicsx?
PETSc doesn’t install BLAS and LAPACK in a central place that a general cmake config can find. You would need to add their installation paths to CMAKE_PREFIX_PATH, as specified in: CMAKE_PREFIX_PATH — CMake 3.30.3 Documentation
It would be helpful to have a reproducible environment and a traceback for this.
Could you tell me the exact way you installed PETSc, and how you are setting the relevant paths afterwards?
For instance, the following runs nicely for me:
FROM ubuntu:24.04 as base
ENV DEB_PYTHON_INSTALL_LAYOUT=deb_system
# PETSC vars
ARG PETSC_VERSION=3.21.1
ENV PETSC_DIR=/usr/local/petsc
ENV PETSC_ARCH=linux-gnu-real-32
# Arguments that can be overridden by a user building the docker image
# Compiler optimisation flags for SLEPc and PETSc, all languages.
ARG PETSC_SLEPC_OPTFLAGS="-O2"
ARG PETSC_SLEPC_DEBUGGING="no"
ARG MPI="mpich"
ARG PETSC_VERSION
# Environment variables
ENV OPENBLAS_NUM_THREADS=1 \
OPENBLAS_VERBOSE=0
ENV DEB_PYTHON_INSTALL_LAYOUT=deb_system
WORKDIR /tmp
# Install dependencies available via apt-get.
# - First set of packages are required to build and run FEniCS.
# - Second set of packages are recommended and/or required to build
# documentation or tests.
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get -qq update && \
apt-get -yq --with-new-pkgs -o Dpkg::Options::="--force-confold" upgrade && \
apt-get -y install \
clang \
cmake \
g++ \
git \
gfortran \
lib${MPI}-dev \
ninja-build \
pkg-config \
python3-dev \
python3-pip \
python3-setuptools \
python3-numpy \
python3.12-venv \
wget && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV VIRTUAL_ENV /dolfinx-env
ENV PATH /dolfinx-env/bin:$PATH
RUN python3 -m venv ${VIRTUAL_ENV}
# Install Python packages (via pip)
RUN python3 -m pip install --upgrade pip setuptools
RUN python3 -m pip install pytest pkgconfig
RUN python3 -m pip install --no-cache-dir mpi4py
# Install PETSc with real and complex types
RUN apt-get -qq update && \
apt-get -y install bison flex && \
git clone -b v${PETSC_VERSION} --single-branch https://gitlab.com/petsc/petsc.git ${PETSC_DIR} && \
cd ${PETSC_DIR} && \
# Real, 32-bit int
python3 ./configure \
--COPTFLAGS=${PETSC_SLEPC_OPTFLAGS} \
--CXXOPTFLAGS=${PETSC_SLEPC_OPTFLAGS} \
--FOPTFLAGS=${PETSC_SLEPC_OPTFLAGS} \
--with-64-bit-indices=no \
--with-debugging=${PETSC_SLEPC_DEBUGGING} \
--with-fortran-bindings=no \
--with-shared-libraries \
--download-ptscotch \
--download-openblas \
--with-scalar-type=real && \
make ${MAKEFLAGS} all && \
# Install petsc4py
cd src/binding/petsc4py && \
python3 -m pip install --no-cache-dir . && \
# Cleanup
apt-get -y purge bison flex && \
apt-get -y autoremove && \
apt-get clean && \
rm -rf \
${PETSC_DIR}/**/tests/ \
${PETSC_DIR}/**/obj/ \
${PETSC_DIR}/**/externalpackages/ \
${PETSC_DIR}/CTAGS \
${PETSC_DIR}/RDict.log \
${PETSC_DIR}/TAGS \
${PETSC_DIR}/docs/ \
${PETSC_DIR}/share/ \
${PETSC_DIR}/src/ \
${PETSC_DIR}/systems/ && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV CMAKE_PREFIX_PATH=${PETSC_DIR}/${PETSC_ARCH}/lib
RUN python3 -m pip install nanobind scikit-build-core[pyproject]
RUN git clone https://github.com/fenics/basix.git
RUN cmake -G Ninja -B build-dir-basix -DCMAKE_INSTALL_PREFIX=${DOLFINX_DIR} -DBLAS_blas_LIBRARY=${BLAS_PATH} -DLAPACK_LIBRARIES=${LAPACK_PATH} -DCMAKE_BUILD_TYPE="Release" -S ./basix/cpp
RUN cmake --build build-dir-basix
RUN cmake --install build-dir-basix
RUN python3 -m pip -v install --check-build-dependencies --config-settings=build-dir=build-dir-basix --config-settings=install.strip=false --config-settings=cmake.build-type="Release" --config-settings=cmake.define.CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES} --no-build-isolation -e ./basix/python/
Note the line: ENV CMAKE_PREFIX_PATH=${PETSC_DIR}/${PETSC_ARCH}/lib
Available BLAS/LAPACK libraries
Most systems (besides Microsoft Windows) come with pre-installed BLAS/LAPACK which are satisfactory for many PETSc simulations.
The freely available Intel MKL mathematics libraries provide BLAS/LAPACK that are generally better performing than the system provided libraries and are generally fine for most users.
For systems that do not provide BLAS/LAPACK, such as Microsoft Windows, PETSc provides the Fortran reference version --download-fblaslapack and a f2c generated C version --download-f2cblaslapack (which also supports 128 bit real number computations). These libraries are less optimized but useful to get started with PETSc easily.
PETSc also provides access to OpenBLAS via the --download-openblas configure option. OpenBLAS uses some highly optimized operations but falls back on reference routines for many other operations. See the OpenBLAS manual for more information. The configure option --download-openblas provides a full BLAS/LAPACK implementation.
BLIS does not bundle LAPACK with it so PETSc’s configure attempts to locate a compatible system LAPACK library to use if --download-blis is selected. One can use --download-f2cblaslapack --download-blis. This is recommended as a portable high-performance option. It is possible if you use --download-blis without --download-f2cblaslapack the BLIS library installed will not be used! Instead, PETSc will link in some LAPACK implementation and the BLAS that comes with that implementation!