.. _install-build-cmake: Build from Source ================= `CMake `__ is our primary build system. If you are new to CMake, we recommend starting with `this concise tutorial `__ from the HEP Software Foundation. For those primarily interested in building the project, focus on these key sections: `1. Introduction `__, `2. Building with CMake `__, and `9. Finding Packages `__. .. grid:: 2 :gutter: 2 .. grid-item-card:: :octicon:`alert` Build on HPC :link: install-hpc :link-type: ref Please refer to the :ref:`install-hpc` section. .. grid-item-card:: Install Dependencies :link: install-build-dependencies :link-type: ref Software dependencies of WarpX. .. grid-item-card:: Build the Code :link: install-build-code :link-type: ref Configuration, compilation and install. .. grid-item-card:: Build Options :link: install-build-options :link-type: ref All build configuration options. .. _install-build-dependencies: Install Dependencies -------------------- To begin, obtain a copy of the WarpX source code: .. code-block:: bash git clone https://github.com/BLAST-WarpX/warpx.git $HOME/src/warpx cd $HOME/src/warpx WarpX relies on :ref:`widely-used third-party software `. Below, you'll find instructions for installing these dependencies using various package managers. To ensure compatibility, pick **one** package manager for your development workflows. .. toctree:: :hidden: dependencies Install with conda-forge ^^^^^^^^^^^^^^^^^^^^^^^^ Conda provides a convenient way to install dependencies across Linux, macOS, and Windows platforms. `conda-forge `__ is a community-led collection of recipes, build infrastructure and distributions for the conda package manager, offering cross-platform compatibility at the user level. .. tip:: We recommend to deactivate that conda self-activates its ``base`` environment. This `avoids interference with the system and other package managers `__. .. code-block:: bash conda config --set auto_activate_base false In order to make sure that the conda configuration uses ``conda-forge`` as the only channel, which will help avoid issues with blocked ``defaults`` or ``anaconda`` repositories, please set the following configurations: .. code-block:: bash conda config --add channels conda-forge conda config --set channel_priority strict .. tab-set:: .. tab-item:: With MPI (only Linux/macOS) .. code-block:: bash conda create -n warpx-cpu-mpich-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp "openpmd-api=*=mpi_mpich*" openpmd-viewer packaging pytest python python-build make numpy pandas scipy setuptools yt "fftw=*=mpi_mpich*" pkg-config matplotlib mamba mpich mpi4py ninja pip virtualenv wheel conda activate warpx-cpu-mpich-dev # compile WarpX with -DWarpX_MPI=ON # for pip, use: export WARPX_MPI=ON .. tab-item:: Without MPI .. code-block:: bash conda create -n warpx-cpu-dev -c conda-forge blaspp boost ccache cmake compilers git lapackpp openpmd-api openpmd-viewer packaging pytest python python-build make numpy pandas scipy setuptools yt fftw pkg-config matplotlib mamba ninja pip virtualenv wheel conda activate warpx-cpu-dev # compile WarpX with -DWarpX_MPI=OFF # for pip, use: export WARPX_MPI=OFF For OpenMP support, you will further need: .. tab-set:: .. tab-item:: Linux .. code-block:: bash mamba install -c conda-forge libgomp .. tab-item:: macOS or Windows .. code-block:: bash mamba install -c conda-forge llvm-openmp For Nvidia CUDA GPU support, you will need to have `a recent CUDA driver installed `__ or you can lower the CUDA version of `the Nvidia cuda package `__ and `conda-forge to match your drivers `__ and then add these packages: .. code-block:: bash mamba install -c nvidia -c conda-forge cuda cuda-nvtx-dev cupy More info for `CUDA-enabled ML packages `__. Install with Spack ^^^^^^^^^^^^^^^^^^ Spack provides another option for installing dependencies on Linux and macOS systems. `Spack `__ is a flexible, user-level package manager designed primarily for Linux, with growing support for macOS and planned future support for Windows. To begin, download a `WarpX Spack desktop development environment `__ configuration. For most desktop development work, we recommend using the OpenMP environment for CPUs, unless you have a supported GPU device. * **Debian/Ubuntu** Linux: * OpenMP: ``system=ubuntu; compute=openmp`` (CPUs) * CUDA: ``system=ubuntu; compute=cuda`` (Nvidia GPUs) * ROCm: ``system=ubuntu; compute=rocm`` (AMD GPUs) * SYCL: *todo* (Intel GPUs) * **macOS**: first, prepare with ``brew install gpg2; brew install gcc`` * OpenMP: ``system=macos; compute=openmp`` If you already `installed Spack `__, we recommend to activate its `binary caches `__ for faster builds: .. code-block:: bash spack mirror add rolling https://binaries.spack.io/develop spack buildcache keys --install --trust Now install the WarpX dependencies in a new WarpX development environment: .. code-block:: bash # download environment file curl -sLO https://raw.githubusercontent.com/BLAST-WarpX/warpx/development/Tools/machines/desktop/spack-${system}-${compute}.yaml # create new development environment spack env create warpx-${compute}-dev spack-${system}-${compute}.yaml spack env activate warpx-${compute}-dev # installation spack install python3 -m pip install jupyter matplotlib numpy openpmd-api openpmd-viewer pandas scipy virtualenv yt In new terminal sessions, re-activate the environment with .. code-block:: bash spack env activate warpx-openmp-dev again. Replace ``openmp`` with the equivalent you chose. Compile WarpX with ``-DWarpX_MPI=ON``. For ``pip``, use ``export WARPX_MPI=ON``. Install with Brew ^^^^^^^^^^^^^^^^^ Brew can be used to install dependencies on Linux and macOS. `Homebrew (Brew) `__ is a user-level package manager primarily for `Apple macOS `__, but also supports Linux. .. code-block:: bash brew update brew tap openpmd/openpmd brew install adios2 # for openPMD brew install ccache brew install cmake brew install fftw # for PSATD brew install git brew install hdf5-mpi # for openPMD brew install libomp brew unlink gcc brew link --force libomp brew install pkg-config # for fftw brew install open-mpi brew install openblas # for PSATD in RZ brew install openpmd-api # for openPMD If you also want to compile with PSATD in RZ, you need to manually install BLAS++ and LAPACK++: .. code-block:: bash sudo mkdir -p /usr/local/bin/ sudo curl -L -o /usr/local/bin/cmake-easyinstall https://raw.githubusercontent.com/ax3l/cmake-easyinstall/main/cmake-easyinstall sudo chmod a+x /usr/local/bin/cmake-easyinstall cmake-easyinstall --prefix=/usr/local git+https://github.com/icl-utk-edu/blaspp.git \ -Duse_openmp=OFF -Dbuild_tests=OFF -DCMAKE_VERBOSE_MAKEFILE=ON cmake-easyinstall --prefix=/usr/local git+https://github.com/icl-utk-edu/lapackpp.git \ -Duse_cmake_find_lapack=ON -Dbuild_tests=OFF -DCMAKE_VERBOSE_MAKEFILE=ON Compile WarpX with ``-DWarpX_MPI=ON``. For ``pip``, use ``export WARPX_MPI=ON``. Install with APT ^^^^^^^^^^^^^^^^ The `Advanced Package Tool (APT) `__ is a system-level package manager on Debian-based Linux distributions, including Ubuntu. .. tab-set:: .. tab-item:: With MPI (only Linux/macOS) .. code-block:: bash sudo apt update sudo apt install build-essential ccache cmake g++ git libfftw3-mpi-dev libfftw3-dev libhdf5-openmpi-dev libopenmpi-dev pkg-config python3 python3-dev python3-matplotlib python3-mpi4py python3-numpy python3-pandas python3-pip python3-scipy python3-venv # optional: # for CUDA, either install # https://developer.nvidia.com/cuda-downloads (preferred) # or, if your Debian/Ubuntu is new enough, use the packages # sudo apt install nvidia-cuda-dev libcub-dev # compile WarpX with -DWarpX_MPI=ON # for pip, use: export WARPX_MPI=ON .. tab-item:: Without MPI .. code-block:: bash sudo apt update sudo apt install build-essential ccache cmake g++ git libfftw3-dev libfftw3-dev libhdf5-dev pkg-config python3 python3-dev python3-matplotlib python3-numpy python3-pandas python3-pip python3-scipy python3-venv # optional: # for CUDA, either install # https://developer.nvidia.com/cuda-downloads (preferred) # or, if your Debian/Ubuntu is new enough, use the packages # sudo apt install nvidia-cuda-dev libcub-dev # compile WarpX with -DWarpX_MPI=OFF # for pip, use: export WARPX_MPI=OFF .. _install-build-code: Build the Code -------------- .. _build-the-executable-with-cmake: Build the Executable with CMake ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To build WarpX from the source directory, execute these commands: .. code-block:: bash # Configure the build system # Additional options available, such as: # -DWarpX_PYTHON=ON # -DCMAKE_INSTALL_PREFIX=$HOME/sw/warpx cmake -S . -B build # Compile using four parallel threads cmake --build build -j 4 **That's it!** The 3D WarpX binary is now available in ``build/bin/`` and is ready to :ref:`run ` with any :ref:`3D example input file `. You can either run the binary directly from this location or copy it to another directory. For a system-wide installation, use the following command: .. code-block:: bash # for default install paths, you will need administrator rights, e.g. with sudo: cmake --build build --target install You can inspect and modify build options after running ``cmake -S . -B build`` with either .. code-block:: bash ccmake build or by adding arguments with ``-D