From 182015de539e473688d7bbc3a677f327ed7dc6e0 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 23 May 2026 21:14:12 +0300 Subject: [PATCH] parallel draw_pictures --- CMakeLists.txt | 6 +++-- .../metrics/metrics_table/metrics_table.cpp | 22 ++++++++++++++----- .../connections_summary.cpp | 2 ++ source/network/network.cpp | 2 ++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8a6511260..3d8cfe327e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ project(nons) # main part of project +find_package(OpenMP REQUIRED) + option(BUILD_PROJECT "Build project" ON) option(PROFILING "Add profiling flag" OFF) @@ -32,7 +34,7 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/external/matplotplusplus/) if (BUILD_PROJECT) set(TARGET_NAME "${PROJECT_NAME}") add_executable(${TARGET_NAME} ${src} source/main.cpp) - target_link_libraries(${TARGET_NAME} yaml-cpp matplot) + target_link_libraries(${TARGET_NAME} yaml-cpp matplot OpenMP::OpenMP_CXX) target_compile_options(${TARGET_NAME} PRIVATE -Wall -Werror -Wextra) if (DEFINED LOG_LEVEL) @@ -55,7 +57,7 @@ if(BUILD_TESTS) target_compile_definitions(${TEST_NAME} PRIVATE PROJECT_ROOT_DIR="${CMAKE_SOURCE_DIR}") target_compile_options(${TEST_NAME} PRIVATE -Wall -Werror -Wextra) - target_link_libraries(${TEST_NAME} gtest gmock gtest_main yaml-cpp matplot) + target_link_libraries(${TEST_NAME} gtest gmock gtest_main yaml-cpp matplot OpenMP::OpenMP_CXX) if (DEFINED LOG_LEVEL) target_compile_definitions(${TEST_NAME} PRIVATE LOG_LEVEL=${LOG_LEVEL}) diff --git a/source/metrics/metrics_table/metrics_table.cpp b/source/metrics/metrics_table/metrics_table.cpp index 2298dcefe5..397b83328c 100644 --- a/source/metrics/metrics_table/metrics_table.cpp +++ b/source/metrics/metrics_table/metrics_table.cpp @@ -5,12 +5,22 @@ namespace sim { void MetricsTable::draw_pictures(std::filesystem::path output_dir) const { - for (const auto& [metric_id, storage] : *this) { - std::filesystem::path plot_path = - output_dir / fmt::format("{}.svg", metric_id.name); - storage->draw_plot( - plot_path, - PlotMetadata{"Time, ns", metric_id.unit_name, metric_id.name}); +#pragma omp parallel + { +#pragma omp single + { + for (const auto& [metric_id, storage] : *this) { + std::filesystem::path plot_path = + output_dir / fmt::format("{}.svg", metric_id.name); +#pragma omp task firstprivate(metric_id, storage, plot_path) + { + storage->draw_plot( + plot_path, PlotMetadata{"Time, ns", metric_id.unit_name, + metric_id.name}); + } + } +#pragma omp taskwait + } } } diff --git a/source/network/connection/connections_summary/connections_summary.cpp b/source/network/connection/connections_summary/connections_summary.cpp index 682a60eb62..043739d6da 100644 --- a/source/network/connection/connections_summary/connections_summary.cpp +++ b/source/network/connection/connections_summary/connections_summary.cpp @@ -1,5 +1,7 @@ #include "connections_summary.hpp" +#include + #include "utils/filesystem.hpp" namespace sim { diff --git a/source/network/network.cpp b/source/network/network.cpp index d56a185d2b..06810314fa 100644 --- a/source/network/network.cpp +++ b/source/network/network.cpp @@ -1,5 +1,7 @@ #include "network.hpp" +#include + #include "connection/connections_summary/connections_summary.hpp" #include "metrics/metrics_table/combine_metrics_tables.hpp"