Skip to content

Commit

Permalink
Merge pull request #92 from ManuelLerchner/performance_cluster
Browse files Browse the repository at this point in the history
Performance cluster
  • Loading branch information
ManuelLerchner authored Jan 8, 2024
2 parents 335f831 + 1340473 commit 84871cb
Show file tree
Hide file tree
Showing 24 changed files with 269 additions and 112 deletions.
58 changes: 18 additions & 40 deletions benchmarks/2DParticleRect/2DParticleRect.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <array>
#include <memory>

#include "../FileLoader.h"
#include "io/input/FileInputHandler.h"
#include "io/logger/Logger.h"
#include "io/output/FileOutputHandler.h"
#include "particles/containers/ParticleContainer.h"
Expand All @@ -16,6 +18,10 @@ void execute2DRectBenchmark(int rect_width, int rect_height, double spacing, dou
Logger::logger->set_level(spdlog::level::info);
Logger::logger->info("Starting 2DRect-benchmark. Dimensions {}x{}...", rect_width, rect_height);

// Parse input file
auto [initial_particles, simulation_arguments] =
FileInputHandler::readFile(FileLoader::get_input_file_path("2DParticleRect/BenchmarkRectFrame.xml"), true);

// Settings for the Linked Cells Container simulation
std::array<double, 3> domain_size = {300, 300, 3};
std::array<LinkedCellsContainer::BoundaryCondition, 6> boundary_conditions = {
Expand All @@ -28,10 +34,6 @@ void execute2DRectBenchmark(int rect_width, int rect_height, double spacing, dou
CuboidSpawner spawner(center_offset - std::array<double, 3>{rect_width * spacing / 2, rect_height * spacing / 2, 0},
{rect_width, rect_height, 1}, spacing, 1, {0, 0, 0}, 0);

// Settings for the forces for both simulations
std::vector<std::shared_ptr<PairwiseForceSource>> forces;
forces.push_back(std::make_shared<LennardJonesForce>());

// ############################################################
// # Direct Sum Container
// ############################################################
Expand All @@ -41,7 +43,7 @@ void execute2DRectBenchmark(int rect_width, int rect_height, double spacing, dou

// Instantiation of the Direct Sum Container simulation

SimulationParams params_ds("2DParticleRect.xml", 0.01, 5, SimulationParams::DirectSumType{}, {}, {}, forces, true, true);
SimulationParams params_ds{*simulation_arguments};

params_ds.num_particles = particles_ds.size();

Expand All @@ -51,6 +53,7 @@ void execute2DRectBenchmark(int rect_width, int rect_height, double spacing, dou
params_ds.logSummary();
SimulationOverview direct_sum_data = simulation_ds.runSimulation();
direct_sum_data.logSummary();
direct_sum_data.savePerformanceDataCSV("DirectSum" + std::to_string(rect_width) + "x" + std::to_string(rect_height));

// ############################################################
// # Linked Cells Container
Expand All @@ -59,52 +62,27 @@ void execute2DRectBenchmark(int rect_width, int rect_height, double spacing, dou
std::vector<Particle> particles_lc;
spawner.spawnParticles(particles_lc);
// Instantiation of the Linked Cells Container simulation
SimulationParams params_lc{"2DParticleRect.xml",
0.01,
5,
SimulationParams::LinkedCellsType{domain_size, lc_cutoff, boundary_conditions},
{},
{},
forces,
true,
true};
SimulationParams params_lc{*simulation_arguments};
params_lc.container_type = SimulationParams::LinkedCellsType{domain_size, lc_cutoff, boundary_conditions};
params_lc.num_particles = particles_lc.size();

Simulation simulation_lc(particles_lc, params_lc);
// Simulating with Linked Cells Container
params_lc.logSummary();
SimulationOverview linked_cells_data = simulation_lc.runSimulation();
linked_cells_data.logSummary();
linked_cells_data.savePerformanceDataCSV("LinkedCells" + std::to_string(rect_width) + "x" + std::to_string(rect_height));

// ############################################################
// # Comparison Logging
// ############################################################

std::string ds_summary = "";
for (auto& summary : direct_sum_data.interceptor_summaries) {
ds_summary += summary + ";";
}

std::string lc_summary = "";
for (auto& summary : linked_cells_data.interceptor_summaries) {
lc_summary += summary + ";";
}

Logger::logger->info("Simulation of {} particles in a {}x{} grid\n", rect_width * rect_height, rect_width, rect_height);

Logger::logger->info("Direct sum container:");
Logger::logger->info(" Simulation took {:.3f}s", direct_sum_data.total_time_seconds);
Logger::logger->info(" Total iterations: {}", direct_sum_data.total_iterations);
Logger::logger->info(" Average time per iteration: {:.3f}ms\n", direct_sum_data.total_time_seconds / direct_sum_data.total_iterations);
Logger::logger->info(" Summary {}", ds_summary);

Logger::logger->info("Linked cells container:");
Logger::logger->info(" Domain size: {:.0f}x{:.0f}x{:.0f}", domain_size[0], domain_size[1], domain_size[2]);
Logger::logger->info(" Linked cells cutoff radius: {:.0f}", lc_cutoff);
Logger::logger->info(" Simulation took {:.3f}s", linked_cells_data.total_time_seconds);
Logger::logger->info(" Total iterations: {}", linked_cells_data.total_iterations);
Logger::logger->info(" Average time per iteration: {:.3f}ms\n",
linked_cells_data.total_time_seconds / linked_cells_data.total_iterations);
Logger::logger->info(" Summary {}", lc_summary);
Logger::logger->info("Comparison of Direct Sum and Linked Cells Container:");
// Ratio between Direct Sum and Linked Cells Container performance
Logger::logger->info("Runtime Direct Sum: {} s", direct_sum_data.total_time_seconds);
Logger::logger->info("Runtime Linked Cells: {} s", linked_cells_data.total_time_seconds);
Logger::logger->info("Performance ratio (DirectSum / LinkedCells): {}",
direct_sum_data.total_time_seconds / linked_cells_data.total_time_seconds);
}

/*
Expand Down
25 changes: 25 additions & 0 deletions benchmarks/2DParticleRect/BenchmarkRectFrame.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!-- just a sanity check: body collision rewritten to xml -->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../simulation_schema.xsd">

<settings>
<delta_t>0.01</delta_t>
<end_time>5.0</end_time>
<third_dimension>false</third_dimension>
<particle_container>
<directsum_container />
</particle_container>
<forces>
<LennardJones />
</forces>
<interceptors>
<ParticleUpdatesPerSecond />
</interceptors>
</settings>


<particle_source>
</particle_source>

</configuration>
57 changes: 57 additions & 0 deletions benchmarks/2D_task4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <array>
#include <memory>

#include "io/logger/Logger.h"
#include "io/output/FileOutputHandler.h"
#include "particles/containers/ParticleContainer.h"
#include "particles/containers/directsum/DirectSumContainer.h"
#include "particles/containers/linkedcells/LinkedCellsContainer.h"
#include "particles/spawners/cuboid/CuboidSpawner.h"
#include "physics/pairwiseforces/GravitationalForce.h"
#include "physics/pairwiseforces/LennardJonesForce.h"
#include "simulation/Simulation.h"
#include "utils/ArrayUtils.h"

void execute2DRectBenchmark(int rect_width, int rect_height, double spacing, double lc_cutoff) {
Logger::logger->set_level(spdlog::level::info);
Logger::logger->info("Starting 2DRect-benchmark. Dimensions {}x{}...", rect_width, rect_height);

// Settings for the Linked Cells Container simulation
std::array<double, 3> domain_size = {300, 300, 3};
std::array<LinkedCellsContainer::BoundaryCondition, 6> boundary_conditions = {
LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE,
LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE,
LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE};

// Settings for the Cuboid spawner
std::array<double, 3> center_offset = {domain_size[0] / 2, domain_size[1] / 2, domain_size[2] / 2};
CuboidSpawner spawner(center_offset - std::array<double, 3>{rect_width * spacing / 2, rect_height * spacing / 2, 0},
{rect_width, rect_height, 1}, spacing, 1, {0, 0, 0}, 0);

std::vector<std::shared_ptr<PairwiseForceSource>> forces;
forces.push_back(std::make_shared<LennardJonesForce>());

std::vector<Particle> particles_lc;
spawner.spawnParticles(particles_lc);
// Instantiation of the Linked Cells Container simulation
SimulationParams params_lc{"2DParticleRect.xml",
0.01,
5,
SimulationParams::LinkedCellsType{domain_size, lc_cutoff, boundary_conditions},
{},
{},
forces,
true};
params_lc.num_particles = particles_lc.size();
Simulation simulation_lc(particles_lc, params_lc);
// Simulating with Linked Cells Container
params_lc.logSummary();
SimulationOverview linked_cells_data = simulation_lc.runSimulation();
linked_cells_data.logSummary();
linked_cells_data.savePerformanceDataCSV("Task4" + std::to_string(rect_width) + "x" + std::to_string(rect_height));
}

int main() {
execute2DRectBenchmark(100, 100, 1.1225, 3);
return 0;
}
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ foreach (_source IN ITEMS ${BENCHMARK_SRC})
add_executable(${_name} EXCLUDE_FROM_ALL ${_source})
target_link_libraries(${_name} project_lib)
add_dependencies(benchmarks ${_name})
target_compile_definitions(${_name} PRIVATE BENCHMARK_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
endforeach ()

30 changes: 30 additions & 0 deletions benchmarks/FileLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <io/logger/Logger.h>

#include <filesystem>
#include <string>

#pragma once

class FileLoader {
public:
/**
* @brief Gets the path to the data directory
*
* Uses the cmake target_compile_definitions PRIVATE BENCHMARK_DATA_DIR to define the path to the data directory.
*/
static std::string get_benchmark_data_dir() {
#ifdef BENCHMARK_DATA_DIR
return BENCHMARK_DATA_DIR;
#else
throw std::runtime_error("Error: BENCHMARK_DATA_DIR not defined");
#endif
}

/**
* @brief Gets the path to a file in the input directory
*
* @param file_name The name of the file
* @return std::filesystem::path The path to the file
*/
static std::filesystem::path get_input_file_path(const std::string& file_name) { return {get_benchmark_data_dir() + "/" + file_name}; }
};
68 changes: 68 additions & 0 deletions benchmarks/contest1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

#include <array>
#include <memory>

#include "io/logger/Logger.h"
#include "io/output/FileOutputHandler.h"
#include "particles/containers/ParticleContainer.h"
#include "particles/containers/directsum/DirectSumContainer.h"
#include "particles/containers/linkedcells/LinkedCellsContainer.h"
#include "particles/spawners/cuboid/CuboidSpawner.h"
#include "physics/pairwiseforces/GravitationalForce.h"
#include "physics/pairwiseforces/LennardJonesForce.h"
#include "physics/simpleforces/GlobalDownwardsGravity.h"
#include "physics/thermostats/Thermostat.cpp"
#include "simulation/Simulation.h"
#include "simulation/interceptors/thermostat/ThermostatInterceptor.h"
#include "utils/ArrayUtils.h"

void execute2DRectBenchmark() {
Logger::logger->set_level(spdlog::level::info);

// Settings for the Linked Cells Container simulation
std::array<double, 3> domain_size = {300, 54, 3};
std::array<LinkedCellsContainer::BoundaryCondition, 6> boundary_conditions = {
LinkedCellsContainer::BoundaryCondition::PERIODIC, LinkedCellsContainer::BoundaryCondition::PERIODIC,
LinkedCellsContainer::BoundaryCondition::REFLECTIVE, LinkedCellsContainer::BoundaryCondition::REFLECTIVE,
LinkedCellsContainer::BoundaryCondition::OUTFLOW, LinkedCellsContainer::BoundaryCondition::OUTFLOW};

// Settings for the Cuboid spawner of task 2
CuboidSpawner spawner1({0.6, 2.0, 0.5}, {250, 20, 1}, 1.2, 1.0, {0.0, 0.0, 0.0}, static_cast<int>(0), 1.0, 1.2, false, 40);
CuboidSpawner spawner2({0.6, 27.0, 0.5}, {250, 20, 1}, 1.2, 2.0, {0.0, 0.0, 0.0}, static_cast<int>(1), 1.0, 1.1, false, 40);

std::vector<std::shared_ptr<PairwiseForceSource>> pairwise_forces;
std::vector<std::shared_ptr<SimpleForceSource>> simple_force_sources;
pairwise_forces.push_back(std::make_shared<LennardJonesForce>());
simple_force_sources.push_back(std::make_shared<GlobalDownwardsGravity>(12.44));

// Set the thermostat:
Thermostat thermostat{40, std::numeric_limits<double>::infinity(), static_cast<size_t>(1000), false};
std::vector<std::shared_ptr<SimulationInterceptor>> simulation_interceptors;
simulation_interceptors.push_back(std::make_shared<ThermostatInterceptor>(thermostat));

std::vector<Particle> particles_lc;
spawner1.spawnParticles(particles_lc);
spawner2.spawnParticles(particles_lc);
// Instantiation of the Linked Cells Container simulation
SimulationParams params_lc{"2DParticleRect.xml",
0.0005,
0.5,
SimulationParams::LinkedCellsType{domain_size, 2.5, boundary_conditions},
simulation_interceptors,
simple_force_sources,
pairwise_forces,
false,
"./output"};
params_lc.num_particles = particles_lc.size();
Simulation simulation_lc(particles_lc, params_lc);
// Simulating with Linked Cells Container
params_lc.logSummary();
SimulationOverview linked_cells_data = simulation_lc.runSimulation();
linked_cells_data.logSummary();
linked_cells_data.savePerformanceDataCSV("Contest");
}

int main() {
execute2DRectBenchmark();
return 0;
}
1 change: 1 addition & 0 deletions benchmarks/simulation_schema.xsd
3 changes: 3 additions & 0 deletions src/MolSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ int main(int argc, char* argsv[]) {
// Print simulation overview
overview.logSummary();

// Save performance data to csv file
overview.savePerformanceDataCSV();

return 0;
}
5 changes: 0 additions & 5 deletions src/io/cli/CLIParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ struct CLIParams {
*/
std::filesystem::path input_file_path;

/**
* Whether to run a performance test
*/
bool performance_test;

/**
* Whether to use cached data or rerun all the (sub)simulations from scratch
*/
Expand Down
8 changes: 1 addition & 7 deletions src/io/cli/CLIParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ CLIParams parse_arguments(int argc, char* argsv[]) {
std::string log_level;
std::string log_output;

bool performance_test = false;
bool fresh = false;

// choosing 0 as one of the parameters (end_time, delta_t, fps, video_length) is equivalent to choosing the default value
Expand All @@ -22,7 +21,6 @@ CLIParams parse_arguments(int argc, char* argsv[]) {
"The path to the input file. Must be specified, otherwise the program will terminate. Can be inserted as positional argument.");
options_desc.add_options()("log_level,l", boost::program_options::value<std::string>(&log_level)->default_value("info"),
"The log level. Possible values: trace, debug, info, warning, error, critical, off");
options_desc.add_options()("performance_test,p", "Run the simulation in performance test mode");
options_desc.add_options()(
"log_output", boost::program_options::value<std::string>(&log_output)->default_value("std"),
"You can only choose between the output options std(only cl output) and file (only file output). Default: no file output");
Expand Down Expand Up @@ -64,11 +62,8 @@ CLIParams parse_arguments(int argc, char* argsv[]) {
Logger::logger->info(help_message.str());
exit(-1);
}
if (variables_map.count("performance_test")) {
performance_test = true;
}

return CLIParams{input_file_path, performance_test, fresh};
return CLIParams{input_file_path, fresh};
}

SimulationParams merge_parameters(const CLIParams& params_cli, const std::optional<SimulationParams>& file_params) {
Expand All @@ -81,7 +76,6 @@ SimulationParams merge_parameters(const CLIParams& params_cli, const std::option

// Update the parameters with the ones from the command line
params.fresh = params_cli.fresh;
params.performance_test = params_cli.performance_test;

return params;
}
6 changes: 3 additions & 3 deletions src/io/input/xml/XMLFileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ std::tuple<std::vector<Particle>, SimulationParams> prepareParticles(std::filesy

auto forces = XSDToInternalTypeAdapter::convertToForces(settings.forces());

auto params = SimulationParams{curr_file_path, settings.delta_t(), settings.end_time(), container_type,
interceptors, std::get<0>(forces), std::get<1>(forces), false,
fresh, output_base_path};
auto params = SimulationParams{curr_file_path, settings.delta_t(), settings.end_time(), container_type,
interceptors, std::get<0>(forces), std::get<1>(forces), fresh,
output_base_path};

if (output_base_path.empty()) {
output_base_path = params.output_dir_path;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void LinkedCellsContainer::updateCellsParticleReferences() {
void LinkedCellsContainer::deleteHaloParticles() {
for (Cell* cell : halo_cell_references) {
for (Particle* p : cell->getParticleReferences()) {
particles.erase(std::find(particles.begin(), particles.end(), *p));
particles.erase(particles.begin() + (p - &particles[0]));
}
}
}
Loading

0 comments on commit 84871cb

Please sign in to comment.