In this project, three algorithms for computing three-body interactions for molecular dynamics simulations are implemented. All algorithms are based on those of P. Koanantakool and K. Yelick [1]. The forces between particle triplets are computed using the Axilrod-Teller potential, and our implementation of this potential is based on that of G. Marcelli [2]. Two direct algorithms were implemented, the Naive All Triplets Algorithm (NATA) and the All Unique Triplets Algorithm (AUTA), as well as the cutoff extension (P3BCA) presented in the paper. This project was developed as part of the bachelor thesis "A Comparison of Three-body Algorithms for Molecular Dynamics Simulations" [3], which can be found at this Link. In the thesis the details of the implementation, as well as results are explained in more detail.
Please use the git parameter --recurse-submodules when cloning the project, so all submodules are loaded.
This program was tested with cmake 3.16.3, eigen 3.4.0, OpenMPI 4.1.2 and gcc 9.4
Execute the following command in the root directory of the project: mkdir build && cd build && cmake ... This prepares the cmake project for compilation.
Execute make in the build directory after executing the above command. The main program is located in build/executables. This command will also build the particle generator into build/executables/tools.
-a: The algorithm to be used for the simulation- Possible values:
NATA,AUTA,P3BCA
- Possible values:
-i: Number of simulation steps (iterations)-d: Delta-time (duration of one time-step)-gx: Gravity in x-direction (analogous:-gy,-gz)-c: The cutoff distance in the case of the p3bca algorithm-csv: relative path to a csv-file containing particles, generated with the particle generator-decomp: The decomposition strategy for the p3bca algorithm.- possible values:
optimal,naive optimal: A dynamic 1D, 2D or 3D regular grid decomposition based on the prime decomposition of the number of processorsnaive: Subdivides the domain along the x-axis in equal slices
- possible values:
-o: specifies a csv outputfile, that stores all updated particles after the simulation
mpiexec -n 27 ./main -a p3bca -i 1 -d 0.001 -gx 0 -gy -9.81 -gz 0 -c 2 -csv uniform_2048.csv -decomp optimal -o out.csv- In this example, 27 processes are launched, which calculate one simulation step using the p3bca algorithm in a 3x3x3 regular grid decomposition with a cutoff radius of c=2. The particles are stored in out.csv after the simulation.
- Pass the following parameter to CMake:
cmake .. -DMEASURESIMSTEP_3BMDA=ON - The main program can be executed as in the upper step. As output, the times of all processors, as well as the maximum time over all processors are printed on the console in a JSON format (in nanoseconds).
The following particle distributions can be generated:
- Uniform: Generates uniformly distributed particles
- Parameters
--numparticles: Number of particles to be generated--blx: Domain-size in x-dir (analogous:--bly,--blz)
- Example:
./particlegenerator --generator uniform --numparticles 2048 --output uniform.csv --vx 0 --vy 0 --vz 0 --mass 1 --seed0 926762934 --blx 10 --bly 10 --blz 10
- Parameters
- Grid: Generates particles with equal spacing
- Parameters
--particlesperx: number of particles in x-dir (analogous:--particlespery,--particlesperz)--particlespacing: spacing between particles in all directions
- Example:
./particlegenerator --generator grid --output grid.csv --vx 0 --vy 0 --vz 0 --mass 1 --particlesperx 10 --particlespery 10 --particlesperz 10 --particlespacing 1
- Parameters
- Closest Packed: Generates hexagonally closest packed particles
- Parameters
--blx: Domain-size in x-dir (analogous:--bly,--blz)--particlespacing: spacing between particles in all directions
- Example:
./particlegenerator --generator closestpacked --output cpacked.csv --vx 0 --vy 0 --vz 0 --mass 1 --blx 10 --bly 10 --blz 10 --particlespacing 0.5
- Parameters
- Clustered Gauss: Generates uniform distributed gaussian clouds
- Parameters
--numparticles: Total number of particles to be generated--blx: Domain-size in x-dir (analogous:--bly,--blz)--numclusters: Number of gaussian clouds to be generated--distmean: Mean for the normal distribution in all directions of all gaussian clouds--diststddev: Variance for the normal distribution in all directions of all gaussian clouds
- Example:
./particlegenerator --generator clusteredgauss --numparticles 2500 --distmean 0 --diststddev 1 --output cgauss.csv --vx 0 --vy 0 --vz 0 --mass 1 --seed0 926762934 --seed1 89347587 --blx 10 --bly 10 --blz 10 --numclusters 25
- Parameters
- Gauss: Generates one gaussian cloud
- Parameters
--numparticles: Total number of particles to be generated--blx: Domain-size in x-dir (analogous:--bly,--blz)--distmean: Mean for the normal distribution in all directions--diststddev: Variance for the normal distribution in all directions
- Example:
./particlegenerator --generator gauss --numparticles 2500 --distmean 5 --diststddev 1 --output gauss.csv --vx 0 --vy 0 --vz 0 --mass 1 --seed0 926762934 --blx 10 --bly 10 --blz 10
- Parameters
--generator: The particle generator to be used- Possible values:
uniform,grid,closestpacked,clusteredgauss,gauss
- Possible values:
--output: Output csv-file that stores the generated particles--vx: Initial particle velocity in x-dir--vy: Initial particle velocity in y-dir--vz: Initial particle velocity in z-dir--mass: particle mass--seed0: seed for the uniform, clusteredgauss and gauss distribution--seed1: additional seed for the clusteredgauss distribution
The following parameters are available for cmake:
- TESTS_3BMDA: This will compile the unit tests into build/executables/tests.
- Usage:
cmake .. -DTESTS_3BMDA=ON && make - Run tests: go to build/executables/tests and execute ./testrunner
- Usage:
- BENCHMARK_3BMDA: This will compile the benchmarks using Google Benchmark into build/executables/benchmarks.
- Note: The most easiest way to measure one simulation step is to use the
MEASURESIMSTEP_3BMDAcmake option below instead of this benchmarks - Usage:
cmake .. -DBENCHMARK_3BMDA=ON && make - Run a benchmark: A benchmark requires as input a YAML file in which the simulation parameters are defined
- Example YAML file:
In the example file, 2 benchmarks are defined, one using the All Unique Triplet algorithm and one using the Naive All Triplet algorithm. The string specified under type refers to the benchmark to be executed. Besides the specified benchmark
benchmarks: - args: cutoff: 2.4 decomposition: optimal deltaT: 0.001 gForce: - 0 - 0 - 0 iterations: 1 name: AUTA subtype: AUTA type: SingleIterationOnlySimStep - args: cutoff: 2.4 decomposition: optimal deltaT: 0.001 gForce: - 0 - 0 - 0 iterations: 1 name: NATA subtype: NATA type: SingleIterationOnlySimStep gbench_iterations: 1 unit: seconds
SingleIterationOnlySimStep, further benchmarks can be defined by inheriting from the classMPIBenchmark. As an example seebenchmarks/MPIBenchmark.cpp,benchmarks/SingleIterationOnlySimStep.cppandbenchmarks/utils.hpp. The subtype refers to the algorithm to be used (NATA, AUTA, P3BCA). The arguments are the duration of a simulation step (deltaT), the gravity (gForce) in x, y and z direction and the number of simulation steps (iterations). The parametersdecompositionandcutoffhave only an influence if the cutoff algorithm (P3BCA) is used. Underdecompositioneitheroptimalornaivecan be specified, whereoptimalselects a 1D, 2D or 3D decomposition from the fileutility/decompositions.hppwith the given number of processors,naivecreates a simple 1D decomposition along the x-axis with the given number of processors. The parametergbench_iterationsspecifies how many times the benchmark should be executed, where the average time of all iterations is calculated and stored.unitspecifies the time unit in which the benchmark should be run. A benchmark can then be run from the/build/executables/benchmarksdirectory as follows:This runs the benchmarks specified in config-filempiexec -n 16 ./benchmain_cluster --benchyaml parameters.yaml --csv uniform_2048.csv --benchmark_out="nata_vs_auta.json" --benchmark_out_format=json --benchmark_counters_tabular=trueparameters.yamlwith 16 processors, the particles inuniform_2048.csvand saves the output asnata_vs_auta.json.
- Example YAML file:
- Note: The most easiest way to measure one simulation step is to use the
- PROFILE_3BMDA: Compiles the main program containing the compiler directives so that individual methods can be measured in more detail. A JSON file is generated as output, which stores the times across all processors spent in different methods.
- Usage:
cmake .. -DPROFILE_3BMDA=ON && make - An exemplary execution looks as follows:
mpiexec -n 4 ./main -a auta -i 1 -d 0.001 -gx 0 -gy 0 -gz 0 -c 0 -csv uniform_2048.csv -decomp optimal -op "profile_auta_uniform_2048_4.json"In the example, individual methods of the All Unique Triplets algorithm are measured and stored in the fileprofile_auta_uniform_2048_4.json. Within the output file the measured times are represented in different ways:avg time all proc: The average time of this method over all substeps and all processorstotal time all proc: The sum of the times of this method over all substeps and processorstotal avg time union proc: The sum of the average times over all processors of each substep.total max time union proc: The sum of the maximum values over all processors of each substeptimes per proc: prints for each processori in {0 ... p-1}the times of all substeps of the respective method as a list
- Usage:
- MEASURESIMSTEP_3BMDA: Compiles the main program so that the time of a simulation step can be measured.
- Usage:
cmake .. -DMEASURESIMSTEP_3BMDA=ON && make - Measure one simulation-step: see the above bullet point "Simple measurement of one Simulation Step"
- Usage:
- VLEVEL: More verbose output is printed to the console when a simulation step is executed
- Usage:
cmake .. -DVLEVEL=1 && make, then the program can be used as described in "Example Execution".
- Usage:
All default values are either OFF, or -1 if a parameter is not specified.
The following external tools are used for this project:
- [1]: P. Koanantakool and K. Yelick, "A Computation- and Communication-Optimal Parallel Direct 3-Body Algorithm," SC '14: Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis, 2014, pp. 363-374, doi: 10.1109/SC.2014.35.
- [2]: Marcelli, Gianluca. The role of three-body interactions on the equilibrium and non-equilibrium properties of fluids from molecular simulation. University of Kent (United Kingdom), 2001.
- [3]: Martin, David. A Comparison of Three-body Algorithms for Molecular Dynamics Simulations. Technical University of Munich, Nov 2022