From e07b139a778fd47f9fa4fd4c046e5c4870ba25e2 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 16 Nov 2025 11:27:17 +0000 Subject: [PATCH 01/36] add student folder --- .../common/include/common.hpp | 15 +++ tasks/luzan_e_matrix_rows_sum/data/pic.jpg | Bin 0 -> 23 bytes tasks/luzan_e_matrix_rows_sum/info.json | 9 ++ .../mpi/include/ops_mpi.hpp | 22 +++++ .../mpi/src/ops_mpi.cpp | 72 +++++++++++++++ tasks/luzan_e_matrix_rows_sum/report.md | 0 .../seq/include/ops_seq.hpp | 22 +++++ .../seq/src/ops_seq.cpp | 60 ++++++++++++ tasks/luzan_e_matrix_rows_sum/settings.json | 7 ++ .../luzan_e_matrix_rows_sum/tests/.clang-tidy | 13 +++ .../tests/functional/main.cpp | 86 ++++++++++++++++++ .../tests/performance/main.cpp | 40 ++++++++ 12 files changed, 346 insertions(+) create mode 100644 tasks/luzan_e_matrix_rows_sum/common/include/common.hpp create mode 100644 tasks/luzan_e_matrix_rows_sum/data/pic.jpg create mode 100644 tasks/luzan_e_matrix_rows_sum/info.json create mode 100644 tasks/luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp create mode 100644 tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp create mode 100644 tasks/luzan_e_matrix_rows_sum/report.md create mode 100644 tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp create mode 100644 tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp create mode 100644 tasks/luzan_e_matrix_rows_sum/settings.json create mode 100644 tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy create mode 100644 tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp create mode 100644 tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp new file mode 100644 index 0000000000..1e671240d8 --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include "task/include/task.hpp" + +namespace luzan_e_matrix_rows_sum { + +using InType = int; +using OutType = int; +using TestType = std::tuple; +using BaseTask = ppc::task::Task; + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/data/pic.jpg b/tasks/luzan_e_matrix_rows_sum/data/pic.jpg new file mode 100644 index 0000000000000000000000000000000000000000..637624238c89d914613ed301968bffbf462bc110 GIT binary patch literal 23 bcmWGA<1$h(;xaNd<@(RSzyQYo|NjR7KDY + +#include +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_matrix_rows_sum { + +LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = 0; +} + +bool LuzanEMatrixRowsSumMPI::ValidationImpl() { + return (GetInput() > 0) && (GetOutput() == 0); +} + +bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { + GetOutput() = 2 * GetInput(); + return GetOutput() > 0; +} + +bool LuzanEMatrixRowsSumMPI::RunImpl() { + auto input = GetInput(); + if (input == 0) { + return false; + } + + for (InType i = 0; i < GetInput(); i++) { + for (InType j = 0; j < GetInput(); j++) { + for (InType k = 0; k < GetInput(); k++) { + std::vector tmp(i + j + k, 1); + GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetOutput() -= i + j + k; + } + } + } + + const int num_threads = ppc::util::GetNumThreads(); + GetOutput() *= num_threads; + + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + if (rank == 0) { + GetOutput() /= num_threads; + } else { + int counter = 0; + for (int i = 0; i < num_threads; i++) { + counter++; + } + + if (counter != 0) { + GetOutput() /= counter; + } + } + + MPI_Barrier(MPI_COMM_WORLD); + return GetOutput() > 0; +} + +bool LuzanEMatrixRowsSumMPI::PostProcessingImpl() { + GetOutput() -= GetInput(); + return GetOutput() > 0; +} + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp b/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp new file mode 100644 index 0000000000..3ca4cd6136 --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumSEQ : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kSEQ; + } + explicit LuzanEMatrixRowsSumSEQ(const InType &in); + + private: + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; +}; + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp new file mode 100644 index 0000000000..ce4fc1eac6 --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -0,0 +1,60 @@ +#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" + +#include +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_matrix_rows_sum { + +LuzanEMatrixRowsSumSEQ::LuzanEMatrixRowsSumSEQ(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = 0; +} + +bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { + return (GetInput() > 0) && (GetOutput() == 0); +} + +bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { + GetOutput() = 2 * GetInput(); + return GetOutput() > 0; +} + +bool LuzanEMatrixRowsSumSEQ::RunImpl() { + if (GetInput() == 0) { + return false; + } + + for (InType i = 0; i < GetInput(); i++) { + for (InType j = 0; j < GetInput(); j++) { + for (InType k = 0; k < GetInput(); k++) { + std::vector tmp(i + j + k, 1); + GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetOutput() -= i + j + k; + } + } + } + + const int num_threads = ppc::util::GetNumThreads(); + GetOutput() *= num_threads; + + int counter = 0; + for (int i = 0; i < num_threads; i++) { + counter++; + } + + if (counter != 0) { + GetOutput() /= counter; + } + return GetOutput() > 0; +} + +bool LuzanEMatrixRowsSumSEQ::PostProcessingImpl() { + GetOutput() -= GetInput(); + return GetOutput() > 0; +} + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/settings.json b/tasks/luzan_e_matrix_rows_sum/settings.json new file mode 100644 index 0000000000..7d2c35b298 --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/settings.json @@ -0,0 +1,7 @@ +{ + "tasks_type": "processes", + "tasks": { + "mpi": "enabled", + "seq": "enabled" + } +} diff --git a/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy b/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy new file mode 100644 index 0000000000..d68523c24e --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy @@ -0,0 +1,13 @@ +InheritParentConfig: true + +Checks: > + -modernize-loop-convert, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-avoid-non-const-global-variables, + -misc-use-anonymous-namespace, + -modernize-use-std-print, + -modernize-type-traits + +CheckOptions: + - key: readability-function-cognitive-complexity.Threshold + value: 50 # Relaxed for tests diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp new file mode 100644 index 0000000000..2c4ec6a584 --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -0,0 +1,86 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" +#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" +#include "util/include/func_test_util.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests { + public: + static std::string PrintTestParam(const TestType &test_param) { + return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param); + } + + protected: + void SetUp() override { + int width = -1; + int height = -1; + int channels = -1; + std::vector img; + // Read image in RGB to ensure consistent channel count + { + std::string abs_path = ppc::util::GetAbsoluteTaskPath(PPC_ID_luzan_e_matrix_rows_sum, "pic.jpg"); + auto *data = stbi_load(abs_path.c_str(), &width, &height, &channels, STBI_rgb); + if (data == nullptr) { + throw std::runtime_error("Failed to load image: " + std::string(stbi_failure_reason())); + } + channels = STBI_rgb; + img = std::vector(data, data + (static_cast(width * height * channels))); + stbi_image_free(data); + if (std::cmp_not_equal(width, height)) { + throw std::runtime_error("width != height: "); + } + } + + TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + input_data_ = width - height + std::min(std::accumulate(img.begin(), img.end(), 0), channels); + } + + bool CheckTestOutputData(OutType &output_data) final { + return (input_data_ == output_data); + } + + InType GetTestInputData() final { + return input_data_; + } + + private: + InType input_data_ = 0; +}; + +namespace { + +TEST_P(LuzanEMatrixRowsSumFuncTests, MatmulFromPic) { + ExecuteTest(GetParam()); +} + +const std::array kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")}; + +const auto kTestTasksList = + std::tuple_cat(ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), + ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum)); + +const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); + +const auto kPerfTestName = LuzanEMatrixRowsSumFuncTests::PrintFuncTestName; + +INSTANTIATE_TEST_SUITE_P(PicMatrixTests, LuzanEMatrixRowsSumFuncTests, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp new file mode 100644 index 0000000000..f916e3a945 --- /dev/null +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -0,0 +1,40 @@ +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" +#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" +#include "util/include/perf_test_util.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { + const int kCount_ = 100; + InType input_data_{}; + + void SetUp() override { + input_data_ = kCount_; + } + + bool CheckTestOutputData(OutType &output_data) final { + return input_data_ == output_data; + } + + InType GetTestInputData() final { + return input_data_; + } +}; + +TEST_P(LuzanEMatrixRowsSumpERFTests, RunPerfModes) { + ExecuteTest(GetParam()); +} + +const auto kAllPerfTasks = + ppc::util::MakeAllPerfTasks(PPC_SETTINGS_luzan_e_matrix_rows_sum); + +const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); + +const auto kPerfTestName = LuzanEMatrixRowsSumpERFTests::CustomPerfTestName; + +INSTANTIATE_TEST_SUITE_P(RunModeTests, LuzanEMatrixRowsSumpERFTests, kGtestValues, kPerfTestName); + +} // namespace luzan_e_matrix_rows_sum From a3bbc5a8b97d51197fe7a9528a380d59078a7654 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Mon, 17 Nov 2025 23:57:55 +0000 Subject: [PATCH 02/36] base task solution --- .../common/include/common.hpp | 6 +- .../mpi/src/ops_mpi.cpp | 69 +++++++++---------- .../seq/include/ops_seq.hpp | 8 +-- .../seq/src/ops_seq.cpp | 49 ++++++------- .../tests/functional/main.cpp | 48 ++++++------- .../tests/performance/main.cpp | 21 +++++- 6 files changed, 101 insertions(+), 100 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 1e671240d8..a545ebaf6f 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -7,9 +7,9 @@ namespace luzan_e_matrix_rows_sum { -using InType = int; -using OutType = int; -using TestType = std::tuple; +using InType = std::tuple, int, int>; // matrix, height, width +using OutType = std::vector; // vec of sums, size = height +using TestType = std::tuple; // height & width using BaseTask = ppc::task::Task; } // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index a8f1d4e575..cdc9c2aa71 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" #include "util/include/util.hpp" @@ -13,60 +14,54 @@ namespace luzan_e_matrix_rows_sum { LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { SetTypeOfTask(GetStaticTypeOfTask()); GetInput() = in; - GetOutput() = 0; + GetOutput() = {}; } bool LuzanEMatrixRowsSumMPI::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + + return std::get<0>(GetInput()).size() == static_cast(height * width) && + height != 0 && width != 0; } bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + int height = std::get<1>(GetInput()); + GetOutput().resize(height); + for (int row = 0; row < height; row++) { + GetOutput()[row] = 0; + } + return true; } bool LuzanEMatrixRowsSumMPI::RunImpl() { - auto input = GetInput(); - if (input == 0) { - return false; - } + const int height = std::get<1>(GetInput()); + const int width = std::get<2>(GetInput()); + const std::tuple_element_t<0, InType>& mat = std::get<0>(GetInput()); + OutType& sum_vec = GetOutput(); + OutType part_sum_vec = GetOutput(); - for (InType i = 0; i < GetInput(); i++) { - for (InType j = 0; j < GetInput(); j++) { - for (InType k = 0; k < GetInput(); k++) { - std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; - } - } - } + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); - const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + int rest = height % size; + int rows_per_proc = height / size; + int begin = rank * rows_per_proc + (rest > rank ? rank : rest); + int end = begin + rows_per_proc + (rest > rank ? 1 : 0); - int rank = 0; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); + for (int i = begin; i < end; i++) + for (int s = 0; s < width; s++) + part_sum_vec[i] += mat[width * i + s]; - if (rank == 0) { - GetOutput() /= num_threads; - } else { - int counter = 0; - for (int i = 0; i < num_threads; i++) { - counter++; - } - - if (counter != 0) { - GetOutput() /= counter; - } - } + MPI_Reduce(part_sum_vec.data(), sum_vec.data(), height, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Bcast(sum_vec.data(), height, MPI_INT, 0, MPI_COMM_WORLD); - MPI_Barrier(MPI_COMM_WORLD); - return GetOutput() > 0; + return true; } bool LuzanEMatrixRowsSumMPI::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + return true; } } // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp b/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp index 3ca4cd6136..67cd7b441f 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp @@ -13,10 +13,10 @@ class LuzanEMatrixRowsSumSEQ : public BaseTask { explicit LuzanEMatrixRowsSumSEQ(const InType &in); private: - bool ValidationImpl() override; - bool PreProcessingImpl() override; - bool RunImpl() override; - bool PostProcessingImpl() override; + bool ValidationImpl() override; //= input data check + bool PreProcessingImpl() override; //= pre proc + bool RunImpl() override; //= PARALLEL + bool PostProcessingImpl() override; //= back to reality }; } // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index ce4fc1eac6..32c219af25 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -11,50 +11,41 @@ namespace luzan_e_matrix_rows_sum { LuzanEMatrixRowsSumSEQ::LuzanEMatrixRowsSumSEQ(const InType &in) { SetTypeOfTask(GetStaticTypeOfTask()); GetInput() = in; - GetOutput() = 0; + GetOutput() = {}; } bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + + return std::get<0>(GetInput()).size() == static_cast(height * width) && + height != 0 && width != 0; } bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + int height = std::get<1>(GetInput()); + GetOutput().resize(height); + for (int row = 0; row < height; row++) { + GetOutput()[row] = 0; + } + return true; } bool LuzanEMatrixRowsSumSEQ::RunImpl() { - if (GetInput() == 0) { - return false; - } + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + const std::tuple_element_t<0, InType>& mat = std::get<0>(GetInput()); - for (InType i = 0; i < GetInput(); i++) { - for (InType j = 0; j < GetInput(); j++) { - for (InType k = 0; k < GetInput(); k++) { - std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; - } + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + GetOutput()[row] += mat[width * row + col]; } } - - const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; - - int counter = 0; - for (int i = 0; i < num_threads; i++) { - counter++; - } - - if (counter != 0) { - GetOutput() /= counter; - } - return GetOutput() > 0; + return true; } bool LuzanEMatrixRowsSumSEQ::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + return true; } } // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index 2c4ec6a584..78cbe74026 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -23,36 +23,36 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam(const TestType &test_param) { - return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param); + return std::to_string(std::get<0>(test_param)) + "_" + std::to_string(std::get<1>(test_param)); } protected: void SetUp() override { - int width = -1; - int height = -1; - int channels = -1; - std::vector img; - // Read image in RGB to ensure consistent channel count - { - std::string abs_path = ppc::util::GetAbsoluteTaskPath(PPC_ID_luzan_e_matrix_rows_sum, "pic.jpg"); - auto *data = stbi_load(abs_path.c_str(), &width, &height, &channels, STBI_rgb); - if (data == nullptr) { - throw std::runtime_error("Failed to load image: " + std::string(stbi_failure_reason())); - } - channels = STBI_rgb; - img = std::vector(data, data + (static_cast(width * height * channels))); - stbi_image_free(data); - if (std::cmp_not_equal(width, height)) { - throw std::runtime_error("width != height: "); - } - } - TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - input_data_ = width - height + std::min(std::accumulate(img.begin(), img.end(), 0), channels); + int height = std::get<0>(params); + int width = std::get<1>(params); + std::tuple_element_t<0, InType> mat(height*width); + + for (int elem = 0; elem < height * width; elem++) { + mat[elem] = (elem * 2) - 42; + } + + input_data_ = std::make_tuple(mat, height, width); } bool CheckTestOutputData(OutType &output_data) final { - return (input_data_ == output_data); + int height = std::get<1>(input_data_); + int width = std::get<2>(input_data_); + std::vector sum(height, 0); + std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); + + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + sum[row] += mat[width * row + col]; + } + } + + return (output_data == sum); } InType GetTestInputData() final { @@ -60,7 +60,7 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")}; +const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70)}; const auto kTestTasksList = std::tuple_cat(ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index f916e3a945..d4ca8dc6e2 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -8,15 +8,30 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const int kCount_ = 100; + const int HEIGHT = 100; + const int WIDTH = 1000; InType input_data_{}; void SetUp() override { - input_data_ = kCount_; + std::tuple_element_t<0, InType> mat(HEIGHT*WIDTH); + for (int elem = 0; elem < HEIGHT * WIDTH; elem++) { + mat[elem] = elem - 42; + } + + input_data_ = std::make_tuple(mat, HEIGHT, WIDTH); } bool CheckTestOutputData(OutType &output_data) final { - return input_data_ == output_data; + std::vector sum(HEIGHT); + std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); + + for (int row = 0; row < HEIGHT; row++) { + for (int col = 0; col < WIDTH; col++) { + sum[row] += mat[WIDTH * row + col]; + } + } + + return (output_data == sum); } InType GetTestInputData() final { From 7d9173ef7d18eea8899ae15ce03479c693de5d55 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 00:44:11 +0000 Subject: [PATCH 03/36] clang-format fix --- .../common/include/common.hpp | 30 +-- .../mpi/include/ops_mpi.hpp | 44 ++--- .../mpi/src/ops_mpi.cpp | 135 +++++++------- .../seq/include/ops_seq.hpp | 44 ++--- .../seq/src/ops_seq.cpp | 101 +++++----- .../tests/functional/main.cpp | 172 +++++++++--------- .../tests/performance/main.cpp | 110 +++++------ 7 files changed, 318 insertions(+), 318 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index a545ebaf6f..a3435392ff 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -1,15 +1,15 @@ -#pragma once - -#include -#include - -#include "task/include/task.hpp" - -namespace luzan_e_matrix_rows_sum { - -using InType = std::tuple, int, int>; // matrix, height, width -using OutType = std::vector; // vec of sums, size = height -using TestType = std::tuple; // height & width -using BaseTask = ppc::task::Task; - -} // namespace luzan_e_matrix_rows_sum +#pragma once + +#include +#include + +#include "task/include/task.hpp" + +namespace luzan_e_matrix_rows_sum { + +using InType = std::tuple, int, int>; // matrix, height, width +using OutType = std::vector; // vec of sums, size = height +using TestType = std::tuple; // height & width +using BaseTask = ppc::task::Task; + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp b/tasks/luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp index cb56647df1..ba0449922d 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp @@ -1,22 +1,22 @@ -#pragma once - -#include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "task/include/task.hpp" - -namespace luzan_e_matrix_rows_sum { - -class LuzanEMatrixRowsSumMPI : public BaseTask { - public: - static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { - return ppc::task::TypeOfTask::kMPI; - } - explicit LuzanEMatrixRowsSumMPI(const InType &in); - - private: - bool ValidationImpl() override; - bool PreProcessingImpl() override; - bool RunImpl() override; - bool PostProcessingImpl() override; -}; - -} // namespace luzan_e_matrix_rows_sum +#pragma once + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumMPI : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kMPI; + } + explicit LuzanEMatrixRowsSumMPI(const InType &in); + + private: + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; +}; + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index cdc9c2aa71..093b4ae37a 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -1,67 +1,68 @@ -#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" - -#include - -#include -#include -#include - -#include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "util/include/util.hpp" - -namespace luzan_e_matrix_rows_sum { - -LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = {}; -} - -bool LuzanEMatrixRowsSumMPI::ValidationImpl() { - int height = std::get<1>(GetInput()); - int width = std::get<2>(GetInput()); - - return std::get<0>(GetInput()).size() == static_cast(height * width) && - height != 0 && width != 0; -} - -bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { - int height = std::get<1>(GetInput()); - GetOutput().resize(height); - for (int row = 0; row < height; row++) { - GetOutput()[row] = 0; - } - return true; -} - -bool LuzanEMatrixRowsSumMPI::RunImpl() { - const int height = std::get<1>(GetInput()); - const int width = std::get<2>(GetInput()); - const std::tuple_element_t<0, InType>& mat = std::get<0>(GetInput()); - OutType& sum_vec = GetOutput(); - OutType part_sum_vec = GetOutput(); - - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int rest = height % size; - int rows_per_proc = height / size; - int begin = rank * rows_per_proc + (rest > rank ? rank : rest); - int end = begin + rows_per_proc + (rest > rank ? 1 : 0); - - for (int i = begin; i < end; i++) - for (int s = 0; s < width; s++) - part_sum_vec[i] += mat[width * i + s]; - - MPI_Reduce(part_sum_vec.data(), sum_vec.data(), height, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Bcast(sum_vec.data(), height, MPI_INT, 0, MPI_COMM_WORLD); - - return true; -} - -bool LuzanEMatrixRowsSumMPI::PostProcessingImpl() { - return true; -} - -} // namespace luzan_e_matrix_rows_sum +#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" + +#include + +#include +#include +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_matrix_rows_sum { + +LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType& in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = {}; +} + +bool LuzanEMatrixRowsSumMPI::ValidationImpl() { + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + + return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; +} + +bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { + int height = std::get<1>(GetInput()); + GetOutput().resize(height); + for (int row = 0; row < height; row++) { + GetOutput()[row] = 0; + } + return true; +} + +bool LuzanEMatrixRowsSumMPI::RunImpl() { + const int height = std::get<1>(GetInput()); + const int width = std::get<2>(GetInput()); + const std::tuple_element_t<0, InType>& mat = std::get<0>(GetInput()); + OutType& sum_vec = GetOutput(); + OutType part_sum_vec = GetOutput(); + + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int rest = height % size; + int rows_per_proc = height / size; + int begin = rank * rows_per_proc + (rest > rank ? rank : rest); + int end = begin + rows_per_proc + (rest > rank ? 1 : 0); + + for (int i = begin; i < end; i++) { + for (int s = 0; s < width; s++) { + part_sum_vec[i] += mat[width * i + s]; + } + } + + MPI_Reduce(part_sum_vec.data(), sum_vec.data(), height, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Bcast(sum_vec.data(), height, MPI_INT, 0, MPI_COMM_WORLD); + + return true; +} + +bool LuzanEMatrixRowsSumMPI::PostProcessingImpl() { + return true; +} + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp b/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp index 67cd7b441f..b7d19c931b 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp @@ -1,22 +1,22 @@ -#pragma once - -#include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "task/include/task.hpp" - -namespace luzan_e_matrix_rows_sum { - -class LuzanEMatrixRowsSumSEQ : public BaseTask { - public: - static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { - return ppc::task::TypeOfTask::kSEQ; - } - explicit LuzanEMatrixRowsSumSEQ(const InType &in); - - private: - bool ValidationImpl() override; //= input data check - bool PreProcessingImpl() override; //= pre proc - bool RunImpl() override; //= PARALLEL - bool PostProcessingImpl() override; //= back to reality -}; - -} // namespace luzan_e_matrix_rows_sum +#pragma once + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumSEQ : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kSEQ; + } + explicit LuzanEMatrixRowsSumSEQ(const InType &in); + + private: + bool ValidationImpl() override; //= input data check + bool PreProcessingImpl() override; //= pre proc + bool RunImpl() override; //= PARALLEL + bool PostProcessingImpl() override; //= back to reality +}; + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 32c219af25..0fcc36d0bf 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -1,51 +1,50 @@ -#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" - -#include -#include - -#include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "util/include/util.hpp" - -namespace luzan_e_matrix_rows_sum { - -LuzanEMatrixRowsSumSEQ::LuzanEMatrixRowsSumSEQ(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = {}; -} - -bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { - int height = std::get<1>(GetInput()); - int width = std::get<2>(GetInput()); - - return std::get<0>(GetInput()).size() == static_cast(height * width) && - height != 0 && width != 0; -} - -bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { - int height = std::get<1>(GetInput()); - GetOutput().resize(height); - for (int row = 0; row < height; row++) { - GetOutput()[row] = 0; - } - return true; -} - -bool LuzanEMatrixRowsSumSEQ::RunImpl() { - int height = std::get<1>(GetInput()); - int width = std::get<2>(GetInput()); - const std::tuple_element_t<0, InType>& mat = std::get<0>(GetInput()); - - for (int row = 0; row < height; row++) { - for (int col = 0; col < width; col++) { - GetOutput()[row] += mat[width * row + col]; - } - } - return true; -} - -bool LuzanEMatrixRowsSumSEQ::PostProcessingImpl() { - return true; -} - -} // namespace luzan_e_matrix_rows_sum +#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" + +#include +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_matrix_rows_sum { + +LuzanEMatrixRowsSumSEQ::LuzanEMatrixRowsSumSEQ(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput() = {}; +} + +bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + + return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; +} + +bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { + int height = std::get<1>(GetInput()); + GetOutput().resize(height); + for (int row = 0; row < height; row++) { + GetOutput()[row] = 0; + } + return true; +} + +bool LuzanEMatrixRowsSumSEQ::RunImpl() { + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + const std::tuple_element_t<0, InType> &mat = std::get<0>(GetInput()); + + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + GetOutput()[row] += mat[width * row + col]; + } + } + return true; +} + +bool LuzanEMatrixRowsSumSEQ::PostProcessingImpl() { + return true; +} + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index 78cbe74026..7d30da9156 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -1,86 +1,86 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" -#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" -#include "util/include/func_test_util.hpp" -#include "util/include/util.hpp" - -namespace luzan_e_matrix_rows_sum { - -class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests { - public: - static std::string PrintTestParam(const TestType &test_param) { - return std::to_string(std::get<0>(test_param)) + "_" + std::to_string(std::get<1>(test_param)); - } - - protected: - void SetUp() override { - TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - int height = std::get<0>(params); - int width = std::get<1>(params); - std::tuple_element_t<0, InType> mat(height*width); - - for (int elem = 0; elem < height * width; elem++) { - mat[elem] = (elem * 2) - 42; - } - - input_data_ = std::make_tuple(mat, height, width); - } - - bool CheckTestOutputData(OutType &output_data) final { - int height = std::get<1>(input_data_); - int width = std::get<2>(input_data_); - std::vector sum(height, 0); - std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - - for (int row = 0; row < height; row++) { - for (int col = 0; col < width; col++) { - sum[row] += mat[width * row + col]; - } - } - - return (output_data == sum); - } - - InType GetTestInputData() final { - return input_data_; - } - - private: - InType input_data_; -}; - -namespace { - -TEST_P(LuzanEMatrixRowsSumFuncTests, MatmulFromPic) { - ExecuteTest(GetParam()); -} - -const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70)}; - -const auto kTestTasksList = - std::tuple_cat(ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), - ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum)); - -const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); - -const auto kPerfTestName = LuzanEMatrixRowsSumFuncTests::PrintFuncTestName; - -INSTANTIATE_TEST_SUITE_P(PicMatrixTests, LuzanEMatrixRowsSumFuncTests, kGtestValues, kPerfTestName); - -} // namespace - -} // namespace luzan_e_matrix_rows_sum +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" +#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" +#include "util/include/func_test_util.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests { + public: + static std::string PrintTestParam(const TestType &test_param) { + return std::to_string(std::get<0>(test_param)) + "_" + std::to_string(std::get<1>(test_param)); + } + + protected: + void SetUp() override { + TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + int height = std::get<0>(params); + int width = std::get<1>(params); + std::tuple_element_t<0, InType> mat(height * width); + + for (int elem = 0; elem < height * width; elem++) { + mat[elem] = (elem * 2) - 42; + } + + input_data_ = std::make_tuple(mat, height, width); + } + + bool CheckTestOutputData(OutType &output_data) final { + int height = std::get<1>(input_data_); + int width = std::get<2>(input_data_); + std::vector sum(height, 0); + std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); + + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + sum[row] += mat[width * row + col]; + } + } + + return (output_data == sum); + } + + InType GetTestInputData() final { + return input_data_; + } + + private: + InType input_data_; +}; + +namespace { + +TEST_P(LuzanEMatrixRowsSumFuncTests, MatmulFromPic) { + ExecuteTest(GetParam()); +} + +const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70)}; + +const auto kTestTasksList = std::tuple_cat( + ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), + ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum)); + +const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); + +const auto kPerfTestName = LuzanEMatrixRowsSumFuncTests::PrintFuncTestName; + +INSTANTIATE_TEST_SUITE_P(PicMatrixTests, LuzanEMatrixRowsSumFuncTests, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index d4ca8dc6e2..c00bba0db7 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,55 +1,55 @@ -#include - -#include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" -#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" -#include "util/include/perf_test_util.hpp" - -namespace luzan_e_matrix_rows_sum { - -class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const int HEIGHT = 100; - const int WIDTH = 1000; - InType input_data_{}; - - void SetUp() override { - std::tuple_element_t<0, InType> mat(HEIGHT*WIDTH); - for (int elem = 0; elem < HEIGHT * WIDTH; elem++) { - mat[elem] = elem - 42; - } - - input_data_ = std::make_tuple(mat, HEIGHT, WIDTH); - } - - bool CheckTestOutputData(OutType &output_data) final { - std::vector sum(HEIGHT); - std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - - for (int row = 0; row < HEIGHT; row++) { - for (int col = 0; col < WIDTH; col++) { - sum[row] += mat[WIDTH * row + col]; - } - } - - return (output_data == sum); - } - - InType GetTestInputData() final { - return input_data_; - } -}; - -TEST_P(LuzanEMatrixRowsSumpERFTests, RunPerfModes) { - ExecuteTest(GetParam()); -} - -const auto kAllPerfTasks = - ppc::util::MakeAllPerfTasks(PPC_SETTINGS_luzan_e_matrix_rows_sum); - -const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); - -const auto kPerfTestName = LuzanEMatrixRowsSumpERFTests::CustomPerfTestName; - -INSTANTIATE_TEST_SUITE_P(RunModeTests, LuzanEMatrixRowsSumpERFTests, kGtestValues, kPerfTestName); - -} // namespace luzan_e_matrix_rows_sum +#include + +#include "luzan_e_matrix_rows_sum/common/include/common.hpp" +#include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" +#include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" +#include "util/include/perf_test_util.hpp" + +namespace luzan_e_matrix_rows_sum { + +class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { + const int HEIGHT = 100; + const int WIDTH = 1000; + InType input_data_{}; + + void SetUp() override { + std::tuple_element_t<0, InType> mat(HEIGHT * WIDTH); + for (int elem = 0; elem < HEIGHT * WIDTH; elem++) { + mat[elem] = elem - 42; + } + + input_data_ = std::make_tuple(mat, HEIGHT, WIDTH); + } + + bool CheckTestOutputData(OutType &output_data) final { + std::vector sum(HEIGHT); + std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); + + for (int row = 0; row < HEIGHT; row++) { + for (int col = 0; col < WIDTH; col++) { + sum[row] += mat[WIDTH * row + col]; + } + } + + return (output_data == sum); + } + + InType GetTestInputData() final { + return input_data_; + } +}; + +TEST_P(LuzanEMatrixRowsSumpERFTests, RunPerfModes) { + ExecuteTest(GetParam()); +} + +const auto kAllPerfTasks = ppc::util::MakeAllPerfTasks( + PPC_SETTINGS_luzan_e_matrix_rows_sum); + +const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); + +const auto kPerfTestName = LuzanEMatrixRowsSumpERFTests::CustomPerfTestName; + +INSTANTIATE_TEST_SUITE_P(RunModeTests, LuzanEMatrixRowsSumpERFTests, kGtestValues, kPerfTestName); + +} // namespace luzan_e_matrix_rows_sum From 1751f660f936d776effe0aede336ebb123315bc8 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 09:23:19 +0000 Subject: [PATCH 04/36] pre-commit fix --- .pre-commit-config.yaml | 104 +++++++++--------- .../mpi/src/ops_mpi.cpp | 6 +- .../luzan_e_matrix_rows_sum/tests/.clang-tidy | 26 ++--- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b70f3d31c9..eeb9844077 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,52 +1,52 @@ -# Pre-commit hooks for automated formatting and linting -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks - -repos: - # C++ formatting with clang-format - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v21.1.2 - hooks: - - id: clang-format - files: \.(cpp|hpp|c|h)$ - exclude: ^(3rdparty/|build.*/|install/) - args: [--style=file] - - # CMake formatting - - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.13 - hooks: - - id: cmake-format - files: \.(cmake|CMakeLists\.txt)$ - exclude: ^(3rdparty/|build.*/|install/) - - # Ruff Python linter - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.14.0 - hooks: - - id: ruff - args: [--fix] - - id: ruff-format - - # Flake8 Python style/lint checker (supplemental to Ruff) - - repo: https://github.com/pycqa/flake8 - rev: 7.3.0 - hooks: - - id: flake8 - - # YAML linting - - repo: https://github.com/adrienverge/yamllint.git - rev: v1.37.1 - hooks: - - id: yamllint - - # Shell script linting with shellcheck - - repo: https://github.com/koalaman/shellcheck-precommit - rev: v0.11.0 - hooks: - - id: shellcheck - files: \.sh$ - -# Configuration -default_stages: [pre-commit] -fail_fast: false +# Pre-commit hooks for automated formatting and linting +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +repos: + # C++ formatting with clang-format + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v21.1.2 + hooks: + - id: clang-format + files: \.(cpp|hpp|c|h)$ + exclude: ^(3rdparty/|build.*/|install/) + args: [--style=file] + + # CMake formatting + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + files: \.(cmake|CMakeLists\.txt)$ + exclude: ^(3rdparty/|build.*/|install/) + + # Ruff Python linter + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.14.0 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + + # Flake8 Python style/lint checker (supplemental to Ruff) + - repo: https://github.com/pycqa/flake8 + rev: 7.3.0 + hooks: + - id: flake8 + + # YAML linting + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.37.1 + hooks: + - id: yamllint + + # Shell script linting with shellcheck + - repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.11.0 + hooks: + - id: shellcheck + files: \.sh$ + +# Configuration +default_stages: [pre-commit] +fail_fast: false diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 093b4ae37a..3c7c8ee609 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -11,7 +11,7 @@ namespace luzan_e_matrix_rows_sum { -LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType& in) { +LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { SetTypeOfTask(GetStaticTypeOfTask()); GetInput() = in; GetOutput() = {}; @@ -36,8 +36,8 @@ bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { bool LuzanEMatrixRowsSumMPI::RunImpl() { const int height = std::get<1>(GetInput()); const int width = std::get<2>(GetInput()); - const std::tuple_element_t<0, InType>& mat = std::get<0>(GetInput()); - OutType& sum_vec = GetOutput(); + const std::tuple_element_t<0, InType> &mat = std::get<0>(GetInput()); + OutType &sum_vec = GetOutput(); OutType part_sum_vec = GetOutput(); int rank, size; diff --git a/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy b/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy index d68523c24e..ef43b7aa8a 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy +++ b/tasks/luzan_e_matrix_rows_sum/tests/.clang-tidy @@ -1,13 +1,13 @@ -InheritParentConfig: true - -Checks: > - -modernize-loop-convert, - -cppcoreguidelines-avoid-goto, - -cppcoreguidelines-avoid-non-const-global-variables, - -misc-use-anonymous-namespace, - -modernize-use-std-print, - -modernize-type-traits - -CheckOptions: - - key: readability-function-cognitive-complexity.Threshold - value: 50 # Relaxed for tests +InheritParentConfig: true + +Checks: > + -modernize-loop-convert, + -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-avoid-non-const-global-variables, + -misc-use-anonymous-namespace, + -modernize-use-std-print, + -modernize-type-traits + +CheckOptions: + - key: readability-function-cognitive-complexity.Threshold + value: 50 # Relaxed for tests From a5371bb235a2061a73258ac85d14aa8def12f901 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 09:36:57 +0000 Subject: [PATCH 05/36] yaml fix --- .pre-commit-config.yaml | 104 ++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eeb9844077..b70f3d31c9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,52 +1,52 @@ -# Pre-commit hooks for automated formatting and linting -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks - -repos: - # C++ formatting with clang-format - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v21.1.2 - hooks: - - id: clang-format - files: \.(cpp|hpp|c|h)$ - exclude: ^(3rdparty/|build.*/|install/) - args: [--style=file] - - # CMake formatting - - repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.13 - hooks: - - id: cmake-format - files: \.(cmake|CMakeLists\.txt)$ - exclude: ^(3rdparty/|build.*/|install/) - - # Ruff Python linter - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.14.0 - hooks: - - id: ruff - args: [--fix] - - id: ruff-format - - # Flake8 Python style/lint checker (supplemental to Ruff) - - repo: https://github.com/pycqa/flake8 - rev: 7.3.0 - hooks: - - id: flake8 - - # YAML linting - - repo: https://github.com/adrienverge/yamllint.git - rev: v1.37.1 - hooks: - - id: yamllint - - # Shell script linting with shellcheck - - repo: https://github.com/koalaman/shellcheck-precommit - rev: v0.11.0 - hooks: - - id: shellcheck - files: \.sh$ - -# Configuration -default_stages: [pre-commit] -fail_fast: false +# Pre-commit hooks for automated formatting and linting +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +repos: + # C++ formatting with clang-format + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v21.1.2 + hooks: + - id: clang-format + files: \.(cpp|hpp|c|h)$ + exclude: ^(3rdparty/|build.*/|install/) + args: [--style=file] + + # CMake formatting + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + files: \.(cmake|CMakeLists\.txt)$ + exclude: ^(3rdparty/|build.*/|install/) + + # Ruff Python linter + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.14.0 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format + + # Flake8 Python style/lint checker (supplemental to Ruff) + - repo: https://github.com/pycqa/flake8 + rev: 7.3.0 + hooks: + - id: flake8 + + # YAML linting + - repo: https://github.com/adrienverge/yamllint.git + rev: v1.37.1 + hooks: + - id: yamllint + + # Shell script linting with shellcheck + - repo: https://github.com/koalaman/shellcheck-precommit + rev: v0.11.0 + hooks: + - id: shellcheck + files: \.sh$ + +# Configuration +default_stages: [pre-commit] +fail_fast: false From 24be0047496d481aac2eba207c81b8e7c0d50354 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 21:59:03 +0000 Subject: [PATCH 06/36] increase matrix sizes --- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index c00bba0db7..66a3429f31 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -8,8 +8,8 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const int HEIGHT = 100; - const int WIDTH = 1000; + const int HEIGHT = 50; // 300 000 000 + const int WIDTH = 3000000; InType input_data_{}; void SetUp() override { From ce8d488ae54b9c5bfd54f975b5c88df513c96b84 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 23:03:14 +0000 Subject: [PATCH 07/36] change int to size_t for matrix sizes --- .../common/include/common.hpp | 4 +-- .../mpi/src/ops_mpi.cpp | 36 ++++++++++--------- .../seq/src/ops_seq.cpp | 18 +++++----- .../tests/functional/main.cpp | 14 ++++---- .../tests/performance/main.cpp | 10 +++--- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index a3435392ff..b0db68008d 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -7,9 +7,9 @@ namespace luzan_e_matrix_rows_sum { -using InType = std::tuple, int, int>; // matrix, height, width +using InType = std::tuple, size_t, size_t>; // matrix, height, width using OutType = std::vector; // vec of sums, size = height -using TestType = std::tuple; // height & width +using TestType = std::tuple; // height & width using BaseTask = ppc::task::Task; } // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 3c7c8ee609..2dc146c711 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -18,46 +18,48 @@ LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { } bool LuzanEMatrixRowsSumMPI::ValidationImpl() { - int height = std::get<1>(GetInput()); - int width = std::get<2>(GetInput()); + size_t height = std::get<1>(GetInput()); + size_t width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; + return std::get<0>(GetInput()).size() == (height * width) && height != 0 && width != 0; } bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { - int height = std::get<1>(GetInput()); + size_t height = std::get<1>(GetInput()); GetOutput().resize(height); - for (int row = 0; row < height; row++) { + for (size_t row = 0; row < height; row++) { GetOutput()[row] = 0; } return true; } bool LuzanEMatrixRowsSumMPI::RunImpl() { - const int height = std::get<1>(GetInput()); - const int width = std::get<2>(GetInput()); + const size_t height = std::get<1>(GetInput()); + const size_t width = std::get<2>(GetInput()); const std::tuple_element_t<0, InType> &mat = std::get<0>(GetInput()); OutType &sum_vec = GetOutput(); OutType part_sum_vec = GetOutput(); - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); + int rank_, size_; + MPI_Comm_rank(MPI_COMM_WORLD, &rank_); + MPI_Comm_size(MPI_COMM_WORLD, &size_); - int rest = height % size; - int rows_per_proc = height / size; - int begin = rank * rows_per_proc + (rest > rank ? rank : rest); - int end = begin + rows_per_proc + (rest > rank ? 1 : 0); + size_t rank = static_cast(rank_); + size_t size = static_cast(size_); + size_t rest = height % size; + size_t rows_per_proc = height / size; + size_t begin = rank * rows_per_proc + (rest > rank ? rank : rest); + size_t end = begin + rows_per_proc + (rest > rank ? 1 : 0); - for (int i = begin; i < end; i++) { - for (int s = 0; s < width; s++) { + for (size_t i = begin; i < end; i++) { + for (size_t s = 0; s < width; s++) { part_sum_vec[i] += mat[width * i + s]; } } MPI_Reduce(part_sum_vec.data(), sum_vec.data(), height, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(sum_vec.data(), height, MPI_INT, 0, MPI_COMM_WORLD); - + //MPI_Barrier(MPI_COMM_WORLD); return true; } diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 0fcc36d0bf..b5dacb6363 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -15,28 +15,28 @@ LuzanEMatrixRowsSumSEQ::LuzanEMatrixRowsSumSEQ(const InType &in) { } bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { - int height = std::get<1>(GetInput()); - int width = std::get<2>(GetInput()); + size_t height = std::get<1>(GetInput()); + size_t width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; + return std::get<0>(GetInput()).size() == (height * width) && height != 0 && width != 0; } bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { - int height = std::get<1>(GetInput()); + size_t height = std::get<1>(GetInput()); GetOutput().resize(height); - for (int row = 0; row < height; row++) { + for (size_t row = 0; row < height; row++) { GetOutput()[row] = 0; } return true; } bool LuzanEMatrixRowsSumSEQ::RunImpl() { - int height = std::get<1>(GetInput()); - int width = std::get<2>(GetInput()); + size_t height = std::get<1>(GetInput()); + size_t width = std::get<2>(GetInput()); const std::tuple_element_t<0, InType> &mat = std::get<0>(GetInput()); - for (int row = 0; row < height; row++) { - for (int col = 0; col < width; col++) { + for (size_t row = 0; row < height; row++) { + for (size_t col = 0; col < width; col++) { GetOutput()[row] += mat[width * row + col]; } } diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index 7d30da9156..2ff12005c3 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -29,11 +29,11 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - int height = std::get<0>(params); - int width = std::get<1>(params); + size_t height = std::get<0>(params); + size_t width = std::get<1>(params); std::tuple_element_t<0, InType> mat(height * width); - for (int elem = 0; elem < height * width; elem++) { + for (size_t elem = 0; elem < height * width; elem++) { mat[elem] = (elem * 2) - 42; } @@ -41,13 +41,13 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests(input_data_); - int width = std::get<2>(input_data_); + size_t height = std::get<1>(input_data_); + size_t width = std::get<2>(input_data_); std::vector sum(height, 0); std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - for (int row = 0; row < height; row++) { - for (int col = 0; col < width; col++) { + for (size_t row = 0; row < height; row++) { + for (size_t col = 0; col < width; col++) { sum[row] += mat[width * row + col]; } } diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 66a3429f31..de6ac5afa5 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -8,13 +8,13 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const int HEIGHT = 50; // 300 000 000 - const int WIDTH = 3000000; + const size_t HEIGHT = 50; // 300 000 000 + const size_t WIDTH = 300000; InType input_data_{}; void SetUp() override { std::tuple_element_t<0, InType> mat(HEIGHT * WIDTH); - for (int elem = 0; elem < HEIGHT * WIDTH; elem++) { + for (size_t elem = 0; elem < HEIGHT * WIDTH; elem++) { mat[elem] = elem - 42; } @@ -25,8 +25,8 @@ class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests sum(HEIGHT); std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - for (int row = 0; row < HEIGHT; row++) { - for (int col = 0; col < WIDTH; col++) { + for (size_t row = 0; row < HEIGHT; row++) { + for (size_t col = 0; col < WIDTH; col++) { sum[row] += mat[WIDTH * row + col]; } } From b51ae83ea77ec1b36dcd0e12c2c4539dc5b7ea55 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 23:10:41 +0000 Subject: [PATCH 08/36] change matrix sizes --- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index de6ac5afa5..ac709ebe7f 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -8,8 +8,8 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t HEIGHT = 50; // 300 000 000 - const size_t WIDTH = 300000; + const size_t HEIGHT = 3000000; + const size_t WIDTH = 1000; InType input_data_{}; void SetUp() override { From c292d20af8889f1ec7edacd60a0ec963d2045ce6 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 18 Nov 2025 23:19:24 +0000 Subject: [PATCH 09/36] clang format fix --- tasks/luzan_e_matrix_rows_sum/common/include/common.hpp | 2 +- tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 2 +- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index b0db68008d..80f8ff08ab 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -8,7 +8,7 @@ namespace luzan_e_matrix_rows_sum { using InType = std::tuple, size_t, size_t>; // matrix, height, width -using OutType = std::vector; // vec of sums, size = height +using OutType = std::vector; // vec of sums, size = height using TestType = std::tuple; // height & width using BaseTask = ppc::task::Task; diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 2dc146c711..bbb982f6a5 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -59,7 +59,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_Reduce(part_sum_vec.data(), sum_vec.data(), height, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(sum_vec.data(), height, MPI_INT, 0, MPI_COMM_WORLD); - //MPI_Barrier(MPI_COMM_WORLD); + // MPI_Barrier(MPI_COMM_WORLD); return true; } diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index ac709ebe7f..cb78ca955c 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -8,7 +8,7 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t HEIGHT = 3000000; + const size_t HEIGHT = 3000000; const size_t WIDTH = 1000; InType input_data_{}; From df0cfa228cbf9bcba733ae71bda1072663b967ab Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 00:33:24 +0000 Subject: [PATCH 10/36] reduce matrix sizes --- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index cb78ca955c..d2cc0bd221 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -9,7 +9,7 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { const size_t HEIGHT = 3000000; - const size_t WIDTH = 1000; + const size_t WIDTH = 10; InType input_data_{}; void SetUp() override { From 35c1fe39010fdac9466e3411d633e19559713c9c Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 12:53:49 +0000 Subject: [PATCH 11/36] clang-tidy fix --- .../common/include/common.hpp | 3 ++- .../mpi/src/ops_mpi.cpp | 23 ++++++++-------- .../seq/src/ops_seq.cpp | 8 +++--- .../tests/functional/main.cpp | 9 ++----- .../tests/performance/main.cpp | 26 +++++++++++-------- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 80f8ff08ab..8e5a4f024e 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -1,7 +1,8 @@ #pragma once -#include #include +#include +#include #include "task/include/task.hpp" diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index bbb982f6a5..4da28707dd 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -2,12 +2,11 @@ #include -#include #include #include +#include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "util/include/util.hpp" namespace luzan_e_matrix_rows_sum { @@ -40,26 +39,26 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { OutType &sum_vec = GetOutput(); OutType part_sum_vec = GetOutput(); - int rank_, size_; + int rank_ = 0; + int size_ = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank_); MPI_Comm_size(MPI_COMM_WORLD, &size_); - size_t rank = static_cast(rank_); - size_t size = static_cast(size_); + auto rank = static_cast(rank_); + auto size = static_cast(size_); size_t rest = height % size; size_t rows_per_proc = height / size; - size_t begin = rank * rows_per_proc + (rest > rank ? rank : rest); + size_t begin = (rank * rows_per_proc) + (rest > rank ? rank : rest); size_t end = begin + rows_per_proc + (rest > rank ? 1 : 0); - for (size_t i = begin; i < end; i++) { - for (size_t s = 0; s < width; s++) { - part_sum_vec[i] += mat[width * i + s]; + for (size_t row = begin; row < end; row++) { + for (size_t col = 0; col < width; col++) { + part_sum_vec[row] += mat[(width * row) + col]; } } - MPI_Reduce(part_sum_vec.data(), sum_vec.data(), height, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Bcast(sum_vec.data(), height, MPI_INT, 0, MPI_COMM_WORLD); - // MPI_Barrier(MPI_COMM_WORLD); + MPI_Reduce(part_sum_vec.data(), sum_vec.data(), static_cast(height), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Bcast(sum_vec.data(), static_cast(height), MPI_INT, 0, MPI_COMM_WORLD); return true; } diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index b5dacb6363..520ffa0616 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -1,10 +1,8 @@ #include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" - -#include #include - #include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include "util/include/util.hpp" +#include +#include namespace luzan_e_matrix_rows_sum { @@ -37,7 +35,7 @@ bool LuzanEMatrixRowsSumSEQ::RunImpl() { for (size_t row = 0; row < height; row++) { for (size_t col = 0; col < width; col++) { - GetOutput()[row] += mat[width * row + col]; + GetOutput()[row] += mat[(width * row) + col]; } } return true; diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index 2ff12005c3..366bd65946 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -1,15 +1,10 @@ #include #include -#include #include #include -#include -#include -#include #include #include -#include #include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" @@ -34,7 +29,7 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests mat(height * width); for (size_t elem = 0; elem < height * width; elem++) { - mat[elem] = (elem * 2) - 42; + mat[elem] = (static_cast(elem) * 2) - 42; } input_data_ = std::make_tuple(mat, height, width); @@ -48,7 +43,7 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests +#include +#include + namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t HEIGHT = 3000000; - const size_t WIDTH = 10; - InType input_data_{}; + const size_t height = 3000000; + const size_t width = 10; + InType input_data_; void SetUp() override { - std::tuple_element_t<0, InType> mat(HEIGHT * WIDTH); - for (size_t elem = 0; elem < HEIGHT * WIDTH; elem++) { - mat[elem] = elem - 42; + std::tuple_element_t<0, InType> mat(height * width); + for (size_t elem = 0; elem < height * width; elem++) { + mat[elem] = static_cast(elem) - 42; } - input_data_ = std::make_tuple(mat, HEIGHT, WIDTH); + input_data_ = std::make_tuple(mat, height, width); } bool CheckTestOutputData(OutType &output_data) final { - std::vector sum(HEIGHT); + std::vector sum(height); std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - for (size_t row = 0; row < HEIGHT; row++) { - for (size_t col = 0; col < WIDTH; col++) { - sum[row] += mat[WIDTH * row + col]; + for (size_t row = 0; row < height; row++) { + for (size_t col = 0; col < width; col++) { + sum[row] += mat[(width * row) + col]; } } From 1e48841b25f8c16d9787e34c6f11acaabb4b999f Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 12:58:41 +0000 Subject: [PATCH 12/36] add func tests --- tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index 366bd65946..e91f1cfec6 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -64,7 +64,8 @@ TEST_P(LuzanEMatrixRowsSumFuncTests, MatmulFromPic) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70)}; +const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70), + std::make_tuple(2000, 5), std::make_tuple(5, 2000), std::make_tuple(1, 1)}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), From 93bae7fd48fae7259b6565b40ce4c62e5bf66ffe Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 13:03:42 +0000 Subject: [PATCH 13/36] clang-format fix --- tasks/luzan_e_matrix_rows_sum/common/include/common.hpp | 3 ++- tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 2 +- tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp | 7 +++++-- tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp | 4 ++-- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 8e5a4f024e..805ce19fd8 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -1,8 +1,9 @@ #pragma once +#include + #include #include -#include #include "task/include/task.hpp" diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 4da28707dd..a4745ccf74 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -1,10 +1,10 @@ #include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" #include +#include #include #include -#include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 520ffa0616..40cc42bb00 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -1,8 +1,11 @@ #include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" + +#include + +#include #include + #include "luzan_e_matrix_rows_sum/common/include/common.hpp" -#include -#include namespace luzan_e_matrix_rows_sum { diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index e91f1cfec6..6f47fa74b6 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -64,8 +64,8 @@ TEST_P(LuzanEMatrixRowsSumFuncTests, MatmulFromPic) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70), - std::make_tuple(2000, 5), std::make_tuple(5, 2000), std::make_tuple(1, 1)}; +const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70), + std::make_tuple(2000, 5), std::make_tuple(5, 2000), std::make_tuple(1, 1)}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index cbeb1258a5..2bc7179fc0 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,13 +1,13 @@ #include +#include + +#include +#include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" #include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" #include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" #include "util/include/perf_test_util.hpp" -#include -#include -#include - namespace luzan_e_matrix_rows_sum { From a08851aa84b9347e485e669cbaa94383ce338fe9 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 15:15:57 +0000 Subject: [PATCH 14/36] another clang-tidy fix --- .../common/include/common.hpp | 2 +- .../mpi/src/ops_mpi.cpp | 14 ++++++------- .../seq/src/ops_seq.cpp | 2 +- .../tests/performance/main.cpp | 20 +++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 805ce19fd8..fde28456a1 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index a4745ccf74..1392b6612c 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -1,7 +1,7 @@ #include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" #include -#include +#include #include #include @@ -39,13 +39,13 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { OutType &sum_vec = GetOutput(); OutType part_sum_vec = GetOutput(); - int rank_ = 0; - int size_ = 0; - MPI_Comm_rank(MPI_COMM_WORLD, &rank_); - MPI_Comm_size(MPI_COMM_WORLD, &size_); + int rank_int = 0; + int size_int = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank_int); + MPI_Comm_size(MPI_COMM_WORLD, &size_int); - auto rank = static_cast(rank_); - auto size = static_cast(size_); + auto rank = static_cast(rank_int); + auto size = static_cast(size_int); size_t rest = height % size; size_t rows_per_proc = height / size; size_t begin = (rank * rows_per_proc) + (rest > rank ? rank : rest); diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 40cc42bb00..7dc4a9ede0 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -1,6 +1,6 @@ #include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" -#include +#include #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 2bc7179fc0..256b15eae8 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -12,26 +12,26 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t height = 3000000; - const size_t width = 10; + const size_t height_ = 3000000; + const size_t width_ = 10; InType input_data_; void SetUp() override { - std::tuple_element_t<0, InType> mat(height * width); - for (size_t elem = 0; elem < height * width; elem++) { + std::tuple_element_t<0, InType> mat(height_ * width_); + for (size_t elem = 0; elem < height_ * width_; elem++) { mat[elem] = static_cast(elem) - 42; } - input_data_ = std::make_tuple(mat, height, width); + input_data_ = std::make_tuple(mat, height_, width_); } bool CheckTestOutputData(OutType &output_data) final { - std::vector sum(height); + std::vector sum(height_); std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - for (size_t row = 0; row < height; row++) { - for (size_t col = 0; col < width; col++) { - sum[row] += mat[(width * row) + col]; + for (size_t row = 0; row < height_; row++) { + for (size_t col = 0; col < width_; col++) { + sum[row] += mat[(width_ * row) + col]; } } From 6f4e8e1739a1e058ed7a6ffa830df21ee7634b4e Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 15:23:44 +0000 Subject: [PATCH 15/36] another clang-format fix --- tasks/luzan_e_matrix_rows_sum/common/include/common.hpp | 1 - tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 2 +- tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp | 1 - tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index fde28456a1..5856092895 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -1,7 +1,6 @@ #pragma once #include - #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 1392b6612c..ddf37b4ebe 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -1,8 +1,8 @@ #include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" #include -#include +#include #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 7dc4a9ede0..d0ff362a48 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -1,7 +1,6 @@ #include "luzan_e_matrix_rows_sum/seq/include/ops_seq.hpp" #include - #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 256b15eae8..06242bb1e1 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include From 36a93a2e874fecc0a44a69fbfd754aded07bc52d Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 22:04:26 +0000 Subject: [PATCH 16/36] change perf tests data --- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 06242bb1e1..9a2e2ad9a7 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -12,14 +12,14 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t height_ = 3000000; - const size_t width_ = 10; + const size_t height_ = 10000; + const size_t width_ = 10000; InType input_data_; void SetUp() override { std::tuple_element_t<0, InType> mat(height_ * width_); for (size_t elem = 0; elem < height_ * width_; elem++) { - mat[elem] = static_cast(elem) - 42; + mat[elem] = static_cast(elem) % 42000; } input_data_ = std::make_tuple(mat, height_, width_); From afc425c40a8cd68cc1a95bb8963f272945245685 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Wed, 19 Nov 2025 23:05:30 +0000 Subject: [PATCH 17/36] add report.md --- tasks/luzan_e_matrix_rows_sum/report.md | 83 +++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md index e69de29bb2..bcb8ea7fdb 100644 --- a/tasks/luzan_e_matrix_rows_sum/report.md +++ b/tasks/luzan_e_matrix_rows_sum/report.md @@ -0,0 +1,83 @@ +# <Сумма значений по строкам матрицы> + +- Student: Лузан Егор Андреевич, group 3823Б1ФИ3 +- Technology: SEQ | MPI +- Variant: 11 + +## 1. Introduction +Цель работы — реализовать и сравнить две версии программы, вычисляющей сумму элементов в каждой строке матрицы: +1. последовательную, +2. параллельную, использующую библиотеку **MPI**. + +Подобная задача встречается при обработке больших таблиц данных, изображений, численных расчётах. + +Ожидается ускорение mpi версии относительно последовательной версии. + +## 2. Problem Statement +Дана матрица A размера `height × width`. +Требуется вычислить вектор $sum$ размера `width`, где: +$$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ + +**Входные данные:** +- Матрица в форме вектора `(std::vector)` размера `height × width` состоящая из целых чисел. + +**Выходные данные**: +- Вектор `(std::vector)` размера `height` состоящий из целых чисел, каждое из которых является суммой строки матрицы. + +**Ограничения:** +- элементы матрицы — целые числа. +- элементы матрицы лежат в диапазоне -`[0; 42000]` + +## 3. Baseline Algorithm (Sequential) +- Инициализация всех элементов выходного вектора нулями. +- Последовательный обход всех строк исходной матрицы, производя суммирование элементов в них и записывая результат в соответствующий элемент выходного вектора. + +## 4. Parallelization Scheme +**Распределение данных:** +- Для каждого процесса: + 1. Делим высоту матрицы нацело на количество проецессов, получая `rows_per_proc`. + 2. Получаем остаток `rest` от предыдущего деления. + 3. Вычисляем суммы строк из блока, за который отвечает текущий процесс (`begin` - первая строка блока, `end` - последняя строка блока). Если остаток не равен 0, то все процессы с `rank` < `rest` получат `rows_per_proc + 1` строк матрицы. Остальные получат `rows_per_proc` строк. + +**Роли рангов:** +- Во время вычисления сумм процессы всех рангов имеют одинаковые задачи. +- После вычисления итоговый результат будет записан в процессе `rank = 0` с помощью `MPI_Reduce()`. + +## 5. Implementation Details +- Code structure (files, key classes/functions) +- Important assumptions and corner cases +- Memory usage considerations + +## 6. Experimental Setup +- Hardware/OS: + - CPU: Intel Core i7-13620H; P-cores-6, E-cores-4, + - RAM: 16 GB RAM, + - OS: Windows 11, x64. +- Toolchain: + - Cmake 3.28.3, + - Компилятор: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, + - Использовался Docker-контейнер с Ubuntu 24.04.2 LTS, + - Режим сборки: Release. + +- Data: Для замера производительности использовалась матрица размером 10 000 × 10 000, элементы которой представляют собой целые последовательные числа от 0 до 42 000. + +## 7. Results and Discussion + +### 7.1 Correctness +Корректность работы проверена с помощью GoogleTest на матрицах размерностями 3×3, 2×5, 10×70, 2000×5, 5×2000, 1×1. + +### 7.2 Performance + +| Mode | Count | Time, s | Speedup | Efficiency | +| ---- | ----- | ------------------ | ------- | ---------- | +| seq | 1 | 0.05721 | 1.00 | N/A | +| mpi | 2 | 0.030963 | 1.84 | 92% | +| mpi | 4 | 0.02039 | 2.8 | 70% | + +## 8. Conclusions + +Разработана программа, выполняющая поиск сумм строк матрицы. Также разработана её параллельная версия с использованием MPI. Эффективность параллельного алгоритма высока, однако на практике не достигает 100% из-за накладных расходов на создание процессов. + +## 9. References +1. Курс лекций ННГУ "Параллельное программирование для кластерных систем". +2. Стандарт MPI. \ No newline at end of file From 2932a7ebf0b5afc2d8e9ac9eb6c3e1749dc04804 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Thu, 20 Nov 2025 00:05:35 +0000 Subject: [PATCH 18/36] add func tests --- tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index 6f47fa74b6..f998833ed1 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -64,8 +64,10 @@ TEST_P(LuzanEMatrixRowsSumFuncTests, MatmulFromPic) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70), - std::make_tuple(2000, 5), std::make_tuple(5, 2000), std::make_tuple(1, 1)}; +const std::array kTestParam = { + std::make_tuple(3, 3), std::make_tuple(2, 5), std::make_tuple(10, 70), + std::make_tuple(2000, 5), std::make_tuple(5, 2000), std::make_tuple(1, 1), + std::make_tuple(1, 100), std::make_tuple(100, 1), std::make_tuple(1000, 1000)}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_luzan_e_matrix_rows_sum), From 349ccb8cf43b52026c0e820402bcdee4265199a1 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 16:58:06 +0000 Subject: [PATCH 19/36] mpi fix --- .../mpi/src/ops_mpi.cpp | 85 ++++++++++++++----- .../tests/performance/main.cpp | 4 +- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index ddf37b4ebe..4927229d20 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -12,15 +12,30 @@ namespace luzan_e_matrix_rows_sum { LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; GetOutput() = {}; + + // saving matrix only if it's rank=0 + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + std::vector tmp(0); + InType in_reduced = std::make_tuple(tmp, std::get<1>(in), std::get<2>(in)); + if (rank == 0) { + GetInput() = in; + } + else { + GetInput() = in_reduced; + } } bool LuzanEMatrixRowsSumMPI::ValidationImpl() { size_t height = std::get<1>(GetInput()); size_t width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == (height * width) && height != 0 && width != 0; + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + size_t mat_size = (rank == 0 ? height * width : 0); + return std::get<0>(GetInput()).size() == mat_size && height != 0 && width != 0; } bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { @@ -35,30 +50,54 @@ bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { bool LuzanEMatrixRowsSumMPI::RunImpl() { const size_t height = std::get<1>(GetInput()); const size_t width = std::get<2>(GetInput()); - const std::tuple_element_t<0, InType> &mat = std::get<0>(GetInput()); - OutType &sum_vec = GetOutput(); - OutType part_sum_vec = GetOutput(); - - int rank_int = 0; - int size_int = 0; - MPI_Comm_rank(MPI_COMM_WORLD, &rank_int); - MPI_Comm_size(MPI_COMM_WORLD, &size_int); - - auto rank = static_cast(rank_int); - auto size = static_cast(size_int); - size_t rest = height % size; - size_t rows_per_proc = height / size; - size_t begin = (rank * rows_per_proc) + (rest > rank ? rank : rest); - size_t end = begin + rows_per_proc + (rest > rank ? 1 : 0); - - for (size_t row = begin; row < end; row++) { - for (size_t col = 0; col < width; col++) { - part_sum_vec[row] += mat[(width * row) + col]; + std::tuple_element_t<0, InType> mat; + + int rank = 0; + int size = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (rank == 0) { + mat = std::get<0>(GetInput()); + } + + int rest = height % size; + std::vector shift(size); + std::vector per_proc(size, height / size); + + shift[0] = 0; + if (rest != 0) { + per_proc[0]++; + rest--; + } + for (int i = 1; i < size; i++) { + if (rest) { + per_proc[i]++; + rest--; } + shift[i] = per_proc[i - 1] + shift[i - 1]; } - MPI_Reduce(part_sum_vec.data(), sum_vec.data(), static_cast(height), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Bcast(sum_vec.data(), static_cast(height), MPI_INT, 0, MPI_COMM_WORLD); + std::vector recv(per_proc[rank] * width); + + for (int i = 0; i < size; i++) { + per_proc[i] *= width; + shift[i] *= width; + } + + MPI_Scatterv(mat.data(), per_proc.data(), shift.data(), MPI_INT, recv.data(), per_proc[rank], MPI_INT, 0, MPI_COMM_WORLD); + mat.clear(); + std::vector sum(height); + int abs_shift = static_cast(shift[rank] / width); + int rows_to_calc = static_cast(per_proc[rank] / width); + for (int row = 0; row < rows_to_calc; row++) + for (size_t col = 0; col < width; col++) + sum[row + abs_shift] += recv[row * width + col]; + + std::vector fin_sum(height); + MPI_Reduce(sum.data(), fin_sum.data(), sum.size(), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Bcast(fin_sum.data(), static_cast(height), MPI_INT, 0, MPI_COMM_WORLD); + GetOutput() = fin_sum; return true; } diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 9a2e2ad9a7..02aa761ed1 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -12,8 +12,8 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t height_ = 10000; - const size_t width_ = 10000; + const size_t height_ = 14000; + const size_t width_ = 14000; InType input_data_; void SetUp() override { From 87a1ba25da8be302fda0ba2152f2b6b420757888 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 18:03:20 +0000 Subject: [PATCH 20/36] load h and w only for root & sizet fix --- .../common/include/common.hpp | 4 +- .../mpi/src/ops_mpi.cpp | 40 ++++++++++++++----- tasks/luzan_e_matrix_rows_sum/report.md | 13 +++--- .../seq/src/ops_seq.cpp | 18 ++++----- .../tests/functional/main.cpp | 16 ++++---- .../tests/performance/main.cpp | 10 ++--- 6 files changed, 61 insertions(+), 40 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 5856092895..7d4f4f8138 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -8,9 +8,9 @@ namespace luzan_e_matrix_rows_sum { -using InType = std::tuple, size_t, size_t>; // matrix, height, width +using InType = std::tuple, int, int>; // matrix, height, width using OutType = std::vector; // vec of sums, size = height -using TestType = std::tuple; // height & width +using TestType = std::tuple; // height & width using BaseTask = ppc::task::Task; } // namespace luzan_e_matrix_rows_sum diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 4927229d20..12b7643f5b 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -29,27 +29,35 @@ LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { } bool LuzanEMatrixRowsSumMPI::ValidationImpl() { - size_t height = std::get<1>(GetInput()); - size_t width = std::get<2>(GetInput()); - int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - size_t mat_size = (rank == 0 ? height * width : 0); - return std::get<0>(GetInput()).size() == mat_size && height != 0 && width != 0; + if (rank != 0) { + return true; + } + + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); + return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; } bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { - size_t height = std::get<1>(GetInput()); + int rank = 0; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + if (rank != 0) { + return true; + } + + int height = std::get<1>(GetInput()); GetOutput().resize(height); - for (size_t row = 0; row < height; row++) { + for (int row = 0; row < height; row++) { GetOutput()[row] = 0; } return true; } bool LuzanEMatrixRowsSumMPI::RunImpl() { - const size_t height = std::get<1>(GetInput()); - const size_t width = std::get<2>(GetInput()); + int height = 0; + int width = 0; std::tuple_element_t<0, InType> mat; int rank = 0; @@ -57,10 +65,20 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); + + int dim[2]; if (rank == 0) { mat = std::get<0>(GetInput()); + height = std::get<1>(GetInput()); + width = std::get<2>(GetInput()); + dim[0] = height; + dim[1] = width; } - + MPI_Bcast(dim, 2, MPI_INT, 0, MPI_COMM_WORLD); + height = dim[0]; + width = dim[1]; + + int rest = height % size; std::vector shift(size); std::vector per_proc(size, height / size); @@ -91,7 +109,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { int abs_shift = static_cast(shift[rank] / width); int rows_to_calc = static_cast(per_proc[rank] / width); for (int row = 0; row < rows_to_calc; row++) - for (size_t col = 0; col < width; col++) + for (int col = 0; col < width; col++) sum[row + abs_shift] += recv[row * width + col]; std::vector fin_sum(height); diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md index bcb8ea7fdb..8ae47fc25f 100644 --- a/tasks/luzan_e_matrix_rows_sum/report.md +++ b/tasks/luzan_e_matrix_rows_sum/report.md @@ -35,18 +35,21 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ ## 4. Parallelization Scheme **Распределение данных:** - Для каждого процесса: - 1. Делим высоту матрицы нацело на количество проецессов, получая `rows_per_proc`. + 1. Делим высоту матрицы нацело на количество проецессов, получая `rows_per_proc` - минимальное количество строк для обработки кажды процессом. 2. Получаем остаток `rest` от предыдущего деления. - 3. Вычисляем суммы строк из блока, за который отвечает текущий процесс (`begin` - первая строка блока, `end` - последняя строка блока). Если остаток не равен 0, то все процессы с `rank` < `rest` получат `rows_per_proc + 1` строк матрицы. Остальные получат `rows_per_proc` строк. + 3. Раскладываем оставшиеся `rest` строк по процессам по одной, начиная с `rank=0`. Также вычисляем `shift` - массив смещений, который будет использован при рассылке данных с корневого процесса. + 4. Таким образом первые `rest` процессов обработают `rows_per_proc` + 1 строку, остальные `rows_per_proc`. **Роли рангов:** +- Root-процесс получает матрицу и её размеры. +- Root-процесс рассылает остальным процессам части матрицы для вычислений. - Во время вычисления сумм процессы всех рангов имеют одинаковые задачи. - После вычисления итоговый результат будет записан в процессе `rank = 0` с помощью `MPI_Reduce()`. ## 5. Implementation Details -- Code structure (files, key classes/functions) -- Important assumptions and corner cases -- Memory usage considerations +- Для тестов производительности матрица генерируется внутри программы. Результат заранее предсказуем. +- Загрузка матрицы производиться только на root-процесс для экономии памяти. +- Работа программы проверена на матрицах на матрицах состоящих только из одного столбца/строки, на матрицы из одного элемента. ## 6. Experimental Setup - Hardware/OS: diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index d0ff362a48..1b9eec265f 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -15,28 +15,28 @@ LuzanEMatrixRowsSumSEQ::LuzanEMatrixRowsSumSEQ(const InType &in) { } bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { - size_t height = std::get<1>(GetInput()); - size_t width = std::get<2>(GetInput()); + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == (height * width) && height != 0 && width != 0; + return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; } bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { - size_t height = std::get<1>(GetInput()); + int height = std::get<1>(GetInput()); GetOutput().resize(height); - for (size_t row = 0; row < height; row++) { + for (int row = 0; row < height; row++) { GetOutput()[row] = 0; } return true; } bool LuzanEMatrixRowsSumSEQ::RunImpl() { - size_t height = std::get<1>(GetInput()); - size_t width = std::get<2>(GetInput()); + int height = std::get<1>(GetInput()); + int width = std::get<2>(GetInput()); const std::tuple_element_t<0, InType> &mat = std::get<0>(GetInput()); - for (size_t row = 0; row < height; row++) { - for (size_t col = 0; col < width; col++) { + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { GetOutput()[row] += mat[(width * row) + col]; } } diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index f998833ed1..ca61b3cbf2 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -23,12 +23,12 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - size_t height = std::get<0>(params); - size_t width = std::get<1>(params); + TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + int height = std::get<0>(params); + int width = std::get<1>(params); std::tuple_element_t<0, InType> mat(height * width); - for (size_t elem = 0; elem < height * width; elem++) { + for (int elem = 0; elem < height * width; elem++) { mat[elem] = (static_cast(elem) * 2) - 42; } @@ -36,13 +36,13 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests(input_data_); - size_t width = std::get<2>(input_data_); + int height = std::get<1>(input_data_); + int width = std::get<2>(input_data_); std::vector sum(height, 0); std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - for (size_t row = 0; row < height; row++) { - for (size_t col = 0; col < width; col++) { + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { sum[row] += mat[(width * row) + col]; } } diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 02aa761ed1..25aa33589b 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -12,13 +12,13 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const size_t height_ = 14000; - const size_t width_ = 14000; + const int height_ = 14000; + const int width_ = 14000; InType input_data_; void SetUp() override { std::tuple_element_t<0, InType> mat(height_ * width_); - for (size_t elem = 0; elem < height_ * width_; elem++) { + for (int elem = 0; elem < height_ * width_; elem++) { mat[elem] = static_cast(elem) % 42000; } @@ -29,8 +29,8 @@ class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests sum(height_); std::tuple_element_t<0, InType> mat = std::get<0>(input_data_); - for (size_t row = 0; row < height_; row++) { - for (size_t col = 0; col < width_; col++) { + for (int row = 0; row < height_; row++) { + for (int col = 0; col < width_; col++) { sum[row] += mat[(width_ * row) + col]; } } From 48d518510470a8eeb2442ea35523ea083967ef12 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 18:25:27 +0000 Subject: [PATCH 21/36] change report --- tasks/luzan_e_matrix_rows_sum/report.md | 11 ++++++----- .../tests/performance/main.cpp | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md index 8ae47fc25f..bb6af77508 100644 --- a/tasks/luzan_e_matrix_rows_sum/report.md +++ b/tasks/luzan_e_matrix_rows_sum/report.md @@ -62,7 +62,7 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ - Использовался Docker-контейнер с Ubuntu 24.04.2 LTS, - Режим сборки: Release. -- Data: Для замера производительности использовалась матрица размером 10 000 × 10 000, элементы которой представляют собой целые последовательные числа от 0 до 42 000. +- Data: Для замера производительности использовалась матрица размером 14 000 × 14 000, элементы которой представляют собой целые последовательные числа от 0 до 42 000. ## 7. Results and Discussion @@ -73,13 +73,14 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ | Mode | Count | Time, s | Speedup | Efficiency | | ---- | ----- | ------------------ | ------- | ---------- | -| seq | 1 | 0.05721 | 1.00 | N/A | -| mpi | 2 | 0.030963 | 1.84 | 92% | -| mpi | 4 | 0.02039 | 2.8 | 70% | +| seq | 1 | 0,126900 | 1.00 | N/A | +| mpi | 2 | 0,906852 | 0.13 | 7% | +| mpi | 4 | 0,792123 | 0.16 | 4% | ## 8. Conclusions -Разработана программа, выполняющая поиск сумм строк матрицы. Также разработана её параллельная версия с использованием MPI. Эффективность параллельного алгоритма высока, однако на практике не достигает 100% из-за накладных расходов на создание процессов. +Разработана программа, выполняющая поиск сумм строк матрицы. Также разработана её параллельная версия с использованием MPI. +Эффективность параллельного очень низкая из-за высоких затрат на пересылку данных и создание процессов. ## 9. References 1. Курс лекций ННГУ "Параллельное программирование для кластерных систем". diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 25aa33589b..b7ced0bd73 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -12,8 +12,8 @@ namespace luzan_e_matrix_rows_sum { class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests { - const int height_ = 14000; - const int width_ = 14000; + const int height_ = 12500; + const int width_ = 12500; InType input_data_; void SetUp() override { From f8c69794374922468b9a654d6404aee9f2219fb8 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 18:28:09 +0000 Subject: [PATCH 22/36] fix grammatical mistakes --- tasks/luzan_e_matrix_rows_sum/report.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md index bb6af77508..a1bd1e9f60 100644 --- a/tasks/luzan_e_matrix_rows_sum/report.md +++ b/tasks/luzan_e_matrix_rows_sum/report.md @@ -35,7 +35,7 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ ## 4. Parallelization Scheme **Распределение данных:** - Для каждого процесса: - 1. Делим высоту матрицы нацело на количество проецессов, получая `rows_per_proc` - минимальное количество строк для обработки кажды процессом. + 1. Делим высоту матрицы нацело на количество процессов, получая `rows_per_proc` - минимальное количество строк для обработки каждый процессом. 2. Получаем остаток `rest` от предыдущего деления. 3. Раскладываем оставшиеся `rest` строк по процессам по одной, начиная с `rank=0`. Также вычисляем `shift` - массив смещений, который будет использован при рассылке данных с корневого процесса. 4. Таким образом первые `rest` процессов обработают `rows_per_proc` + 1 строку, остальные `rows_per_proc`. @@ -80,7 +80,7 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ ## 8. Conclusions Разработана программа, выполняющая поиск сумм строк матрицы. Также разработана её параллельная версия с использованием MPI. -Эффективность параллельного очень низкая из-за высоких затрат на пересылку данных и создание процессов. +Эффективность параллельного очень низкая из-за высоких затрат на пересылку данных и создание процессов. ## 9. References 1. Курс лекций ННГУ "Параллельное программирование для кластерных систем". From ac5822801a5a1036a5ed3a4954058c38c2a3579d Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 18:31:56 +0000 Subject: [PATCH 23/36] clang-format fix --- .../common/include/common.hpp | 2 +- .../mpi/src/ops_mpi.cpp | 40 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 7d4f4f8138..25655e85bb 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -9,7 +9,7 @@ namespace luzan_e_matrix_rows_sum { using InType = std::tuple, int, int>; // matrix, height, width -using OutType = std::vector; // vec of sums, size = height +using OutType = std::vector; // vec of sums, size = height using TestType = std::tuple; // height & width using BaseTask = ppc::task::Task; diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 12b7643f5b..930292ade9 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -14,16 +14,15 @@ LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { SetTypeOfTask(GetStaticTypeOfTask()); GetOutput() = {}; - // saving matrix only if it's rank=0 + // saving matrix only if it's rank=0 int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - + std::vector tmp(0); InType in_reduced = std::make_tuple(tmp, std::get<1>(in), std::get<2>(in)); if (rank == 0) { GetInput() = in; - } - else { + } else { GetInput() = in_reduced; } } @@ -33,7 +32,7 @@ bool LuzanEMatrixRowsSumMPI::ValidationImpl() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank != 0) { return true; - } + } int height = std::get<1>(GetInput()); int width = std::get<2>(GetInput()); @@ -45,7 +44,7 @@ bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank != 0) { return true; - } + } int height = std::get<1>(GetInput()); GetOutput().resize(height); @@ -56,16 +55,15 @@ bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { } bool LuzanEMatrixRowsSumMPI::RunImpl() { - int height = 0; - int width = 0; + int height = 0; + int width = 0; std::tuple_element_t<0, InType> mat; - - int rank = 0; + + int rank = 0; int size = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - int dim[2]; if (rank == 0) { mat = std::get<0>(GetInput()); @@ -77,8 +75,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_Bcast(dim, 2, MPI_INT, 0, MPI_COMM_WORLD); height = dim[0]; width = dim[1]; - - + int rest = height % size; std::vector shift(size); std::vector per_proc(size, height / size); @@ -97,23 +94,26 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { } std::vector recv(per_proc[rank] * width); - + for (int i = 0; i < size; i++) { per_proc[i] *= width; shift[i] *= width; } - - MPI_Scatterv(mat.data(), per_proc.data(), shift.data(), MPI_INT, recv.data(), per_proc[rank], MPI_INT, 0, MPI_COMM_WORLD); + + MPI_Scatterv(mat.data(), per_proc.data(), shift.data(), MPI_INT, recv.data(), per_proc[rank], MPI_INT, 0, + MPI_COMM_WORLD); mat.clear(); std::vector sum(height); int abs_shift = static_cast(shift[rank] / width); int rows_to_calc = static_cast(per_proc[rank] / width); - for (int row = 0; row < rows_to_calc; row++) - for (int col = 0; col < width; col++) + for (int row = 0; row < rows_to_calc; row++) { + for (int col = 0; col < width; col++) { sum[row + abs_shift] += recv[row * width + col]; - + } + } + std::vector fin_sum(height); - MPI_Reduce(sum.data(), fin_sum.data(), sum.size(), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(sum.data(), fin_sum.data(), sum.size(), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Bcast(fin_sum.data(), static_cast(height), MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = fin_sum; return true; From 6a3322a744bf77af7f91b767232f3c0225fe7a3d Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 20:56:59 +0000 Subject: [PATCH 24/36] clang-tidy fix --- .../common/include/common.hpp | 1 - .../luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 16 ++++++++-------- .../luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp | 3 ++- .../tests/functional/main.cpp | 5 ++--- .../tests/performance/main.cpp | 5 ++--- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp index 25655e85bb..93163bba16 100644 --- a/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp +++ b/tasks/luzan_e_matrix_rows_sum/common/include/common.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 930292ade9..e58e6f3615 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -36,7 +36,7 @@ bool LuzanEMatrixRowsSumMPI::ValidationImpl() { int height = std::get<1>(GetInput()); int width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; + return static_cast(std::get<0>(GetInput()).size()) == (height * width) && height != 0 && width != 0; } bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { @@ -64,7 +64,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - int dim[2]; + std::vector dim(2, 0); if (rank == 0) { mat = std::get<0>(GetInput()); height = std::get<1>(GetInput()); @@ -72,7 +72,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { dim[0] = height; dim[1] = width; } - MPI_Bcast(dim, 2, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Bcast(dim.data(), 2, MPI_INT, 0, MPI_COMM_WORLD); height = dim[0]; width = dim[1]; @@ -86,14 +86,14 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { rest--; } for (int i = 1; i < size; i++) { - if (rest) { + if (rest != 0) { per_proc[i]++; rest--; } shift[i] = per_proc[i - 1] + shift[i - 1]; } - std::vector recv(per_proc[rank] * width); + std::vector recv(static_cast(per_proc[rank] * width)); for (int i = 0; i < size; i++) { per_proc[i] *= width; @@ -108,13 +108,13 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { int rows_to_calc = static_cast(per_proc[rank] / width); for (int row = 0; row < rows_to_calc; row++) { for (int col = 0; col < width; col++) { - sum[row + abs_shift] += recv[row * width + col]; + sum[row + abs_shift] += recv[(row * width) + col]; } } std::vector fin_sum(height); - MPI_Reduce(sum.data(), fin_sum.data(), sum.size(), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Bcast(fin_sum.data(), static_cast(height), MPI_INT, 0, MPI_COMM_WORLD); + MPI_Reduce(sum.data(), fin_sum.data(), static_cast(sum.size()), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Bcast(fin_sum.data(), height, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = fin_sum; return true; } diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 1b9eec265f..3ad8194570 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -18,7 +18,8 @@ bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { int height = std::get<1>(GetInput()); int width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == static_cast(height * width) && height != 0 && width != 0; + return std::get<0>(GetInput()).size() == static_cast(height) * static_cast(width) && height != 0 && + width != 0; } bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index ca61b3cbf2..ecff80a821 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -26,10 +25,10 @@ class LuzanEMatrixRowsSumFuncTests : public ppc::util::BaseRunFuncTests(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); int height = std::get<0>(params); int width = std::get<1>(params); - std::tuple_element_t<0, InType> mat(height * width); + std::tuple_element_t<0, InType> mat(static_cast(height) * static_cast(width)); for (int elem = 0; elem < height * width; elem++) { - mat[elem] = (static_cast(elem) * 2) - 42; + mat[elem] = (elem * 2) - 42; } input_data_ = std::make_tuple(mat, height, width); diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index b7ced0bd73..4fea578121 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,6 +1,5 @@ #include -#include #include #include @@ -17,9 +16,9 @@ class LuzanEMatrixRowsSumpERFTests : public ppc::util::BaseRunPerfTests mat(height_ * width_); + std::tuple_element_t<0, InType> mat(static_cast(height_) * static_cast(width_)); for (int elem = 0; elem < height_ * width_; elem++) { - mat[elem] = static_cast(elem) % 42000; + mat[elem] = elem % 42000; } input_data_ = std::make_tuple(mat, height_, width_); From c54828cbbddb4b69b133aa24f8e411fac93a54f5 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 21:49:41 +0000 Subject: [PATCH 25/36] add cstddef for sizet --- tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp | 1 + tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index ecff80a821..c7fcb110d2 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 4fea578121..3104bc2e8f 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" #include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" From 394fd883e064431328ed545b5ee20870012312ba Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 21:52:48 +0000 Subject: [PATCH 26/36] clang-format fix --- tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp | 2 +- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp index c7fcb110d2..178caa494e 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/functional/main.cpp @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include #include diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 3104bc2e8f..4a2bc8ba74 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,8 +1,8 @@ #include +#include #include #include -#include #include "luzan_e_matrix_rows_sum/common/include/common.hpp" #include "luzan_e_matrix_rows_sum/mpi/include/ops_mpi.hpp" From 5fed4ab38058a3459c5ca0c58eee6b654170b1f6 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 22 Nov 2025 22:01:09 +0000 Subject: [PATCH 27/36] fix include --- tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp index 4a2bc8ba74..e7529440c6 100644 --- a/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp +++ b/tasks/luzan_e_matrix_rows_sum/tests/performance/main.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include From 8898854d0c5e8b426eabb4707766a24cca84c936 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 23 Nov 2025 09:10:25 +0000 Subject: [PATCH 28/36] codecov fix --- tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index e58e6f3615..11781bece0 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -81,16 +81,14 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { std::vector per_proc(size, height / size); shift[0] = 0; - if (rest != 0) { - per_proc[0]++; - rest--; - } - for (int i = 1; i < size; i++) { + int accumulator = 0; + for (int i = 0; i < size; i++) { if (rest != 0) { per_proc[i]++; rest--; } - shift[i] = per_proc[i - 1] + shift[i - 1]; + shift[i] = accumulator; + accumulator = per_proc[i] + shift[i]; } std::vector recv(static_cast(per_proc[rank] * width)); From 79b30b4848ec7dd4ce7e420ae1d57e66a21f03f3 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 23 Nov 2025 11:15:16 +0000 Subject: [PATCH 29/36] points --- tasks/luzan_e_matrix_rows_sum/report.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md index a1bd1e9f60..a288b38642 100644 --- a/tasks/luzan_e_matrix_rows_sum/report.md +++ b/tasks/luzan_e_matrix_rows_sum/report.md @@ -26,7 +26,7 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ **Ограничения:** - элементы матрицы — целые числа. -- элементы матрицы лежат в диапазоне -`[0; 42000]` +- элементы матрицы лежат в диапазоне -`[0; 42000]`. ## 3. Baseline Algorithm (Sequential) - Инициализация всех элементов выходного вектора нулями. @@ -53,13 +53,13 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ ## 6. Experimental Setup - Hardware/OS: - - CPU: Intel Core i7-13620H; P-cores-6, E-cores-4, - - RAM: 16 GB RAM, + - CPU: Intel Core i7-13620H; P-cores-6, E-cores-4. + - RAM: 16 GB RAM. - OS: Windows 11, x64. - Toolchain: - - Cmake 3.28.3, - - Компилятор: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, - - Использовался Docker-контейнер с Ubuntu 24.04.2 LTS, + - Cmake 3.28.3. + - Компилятор: gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0. + - Использовался Docker-контейнер с Ubuntu 24.04.2 LTS. - Режим сборки: Release. - Data: Для замера производительности использовалась матрица размером 14 000 × 14 000, элементы которой представляют собой целые последовательные числа от 0 до 42 000. From 55a1ab4cd3e4782575beaa55b34ded5a4796ec1c Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 23 Nov 2025 21:07:16 +0000 Subject: [PATCH 30/36] remove unused picture --- tasks/luzan_e_matrix_rows_sum/data/pic.jpg | Bin 23 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tasks/luzan_e_matrix_rows_sum/data/pic.jpg diff --git a/tasks/luzan_e_matrix_rows_sum/data/pic.jpg b/tasks/luzan_e_matrix_rows_sum/data/pic.jpg deleted file mode 100644 index 637624238c89d914613ed301968bffbf462bc110..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23 bcmWGA<1$h(;xaNd<@(RSzyQYo|NjR7KDY Date: Mon, 24 Nov 2025 22:06:50 +0000 Subject: [PATCH 31/36] fix checks --- tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 3 ++- tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 11781bece0..3c82610691 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -36,7 +36,8 @@ bool LuzanEMatrixRowsSumMPI::ValidationImpl() { int height = std::get<1>(GetInput()); int width = std::get<2>(GetInput()); - return static_cast(std::get<0>(GetInput()).size()) == (height * width) && height != 0 && width != 0; + return std::get<0>(GetInput()).size() == static_cast(height) * static_cast(width) && height > 0 && + width > 0; } bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { diff --git a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp index 3ad8194570..f2af5b681d 100644 --- a/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp +++ b/tasks/luzan_e_matrix_rows_sum/seq/src/ops_seq.cpp @@ -18,8 +18,8 @@ bool LuzanEMatrixRowsSumSEQ::ValidationImpl() { int height = std::get<1>(GetInput()); int width = std::get<2>(GetInput()); - return std::get<0>(GetInput()).size() == static_cast(height) * static_cast(width) && height != 0 && - width != 0; + return std::get<0>(GetInput()).size() == static_cast(height) * static_cast(width) && height > 0 && + width > 0; } bool LuzanEMatrixRowsSumSEQ::PreProcessingImpl() { From a0d559af4a9edefa0a5f94805089e53ded690027 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 25 Nov 2025 20:04:48 +0000 Subject: [PATCH 32/36] change mpi_reduce to mpi_gatherv --- .../mpi/src/ops_mpi.cpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 3c82610691..10015c73b4 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -56,6 +56,7 @@ bool LuzanEMatrixRowsSumMPI::PreProcessingImpl() { } bool LuzanEMatrixRowsSumMPI::RunImpl() { + // mpi things int height = 0; int width = 0; std::tuple_element_t<0, InType> mat; @@ -65,6 +66,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); + // sharing matrix sizes std::vector dim(2, 0); if (rank == 0) { mat = std::get<0>(GetInput()); @@ -77,9 +79,10 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { height = dim[0]; width = dim[1]; + // calcilating shifts & rows_per_proc (only about rows rigth now) int rest = height % size; - std::vector shift(size); - std::vector per_proc(size, height / size); + std::vector shift(size); + std::vector per_proc(size, height / size); // rows per proc shift[0] = 0; int accumulator = 0; @@ -92,27 +95,35 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { accumulator = per_proc[i] + shift[i]; } + // preparing to recieve data std::vector recv(static_cast(per_proc[rank] * width)); for (int i = 0; i < size; i++) { - per_proc[i] *= width; + per_proc[i] *= width; // now it's about elements shift[i] *= width; } - MPI_Scatterv(mat.data(), per_proc.data(), shift.data(), MPI_INT, recv.data(), per_proc[rank], MPI_INT, 0, MPI_COMM_WORLD); - mat.clear(); - std::vector sum(height); - int abs_shift = static_cast(shift[rank] / width); + mat.clear(); // no need anymore + + std::vector rows_sum(static_cast(per_proc[rank] / width)); // sums + //int abs_shift = static_cast(shift[rank] / width); int rows_to_calc = static_cast(per_proc[rank] / width); for (int row = 0; row < rows_to_calc; row++) { for (int col = 0; col < width; col++) { - sum[row + abs_shift] += recv[(row * width) + col]; + rows_sum[row] += recv[(row * width) + col]; } } + for (int i = 0; i < size; i++) { + per_proc[i] /= width; + shift[i] /= width; + } + std::vector fin_sum(height); - MPI_Reduce(sum.data(), fin_sum.data(), static_cast(sum.size()), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + //MPI_Reduce(sum.data(), fin_sum.data(), static_cast(sum.size()), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Gatherv(rows_sum.data(), rows_to_calc, MPI_INT, fin_sum.data(), per_proc.data(), shift.data(), MPI_INT, + 0, MPI_COMM_WORLD); MPI_Bcast(fin_sum.data(), height, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = fin_sum; return true; From 708650c32f911bd75cac2ce81cf9d87dc7a0ba08 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 25 Nov 2025 20:11:10 +0000 Subject: [PATCH 33/36] change matrix sizes sharing --- tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 10015c73b4..f1706df76b 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -66,18 +66,16 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - // sharing matrix sizes + // getting input matrix on rank=0 + // getting & sharing matrix sizes std::vector dim(2, 0); if (rank == 0) { mat = std::get<0>(GetInput()); height = std::get<1>(GetInput()); width = std::get<2>(GetInput()); - dim[0] = height; - dim[1] = width; } - MPI_Bcast(dim.data(), 2, MPI_INT, 0, MPI_COMM_WORLD); - height = dim[0]; - width = dim[1]; + MPI_Bcast(&height, 1, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Bcast(&width, 1, MPI_INT, 0, MPI_COMM_WORLD); // calcilating shifts & rows_per_proc (only about rows rigth now) int rest = height % size; @@ -107,7 +105,6 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { mat.clear(); // no need anymore std::vector rows_sum(static_cast(per_proc[rank] / width)); // sums - //int abs_shift = static_cast(shift[rank] / width); int rows_to_calc = static_cast(per_proc[rank] / width); for (int row = 0; row < rows_to_calc; row++) { for (int col = 0; col < width; col++) { @@ -116,12 +113,11 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { } for (int i = 0; i < size; i++) { - per_proc[i] /= width; + per_proc[i] /= width; // back to rows shift[i] /= width; } std::vector fin_sum(height); - //MPI_Reduce(sum.data(), fin_sum.data(), static_cast(sum.size()), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Gatherv(rows_sum.data(), rows_to_calc, MPI_INT, fin_sum.data(), per_proc.data(), shift.data(), MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(fin_sum.data(), height, MPI_INT, 0, MPI_COMM_WORLD); From 187c7acbc613b838c632ef8acb04ad996ed67c35 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 25 Nov 2025 20:23:32 +0000 Subject: [PATCH 34/36] some changes --- tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index f1706df76b..1194b06b75 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -18,12 +18,10 @@ LuzanEMatrixRowsSumMPI::LuzanEMatrixRowsSumMPI(const InType &in) { int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - std::vector tmp(0); - InType in_reduced = std::make_tuple(tmp, std::get<1>(in), std::get<2>(in)); if (rank == 0) { GetInput() = in; } else { - GetInput() = in_reduced; + GetInput() = {}; } } @@ -79,13 +77,12 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { // calcilating shifts & rows_per_proc (only about rows rigth now) int rest = height % size; - std::vector shift(size); + std::vector shift(size, 0); std::vector per_proc(size, height / size); // rows per proc - shift[0] = 0; int accumulator = 0; for (int i = 0; i < size; i++) { - if (rest != 0) { + if (rest > 0) { per_proc[i]++; rest--; } @@ -104,6 +101,7 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { MPI_COMM_WORLD); mat.clear(); // no need anymore + // calculating std::vector rows_sum(static_cast(per_proc[rank] / width)); // sums int rows_to_calc = static_cast(per_proc[rank] / width); for (int row = 0; row < rows_to_calc; row++) { From 16dced1beb0c34586725217926786603e178cff2 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 25 Nov 2025 20:24:23 +0000 Subject: [PATCH 35/36] clang-format fix --- .../mpi/src/ops_mpi.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp index 1194b06b75..fcc40624f0 100644 --- a/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp +++ b/tasks/luzan_e_matrix_rows_sum/mpi/src/ops_mpi.cpp @@ -77,8 +77,8 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { // calcilating shifts & rows_per_proc (only about rows rigth now) int rest = height % size; - std::vector shift(size, 0); - std::vector per_proc(size, height / size); // rows per proc + std::vector shift(size, 0); + std::vector per_proc(size, height / size); // rows per proc int accumulator = 0; for (int i = 0; i < size; i++) { @@ -94,15 +94,15 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { std::vector recv(static_cast(per_proc[rank] * width)); for (int i = 0; i < size; i++) { - per_proc[i] *= width; // now it's about elements + per_proc[i] *= width; // now it's about elements shift[i] *= width; } MPI_Scatterv(mat.data(), per_proc.data(), shift.data(), MPI_INT, recv.data(), per_proc[rank], MPI_INT, 0, MPI_COMM_WORLD); - mat.clear(); // no need anymore - + mat.clear(); // no need anymore + // calculating - std::vector rows_sum(static_cast(per_proc[rank] / width)); // sums + std::vector rows_sum(static_cast(per_proc[rank] / width)); // sums int rows_to_calc = static_cast(per_proc[rank] / width); for (int row = 0; row < rows_to_calc; row++) { for (int col = 0; col < width; col++) { @@ -111,13 +111,13 @@ bool LuzanEMatrixRowsSumMPI::RunImpl() { } for (int i = 0; i < size; i++) { - per_proc[i] /= width; // back to rows - shift[i] /= width; + per_proc[i] /= width; // back to rows + shift[i] /= width; } std::vector fin_sum(height); - MPI_Gatherv(rows_sum.data(), rows_to_calc, MPI_INT, fin_sum.data(), per_proc.data(), shift.data(), MPI_INT, - 0, MPI_COMM_WORLD); + MPI_Gatherv(rows_sum.data(), rows_to_calc, MPI_INT, fin_sum.data(), per_proc.data(), shift.data(), MPI_INT, 0, + MPI_COMM_WORLD); MPI_Bcast(fin_sum.data(), height, MPI_INT, 0, MPI_COMM_WORLD); GetOutput() = fin_sum; return true; From 56be159ca4359b57592f0ed1279e599fa8b4acb2 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Tue, 25 Nov 2025 21:41:56 +0000 Subject: [PATCH 36/36] report update --- tasks/luzan_e_matrix_rows_sum/report.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/luzan_e_matrix_rows_sum/report.md b/tasks/luzan_e_matrix_rows_sum/report.md index a288b38642..20c0c40323 100644 --- a/tasks/luzan_e_matrix_rows_sum/report.md +++ b/tasks/luzan_e_matrix_rows_sum/report.md @@ -73,9 +73,9 @@ $$sum[i] = \sum_{j=0}^{width-1} A_{i\_j}$$ | Mode | Count | Time, s | Speedup | Efficiency | | ---- | ----- | ------------------ | ------- | ---------- | -| seq | 1 | 0,126900 | 1.00 | N/A | -| mpi | 2 | 0,906852 | 0.13 | 7% | -| mpi | 4 | 0,792123 | 0.16 | 4% | +| seq | 1 | 0,06262 | 1.00 | N/A | +| mpi | 2 | 0,71973 | 0.08 | 4% | +| mpi | 4 | 0,60037 | 0.10 | 2% | ## 8. Conclusions