BLAS_LIBRARIES not found

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?

Thanks
~anoop

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

Thanks !

I as much thought so - but using CMAKE_PREFIX_PATH did not succeed in compilation either.

Is there a difference between using openblas-dev vs those from PETSc - as the earlier seems an easier solution

thanks
~anoop

See: The Use of BLAS and LAPACK in PETSc and external libraries — PETSc v3.21.5-480-gbfe78e4cfe0 documentation
and
Configuring PETSc — PETSc 3.21.5 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

Thank you so much for sharing your working Dockerfile. I will compare it with mine and figure out my errors. Much appreciated.

BTW, my Dockerfile is rather lengthy, but here is an extract of how I build the PETSc

FROM ubuntu:22.04

ENV TOPDIR="/opt"
ENV WORKDIR=${TOPDIR}

# Install packages for PETSc and openCARP
RUN export DEBIAN_FRONTEND="noninteractive" \
 && apt update && apt install -y --no-install-recommends \
    ca-certificates \
    curl \
    dpkg-dev \
    file \
    g++ \
    gengetopt \
    gfortran \
    git \
    libfftw3-dev \
    libgomp1 \
    make \
    pkg-config \
    python3 \
    python3-distutils \
    ssh \
    valgrind \
    zlib1g-dev \
    libjpeg-dev \
    cmake \
    vim \
 && ln -sf /usr/bin/python3 /usr/bin/python \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install PETSc
RUN git clone -b release https://gitlab.com/petsc/petsc.git petsc \
 && mkdir ${TOPDIR}/petsc_build \
 && cd $(ls | grep petsc) \
 && ./configure \
        PETSC_ARCH=arch-linux-c-opt \
        --prefix=${TOPDIR}/petsc_build \
        --download-mpich \
        --download-fblaslapack \
        --download-metis \
        --download-parmetis \
        --download-hypre \
        --with-debugging=0 \
        COPTFLAGS='-O2' \
        CXXOPTFLAGS='-O2' \
        FOPTFLAGS='-O2' \
 && make \
 && make install \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
 && cd ${TOPDIR}

ENV PETSC_DIR="${TOPDIR}/petsc"
ENV PETSC_ARCH="arch-linux-c-opt"

I was then using it with CMAKE_PREFIX_PATH=/opt/petsc_build/lib

Thanks and regards
~anoop

I do not think --download-fblaslapack gives you a sufficient installation of blas and lapack.
See: The Use of BLAS and LAPACK in PETSc and external libraries — PETSc v3.21.5-480-gbfe78e4cfe0 documentation

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!

Yes. That was it… thanks for guiding me through this. my apologies… thanks for your time…

~anoop