Installation
This section describes how libgran can be installed into a project. If your project is a git repository, libgran can be added to it as a git submodule. To install libgran and its dependency libtimestep in a directory named deps under your project root, execute the following commands:
Since libgran and libtimestep are header-only libraries, they can be included in your project without linking against an object. Simply, add the include directories of libgran and libtimestep in your CMakeLists.txt file:
By default, libgran uses C++ 17 parallel algorithms for computation of binary interactions. In case you would like to use OpenMP instead, LIBGRAN_USE_OMP
compile definition needs to be added. In your CMakeLists.txt, add the following line:
Note that for improved performance / parallelization capabilities, additional compiler flags might be required on your system. Platform- and toolchain-specific instructions are provided below. Also, the optimal number of threads depends on the size of the granular system. Using too many threads can be detrimental to performance.
Linux & GNU C++ compiler
The following compiler flags are recommended for best performance:
If you opted for C++ 17 parallel algorithms, Intel TBB library needs to be installed and linked against. On Ubuntu, TBB can be installed with:
Then, in your CMakeLists.txt file, add:
If you opted for OpenMP, the following flag needs to be added:
Then, every time you run your simulation, the number of threads can be set prior to execution with:
Windows & MSVC compiler
The following compiler flags are recommended for best performance:
It is important that you build configuration is set to Release. Otherwise, MSVC produces very slow binaries.
C++ 17 parallel algorithms work out of the box under MSVC without the need for additional compiler flags or libraries.
If you opted for OpenMP, the following flag needs to be added:
Then, every time you run your simulation, the number of threads can be set prior to execution with:
macOS & LLVM/clang compiler
LLVM/clang compiler has to be used with OpenMP parallelization. LLVM/clang and OpenMP need to be installed:
To use LLVM/clang instead of AppleClang with CMake, run:
The following compiler flags are recommended for best performance:
The following linker flags are recommended for best performance:
Every time you run your simulation, the number of threads can be set prior to execution with:
macOS & AppleClang compiler
The default AppleClang compiler bundled with XCode is not supported, because it does not support C++ 17 parallel algorithms or OpenMP.