Skip to content

Instantly share code, notes, and snippets.

@ampdes
Forked from jorgensd/bash_commands.md
Last active June 18, 2024 22:51
Show Gist options
  • Select an option

  • Save ampdes/0fdd39e73a36791b7bb0c4130edf2bde to your computer and use it in GitHub Desktop.

Select an option

Save ampdes/0fdd39e73a36791b7bb0c4130edf2bde 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 install -r ./python/build-requirements.txt &&\
        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==0.5.1" 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

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

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

@ampdes
Copy link
Author

ampdes commented Jun 18, 2024

export and source commands listed in the end in the bash_commands.md can be split into prebuild and post build and also be put into functions.

@ampdes
Copy link
Author

ampdes commented Jun 18, 2024

umask 0011 to let host user have read write access to the files created from inside the docker container

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