parallel draw_pictures - #564
Conversation
| #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 | ||
| } |
There was a problem hiding this comment.
Даже посрпшивав нейроку, я только крайне относительно понял, как и что здесь работает:) Схема жесть перегруженная, и я бы советовал уменьшить количество приседаний для достижения в общем-то простой цели (распараллелить форик по unordered map). Да, OpenMP не умеет из коробки вот так просто в одну прагму параллелить такое, но зато умеет это делать с обычными фориками, где мы идем счетчиком, а не итератором:
| #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}); | |
| } |
| @@ -5,12 +5,22 @@ | |||
| namespace sim { | |||
There was a problem hiding this comment.
Ты не доделал задачу. Классно, что распараллелились картинки, но еще остаются тектовые метрики. С ними немного сложно и неочевидно, но разобраться реально. Есть еще два основных файла, где нужны правки:
algnet/source/network/network.cpp
Line 20 in 8720cfd
| #include <omp.h> | ||
|
|
There was a problem hiding this comment.
Выглядит лишним
| #include <omp.h> |
| #include <omp.h> | ||
|
|
There was a problem hiding this comment.
Сейм
| #include <omp.h> |
close #559