Skip to content

Instantly share code, notes, and snippets.

@jorgensd
Last active February 27, 2025 08:13
Show Gist options
  • Save jorgensd/e1984f6055b0f91197be6e406f0c901f to your computer and use it in GitHub Desktop.
Save jorgensd/e1984f6055b0f91197be6e406f0c901f to your computer and use it in GitHub Desktop.
Commands for bash file for rebuilding dolfinx/dolfinx-mpc

Bash commands

compile_demo(){
    cmake -G Ninja -B build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION} -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS="${DOLFINX_CMAKE_CXX_FLAGS}" . && ninja -j8 -C build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION}
}

rebuild(){
    BASEDIR=$(pwd)
    cd /root/shared/"$1"
    BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE}
    for var in "$@"
    do
    if [ "$var" = "clean" ]; then
       rm -rf build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION} python/build python/$1/cpp.cpython-*.so
    elif [ "$var" = "cpp" ]; then
      CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES} cmake -G Ninja -B build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION} -DCMAKE_INSTALL_PREFIX=${DOLFINX_DIR} -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_FLAGS="${DOLFINX_CMAKE_CXX_FLAGS}" -S cpp &&\
      CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES} cmake --build build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION}
      cmake --install build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION}
    elif [ $var == "python" ]; then
        python3 -m pip -v install --check-build-dependencies --config-settings=build-dir="build-${DOLFINX_CMAKE_BUILD_TYPE}-${DOLFINX_MODE}-${DOLFINX_PRECISION}" --config-settings=install.strip=false --config-settings=cmake.build-type="${DOLFINX_CMAKE_BUILD_TYPE}" --config-settings=cmake.define.CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES}  --no-build-isolation -e ./python/
    fi
    done
    cd $BASEDIR
}


basix(){
    BASEDIR=$(pwd)
    cd /root/shared/basix
    CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES} cmake -G Ninja -B build-dir -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -S ./cpp/
    CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES} cmake --build build-dir --parallel 3
    CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES} cmake --install build-dir
    python3 -m pip -v install nanobind scikit-build-core pyproject_metadata pathspec
    python3 -m pip -v install --check-build-dependencies --config-settings=install.strip=false--config-settings=build-dir="build" --config-settings=cmake.build-type="${DOLFINX_CMAKE_BUILD_TYPE}" --config-settings=cmake.define.CMAKE_BUILD_PARALLEL_LEVEL=${CMAKE_NUM_PROCESSES}  --no-build-isolation ./python
    cd $BASEDIR
}

ufl_ffcx(){
    BASEDIR=$(pwd)
    cd /root/shared/ufl
    python3 -m pip install -e . -v --upgrade
    cd /root/shared/ffcx
    python3 -m pip install -e . -v --upgrade
    cd $BASEDIR

}
export DEB_PYTHON_INSTALL_LAYOUT=deb_system
export CC="gcc"
export CXX="c++"
export DOLFINX_MODE=real
export DOLFINX_PRECISION=64
export PETSC_INT_SIZE=32
export DOLFINX_DIR=/usr/local/dolfinx-${DOLFINX_MODE}${DOLFINX_PRECISION}
export PETSC_ARCH=linux-gnu-${DOLFINX_MODE}${DOLFINX_PRECISION}-${PETSC_INT_SIZE}
source ${DOLFINX_DIR}/lib/dolfinx/dolfinx.conf
export LD_LIBRARY_PATH="/usr/local/petsc/${PETSC_ARCH}/lib/:${DOLFINX_DIR}/lib/:$LD_LIBRARY_PATH"
export PYVISTA_OFF_SCREEN=True
export DOLFINX_CMAKE_CXX_FLAGS="-march=native"
#-Ofast -march=native -g -Wall -Werror -pedantic" #-fmax-errors=1"
export DOLFINX_CMAKE_BUILD_TYPE="Developer"  #"Release" # "RelWithDebInfo" # "Debug"
export PATH=$PATH:/root/.local/bin
export CMAKE_NUM_PROCESSES=8
export LIBGL_ALWAYS_SOFTWARE=1
export HDF5_DIR=/usr/local
export HDF5_MPI="ON"

Run docker container

On local computer add

xhost si:localuser:root
docker pull ghcr.io/fenics/test-env:current-mpich
docker run -ti --network=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/root/shared -w /root/shared --name=dolfinx_src --shm-size=512m ghcr.io/fenics/test-env:current-mpich

Make all git directories safe

find /root/shared -name '.git' -type d -exec bash -c 'git config --global --add safe.directory ${0%/.git}' {} \;

Build h5py and meshio

HDF5_MPI="ON" HDF5_DIR="/usr/local" python3 -m pip install --no-build-isolation --no-cache-dir --no-binary=h5py h5py --upgrade
python3 -m pip install meshio

Install PYVISTA

Potential mesa glu issues:

apt-get update
apt -y install mesa-utils
glxinfo | grep "OpenGL version"
export MESA_LOADER_DRIVER_OVERRIDE=i965
glxinfo | grep "OpenGL version"

Other solution is to add

`-v /dev/dri:/dev/dri` to docker mount

to docker

export PYVISTA_OFF_SCREEN=False
apt-get -qq update
apt-get install -y libgl1-mesa-dev xvfb
python3 -m pip install pyvista[all]

Autopep8 and clang-format

python3 -m pip install autopep8 clang-format ruff

IPython and pdbpp

python3 -m pip install ipython pdbpp
@jorgensd
Copy link
Author

jorgensd commented May 23, 2022

Workaround for Python3.10:

pip3 install --find-links https://wheels.pyvista.org/ pyvista
HDF5_MPI="ON" HDF5_DIR="/usr/local" pip3 install --no-cache-dir --no-binary=h5py h5py --upgrade

@jorgensd
Copy link
Author

jorgensd commented Jan 20, 2023

docker run -ti --network=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/root/shared -w /root/shared --name=stubs --shm-size=512m ghcr.io/scientificcomputing/fenics:2023-01-16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment