Skip to content

panagiotistsap/BLonD

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

image

image

Copyright 2019 CERN. This software is distributed under the terms of the GNU General Public Licence version 3 (GPL Version 3), copied verbatim in the file LICENCE.txt. In applying this licence, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction.

CODE NAME

BLonD (Beam Longitudinal Dynamics)

DESCRIPTION

CERN code for the simulation of longitudinal beam dynamics in synchrotrons.

LINKS

Repository: https://github.com/blond-admin/BLonD

Documentation: http://blond-admin.github.io/BLonD/

Project website: http://blond.web.cern.ch

INSTALL

Requirements

  1. A gcc compiler with C++11 support (version greater than 4.8.4).
  2. An Anaconda distribution (Python 3 recommended).
  3. That's all!

Windows GCC Installation Instructions

  1. Download the latest mingw-w64 using this link: https://sourceforge.net/projects/mingw-w64/files/latest/download
  2. Run the downloaded executable.
  3. Make sure to select: Architecture: x86_64, Threads: posix and Exception: seh
  4. Select the installation location, e.g.: "C:\Users\myname\mingw-64"
  5. Wait for the installation to complete, then add the following path to your User Environment Variable Path: "C:\Users\myname\mingw-64\mingw64\bin"
  6. To validate the correct setup of gcc, open a command prompt and type: gcc --version. The first output line should contain the gcc version you just installed.

Install Steps

Installing BLonD as a python package.

  • Using the pip package manager:
    $ pip install blond
  • If this fails try to:

    1. Clone the repository from github or download and extract the zip from https://github.com/blond-admin/BLonD/archive/master.zip.
    2. Navigate to the downloaded BLonD directory and run:
    $ python setup.py install
  • If it still fails, navigate to the BLonD directory and run:

    1.
    $ python setup.py compile
    1. Then you have to use the PYTHONPATH variable or some other mechanism to point to the BLonD installation.
  • In the extremely rare occasion that it continues to fail, you can submit an issue and we will handle it ASAP.

For advanced users or developers.

  1. You are advised to install git in your system.
  2. Clone the repository or download and extract it.
  3. From within the BLonD directory run:
$ python blond/compile.py
  1. Adjust the PYTHONPATH to contain the path to the cloned repository.

Confirm proper installation

  • Run the unittests with pytest (may need to be installed first with pip install pytest):
    $ pytest -v unittests
  • Try to run some of the main files found in the examples:
    $ python __EXAMPLES/main_files/EX_01_Acceleration.py
    $ python __EXAMPLES/main_files/EX_02_Main_long_ps_booster.py
    $ etc..

Performace Optimizations

There are some easy ways to reduce the execution time of your simulation:

  1. Use the multi-threaded C library. To use it you have to add the -p flag when compiling the C library:
    $ python blond/compile.py --parallel
  2. Enable processor specific compiler optimizations:
    $ python blond/compile.py --flags='-march=native'
  3. If you are test-case is calling the synchrotron radiation tracking method, you can accelerate it by using the Boost library. To do so you have to:
    1. Download Boost: https://www.boost.org/. Let's say the version you downloaded is boost_1_70.
    2. Extract it, let's say in /user/path/to/boost_1_70.
    3. Pass the boost installation path when compiling BLonD:
      $ python blond/compile.py --boost=/user/path/to/boost_1_7_70/include
  4. Check the following section about the FFTW3 library.
  5. All the above can be combined.

Changing the floating point precision (32 bit floats or 64 bit floats)

  • By default BLonD uses double precision calculations (float64). To change to single precision, for faster calculations, in the beginning of your mainfile you will have to add the code lines:
    from blond.utils import bmath as bm
    bm.use_precision('single') 
  • No other modifications are needed.

Use the FFTW3 library for the FFTs

So far only the rfft(), irfft() and fftfreq() routines are supported. fft_convolve() to be added soon.

  • Windows:
    1. Download and unzip the pre-compiled FFTW3 library. Link: ftp://ftp.fftw.org/pub/fftw/fftw-3.3.5-dll64.zip
    2. Copy the libfftw3-3.dll under your python's distribution directory.
    3. Run the blond/compile.py with the flag --with-fftw.
    4. If the FFTW3 library is not installed in one of the default directories, use the --with-fftw-lib and --with-fftw-header to point to the directories where the shared library and header files are stored.
    5. To use the supported routines, you need to call the function use_fftw() from bmath.py:
      from blond.utils import bmath as bm
      bm.use_fftw()
      ...
      bm.rfft(...)
      bm.irfft(...)
      bm.rfftfreq(...)
  • Linux:
    1. Download and compile the FFTW3 library. Link: http://www.fftw.org/fftw-3.3.8.tar.gz
    2. Run the blond/compile.py with the flag: --with-fftw.
    3. If the FFTW3 library is not installed in one of the default directories, use the --with-fftw-lib and --with-fftw-header to point to the directories where the shared library and header files are stored.
    4. Optionally, you can enable one of the flags --with-fftw-omp or --with-fftw-threads to use the multithreaded FFTs.
    5. To use the supported routines, you need to call the function use_fftw() from bmath.py:
      from blond.utils import bmath as bm
      bm.use_fftw()
      ...
      bm.rfft(...)
      bm.irfft(...)
      bm.rfftfreq(...)

Using the multi-node (MPI) implementation

Set-up Instructions

  • Add the following lines in your ~/.bashrc, then source it:

    # Environment variables definitions
    export LD_LIBRARY_PATH="$HOME/install/lib"
    export INSTALL_DIR="$HOME/install"
    export BLONDHOME="$HOME/git/BLonD"
    
    # User aliases
    alias mysqueue="squeue -u $USER"
    alias myscancel="scancel -u $USER"
    alias mywatch="watch -n 30 'squeue -u $USER'"
    
    # Module loads
    module load compiler/gcc7
    module load mpi/mvapich2/2.3
  • Download and install anaconda3:

    cd ~
    mkdir -p ~/downloads
    cd downloads
    wget https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh
    bash Anaconda3-2018.12-Linux-x86_64.sh -b -p $HOME/install/anaconda3
  • Download and install fftw3 (with the appropriate flags):

    cd ~
    mkdir -p ~/downloads
    cd downloads
    wget http://www.fftw.org/fftw-3.3.8.tar.gz
    tar -xzvf fftw-3.3.8.tar.gz
    cd fftw-3.3.8
    ./configure --prefix=$HOME/install/ --enable-openmp --enable-single --enable-sse2 --enable-avx --enable-avx2 --enable-fma --enable-avx-128-fma  --with-our-malloc --disable-fortran --enable-shared
    make -j4
    make install
  • install mpi4py with pip:

    pip install mpi4py
  • clone this repo, compile the library and link with fftw3_omp

    cd ~
    mkdir -p git
    cd git
    git clone --branch=master https://github.com/blond-admin/BLonD.git
    cd BLonD
    python blond/compile.py -p --with-fftw --with-fftw-threads --with-fftw-lib=$INSTALL_DIR/lib --with-fftw-header=$INSTALL_DIR/include
  • adjust your main file as needed (described bellow).
  • example scripts to setup and run a parameter scan in the HPC Slurm cluster: https://cernbox.cern.ch/index.php/s/shqtotwyn4rm8ws

Changes required in the main file for MPI

  1. This statements in the beginning of the script:
from blond.utils import bmath as bm
from blond.utils.mpi_config import worker, mpiprint
bm.use_mpi()  
  1. After having initialized the beam and preferably just before the start of the main loop:
beam.split()

This line splits the beam coordinates equally among the workers.

  1. If there is code block that you want it to be executed by a single worker only, you need to surround it with this if condition:
if worker.isMaster:
    foo()
    ...
  1. If you need to re-assemble the whole beam back to the master worker you need to run:
beam.gather()
  1. Finally, in the end of the simulation main loop, you can terminate all workers except from the master with:
worker.finalize()
  1. To run your script, you need to pass it to mpirun or mpiexec. To spawn P MPI processes run:
$ mpirun -n P python main_file.py
  1. For more examples have a look at the __EXAMPLES/mpi_main_files/ directory.

Using the GPU Implementation

Setup Instructions

Install Cuda from the following link https://developer.nvidia.com/cuda-downloads.

Install the python module pycuda and scikit-cuda with

$ pip install pycuda
$ pip install scikit-cuda

To verify your installation open a python terminal and execute the following script

import pycuda.autoinit 
from pycuda import gpuarray 
import numpy as np 
a = gpuarray.to_gpu(np.zeros(1000,np.float64)) 

To compile the Cuda files add the flag --gpu and pass the Compute Capability of your GPU as an argument. You can find your GPU's compute capability in this link https://en.wikipedia.org/wiki/CUDA. For example if your GPU is the GTX 1050 Ti and so you Compute Capability is 6.1, you need to run .. code-block:: bash

$ python blond/compile --gpu 61

Changes required in the main file for GPU

  1. Right before your main loop you need to add:
from blond.utils import bmath as bm
bm.use_gpu() # change some of the basic functions(kick, drift, ffts etc) to their GPU equivalent
bm.use_cucache() # enable a feature for better GPU performance
  1. Also for every object you are using in your main loop that is in the following list
GPU objects
Beam
Profile
RingAndRFTracker
TotalInducedVoltage
_InducedVoltage
InducedVoltageFreq
InductiveImpedance
InducedVoltageResonator
RFStation
BeamFeedback

you need to call their use_gpu() method. The following is a typical example from the __EXAMPLES/gpu_main_files/EX_01_Acceleration.py mainfile.

beam.use_gpu()
long_tracker.use_gpu()
profile.use_gpu()

If an object of this list is contained inside a different one you don't need to use the use_gpu() for the contained object. In the previous example, we don't the first and the third line since beam, and profile is contained inside the tracker. The same would apply in a TotalInducedVoltage object and the objects in its induced_voltage_list.

CURRENT DEVELOPERS

  • Simon Albright (simon.albright (at) cern.ch)
  • Theodoros Argyropoulos (theodoros.argyropoulos (at) cern.ch)
  • Konstantinos Iliakis (konstantinos.iliakis (at) cern.ch)
  • Ivan Karpov (ivan.karpov (at) cern.ch)
  • Alexandre Lasheen (alexandre.lasheen (at) cern.ch)
  • Markus Schwarz (markus.schwarz (at) kit.edu)
  • Helga Timko (Helga.Timko (at) cern.ch)

PREVIOUS DEVELOPERS

Juan Esteban Muller

Joel Repond

Danilo Quartullo

STRUCTURE

  • the folder __TEST_CASES contains several main files which show how to use the principal features of the code;
  • the __doc folder contains the source files for the documentation on-line;
  • the various packages which constitute the code;
  • setup_cpp.py is needed to compile all the C++ files present in the project; this file should be run once before launching any simulation. The compiler C++ GCC (at least version 4.8) is necessary.
  • WARNINGS.txt contains useful information related to code usage.

VERSION CONTENTS

  • 2017-03-28 v1.19.0 - Several files have been rearranged and simplified
  • 2017-02-10 v1.18.0 - Fixed an important bug in linear_interp_kick.cpp: before the acceleration kick was not applied if rf_kick_interp==TRUE in RingAndRFSection
  • v1.17.0 - Numerical synchrotron frequency distribution added (TC12) - Possibility to compute multi-turn wake with acceleration (inimpedance.py) - fixed a bug in the periodicity routine (in tracker.py)
  • 2016-10-24 v1.16.0 - MuSiC algorithm introduced, TC11 added, minor bugs fixed
  • 2016-07-29 v1.15.1 - several upgrades and bug fixes
  • 2016-06-23 v1.14.5 - RF modulation file added in llrf folder - documentation on-line for PSB phase loop added - setup_cython.py removed because not used
  • 2016-06-21 v1.14.4 -

About

BLonD (Beam Longitudinal Dynamics)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 83.5%
  • C++ 7.8%
  • Cuda 6.9%
  • HTML 1.1%
  • JavaScript 0.4%
  • Shell 0.3%