Bmad Installation
Note: This documentation is for the installation of Bmad outside of the Cornell CLASSE Release system.
Bmad Release Overview
Off-site (outside of the Cornell CLASSE Release system), the Bmad ecosystem is hosted on GitHub at
https://github.com/bmad-sim/bmad-ecosystem . Releases can be downloaded from there.
- The Bmad ecosystem consists of the the Bmad library, supporting libraries, and Bmad based programs including Tao.
- Releases can be built on Linux or Mac OS X (intel) computers. For Windows systems, WSL2 should be used.
A Release contains:
- The Bmad source code to build a collection of libraries and executables. (The term " Bmad source code" includes not only the Bmad code library as well as the subsidiary libraries, like cesr_utils, but also the code for programs like Tao.)
- Script files to build the libraries and executables.
Release names are generally of the form:
bmad_dist_YYYY_MMDD-N.tgz where YYYY_MMDD is the year_month-day tag of the release and N is the version number which starts with "0" for the first version generated on a given date, etc.
Bmad has been successfully been compiled on:
- Linux / Intel ifort compiler (v 17.0.7.259 or later).
- Linux / gcc gfortran compiler (v 6.3 or later).
- Mac Intel / gcc gfortran compiler (v 6.3 or later).
Note: ifort and gcc versions earlier than what is stated above are known to fail.
Note: Bmad can be built on
Windows by installing a Linux Release via WSL2.
For more information on
Bmad, please see
http://www.lepp.cornell.edu/~dcs/bmad/
Conda-Forge installation
Pre-compiled Bmad executables (Tao, etc) can be installed via
conda-forge (a Python package manager). Conda can be used on Windows using WSL2. Using Conda is convenient since Conda takes care of the many package dependencies that Bmad based programs have.
Important note! Do not invoke the Release script dist_source_me if you are using conda-forge. There can be environment variable conflicts such that Releases and conda-forge cannot both be active at once.
The following instructions for conda are for installing under MacOS or Linux. For installing on Windows, you need to install a Linux Release under WSL2. Follow the instructions under
MS Windows for setting up and running under WSL2 (read that
entire section), but replace the step of building Bmad with the following steps, run under the Linux Release that you installed under WSL2. Do not install the conda package manger for Windows, install the Linux version while running in Linux.
Conda Install instructions:
- Install the conda package manager via the conda-forge installer (miniforge) according to your platform: https://conda-forge.org/download/. Note that the following steps will require the conda environment to have been activated; to do so you must either allow the installer to modify your startup scripts and start a new shell, or you will have to follow the instructions given near the end of the installation for the remaining steps and for each time you wish to use Bmad. Anaconda/miniconda users: note that getting packages from both anaconda and conda-forge may result in problems; if possible you want an environment that only uses conda-forge.
- Install Bmad via:
conda install -c conda-forge bmad
The executables will be added to your path. For example, type:
tao
to run Tao.
By default this will install the latest Release. All Releases can be listed using:
conda search -c conda-forge bmad
A specific Release can be installed as:
conda install -c conda-forge bmad=20211013.0
To update the Bmad version use:
conda update -c conda-forge bmad
To install MPI versions of programs that have MPI versions (Note: Tao does
not have an MPI version) use
conda install -c conda-forge bmad="*=mpi_openmpi*"
Unlike MPI, OpenMP is always enabled with a conda installation.
Note: If you want to modify existing Bmad based program or create new ones under conda, you can link to the libraries at
$CONDA_PREFIX/lib and use headers from
$CONDA_PREFIX/include. The only drawback is that you will need a compatible compiler as the one used by conda-forge which can be installed with:
conda install -c conda-forge compilers # this will install C, CXX and FC
If it is ever desired to using a Bmad Release instead of using conda-forge, uninstallation can be done with the command:
conda uninstall -c conda-forge bmad
Bmad Release build steps
To build a Bmad Release (as opposed to using Conda-Forge), do the following steps:
- Install the required packages for your operating system and do any required setup
- Download a Release
- Set up the Release environment (this step will also need to be executed any time you use Bmad)
- Compile the Release
Downloading a Release tarball
- Check compiler requirements for compiling Releases.
- Download a Release tarball from !GitHub
The latest Release is recommended.
Installing Packages for Various Operating Systems
Detailed instructions are given below for
For any other operating systems, here is some general guidance:
Besides
cmake (v
2.8.5 or later) and
GCC, there are several standard unix/linux tools needed for compiling the
xraylib library. They are:
- gmake
- automake
- autoconf
- libtool
- m4
The
Tao program needs the following standard packages:
- readline
- ncurses
- termcap
- X11 Core and Development Libraries (libX11 and libX11-devel)
PLplot (if it is used instead of PGPLOT) requires two more packages installed on your system:
- cairo
- pango
- libXt-devel (usually installs as a dependency for cairo/pango)
Use the appropriate package manager (
yum or
rpm for Red Hat based systems, etc.) to install any needed tools. Note: The name of the package can vary from platform to platform. For example, the
readline package is installed with yum by installing
readline-devel. A google search will generally reveal the appropriate name.
Note: The relevant compilers for your platform must appear in each user's default
PATH , otherwise the scripts in the Release will not work!
Note: The SHELL for building Bmad is bash.
- If prompted, please don't follow Apple's warning to "upgrade" to zsh.
- If your SHELL set to zsh, please use the command below to switch back to bash:
chsh -s /bin/bash
Note: There are various Xcode/OS problems. See the Troubleshooting page for details.
- XQuartz -- provides core and development libraries for X11 X-Windows graphics support for tao and other packages that require graphical output.
- Xcode -- Install the latest version from the Apple developer website or get it using the Mac App Store. Once you have Xcode installed, open a terminal, run
sudo xcode-select --install
Then click the Install button to install the required command line developer tools.
- To complete the Apple Xcode License Agreement, please type:
sudo xcodebuild -license
Setup with MacPorts Package Management System
MacPorts documentation and download
here.
Setup with Homebrew Package Management System
Note: Using Homebrew and
MacPorts on the same computer can lead to conflicts. It is highly recommended that only one be used.
Install the required packages from Homebrew using the following commands:
brew install make
brew install gcc
brew install cmake
brew install automake
brew install autoconf
brew install libtool
brew install pkgconfig
brew install pango
brew install zlib
When building Bmad, you will need to set your path according to
the instructions given after the libtool installation. This change to PATH is only needed when building Bmad.
The instructions here assume that ACC_PLOT_PACKAGE="plplot" in dist_prefs.
For RHEL8 or 9 heand its derivatives (Rocky, CentOS-8), install the required packages with
yum install bc cmake gcc-c++ gcc-gfortran libtool make openssl-devel pango-devel readline-devel
then follow the build instructions.
For RHEL7 and its derivatives (CentOS, Scientific Linux), you will need a newer compiler than the default that is available, which will require the
RHEL Developer Toolset. For RHEL7 itself, you will need to adjust your subscription accordingly. For the RHEL derivatives, you will ned need to first install the Software Collections repository as follows:
CentOS 7 | yum install centos-release-scl |
Scientific Linux 7 | yum install yum-conf-softwarecollections |
Next, you can install the required packages with
yum install cmake devtoolset-12-gcc-gfortran devtoolset-12-gcc-c++ devtoolset-12-make libtool openssl-devel pango-devel readline-devel
Before starting the build process, you will need to execute
scl enable devtoolset-12 bash
This will create a new subshell where your environment is set up to use the required compilers. If you quit and come back to the build process, you will need to re-execute this latter command to again give yourself the required build environment.
Debain Variants (Ubuntu, etc.)
Your Ubuntu installation should be at version 18.04 or higher. The required packages for a PLPlot build (the default) are installed by:
sudo apt-get install gfortran g++ cmake libtool-bin libreadline-dev libpango1.0-dev libssl-dev bc
When building with PGPLOT add
sudo apt-get install libxt-dev
MS Windows
To install Bmad on Windows 10/11:
- Install WSL2, which will allow you to run a Linux Release under Windows. For most users the best choice will be to install the latest Ubuntu Release (which is what you will get by default). This may not perform well on a system with a small amount of memory (you're effectively running a second computer on your hardware). Note it is no longer necessary to install an X server, the latest WSL (Windows Store version) has one built-in.
- Build Bmad as described above on whatever Linux Release you've chosen.
Release Environment Setup
Important! The Release environment setup must be done before building or running programs. It is recommended that the setup commands be put in the appropriate shell startup file so that the setup is done automatically when logging in.
- Releases are compiled using bash, sh, or ksh. If your default shell is not one of these, you have two options:
- Switch the default shell to bash (recommended), or
- Switch to the bash shell each time you want to compile or run using the command
/bin/bash
- Users should add the following text to their local account login or profile files (or put these commands in a command file and run the command file each time you create a new command window).
- Note: Replace PATH-to-Release with the full path to the directory where the Release archive was unpacked.
- The following stuff should be put in your ~/.bashrc file (or ~/.bash or ~/.profile file whatever one is appropriate):
export DIST_BASE_DIR="PATH-to-Release"
source ${DIST_BASE_DIR}/util/dist_source_me
ulimit -S -c 0
ulimit -S -s 10240 # Remove this line when using a Mac
ulimit -d unlimited
The first ulimit prevents core dump files from being generated (takes up space and no one ever looks at them anyway). The next two ulimit lines helps prevent programs from bombing due to software limits on internal stack and heap sizes.
- If you are using the multiple Release scheme as discussed above, PATH-to-Release should refer the bmad_dist soft link. For example, the definition of DIST_BASE_DIR might look like:
export DIST_BASE_DIR="..../Release_base_dir/bmad_dist"
- Note: The default behavior is for the setup process to print out informational messages. To suppress this output, you may define the environment variable
DIST_SETUP_QUIET
to have the value "Y"
. This is entirely optional.
- If you have put the initalization commands in a shell startup file, setup the environment by simply logging out and logging back in again (and using the /bin/bash command if needed). Otherwise, if not in a shell startup file, source the command file the initialization commands are in.
- To see information about the Release that is being used by a terminal session, and to make sure the environment is properly setup, use either of the commands:
distinfo
accinfo
Either command will display a summary of the active Release's information, build architecture, selected Fortran compiler and enviromental configuration. In particular, you should see a set of environment variables starting with the prefix ACC_. If you do not see this, the environment has not been properly setup.
Compiling a Release
- Unzip and extract the tar archive into a working directory of your choice with the command:
tar -zxf bmad_dist_YYYY_MMDD-N.tgz
- Set up the Release environment as explained in the Release Environment Setup section. Notice that the environmental variable DIST_BASE_DIR points to the root directory (with a name like to bmad_dist_YYYY_MMDD-N).
- Change to the root directory:
cd $DIST_BASE_DIR
- Edit the file:
$DIST_BASE_DIR/util/dist_prefs
This file contains the preferences for custimizing the build. Documentation for dist_prefs is contained in the file itself. In particular, one can set:
- After editing dist_prefs, run your initialization file by loggin out and logging back in again.
- The final step is to build the source. For building production libraries and executables, type:
util/dist_build_production
For building debug libraries and executables, type: util/dist_build_debug
- Note: If you ever want to restart the build from scratch, before using one of the build commands above, first remove all compiled files using the command:
util/dist_clean
Organizing Multiple Releases
It can be convenient to have multiple Releases. Older Releases can act as backups in case, for example, the results of simulation programs change. The recommended way to handle multiple Releases is to create a root directory to hold the different Releases. An example directory structure is:
Release_base_dir
|
+--------------------------+------------------------+---------------------+
| | | |
bmad_dist_2020_0507-0 bmad_dist_2020_0821-0 bmad_dist_2121_0107-0 bmad_dist (soft link)
Here the Release root directory is called
Release_base_dir. This directory hold three Releases and a directory soft link called
bmad_dist. The soft link will point to the Release currently being used. For example, if the Release named
bmad_dist_2021_0107-0 is to be used, the soft link is created by the command (do this in the
Release_base_dir):
ln -sfn bmad_dist_2021_0107-0 bmad_dist
The idea is that to switch from using one Release to another, only the
bmad_dist soft link needs to be changed. The setup scripts discussed below do not have to be modified since they refer to the
bmad_dist soft link.
Directories in a Release
Directories Containing Executables
production/bin |
Production executables are meant for ordinary use. |
debug/bin |
Debug executables are meant for debugging code. Debug executables run slower but do more error checking and can be used with a debugger. |
Cornell Developed Library Directories:
bmad |
Main simulation library. |
cpp_bmad_interface |
C++ interface to Bmad |
sim_utils |
Helper routines (matrix , plotting, file manipulation, etc.) |
Cornell Developed Directories containing programs:
bsim |
Beam simulation programs |
code_examples |
Example programs and example lattices. |
regression_tests |
Bmad regression testing suite. |
tao |
General simulation program. |
util_programs |
Utility programs (EG lattice format converters, etc.) |
Other Cornell Developed Directories:
bmad-doc |
Documentation of Bmad and associated programs. |
util |
Utility scripts. |
build_system |
Build system script. |
3rd-Party Libraries ("Packages"):
fftw |
Discrete Fourier transform library |
forest |
FPP/PTC Full Polymorphic Package/Particle Tracking Code from Etienne Forest |
fgsl |
A Fortran interface to the GNU Scientific Library |
gsl |
GNU Scientific Library |
hdf5 |
library for storing and managing data. |
lapack |
Linear Algebra PACKage |
PGPLOT |
"the Pretty Good Plotting Package". For setup information, see the Plotting Packages wiki page. |
plplot |
A cross-platform software package for creating scientific plots. For setup information, see the Plotting Packages wiki page. |
xraylib |
A library for X-ray matter interaction cross sections for X-ray fluorescence applications |
Building your own code using a Release
To build your own code, after successfully installing a Release, please see the
Code Development wiki page.
The following is the ordered list of libraries to link to. Different programs will need different subsets of this list for linking. The libraries that the linker uses is specified by the
LINK_LIBS variable in the
cmake.XXX file used to compile and link your program. See the file bmad_dist/tao/cmake.tao for an example. The linker at link time will notify you if there are any missing libraries from the LINK_LIBS list. The order of the libraries in the LINK_LIBS list is important.
Licensing Issues
The
FOREST FPP/PTC (Polymorphic Tracking Code) package, from Etienne Forest, has no licensing issues.
The
PGPLOT (pretty good plotting) package from Tim Pearson, states on the PGPLOT web page:
PGPLOT is not public-domain software. However, it is freely available for non-commercial use.
The source code and documentation are copyrighted by California Institute of Technology,
and may not be redistributed or placed on public Web servers without permission.
The software is provided ``as is'' with no warranty.
Issues with building a Release: Troubleshooting Page
Please see our wiki page on
Troubleshooting ACC Code Issues
Getting Help
To request help, Please see our
Help and Mailing List Information wiki page for email contacts.
Old: Docker Setup
Using Docker to setup a Bmad Release has essentially been abandoned in favor of using Conda-Forge. The
Docker setup instructions are kept for reference.