From fa60d445dbdcdc6c3fe6ffff77a9e1253cab434d Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 18 Apr 2026 23:31:05 +0000 Subject: [PATCH 01/10] [FIX] change folders & namespaces names --- .../common/include/common.hpp | 247 ++++++++++++++++++ .../data/ans_test_1.txt | 4 + .../data/ans_test_2.txt | 4 + .../data/ans_test_3.txt | 4 + .../data/ans_test_4.txt | 4 + .../data/ans_test_5.txt | 4 + .../data/ans_test_6.txt | 4 + .../data/test_1.txt | 8 + .../data/test_2.txt | 5 + .../data/test_3.txt | 15 ++ .../data/test_4.txt | 13 + .../data/test_5.txt | 9 + .../data/test_6.txt | 8 + .../info.json | 9 + .../seq/include/ops_seq.hpp | 22 ++ .../seq/src/ops_seq.cpp | 36 +++ .../settings.json | 10 + .../tests/functional/main.cpp | 86 ++++++ .../tests/performance/main.cpp | 59 +++++ 19 files changed, 551 insertions(+) create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_1.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_2.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_3.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_4.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_5.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_6.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/test_1.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/test_2.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/test_3.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/test_4.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/test_5.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/data/test_6.txt create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/info.json create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/seq/src/ops_seq.cpp create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/settings.json create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/tests/functional/main.cpp create mode 100644 tasks/luzan_e_double_sparse_matrix_mult/tests/performance/main.cpp diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp new file mode 100644 index 000000000..1ae5799a0 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -0,0 +1,247 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include "task/include/task.hpp" + +namespace luzan_e_double_sparse_matrix_mult { + +const double kEPS = 1e-8; + +class SparseMatrix { + std::vector value_; + std::vector row_; + std::vector col_index_; + + unsigned cols_; + unsigned rows_; + + public: + SparseMatrix(unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { + col_index_.clear(); + row_.clear(); + value_.clear(); + } + + SparseMatrix() : cols_(0), rows_(0) { + col_index_.clear(); + row_.clear(); + value_.clear(); + } + + SparseMatrix(const std::vector &matrix, unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { + col_index_.clear(); + row_.clear(); + value_.clear(); + + Sparse(matrix); + } + + void GenLineMatrix(unsigned rows, unsigned cols) { + col_index_.clear(); + row_.clear(); + value_.clear(); + + rows_ = rows; + cols_ = cols; + + col_index_.push_back(0); + for (unsigned j = 0; j < cols_; j++) { + for (unsigned i = 0; i < rows_; i++) { + if (i % 5 == 0) { + value_.push_back(1.0); + row_.push_back(i); + } + } + col_index_.push_back(value_.size()); + } + } + + void GenColsMatrix(unsigned rows, unsigned cols) { + col_index_.clear(); + row_.clear(); + value_.clear(); + + rows_ = rows; + cols_ = cols; + col_index_.push_back(0); + + for (unsigned j = 0; j < cols_; j++) { + if (j % 5 == 0) { + for (unsigned i = 0; i < rows_; i++) { + value_.push_back(1.0); + row_.push_back(i); + } + } + + col_index_.push_back(value_.size()); + } + } + + void GenPerfAns(unsigned n, unsigned m, unsigned k) { + col_index_.clear(); + row_.clear(); + value_.clear(); + rows_ = n; + cols_ = m; + + col_index_.push_back(0); + for (unsigned j = 0; j < m; j++) { + if (j % 5 == 0) // только чётные столбцы ненулевые + { + for (unsigned i = 0; i < n; i++) { + if (i % 5 == 0) // только чётные строки + { + value_.push_back(static_cast(k)); + row_.push_back(i); + } + } + } + + col_index_.push_back(value_.size()); + } + } + + [[nodiscard]] unsigned GetCols() const { + return cols_; + } + + [[nodiscard]] unsigned GetRows() const { + return rows_; + } + + std::vector GetVal() { + return value_; + } + + bool operator==(const SparseMatrix &b) const { + bool tmp = false; + if (value_.size() == b.value_.size()) { + tmp = true; + for (size_t long_i = 0; long_i < value_.size(); long_i++) { + if (fabs(value_[long_i] - b.value_[long_i]) > kEPS) { + tmp = false; + break; + } + } + } + + return tmp && (row_ == b.row_) && (col_index_ == b.col_index_) && (cols_ == b.cols_) && (rows_ == b.rows_); + } + + double GetXy(unsigned x = 1, unsigned y = 2) { + for (unsigned verylongs = col_index_[y]; verylongs < col_index_[y + 1]; verylongs++) { + if (row_[verylongs] == x) { + return value_[verylongs]; + } + } + return 0.0; + } + void Sparse(std::vector matrix) { + col_index_.push_back(0); + bool flag = false; + for (unsigned j = 0; j < cols_; j++) { + col_index_.push_back(value_.size()); + + for (unsigned i = 0; i < rows_; i++) { + if (fabs(matrix[(i * cols_) + j]) > kEPS) { + value_.push_back(matrix[(i * cols_) + j]); + row_.push_back(i); + flag = true; + } + } + if (flag) { + col_index_.pop_back(); + col_index_.push_back(value_.size()); + flag = false; + } + } + } + + SparseMatrix operator*(const SparseMatrix &b) const { + SparseMatrix c(rows_, b.cols_); + c.col_index_.push_back(0); + + for (unsigned b_col = 0; b_col < b.cols_; b_col++) { + std::vector tmp_col(rows_, 0); + unsigned b_rows_start = b.col_index_[b_col]; + unsigned b_rows_end = b.col_index_[b_col + 1]; + + for (unsigned b_pos = b_rows_start; b_pos < b_rows_end; b_pos++) { + double b_val = b.value_[b_pos]; + unsigned b_row = b.row_[b_pos]; + + unsigned a_rows_start = col_index_[b_row]; + unsigned a_rows_end = col_index_[b_row + 1]; + + for (unsigned a_pos = a_rows_start; a_pos < a_rows_end; a_pos++) { + double a_val = value_[a_pos]; + unsigned a_row = row_[a_pos]; + tmp_col[a_row] += a_val * b_val; + } + } + for (unsigned i = 0; i < rows_; i++) { + if (fabs(tmp_col[i]) > kEPS) { + c.value_.push_back(tmp_col[i]); + c.row_.push_back(i); + } + } + c.col_index_.push_back(c.value_.size()); + } + return c; + } + + void GetSparsedMatrixFromFile(std::ifstream &file) { + if (!file) { + throw std::runtime_error("Cannot open file with sparsed matrix"); + } + unsigned n = 0; + file >> n >> rows_ >> cols_; + + double tmp_val = 0; + for (unsigned i = 0; i < n; i++) { + file >> tmp_val; + value_.push_back(tmp_val); + } + + unsigned tmp = 0; + for (unsigned i = 0; i < n; i++) { + file >> tmp; + row_.push_back(tmp); + } + + for (unsigned i = 0; i < cols_ + 1; i++) { + file >> tmp; + col_index_.push_back(tmp); + } + } +}; + +inline SparseMatrix GetFromFile(std::ifstream &file) { + size_t r = 0; + size_t c = 0; + file >> r >> c; + + std::vector dense(r * c); + + for (unsigned i = 0; i < r; i++) { + for (unsigned j = 0; j < c; j++) { + file >> dense[(i * c) + j]; + } + } + SparseMatrix a(dense, r, c); + return a; +}; + +using InType = std::tuple; +using OutType = SparseMatrix; +using TestType = std::tuple; +using BaseTask = ppc::task::Task; + +} // namespace luzan_e_double_sparse_matrix_mult diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_1.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_1.txt new file mode 100644 index 000000000..bdd918d01 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_1.txt @@ -0,0 +1,4 @@ +3 3 3 +1.0 9.0 24.0 +0 1 1 +0 1 2 3 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_2.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_2.txt new file mode 100644 index 000000000..9ee1a60f6 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_2.txt @@ -0,0 +1,4 @@ +1 1 1 +2 +0 +0 1 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_3.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_3.txt new file mode 100644 index 000000000..f6e841000 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_3.txt @@ -0,0 +1,4 @@ +8 4 2 +57 57 57 57 72 72 72 72 +0 1 2 3 0 1 2 3 +0 4 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_4.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_4.txt new file mode 100644 index 000000000..c7fc0c83d --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_4.txt @@ -0,0 +1,4 @@ +0 5 3 + + +0 0 0 0 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_5.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_5.txt new file mode 100644 index 000000000..47b11f9dc --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_5.txt @@ -0,0 +1,4 @@ +8 5 3 +1 2 2 3 8 16 16 24 +0 1 2 3 0 1 2 3 +0 4 4 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_6.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_6.txt new file mode 100644 index 000000000..f0426e00d --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/ans_test_6.txt @@ -0,0 +1,4 @@ +10 3 4 +8.34 4.08 6.6 2.76 7.82 12.65 12.65 1.2 3.4 5.5 +0 1 2 0 1 2 0 0 1 2 +0 3 6 7 10 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/test_1.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/test_1.txt new file mode 100644 index 000000000..cd31368bf --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/test_1.txt @@ -0,0 +1,8 @@ +3 2 +1.0 0 +0 3.0 +0 0 + +2 3 +1.0 0 0 +0 3.0 8.0 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/test_2.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/test_2.txt new file mode 100644 index 000000000..f8b902e8e --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/test_2.txt @@ -0,0 +1,5 @@ +1 1 +1 + +1 1 +2 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/test_3.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/test_3.txt new file mode 100644 index 000000000..1ee9e8e0a --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/test_3.txt @@ -0,0 +1,15 @@ +4 8 +1 0 0 0 0 2 5 4 +1 0 0 0 0 2 5 4 +1 0 0 0 0 2 5 4 +1 0 0 0 0 2 5 4 + +8 2 +4 5 +5 4 +1 0 +0 0 +0 0 +0 0 +5 7 +7 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/test_4.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/test_4.txt new file mode 100644 index 000000000..897f4b98a --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/test_4.txt @@ -0,0 +1,13 @@ +5 5 +0 0 0 0 0 +0 0 0 0 0 +0 0 0 0 0 +0 0 0 0 0 +0 0 0 0 0 + +5 3 +0 0 0 +0 0 0 +0 0 0 +0 0 0 +0 0 0 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/test_5.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/test_5.txt new file mode 100644 index 000000000..9c91dbedc --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/test_5.txt @@ -0,0 +1,9 @@ +5 1 +1 +2 +2 +3 +0 + +1 3 +1 0 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult/data/test_6.txt b/tasks/luzan_e_double_sparse_matrix_mult/data/test_6.txt new file mode 100644 index 000000000..0899139c2 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/data/test_6.txt @@ -0,0 +1,8 @@ +3 2 +1.2 2.3 +3.4 0.0 +5.5 0.0 + +2 4 +1.2 2.3 0.0 1.0 +3.0 0.0 5.5 0.0 diff --git a/tasks/luzan_e_double_sparse_matrix_mult/info.json b/tasks/luzan_e_double_sparse_matrix_mult/info.json new file mode 100644 index 000000000..f8f58986e --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/info.json @@ -0,0 +1,9 @@ +{ + "student": { + "first_name": "Егор", + "group_number": "3823Б1ФИ3", + "last_name": "Лузан", + "middle_name": "Андреевич", + "task_number": "1" + } +} diff --git a/tasks/luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp b/tasks/luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp new file mode 100644 index 000000000..f58a00789 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "luzan_e_double_sparse_matrix_mult/common/include/common.hpp" +#include "task/include/task.hpp" + +namespace luzan_e_double_sparse_matrix_mult { + +class LuzanEDoubleSparseMatrixMultSeq : public BaseTask { + public: + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kSEQ; + } + explicit LuzanEDoubleSparseMatrixMultSeq(const InType &in); + + private: + bool ValidationImpl() override; + bool PreProcessingImpl() override; + bool RunImpl() override; + bool PostProcessingImpl() override; +}; + +} // namespace luzan_e_double_sparse_matrix_mult diff --git a/tasks/luzan_e_double_sparse_matrix_mult/seq/src/ops_seq.cpp b/tasks/luzan_e_double_sparse_matrix_mult/seq/src/ops_seq.cpp new file mode 100644 index 000000000..4a947e36c --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/seq/src/ops_seq.cpp @@ -0,0 +1,36 @@ +#include "luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp" + +#include "luzan_e_double_sparse_matrix_mult/common/include/common.hpp" +// #include "util/include/util.hpp" + +namespace luzan_e_double_sparse_matrix_mult { + +LuzanEDoubleSparseMatrixMultSeq::LuzanEDoubleSparseMatrixMultSeq(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + // GetOutput() = 0; +} + +bool LuzanEDoubleSparseMatrixMultSeq::ValidationImpl() { + const auto &a = std::get<0>(GetInput()); + const auto &b = std::get<1>(GetInput()); + return a.GetCols() == b.GetRows() && a.GetCols() != 0 && a.GetRows() != 0 && b.GetCols() != 0; +} + +bool LuzanEDoubleSparseMatrixMultSeq::PreProcessingImpl() { + return true; +} + +bool LuzanEDoubleSparseMatrixMultSeq::RunImpl() { + const auto &a = std::get<0>(GetInput()); + const auto &b = std::get<1>(GetInput()); + + GetOutput() = a * b; + return true; +} + +bool LuzanEDoubleSparseMatrixMultSeq::PostProcessingImpl() { + return true; +} + +} // namespace luzan_e_double_sparse_matrix_mult diff --git a/tasks/luzan_e_double_sparse_matrix_mult/settings.json b/tasks/luzan_e_double_sparse_matrix_mult/settings.json new file mode 100644 index 000000000..0be0208fc --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/settings.json @@ -0,0 +1,10 @@ +{ + "tasks": { + "all": "enabled", + "omp": "enabled", + "seq": "enabled", + "stl": "enabled", + "tbb": "enabled" + }, + "tasks_type": "threads" +} diff --git a/tasks/luzan_e_double_sparse_matrix_mult/tests/functional/main.cpp b/tasks/luzan_e_double_sparse_matrix_mult/tests/functional/main.cpp new file mode 100644 index 000000000..7c0651af8 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/tests/functional/main.cpp @@ -0,0 +1,86 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "luzan_e_double_sparse_matrix_mult/common/include/common.hpp" +#include "luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp" +#include "util/include/func_test_util.hpp" +#include "util/include/util.hpp" + +namespace luzan_e_double_sparse_matrix_mult { + +class LuzanEDoubleSparseMatrixMultSeqestsThreads : public ppc::util::BaseRunFuncTests { + public: + static std::string PrintTestParam(const TestType &test_param) { + return "test" + std::get<1>(test_param); + } + + protected: + void SetUp() override { + TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + std::string file_name = std::get<0>(params); + std::string abs_path = + ppc::util::GetAbsoluteTaskPath(std::string(PPC_ID_luzan_e_double_sparse_matrix_mult), file_name); + std::ifstream test_file(abs_path); + if (!test_file) { + throw std::runtime_error("Cannot open task file"); + } + + SparseMatrix a = GetFromFile(test_file); + SparseMatrix b = GetFromFile(test_file); + test_file.close(); + + input_data_ = std::make_tuple(a, b); + + file_name = "ans_" + std::get<0>(params); + abs_path = ppc::util::GetAbsoluteTaskPath(std::string(PPC_ID_luzan_e_double_sparse_matrix_mult), file_name); + std::ifstream ans_file(abs_path); + if (!ans_file) { + throw std::runtime_error("Cannot open asn file"); + } + output_data_.GetSparsedMatrixFromFile(ans_file); + ans_file.close(); + } + + bool CheckTestOutputData(OutType &output_data) final { + return (output_data == output_data_); + } + + InType GetTestInputData() final { + return input_data_; + } + + private: + InType input_data_; + OutType output_data_; +}; + +namespace { + +TEST_P(LuzanEDoubleSparseMatrixMultSeqestsThreads, MatmulFromPic) { + ExecuteTest(GetParam()); +} + +const std::array kTestParam = {std::make_tuple("test_1.txt", "01"), std::make_tuple("test_2.txt", "02"), + std::make_tuple("test_3.txt", "03"), std::make_tuple("test_4.txt", "04"), + std::make_tuple("test_5.txt", "05"), std::make_tuple("test_6.txt", "06")}; + +const auto kTestTasksList = std::tuple_cat(ppc::util::AddFuncTask( + kTestParam, PPC_SETTINGS_luzan_e_double_sparse_matrix_mult)); + +const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); + +const auto kPerfTestName = + LuzanEDoubleSparseMatrixMultSeqestsThreads::PrintFuncTestName; + +INSTANTIATE_TEST_SUITE_P(FuncTests, LuzanEDoubleSparseMatrixMultSeqestsThreads, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace luzan_e_double_sparse_matrix_mult diff --git a/tasks/luzan_e_double_sparse_matrix_mult/tests/performance/main.cpp b/tasks/luzan_e_double_sparse_matrix_mult/tests/performance/main.cpp new file mode 100644 index 000000000..801568ac5 --- /dev/null +++ b/tasks/luzan_e_double_sparse_matrix_mult/tests/performance/main.cpp @@ -0,0 +1,59 @@ +#include + +#include +#include + +#include "luzan_e_double_sparse_matrix_mult/common/include/common.hpp" +#include "luzan_e_double_sparse_matrix_mult/seq/include/ops_seq.hpp" +#include "util/include/perf_test_util.hpp" + +namespace luzan_e_double_sparse_matrix_mult { + +class LuzanEDoubleSparseMatrixMultSeqPerfTestThreads : public ppc::util::BaseRunPerfTests { + const int kCount_ = 2500; + // const unsigned cols_ = 5000; + // const unsigned rows_ = 5000; + InType input_data_; + OutType output_data_; + + void SetUp() override { + std::vector value; + std::vector row; + std::vector col_index; + + SparseMatrix lhs; + lhs.GenLineMatrix(kCount_, kCount_); + + SparseMatrix rhs; + rhs.GenColsMatrix(kCount_, kCount_); + input_data_ = std::make_tuple(lhs, rhs); + output_data_.GenPerfAns(kCount_, kCount_, kCount_); + } + + bool CheckTestOutputData(OutType &output_data) final { + return (output_data == output_data_); + } + + InType GetTestInputData() final { + return input_data_; + } +}; + +TEST_P(LuzanEDoubleSparseMatrixMultSeqPerfTestThreads, RunPerfModes) { + ExecuteTest(GetParam()); +} + +namespace { + +const auto kAllPerfTasks = ppc::util::MakeAllPerfTasks( + PPC_SETTINGS_luzan_e_double_sparse_matrix_mult); + +const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); + +const auto kPerfTestName = LuzanEDoubleSparseMatrixMultSeqPerfTestThreads::CustomPerfTestName; + +INSTANTIATE_TEST_SUITE_P(RunModeTests, LuzanEDoubleSparseMatrixMultSeqPerfTestThreads, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace luzan_e_double_sparse_matrix_mult From 896c704cc882db8be2d88966892f9576190c6307 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sat, 18 Apr 2026 23:41:10 +0000 Subject: [PATCH 02/10] [FIX] clang-tidy/add no-discard --- .../luzan_e_double_sparse_matrix_mult/common/include/common.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index 1ae5799a0..ef14aff15 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -116,7 +116,7 @@ class SparseMatrix { return rows_; } - std::vector GetVal() { + [[nodiscard]] std::vector GetVal() { return value_; } From 8ba69b56fd8ba5bdd8a83fdc580187b91f13daee Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 00:04:14 +0000 Subject: [PATCH 03/10] [FIX] delete old directory --- .../common/include/common.hpp | 247 ------------------ .../data/ans_test_1.txt | 4 - .../data/ans_test_2.txt | 4 - .../data/ans_test_3.txt | 4 - .../data/ans_test_4.txt | 4 - .../data/ans_test_5.txt | 4 - .../data/ans_test_6.txt | 4 - .../data/test_1.txt | 8 - .../data/test_2.txt | 5 - .../data/test_3.txt | 15 -- .../data/test_4.txt | 13 - .../data/test_5.txt | 9 - .../data/test_6.txt | 8 - .../info.json | 9 - .../seq/include/ops_seq.hpp | 22 -- .../seq/src/ops_seq.cpp | 36 --- .../settings.json | 10 - .../tests/functional/main.cpp | 86 ------ .../tests/performance/main.cpp | 59 ----- 19 files changed, 551 deletions(-) delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_1.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_2.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_3.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_4.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_5.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_6.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_1.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_2.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_3.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_4.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_5.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_6.txt delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/info.json delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/seq/src/ops_seq.cpp delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/settings.json delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/tests/functional/main.cpp delete mode 100644 tasks/luzan_e_double_sparse_matrix_mult_seq/tests/performance/main.cpp diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp deleted file mode 100644 index 72d63eb51..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp +++ /dev/null @@ -1,247 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include "task/include/task.hpp" - -namespace luzan_e_double_sparse_matrix_mult_seq { - -const double kEPS = 1e-8; - -class SparseMatrix { - std::vector value_; - std::vector row_; - std::vector col_index_; - - unsigned cols_; - unsigned rows_; - - public: - SparseMatrix(unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { - col_index_.clear(); - row_.clear(); - value_.clear(); - } - - SparseMatrix() : cols_(0), rows_(0) { - col_index_.clear(); - row_.clear(); - value_.clear(); - } - - SparseMatrix(const std::vector &matrix, unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { - col_index_.clear(); - row_.clear(); - value_.clear(); - - Sparse(matrix); - } - - void GenLineMatrix(unsigned rows, unsigned cols) { - col_index_.clear(); - row_.clear(); - value_.clear(); - - rows_ = rows; - cols_ = cols; - - col_index_.push_back(0); - for (unsigned j = 0; j < cols_; j++) { - for (unsigned i = 0; i < rows_; i++) { - if (i % 5 == 0) { - value_.push_back(1.0); - row_.push_back(i); - } - } - col_index_.push_back(value_.size()); - } - } - - void GenColsMatrix(unsigned rows, unsigned cols) { - col_index_.clear(); - row_.clear(); - value_.clear(); - - rows_ = rows; - cols_ = cols; - col_index_.push_back(0); - - for (unsigned j = 0; j < cols_; j++) { - if (j % 5 == 0) { - for (unsigned i = 0; i < rows_; i++) { - value_.push_back(1.0); - row_.push_back(i); - } - } - - col_index_.push_back(value_.size()); - } - } - - void GenPerfAns(unsigned n, unsigned m, unsigned k) { - col_index_.clear(); - row_.clear(); - value_.clear(); - rows_ = n; - cols_ = m; - - col_index_.push_back(0); - for (unsigned j = 0; j < m; j++) { - if (j % 5 == 0) // только чётные столбцы ненулевые - { - for (unsigned i = 0; i < n; i++) { - if (i % 5 == 0) // только чётные строки - { - value_.push_back(static_cast(k)); - row_.push_back(i); - } - } - } - - col_index_.push_back(value_.size()); - } - } - - [[nodiscard]] unsigned GetCols() const { - return cols_; - } - - [[nodiscard]] unsigned GetRows() const { - return rows_; - } - - std::vector GetVal() { - return value_; - } - - bool operator==(const SparseMatrix &b) const { - bool tmp = false; - if (value_.size() == b.value_.size()) { - tmp = true; - for (size_t long_i = 0; long_i < value_.size(); long_i++) { - if (fabs(value_[long_i] - b.value_[long_i]) > kEPS) { - tmp = false; - break; - } - } - } - - return tmp && (row_ == b.row_) && (col_index_ == b.col_index_) && (cols_ == b.cols_) && (rows_ == b.rows_); - } - - double GetXy(unsigned x = 1, unsigned y = 2) { - for (unsigned verylongs = col_index_[y]; verylongs < col_index_[y + 1]; verylongs++) { - if (row_[verylongs] == x) { - return value_[verylongs]; - } - } - return 0.0; - } - void Sparse(std::vector matrix) { - col_index_.push_back(0); - bool flag = false; - for (unsigned j = 0; j < cols_; j++) { - col_index_.push_back(value_.size()); - - for (unsigned i = 0; i < rows_; i++) { - if (fabs(matrix[(i * cols_) + j]) > kEPS) { - value_.push_back(matrix[(i * cols_) + j]); - row_.push_back(i); - flag = true; - } - } - if (flag) { - col_index_.pop_back(); - col_index_.push_back(value_.size()); - flag = false; - } - } - } - - SparseMatrix operator*(const SparseMatrix &b) const { - SparseMatrix c(rows_, b.cols_); - c.col_index_.push_back(0); - - for (unsigned b_col = 0; b_col < b.cols_; b_col++) { - std::vector tmp_col(rows_, 0); - unsigned b_rows_start = b.col_index_[b_col]; - unsigned b_rows_end = b.col_index_[b_col + 1]; - - for (unsigned b_pos = b_rows_start; b_pos < b_rows_end; b_pos++) { - double b_val = b.value_[b_pos]; - unsigned b_row = b.row_[b_pos]; - - unsigned a_rows_start = col_index_[b_row]; - unsigned a_rows_end = col_index_[b_row + 1]; - - for (unsigned a_pos = a_rows_start; a_pos < a_rows_end; a_pos++) { - double a_val = value_[a_pos]; - unsigned a_row = row_[a_pos]; - tmp_col[a_row] += a_val * b_val; - } - } - for (unsigned i = 0; i < rows_; i++) { - if (fabs(tmp_col[i]) > kEPS) { - c.value_.push_back(tmp_col[i]); - c.row_.push_back(i); - } - } - c.col_index_.push_back(c.value_.size()); - } - return c; - } - - void GetSparsedMatrixFromFile(std::ifstream &file) { - if (!file) { - throw std::runtime_error("Cannot open file with sparsed matrix"); - } - unsigned n = 0; - file >> n >> rows_ >> cols_; - - double tmp_val = 0; - for (unsigned i = 0; i < n; i++) { - file >> tmp_val; - value_.push_back(tmp_val); - } - - unsigned tmp = 0; - for (unsigned i = 0; i < n; i++) { - file >> tmp; - row_.push_back(tmp); - } - - for (unsigned i = 0; i < cols_ + 1; i++) { - file >> tmp; - col_index_.push_back(tmp); - } - } -}; - -inline SparseMatrix GetFromFile(std::ifstream &file) { - size_t r = 0; - size_t c = 0; - file >> r >> c; - - std::vector dense(r * c); - - for (unsigned i = 0; i < r; i++) { - for (unsigned j = 0; j < c; j++) { - file >> dense[(i * c) + j]; - } - } - SparseMatrix a(dense, r, c); - return a; -}; - -using InType = std::tuple; -using OutType = SparseMatrix; -using TestType = std::tuple; -using BaseTask = ppc::task::Task; - -} // namespace luzan_e_double_sparse_matrix_mult_seq diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_1.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_1.txt deleted file mode 100644 index bdd918d01..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_1.txt +++ /dev/null @@ -1,4 +0,0 @@ -3 3 3 -1.0 9.0 24.0 -0 1 1 -0 1 2 3 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_2.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_2.txt deleted file mode 100644 index 9ee1a60f6..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_2.txt +++ /dev/null @@ -1,4 +0,0 @@ -1 1 1 -2 -0 -0 1 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_3.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_3.txt deleted file mode 100644 index f6e841000..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_3.txt +++ /dev/null @@ -1,4 +0,0 @@ -8 4 2 -57 57 57 57 72 72 72 72 -0 1 2 3 0 1 2 3 -0 4 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_4.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_4.txt deleted file mode 100644 index c7fc0c83d..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_4.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 5 3 - - -0 0 0 0 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_5.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_5.txt deleted file mode 100644 index 47b11f9dc..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_5.txt +++ /dev/null @@ -1,4 +0,0 @@ -8 5 3 -1 2 2 3 8 16 16 24 -0 1 2 3 0 1 2 3 -0 4 4 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_6.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_6.txt deleted file mode 100644 index f0426e00d..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/ans_test_6.txt +++ /dev/null @@ -1,4 +0,0 @@ -10 3 4 -8.34 4.08 6.6 2.76 7.82 12.65 12.65 1.2 3.4 5.5 -0 1 2 0 1 2 0 0 1 2 -0 3 6 7 10 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_1.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_1.txt deleted file mode 100644 index cd31368bf..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_1.txt +++ /dev/null @@ -1,8 +0,0 @@ -3 2 -1.0 0 -0 3.0 -0 0 - -2 3 -1.0 0 0 -0 3.0 8.0 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_2.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_2.txt deleted file mode 100644 index f8b902e8e..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_2.txt +++ /dev/null @@ -1,5 +0,0 @@ -1 1 -1 - -1 1 -2 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_3.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_3.txt deleted file mode 100644 index 1ee9e8e0a..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_3.txt +++ /dev/null @@ -1,15 +0,0 @@ -4 8 -1 0 0 0 0 2 5 4 -1 0 0 0 0 2 5 4 -1 0 0 0 0 2 5 4 -1 0 0 0 0 2 5 4 - -8 2 -4 5 -5 4 -1 0 -0 0 -0 0 -0 0 -5 7 -7 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_4.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_4.txt deleted file mode 100644 index 897f4b98a..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_4.txt +++ /dev/null @@ -1,13 +0,0 @@ -5 5 -0 0 0 0 0 -0 0 0 0 0 -0 0 0 0 0 -0 0 0 0 0 -0 0 0 0 0 - -5 3 -0 0 0 -0 0 0 -0 0 0 -0 0 0 -0 0 0 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_5.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_5.txt deleted file mode 100644 index 9c91dbedc..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_5.txt +++ /dev/null @@ -1,9 +0,0 @@ -5 1 -1 -2 -2 -3 -0 - -1 3 -1 0 8 \ No newline at end of file diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_6.txt b/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_6.txt deleted file mode 100644 index 0899139c2..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/data/test_6.txt +++ /dev/null @@ -1,8 +0,0 @@ -3 2 -1.2 2.3 -3.4 0.0 -5.5 0.0 - -2 4 -1.2 2.3 0.0 1.0 -3.0 0.0 5.5 0.0 diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/info.json b/tasks/luzan_e_double_sparse_matrix_mult_seq/info.json deleted file mode 100644 index f8f58986e..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/info.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "student": { - "first_name": "Егор", - "group_number": "3823Б1ФИ3", - "last_name": "Лузан", - "middle_name": "Андреевич", - "task_number": "1" - } -} diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp b/tasks/luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp deleted file mode 100644 index d930b32da..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp" -#include "task/include/task.hpp" - -namespace luzan_e_double_sparse_matrix_mult_seq { - -class LuzanEDoubleSparseMatrixMultSeq : public BaseTask { - public: - static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { - return ppc::task::TypeOfTask::kSEQ; - } - explicit LuzanEDoubleSparseMatrixMultSeq(const InType &in); - - private: - bool ValidationImpl() override; - bool PreProcessingImpl() override; - bool RunImpl() override; - bool PostProcessingImpl() override; -}; - -} // namespace luzan_e_double_sparse_matrix_mult_seq diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/seq/src/ops_seq.cpp b/tasks/luzan_e_double_sparse_matrix_mult_seq/seq/src/ops_seq.cpp deleted file mode 100644 index 6dc7a5e79..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/seq/src/ops_seq.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp" - -#include "luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp" -// #include "util/include/util.hpp" - -namespace luzan_e_double_sparse_matrix_mult_seq { - -LuzanEDoubleSparseMatrixMultSeq::LuzanEDoubleSparseMatrixMultSeq(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - // GetOutput() = 0; -} - -bool LuzanEDoubleSparseMatrixMultSeq::ValidationImpl() { - const auto &a = std::get<0>(GetInput()); - const auto &b = std::get<1>(GetInput()); - return a.GetCols() == b.GetRows() && a.GetCols() != 0 && a.GetRows() != 0 && b.GetCols() != 0; -} - -bool LuzanEDoubleSparseMatrixMultSeq::PreProcessingImpl() { - return true; -} - -bool LuzanEDoubleSparseMatrixMultSeq::RunImpl() { - const auto &a = std::get<0>(GetInput()); - const auto &b = std::get<1>(GetInput()); - - GetOutput() = a * b; - return true; -} - -bool LuzanEDoubleSparseMatrixMultSeq::PostProcessingImpl() { - return true; -} - -} // namespace luzan_e_double_sparse_matrix_mult_seq diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/settings.json b/tasks/luzan_e_double_sparse_matrix_mult_seq/settings.json deleted file mode 100644 index 0be0208fc..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/settings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "tasks": { - "all": "enabled", - "omp": "enabled", - "seq": "enabled", - "stl": "enabled", - "tbb": "enabled" - }, - "tasks_type": "threads" -} diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/tests/functional/main.cpp b/tasks/luzan_e_double_sparse_matrix_mult_seq/tests/functional/main.cpp deleted file mode 100644 index c252af9c7..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/tests/functional/main.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp" -#include "luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp" -#include "util/include/func_test_util.hpp" -#include "util/include/util.hpp" - -namespace luzan_e_double_sparse_matrix_mult_seq { - -class LuzanEDoubleSparseMatrixMultSeqestsThreads : public ppc::util::BaseRunFuncTests { - public: - static std::string PrintTestParam(const TestType &test_param) { - return "test" + std::get<1>(test_param); - } - - protected: - void SetUp() override { - TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); - std::string file_name = std::get<0>(params); - std::string abs_path = - ppc::util::GetAbsoluteTaskPath(std::string(PPC_ID_luzan_e_double_sparse_matrix_mult_seq), file_name); - std::ifstream test_file(abs_path); - if (!test_file) { - throw std::runtime_error("Cannot open task file"); - } - - SparseMatrix a = GetFromFile(test_file); - SparseMatrix b = GetFromFile(test_file); - test_file.close(); - - input_data_ = std::make_tuple(a, b); - - file_name = "ans_" + std::get<0>(params); - abs_path = ppc::util::GetAbsoluteTaskPath(std::string(PPC_ID_luzan_e_double_sparse_matrix_mult_seq), file_name); - std::ifstream ans_file(abs_path); - if (!ans_file) { - throw std::runtime_error("Cannot open asn file"); - } - output_data_.GetSparsedMatrixFromFile(ans_file); - ans_file.close(); - } - - bool CheckTestOutputData(OutType &output_data) final { - return (output_data == output_data_); - } - - InType GetTestInputData() final { - return input_data_; - } - - private: - InType input_data_; - OutType output_data_; -}; - -namespace { - -TEST_P(LuzanEDoubleSparseMatrixMultSeqestsThreads, MatmulFromPic) { - ExecuteTest(GetParam()); -} - -const std::array kTestParam = {std::make_tuple("test_1.txt", "01"), std::make_tuple("test_2.txt", "02"), - std::make_tuple("test_3.txt", "03"), std::make_tuple("test_4.txt", "04"), - std::make_tuple("test_5.txt", "05"), std::make_tuple("test_6.txt", "06")}; - -const auto kTestTasksList = std::tuple_cat(ppc::util::AddFuncTask( - kTestParam, PPC_SETTINGS_luzan_e_double_sparse_matrix_mult_seq)); - -const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); - -const auto kPerfTestName = - LuzanEDoubleSparseMatrixMultSeqestsThreads::PrintFuncTestName; - -INSTANTIATE_TEST_SUITE_P(FuncTests, LuzanEDoubleSparseMatrixMultSeqestsThreads, kGtestValues, kPerfTestName); - -} // namespace - -} // namespace luzan_e_double_sparse_matrix_mult_seq diff --git a/tasks/luzan_e_double_sparse_matrix_mult_seq/tests/performance/main.cpp b/tasks/luzan_e_double_sparse_matrix_mult_seq/tests/performance/main.cpp deleted file mode 100644 index d129dd3a1..000000000 --- a/tasks/luzan_e_double_sparse_matrix_mult_seq/tests/performance/main.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include -#include - -#include "luzan_e_double_sparse_matrix_mult_seq/common/include/common.hpp" -#include "luzan_e_double_sparse_matrix_mult_seq/seq/include/ops_seq.hpp" -#include "util/include/perf_test_util.hpp" - -namespace luzan_e_double_sparse_matrix_mult_seq { - -class LuzanEDoubleSparseMatrixMultSeqPerfTestThreads : public ppc::util::BaseRunPerfTests { - const int kCount_ = 2500; - // const unsigned cols_ = 5000; - // const unsigned rows_ = 5000; - InType input_data_; - OutType output_data_; - - void SetUp() override { - std::vector value; - std::vector row; - std::vector col_index; - - SparseMatrix lhs; - lhs.GenLineMatrix(kCount_, kCount_); - - SparseMatrix rhs; - rhs.GenColsMatrix(kCount_, kCount_); - input_data_ = std::make_tuple(lhs, rhs); - output_data_.GenPerfAns(kCount_, kCount_, kCount_); - } - - bool CheckTestOutputData(OutType &output_data) final { - return (output_data == output_data_); - } - - InType GetTestInputData() final { - return input_data_; - } -}; - -TEST_P(LuzanEDoubleSparseMatrixMultSeqPerfTestThreads, RunPerfModes) { - ExecuteTest(GetParam()); -} - -namespace { - -const auto kAllPerfTasks = ppc::util::MakeAllPerfTasks( - PPC_SETTINGS_luzan_e_double_sparse_matrix_mult_seq); - -const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); - -const auto kPerfTestName = LuzanEDoubleSparseMatrixMultSeqPerfTestThreads::CustomPerfTestName; - -INSTANTIATE_TEST_SUITE_P(RunModeTests, LuzanEDoubleSparseMatrixMultSeqPerfTestThreads, kGtestValues, kPerfTestName); - -} // namespace - -} // namespace luzan_e_double_sparse_matrix_mult_seq From 6fc792a9cca4bf84b23446b19ee5fd3d8d6e1e88 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 00:12:19 +0000 Subject: [PATCH 04/10] [FIX] fix common --- .../common/include/common.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index ef14aff15..0e8187216 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -116,7 +116,7 @@ class SparseMatrix { return rows_; } - [[nodiscard]] std::vector GetVal() { + [[nodiscard]] std::vector GetVal() const { return value_; } @@ -143,7 +143,7 @@ class SparseMatrix { } return 0.0; } - void Sparse(std::vector matrix) { + void Sparse(const std::vector& matrix) { col_index_.push_back(0); bool flag = false; for (unsigned j = 0; j < cols_; j++) { @@ -201,6 +201,9 @@ class SparseMatrix { if (!file) { throw std::runtime_error("Cannot open file with sparsed matrix"); } + value_.clear(); + row_.clear(); + col_index_.clear(); unsigned n = 0; file >> n >> rows_ >> cols_; From acd335b22c17168d342a3a0607e1fccde34db7ee Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 00:17:09 +0000 Subject: [PATCH 05/10] [FIX] clang-format fix --- .../luzan_e_double_sparse_matrix_mult/common/include/common.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index 0e8187216..a5f5a2d56 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -143,7 +143,7 @@ class SparseMatrix { } return 0.0; } - void Sparse(const std::vector& matrix) { + void Sparse(const std::vector &matrix) { col_index_.push_back(0); bool flag = false; for (unsigned j = 0; j < cols_; j++) { From 738b6c7aa1a1a87107f38119875b0352291cce60 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 01:07:03 +0000 Subject: [PATCH 06/10] [DEV] class -> struct --- .../common/include/common.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index a5f5a2d56..1bae9bc44 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -14,7 +14,7 @@ namespace luzan_e_double_sparse_matrix_mult { const double kEPS = 1e-8; -class SparseMatrix { +struct SparseMatrix { std::vector value_; std::vector row_; std::vector col_index_; @@ -22,7 +22,6 @@ class SparseMatrix { unsigned cols_; unsigned rows_; - public: SparseMatrix(unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { col_index_.clear(); row_.clear(); From 3ae8efd90ea9877e261a5d52b631d6f43f87394e Mon Sep 17 00:00:00 2001 From: smallAbyss <68540848+smallAbyss@users.noreply.github.com> Date: Sun, 19 Apr 2026 12:20:04 +0300 Subject: [PATCH 07/10] [CI] restart ci From 1bd7df22c5170755bf3886c25a3b01a6899b3b0e Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 10:08:55 +0000 Subject: [PATCH 08/10] [FIX] clang-tidy fix --- .../common/include/common.hpp | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index 1bae9bc44..70599dd5a 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -15,95 +15,95 @@ namespace luzan_e_double_sparse_matrix_mult { const double kEPS = 1e-8; struct SparseMatrix { - std::vector value_; - std::vector row_; - std::vector col_index_; + std::vector value; + std::vector row; + std::vector col_index; unsigned cols_; unsigned rows_; SparseMatrix(unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { - col_index_.clear(); - row_.clear(); - value_.clear(); + col_index.clear(); + row.clear(); + value.clear(); } SparseMatrix() : cols_(0), rows_(0) { - col_index_.clear(); - row_.clear(); - value_.clear(); + col_index.clear(); + row.clear(); + value.clear(); } SparseMatrix(const std::vector &matrix, unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { - col_index_.clear(); - row_.clear(); - value_.clear(); + col_index.clear(); + row.clear(); + value.clear(); Sparse(matrix); } void GenLineMatrix(unsigned rows, unsigned cols) { - col_index_.clear(); - row_.clear(); - value_.clear(); + col_index.clear(); + row.clear(); + value.clear(); rows_ = rows; cols_ = cols; - col_index_.push_back(0); + col_index.push_back(0); for (unsigned j = 0; j < cols_; j++) { for (unsigned i = 0; i < rows_; i++) { if (i % 5 == 0) { - value_.push_back(1.0); - row_.push_back(i); + value.push_back(1.0); + row.push_back(i); } } - col_index_.push_back(value_.size()); + col_index.push_back(value.size()); } } void GenColsMatrix(unsigned rows, unsigned cols) { - col_index_.clear(); - row_.clear(); - value_.clear(); + col_index.clear(); + row.clear(); + value.clear(); rows_ = rows; cols_ = cols; - col_index_.push_back(0); + col_index.push_back(0); for (unsigned j = 0; j < cols_; j++) { if (j % 5 == 0) { for (unsigned i = 0; i < rows_; i++) { - value_.push_back(1.0); - row_.push_back(i); + value.push_back(1.0); + row.push_back(i); } } - col_index_.push_back(value_.size()); + col_index.push_back(value.size()); } } void GenPerfAns(unsigned n, unsigned m, unsigned k) { - col_index_.clear(); - row_.clear(); - value_.clear(); + col_index.clear(); + row.clear(); + value.clear(); rows_ = n; cols_ = m; - col_index_.push_back(0); + col_index.push_back(0); for (unsigned j = 0; j < m; j++) { if (j % 5 == 0) // только чётные столбцы ненулевые { for (unsigned i = 0; i < n; i++) { if (i % 5 == 0) // только чётные строки { - value_.push_back(static_cast(k)); - row_.push_back(i); + value.push_back(static_cast(k)); + row.push_back(i); } } } - col_index_.push_back(value_.size()); + col_index.push_back(value.size()); } } @@ -116,48 +116,48 @@ struct SparseMatrix { } [[nodiscard]] std::vector GetVal() const { - return value_; + return value; } bool operator==(const SparseMatrix &b) const { bool tmp = false; - if (value_.size() == b.value_.size()) { + if (value.size() == b.value.size()) { tmp = true; - for (size_t long_i = 0; long_i < value_.size(); long_i++) { - if (fabs(value_[long_i] - b.value_[long_i]) > kEPS) { + for (size_t long_i = 0; long_i < value.size(); long_i++) { + if (fabs(value[long_i] - b.value[long_i]) > kEPS) { tmp = false; break; } } } - return tmp && (row_ == b.row_) && (col_index_ == b.col_index_) && (cols_ == b.cols_) && (rows_ == b.rows_); + return tmp && (row == b.row) && (col_index == b.col_index) && (cols_ == b.cols_) && (rows_ == b.rows_); } double GetXy(unsigned x = 1, unsigned y = 2) { - for (unsigned verylongs = col_index_[y]; verylongs < col_index_[y + 1]; verylongs++) { - if (row_[verylongs] == x) { - return value_[verylongs]; + for (unsigned verylongs = col_index[y]; verylongs < col_index[y + 1]; verylongs++) { + if (row[verylongs] == x) { + return value[verylongs]; } } return 0.0; } void Sparse(const std::vector &matrix) { - col_index_.push_back(0); + col_index.push_back(0); bool flag = false; for (unsigned j = 0; j < cols_; j++) { - col_index_.push_back(value_.size()); + col_index.push_back(value.size()); for (unsigned i = 0; i < rows_; i++) { if (fabs(matrix[(i * cols_) + j]) > kEPS) { - value_.push_back(matrix[(i * cols_) + j]); - row_.push_back(i); + value.push_back(matrix[(i * cols_) + j]); + row.push_back(i); flag = true; } } if (flag) { - col_index_.pop_back(); - col_index_.push_back(value_.size()); + col_index.pop_back(); + col_index.push_back(value.size()); flag = false; } } @@ -165,33 +165,33 @@ struct SparseMatrix { SparseMatrix operator*(const SparseMatrix &b) const { SparseMatrix c(rows_, b.cols_); - c.col_index_.push_back(0); + c.col_index.push_back(0); for (unsigned b_col = 0; b_col < b.cols_; b_col++) { std::vector tmp_col(rows_, 0); - unsigned b_rows_start = b.col_index_[b_col]; - unsigned b_rows_end = b.col_index_[b_col + 1]; + unsigned b_rows_start = b.col_index[b_col]; + unsigned b_rows_end = b.col_index[b_col + 1]; for (unsigned b_pos = b_rows_start; b_pos < b_rows_end; b_pos++) { - double b_val = b.value_[b_pos]; - unsigned b_row = b.row_[b_pos]; + double b_val = b.value[b_pos]; + unsigned b_row = b.row[b_pos]; - unsigned a_rows_start = col_index_[b_row]; - unsigned a_rows_end = col_index_[b_row + 1]; + unsigned a_rows_start = col_index[b_row]; + unsigned a_rows_end = col_index[b_row + 1]; for (unsigned a_pos = a_rows_start; a_pos < a_rows_end; a_pos++) { - double a_val = value_[a_pos]; - unsigned a_row = row_[a_pos]; + double a_val = value[a_pos]; + unsigned a_row = row[a_pos]; tmp_col[a_row] += a_val * b_val; } } for (unsigned i = 0; i < rows_; i++) { if (fabs(tmp_col[i]) > kEPS) { - c.value_.push_back(tmp_col[i]); - c.row_.push_back(i); + c.value.push_back(tmp_col[i]); + c.row.push_back(i); } } - c.col_index_.push_back(c.value_.size()); + c.col_index.push_back(c.value.size()); } return c; } @@ -200,27 +200,27 @@ struct SparseMatrix { if (!file) { throw std::runtime_error("Cannot open file with sparsed matrix"); } - value_.clear(); - row_.clear(); - col_index_.clear(); + value.clear(); + row.clear(); + col_index.clear(); unsigned n = 0; file >> n >> rows_ >> cols_; double tmp_val = 0; for (unsigned i = 0; i < n; i++) { file >> tmp_val; - value_.push_back(tmp_val); + value.push_back(tmp_val); } unsigned tmp = 0; for (unsigned i = 0; i < n; i++) { file >> tmp; - row_.push_back(tmp); + row.push_back(tmp); } for (unsigned i = 0; i < cols_ + 1; i++) { file >> tmp; - col_index_.push_back(tmp); + col_index.push_back(tmp); } } }; From 292e15ad86de5bd6da7c452353474758c6004df6 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 10:43:00 +0000 Subject: [PATCH 09/10] [FIX] clang-tidy/fields rename --- .../common/include/common.hpp | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index 70599dd5a..916d068f5 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -19,22 +19,22 @@ struct SparseMatrix { std::vector row; std::vector col_index; - unsigned cols_; - unsigned rows_; + unsigned cols; + unsigned rows; - SparseMatrix(unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { + SparseMatrix(unsigned rows_out, unsigned cols_out) : cols(cols_out), rows(rows_out) { col_index.clear(); row.clear(); value.clear(); } - SparseMatrix() : cols_(0), rows_(0) { + SparseMatrix() : cols(0), rows(0) { col_index.clear(); row.clear(); value.clear(); } - SparseMatrix(const std::vector &matrix, unsigned rows, unsigned cols) : cols_(cols), rows_(rows) { + SparseMatrix(const std::vector &matrix, unsigned rows_out, unsigned cols_out) : cols(cols_out), rows(rows_out) { col_index.clear(); row.clear(); value.clear(); @@ -42,17 +42,17 @@ struct SparseMatrix { Sparse(matrix); } - void GenLineMatrix(unsigned rows, unsigned cols) { + void GenLineMatrix(unsigned rows_out, unsigned cols_out) { col_index.clear(); row.clear(); value.clear(); - rows_ = rows; - cols_ = cols; + rows = rows_out; + cols = cols_out; col_index.push_back(0); - for (unsigned j = 0; j < cols_; j++) { - for (unsigned i = 0; i < rows_; i++) { + for (unsigned j = 0; j < cols; j++) { + for (unsigned i = 0; i < rows; i++) { if (i % 5 == 0) { value.push_back(1.0); row.push_back(i); @@ -62,18 +62,18 @@ struct SparseMatrix { } } - void GenColsMatrix(unsigned rows, unsigned cols) { + void GenColsMatrix(unsigned rows_out, unsigned cols_out) { col_index.clear(); row.clear(); value.clear(); - rows_ = rows; - cols_ = cols; + rows = rows_out; + cols = cols_out; col_index.push_back(0); - for (unsigned j = 0; j < cols_; j++) { + for (unsigned j = 0; j < cols; j++) { if (j % 5 == 0) { - for (unsigned i = 0; i < rows_; i++) { + for (unsigned i = 0; i < rows; i++) { value.push_back(1.0); row.push_back(i); } @@ -87,8 +87,8 @@ struct SparseMatrix { col_index.clear(); row.clear(); value.clear(); - rows_ = n; - cols_ = m; + rows = n; + cols = m; col_index.push_back(0); for (unsigned j = 0; j < m; j++) { @@ -108,11 +108,11 @@ struct SparseMatrix { } [[nodiscard]] unsigned GetCols() const { - return cols_; + return cols; } [[nodiscard]] unsigned GetRows() const { - return rows_; + return rows; } [[nodiscard]] std::vector GetVal() const { @@ -131,7 +131,7 @@ struct SparseMatrix { } } - return tmp && (row == b.row) && (col_index == b.col_index) && (cols_ == b.cols_) && (rows_ == b.rows_); + return tmp && (row == b.row) && (col_index == b.col_index) && (cols == b.cols) && (rows == b.rows); } double GetXy(unsigned x = 1, unsigned y = 2) { @@ -145,12 +145,12 @@ struct SparseMatrix { void Sparse(const std::vector &matrix) { col_index.push_back(0); bool flag = false; - for (unsigned j = 0; j < cols_; j++) { + for (unsigned j = 0; j < cols; j++) { col_index.push_back(value.size()); - for (unsigned i = 0; i < rows_; i++) { - if (fabs(matrix[(i * cols_) + j]) > kEPS) { - value.push_back(matrix[(i * cols_) + j]); + for (unsigned i = 0; i < rows; i++) { + if (fabs(matrix[(i * cols) + j]) > kEPS) { + value.push_back(matrix[(i * cols) + j]); row.push_back(i); flag = true; } @@ -164,11 +164,11 @@ struct SparseMatrix { } SparseMatrix operator*(const SparseMatrix &b) const { - SparseMatrix c(rows_, b.cols_); + SparseMatrix c(rows, b.cols); c.col_index.push_back(0); - for (unsigned b_col = 0; b_col < b.cols_; b_col++) { - std::vector tmp_col(rows_, 0); + for (unsigned b_col = 0; b_col < b.cols; b_col++) { + std::vector tmp_col(rows, 0); unsigned b_rows_start = b.col_index[b_col]; unsigned b_rows_end = b.col_index[b_col + 1]; @@ -185,7 +185,7 @@ struct SparseMatrix { tmp_col[a_row] += a_val * b_val; } } - for (unsigned i = 0; i < rows_; i++) { + for (unsigned i = 0; i < rows; i++) { if (fabs(tmp_col[i]) > kEPS) { c.value.push_back(tmp_col[i]); c.row.push_back(i); @@ -204,7 +204,7 @@ struct SparseMatrix { row.clear(); col_index.clear(); unsigned n = 0; - file >> n >> rows_ >> cols_; + file >> n >> rows >> cols; double tmp_val = 0; for (unsigned i = 0; i < n; i++) { @@ -218,7 +218,7 @@ struct SparseMatrix { row.push_back(tmp); } - for (unsigned i = 0; i < cols_ + 1; i++) { + for (unsigned i = 0; i < cols + 1; i++) { file >> tmp; col_index.push_back(tmp); } From fd429334c0532864239376c3f2455c5b0bc6e6f0 Mon Sep 17 00:00:00 2001 From: smallAbyss Date: Sun, 19 Apr 2026 10:54:48 +0000 Subject: [PATCH 10/10] [FIX] clang-format fix --- .../common/include/common.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp index 916d068f5..2f040cab9 100644 --- a/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp +++ b/tasks/luzan_e_double_sparse_matrix_mult/common/include/common.hpp @@ -34,7 +34,8 @@ struct SparseMatrix { value.clear(); } - SparseMatrix(const std::vector &matrix, unsigned rows_out, unsigned cols_out) : cols(cols_out), rows(rows_out) { + SparseMatrix(const std::vector &matrix, unsigned rows_out, unsigned cols_out) + : cols(cols_out), rows(rows_out) { col_index.clear(); row.clear(); value.clear();