Skip to content

Instantly share code, notes, and snippets.

@jorgensd
Last active May 6, 2024 07:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 --break-system-packages --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==0.5.1" pyproject_metadata pathspec
    python3 -m pip -v install --check-build-dependencies --break-system-packages --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 --break-system-packages --user --upgrade
    cd /root/shared/ffcx
    python3 -m pip install -e . -v --break-system-packages --user --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="RELWITHDEBUG"  #"Release" # "RelWithDebInfo" # "Debug"
export PATH=$PATH:/root/.local/bin
export CMAKE_NUM_PROCESSES=8

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}' {} \;

Boost programming options

apt-get update
apt-get install -y libboost-program-options-dev

Update python-pip

apt-get install -y python3-pip
python3 -m pip install --break-system-packages --upgrade pip setuptools

Build h5py and meshio

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

Install PYVISTA

Potential mesa glu issues:

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 --break-system-packages pyvista

Autopep8 and clang-format

python3 -m pip install --break-system-packages autopep8 clang-format ruff

IPython

python3 -m pip install --break-system-packages ipython

Workspace settings

{
	"folders": [
		{
			"path": "dolfinx"
		},
	],
	"settings": {
		"editor.formatOnSave": true,
		"python.formatting.autopep8Path": "/usr/local/bin/autopep8",
		"python.formatting.provider": "autopep8",
		"python.formatting.autopep8Args": [
			"--ignore=W503",
			"--max-line-length=120"
		],
		"C_Cpp.default.includePath": [
			"/usr/include/python3.10/",
			"${workspaceFolder}/",
			"/usr/include/eigen3/",
			"/usr/local/petsc/include/",
			"/home/shared/dolfinx_src/ffcX/ffcx/codegeneration/",
			"/usr/include/x86_64-linux-gnu/mpich/",
			"/usr/local/dolfinx-real/include/",
			"/usr/local/petsc/linux-gnu-real-32/include/",
			"/root/shared/ffcx/ffcx/codegeneration/",
			"/usr/local/lib/python3.10/dist-packages/pybind11/include/",
			"/usr/include/python3.10/",
			"/usr/local/lib/python3.10/dist-packages/petsc4py/include/",
			"/root/shared/basix/cpp/"
		],
		"files.associations": {
			"string": "cpp"
		}
	}
}

j

@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