Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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})
Expand Down
22 changes: 16 additions & 6 deletions source/metrics/metrics_table/metrics_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
namespace sim {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ты не доделал задачу. Классно, что распараллелились картинки, но еще остаются тектовые метрики. С ними немного сложно и неочевидно, но разобраться реально. Есть еще два основных файла, где нужны правки:

void collect_and_save_all_metrics(const utils::IdTable<T>& id_table,

for (const auto& [link_id, link] :


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
}
Comment on lines +8 to +23

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Даже посрпшивав нейроку, я только крайне относительно понял, как и что здесь работает:) Схема жесть перегруженная, и я бы советовал уменьшить количество приседаний для достижения в общем-то простой цели (распараллелить форик по unordered map). Да, OpenMP не умеет из коробки вот так просто в одну прагму параллелить такое, но зато умеет это делать с обычными фориками, где мы идем счетчиком, а не итератором:

Suggested change
#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
}
std::vector<std::reference_wrapper<const value_type>> items;
items.reserve(size());
for (const auto& kv : *this) {
items.push_back(kv);
}
#pragma omp parallel for schedule(dynamic)
for (std::size_t i = 0; i < items.size(); ++i) {
const auto& [metric_id, storage] = items[i].get();
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});
}

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "connections_summary.hpp"

#include <omp.h>

Comment on lines +3 to +4

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выглядит лишним

Suggested change
#include <omp.h>

#include "utils/filesystem.hpp"

namespace sim {
Expand Down
2 changes: 2 additions & 0 deletions source/network/network.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "network.hpp"

#include <omp.h>

Comment on lines +3 to +4

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сейм

Suggested change
#include <omp.h>

#include "connection/connections_summary/connections_summary.hpp"
#include "metrics/metrics_table/combine_metrics_tables.hpp"

Expand Down
Loading