From 2f4341b260f843a700e931564667851d995a7aeb Mon Sep 17 00:00:00 2001 From: vlad3005 Date: Mon, 23 Feb 2026 16:41:47 +0300 Subject: [PATCH 1/3] seq version 1 --- .../common/include/common.hpp | 30 ++++ tasks/borunov_v_complex_ccs/data/pic.ppm | Bin 0 -> 23 bytes tasks/borunov_v_complex_ccs/info.json | 9 ++ tasks/borunov_v_complex_ccs/report.md | 0 .../seq/include/ops_seq.hpp | 22 +++ tasks/borunov_v_complex_ccs/seq/report.md | 0 .../borunov_v_complex_ccs/seq/src/ops_seq.cpp | 96 ++++++++++++ tasks/borunov_v_complex_ccs/settings.json | 10 ++ .../tests/functional/main.cpp | 145 ++++++++++++++++++ .../tests/performance/main.cpp | 71 +++++++++ 10 files changed, 383 insertions(+) create mode 100644 tasks/borunov_v_complex_ccs/common/include/common.hpp create mode 100644 tasks/borunov_v_complex_ccs/data/pic.ppm create mode 100644 tasks/borunov_v_complex_ccs/info.json create mode 100644 tasks/borunov_v_complex_ccs/report.md create mode 100644 tasks/borunov_v_complex_ccs/seq/include/ops_seq.hpp create mode 100644 tasks/borunov_v_complex_ccs/seq/report.md create mode 100644 tasks/borunov_v_complex_ccs/seq/src/ops_seq.cpp create mode 100644 tasks/borunov_v_complex_ccs/settings.json create mode 100644 tasks/borunov_v_complex_ccs/tests/functional/main.cpp create mode 100644 tasks/borunov_v_complex_ccs/tests/performance/main.cpp diff --git a/tasks/borunov_v_complex_ccs/common/include/common.hpp b/tasks/borunov_v_complex_ccs/common/include/common.hpp new file mode 100644 index 00000000..8afdf846 --- /dev/null +++ b/tasks/borunov_v_complex_ccs/common/include/common.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +#include "task/include/task.hpp" + +namespace borunov_v_complex_ccs_seq { + +struct SparseMatrix { + int num_rows = 0; + int num_cols = 0; + std::vector> values; + std::vector row_indices; + std::vector col_ptrs; + + bool operator==(const SparseMatrix& other) const { + return num_rows == other.num_rows && num_cols == other.num_cols && values == other.values && + row_indices == other.row_indices && col_ptrs == other.col_ptrs; + } +}; + +using InType = std::vector; +using OutType = std::vector; +using TestType = std::tuple; +using BaseTask = ppc::task::Task; + +} // namespace borunov_v_complex_ccs_seq diff --git a/tasks/borunov_v_complex_ccs/data/pic.ppm b/tasks/borunov_v_complex_ccs/data/pic.ppm new file mode 100644 index 0000000000000000000000000000000000000000..637624238c89d914613ed301968bffbf462bc110 GIT binary patch literal 23 bcmWGA<1$h(;xaNd<@(RSzyQYo|NjR7KDY +#include +#include + +#include "borunov_v_complex_ccs/common/include/common.hpp" +#include "util/include/util.hpp" + +namespace borunov_v_complex_ccs_seq { + +BorunovVComplexCcsSEQ::BorunovVComplexCcsSEQ(const InType &in) { + SetTypeOfTask(GetStaticTypeOfTask()); + GetInput() = in; + GetOutput().resize(1); +} + +bool BorunovVComplexCcsSEQ::ValidationImpl() { + if (GetInput().size() != 2) { + return false; + } + const auto& A = GetInput()[0]; + const auto& B = GetInput()[1]; + if (A.num_cols != B.num_rows) { + return false; + } + if (A.col_ptrs.size() != static_cast(A.num_cols + 1) || + B.col_ptrs.size() != static_cast(B.num_cols + 1)) { + return false; + } + return true; +} + +bool BorunovVComplexCcsSEQ::PreProcessingImpl() { + const auto& A = GetInput()[0]; + const auto& B = GetInput()[1]; + auto& C = GetOutput()[0]; + + C.num_rows = A.num_rows; + C.num_cols = B.num_cols; + C.col_ptrs.assign(C.num_cols + 1, 0); + C.values.clear(); + C.row_indices.clear(); + + return true; +} + +bool BorunovVComplexCcsSEQ::RunImpl() { + const auto& A = GetInput()[0]; + const auto& B = GetInput()[1]; + auto& C = GetOutput()[0]; + + std::vector> col_accumulator(A.num_rows, {0.0, 0.0}); + std::vector non_zero_indices; + std::vector is_non_zero(A.num_rows, false); + + for (int j = 0; j < B.num_cols; ++j) { + for (int b_idx = B.col_ptrs[j]; b_idx < B.col_ptrs[j + 1]; ++b_idx) { + int p = B.row_indices[b_idx]; + std::complex b_val = B.values[b_idx]; + + for (int a_idx = A.col_ptrs[p]; a_idx < A.col_ptrs[p + 1]; ++a_idx) { + int i = A.row_indices[a_idx]; + std::complex a_val = A.values[a_idx]; + + if (!is_non_zero[i]) { + is_non_zero[i] = true; + non_zero_indices.push_back(i); + } + col_accumulator[i] += a_val * b_val; + } + } + + std::sort(non_zero_indices.begin(), non_zero_indices.end()); + + for (int i : non_zero_indices) { + if (std::abs(col_accumulator[i]) > 1e-9) { + C.values.push_back(col_accumulator[i]); + C.row_indices.push_back(i); + } + col_accumulator[i] = {0.0, 0.0}; + is_non_zero[i] = false; + } + non_zero_indices.clear(); + + C.col_ptrs[j + 1] = C.values.size(); + } + + return true; +} + +bool BorunovVComplexCcsSEQ::PostProcessingImpl() { + return true; +} + +} // namespace borunov_v_complex_ccs_seq diff --git a/tasks/borunov_v_complex_ccs/settings.json b/tasks/borunov_v_complex_ccs/settings.json new file mode 100644 index 00000000..0be0208f --- /dev/null +++ b/tasks/borunov_v_complex_ccs/settings.json @@ -0,0 +1,10 @@ +{ + "tasks": { + "all": "enabled", + "omp": "enabled", + "seq": "enabled", + "stl": "enabled", + "tbb": "enabled" + }, + "tasks_type": "threads" +} diff --git a/tasks/borunov_v_complex_ccs/tests/functional/main.cpp b/tasks/borunov_v_complex_ccs/tests/functional/main.cpp new file mode 100644 index 00000000..0aa329f7 --- /dev/null +++ b/tasks/borunov_v_complex_ccs/tests/functional/main.cpp @@ -0,0 +1,145 @@ +#include + +#include +#include +#include +#include +#include + +#include "borunov_v_complex_ccs/common/include/common.hpp" +#include "borunov_v_complex_ccs/seq/include/ops_seq.hpp" +#include "util/include/func_test_util.hpp" +#include "util/include/util.hpp" + +namespace borunov_v_complex_ccs_seq { + +SparseMatrix GenerateRandomSparseMatrix(int num_rows, int num_cols, double sparsity) { + SparseMatrix mat; + mat.num_rows = num_rows; + mat.num_cols = num_cols; + mat.col_ptrs.assign(num_cols + 1, 0); + + std::mt19937 gen(42); + std::uniform_real_distribution dist_val(-10.0, 10.0); + std::uniform_real_distribution dist_prob(0.0, 1.0); + + for (int j = 0; j < num_cols; ++j) { + for (int i = 0; i < num_rows; ++i) { + if (dist_prob(gen) < sparsity) { + mat.values.push_back({dist_val(gen), dist_val(gen)}); + mat.row_indices.push_back(i); + } + } + mat.col_ptrs[j + 1] = mat.values.size(); + } + return mat; +} + +SparseMatrix MultiplyDense(const SparseMatrix& A, const SparseMatrix& B) { + SparseMatrix C; + C.num_rows = A.num_rows; + C.num_cols = B.num_cols; + C.col_ptrs.assign(C.num_cols + 1, 0); + + std::vector>> dense_A(A.num_rows, std::vector>(A.num_cols, {0.0, 0.0})); + std::vector>> dense_B(B.num_rows, std::vector>(B.num_cols, {0.0, 0.0})); + std::vector>> dense_C(A.num_rows, std::vector>(B.num_cols, {0.0, 0.0})); + + for (int j = 0; j < A.num_cols; ++j) { + for (int idx = A.col_ptrs[j]; idx < A.col_ptrs[j + 1]; ++idx) { + dense_A[A.row_indices[idx]][j] = A.values[idx]; + } + } + + for (int j = 0; j < B.num_cols; ++j) { + for (int idx = B.col_ptrs[j]; idx < B.col_ptrs[j + 1]; ++idx) { + dense_B[B.row_indices[idx]][j] = B.values[idx]; + } + } + + for (int i = 0; i < A.num_rows; ++i) { + for (int j = 0; j < B.num_cols; ++j) { + for (int k = 0; k < A.num_cols; ++k) { + dense_C[i][j] += dense_A[i][k] * dense_B[k][j]; + } + } + } + + for (int j = 0; j < B.num_cols; ++j) { + for (int i = 0; i < A.num_rows; ++i) { + if (std::abs(dense_C[i][j]) > 1e-9) { + C.values.push_back(dense_C[i][j]); + C.row_indices.push_back(i); + } + } + C.col_ptrs[j + 1] = C.values.size(); + } + + return C; +} + +class BorunovVRunFuncTestsThreads : 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)) + "_" + std::to_string(std::get<2>(test_param)); + } + + protected: + void SetUp() override { + TestType params = std::get(ppc::util::GTestParamIndex::kTestParams)>(GetParam()); + int m = std::get<0>(params); + int k = std::get<1>(params); + int n = std::get<2>(params); + + SparseMatrix A = GenerateRandomSparseMatrix(m, k, 0.2); + SparseMatrix B = GenerateRandomSparseMatrix(k, n, 0.2); + + input_data_ = {A, B}; + expected_output_ = {MultiplyDense(A, B)}; + } + + bool CheckTestOutputData(OutType &output_data) final { + if (expected_output_.size() != output_data.size()) return false; + const auto& expected = expected_output_[0]; + const auto& actual = output_data[0]; + + if (expected.num_rows != actual.num_rows || expected.num_cols != actual.num_cols) return false; + if (expected.col_ptrs != actual.col_ptrs) return false; + if (expected.row_indices != actual.row_indices) return false; + if (expected.values.size() != actual.values.size()) return false; + + for (size_t i = 0; i < expected.values.size(); ++i) { + if (std::abs(expected.values[i] - actual.values[i]) > 1e-6) return false; + } + return true; + } + + InType GetTestInputData() final { + return input_data_; + } + + private: + InType input_data_; + OutType expected_output_; +}; + +namespace { + +TEST_P(BorunovVRunFuncTestsThreads, MatmulTests) { + ExecuteTest(GetParam()); +} + +const std::array kTestParam = {std::make_tuple(10, 10, 10), std::make_tuple(20, 15, 25), std::make_tuple(5, 30, 5)}; + +const auto kTestTasksList = + std::tuple_cat(ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_borunov_v_complex_ccs)); + +const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); + +const auto kPerfTestName = BorunovVRunFuncTestsThreads::PrintFuncTestName; + +INSTANTIATE_TEST_SUITE_P(SparseMatrixTests, BorunovVRunFuncTestsThreads, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace borunov_v_complex_ccs_seq diff --git a/tasks/borunov_v_complex_ccs/tests/performance/main.cpp b/tasks/borunov_v_complex_ccs/tests/performance/main.cpp new file mode 100644 index 00000000..e55de1f5 --- /dev/null +++ b/tasks/borunov_v_complex_ccs/tests/performance/main.cpp @@ -0,0 +1,71 @@ +#include + +#include +#include +#include + +#include "borunov_v_complex_ccs/common/include/common.hpp" +#include "borunov_v_complex_ccs/seq/include/ops_seq.hpp" +#include "util/include/perf_test_util.hpp" + +namespace borunov_v_complex_ccs_seq { + +SparseMatrix GenerateSparseMatrixPerf(int num_rows, int num_cols, int non_zeros_per_col) { + SparseMatrix mat; + mat.num_rows = num_rows; + mat.num_cols = num_cols; + mat.col_ptrs.assign(num_cols + 1, 0); + + int step = std::max(1, num_rows / non_zeros_per_col); + + for (int j = 0; j < num_cols; ++j) { + for (int i = 0; i < num_rows; i += step) { + mat.values.push_back({static_cast(i + 1), static_cast(j + 1)}); + mat.row_indices.push_back(i); + } + mat.col_ptrs[j + 1] = mat.values.size(); + } + return mat; +} + +class BorunovVRunPerfTestThreads : public ppc::util::BaseRunPerfTests { + InType input_data_{}; + + void SetUp() override { + int m = 200000; + int k = 200000; + int n = 200000; + + SparseMatrix A = GenerateSparseMatrixPerf(m, k, 20); + SparseMatrix B = GenerateSparseMatrixPerf(k, n, 20); + + input_data_ = {A, B}; + } + + bool CheckTestOutputData(OutType &output_data) final { + return output_data.size() == 1; + } + + InType GetTestInputData() final { + return input_data_; + } +}; + +TEST_P(BorunovVRunPerfTestThreads, RunPerfModes) { + ExecuteTest(GetParam()); +} + +namespace { + +const auto kAllPerfTasks = + ppc::util::MakeAllPerfTasks(PPC_SETTINGS_borunov_v_complex_ccs); + +const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks); + +const auto kPerfTestName = BorunovVRunPerfTestThreads::CustomPerfTestName; + +INSTANTIATE_TEST_SUITE_P(RunModeTests, BorunovVRunPerfTestThreads, kGtestValues, kPerfTestName); + +} // namespace + +} // namespace borunov_v_complex_ccs_seq From 2b3b75698e9fe2ed2fe4574834bfd8ac98c438b7 Mon Sep 17 00:00:00 2001 From: vlad3005 Date: Mon, 23 Feb 2026 17:02:17 +0300 Subject: [PATCH 2/3] seq static fix --- .../common/include/common.hpp | 3 +- .../borunov_v_complex_ccs/seq/src/ops_seq.cpp | 61 ++++---- .../tests/functional/main.cpp | 138 +++++++++++------- .../tests/performance/main.cpp | 17 ++- 4 files changed, 130 insertions(+), 89 deletions(-) diff --git a/tasks/borunov_v_complex_ccs/common/include/common.hpp b/tasks/borunov_v_complex_ccs/common/include/common.hpp index 8afdf846..07cfd754 100644 --- a/tasks/borunov_v_complex_ccs/common/include/common.hpp +++ b/tasks/borunov_v_complex_ccs/common/include/common.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -16,7 +15,7 @@ struct SparseMatrix { std::vector row_indices; std::vector col_ptrs; - bool operator==(const SparseMatrix& other) const { + bool operator==(const SparseMatrix &other) const { return num_rows == other.num_rows && num_cols == other.num_cols && values == other.values && row_indices == other.row_indices && col_ptrs == other.col_ptrs; } diff --git a/tasks/borunov_v_complex_ccs/seq/src/ops_seq.cpp b/tasks/borunov_v_complex_ccs/seq/src/ops_seq.cpp index efaaefaf..124a6a25 100644 --- a/tasks/borunov_v_complex_ccs/seq/src/ops_seq.cpp +++ b/tasks/borunov_v_complex_ccs/seq/src/ops_seq.cpp @@ -1,11 +1,12 @@ #include "borunov_v_complex_ccs/seq/include/ops_seq.hpp" #include +#include #include +#include #include #include "borunov_v_complex_ccs/common/include/common.hpp" -#include "util/include/util.hpp" namespace borunov_v_complex_ccs_seq { @@ -19,49 +20,49 @@ bool BorunovVComplexCcsSEQ::ValidationImpl() { if (GetInput().size() != 2) { return false; } - const auto& A = GetInput()[0]; - const auto& B = GetInput()[1]; - if (A.num_cols != B.num_rows) { + const auto &a = GetInput()[0]; + const auto &b = GetInput()[1]; + if (a.num_cols != b.num_rows) { return false; } - if (A.col_ptrs.size() != static_cast(A.num_cols + 1) || - B.col_ptrs.size() != static_cast(B.num_cols + 1)) { + if (a.col_ptrs.size() != static_cast(a.num_cols) + 1 || + b.col_ptrs.size() != static_cast(b.num_cols) + 1) { return false; } return true; } bool BorunovVComplexCcsSEQ::PreProcessingImpl() { - const auto& A = GetInput()[0]; - const auto& B = GetInput()[1]; - auto& C = GetOutput()[0]; + const auto &a = GetInput()[0]; + const auto &b = GetInput()[1]; + auto &c = GetOutput()[0]; - C.num_rows = A.num_rows; - C.num_cols = B.num_cols; - C.col_ptrs.assign(C.num_cols + 1, 0); - C.values.clear(); - C.row_indices.clear(); + c.num_rows = a.num_rows; + c.num_cols = b.num_cols; + c.col_ptrs.assign(c.num_cols + 1, 0); + c.values.clear(); + c.row_indices.clear(); return true; } bool BorunovVComplexCcsSEQ::RunImpl() { - const auto& A = GetInput()[0]; - const auto& B = GetInput()[1]; - auto& C = GetOutput()[0]; + const auto &a = GetInput()[0]; + const auto &b = GetInput()[1]; + auto &c = GetOutput()[0]; - std::vector> col_accumulator(A.num_rows, {0.0, 0.0}); + std::vector> col_accumulator(a.num_rows, {0.0, 0.0}); std::vector non_zero_indices; - std::vector is_non_zero(A.num_rows, false); + std::vector is_non_zero(a.num_rows, false); - for (int j = 0; j < B.num_cols; ++j) { - for (int b_idx = B.col_ptrs[j]; b_idx < B.col_ptrs[j + 1]; ++b_idx) { - int p = B.row_indices[b_idx]; - std::complex b_val = B.values[b_idx]; + for (int j = 0; j < b.num_cols; ++j) { + for (int b_idx = b.col_ptrs[j]; b_idx < b.col_ptrs[j + 1]; ++b_idx) { + int p = b.row_indices[b_idx]; + std::complex b_val = b.values[b_idx]; - for (int a_idx = A.col_ptrs[p]; a_idx < A.col_ptrs[p + 1]; ++a_idx) { - int i = A.row_indices[a_idx]; - std::complex a_val = A.values[a_idx]; + for (int a_idx = a.col_ptrs[p]; a_idx < a.col_ptrs[p + 1]; ++a_idx) { + int i = a.row_indices[a_idx]; + std::complex a_val = a.values[a_idx]; if (!is_non_zero[i]) { is_non_zero[i] = true; @@ -71,19 +72,19 @@ bool BorunovVComplexCcsSEQ::RunImpl() { } } - std::sort(non_zero_indices.begin(), non_zero_indices.end()); + std::ranges::sort(non_zero_indices); for (int i : non_zero_indices) { if (std::abs(col_accumulator[i]) > 1e-9) { - C.values.push_back(col_accumulator[i]); - C.row_indices.push_back(i); + c.values.push_back(col_accumulator[i]); + c.row_indices.push_back(i); } col_accumulator[i] = {0.0, 0.0}; is_non_zero[i] = false; } non_zero_indices.clear(); - C.col_ptrs[j + 1] = C.values.size(); + c.col_ptrs[j + 1] = static_cast(c.values.size()); } return true; diff --git a/tasks/borunov_v_complex_ccs/tests/functional/main.cpp b/tasks/borunov_v_complex_ccs/tests/functional/main.cpp index 0aa329f7..a8f6f6cd 100644 --- a/tasks/borunov_v_complex_ccs/tests/functional/main.cpp +++ b/tasks/borunov_v_complex_ccs/tests/functional/main.cpp @@ -1,8 +1,11 @@ #include -#include +#include +#include #include +#include #include +#include #include #include @@ -13,75 +16,94 @@ namespace borunov_v_complex_ccs_seq { +namespace { + +using DenseMatrix = std::vector>>; + SparseMatrix GenerateRandomSparseMatrix(int num_rows, int num_cols, double sparsity) { SparseMatrix mat; mat.num_rows = num_rows; mat.num_cols = num_cols; mat.col_ptrs.assign(num_cols + 1, 0); - std::mt19937 gen(42); + const int sparsity_seed = static_cast(sparsity * 1000.0); + std::seed_seq seed{num_rows, num_cols, sparsity_seed}; + std::mt19937 gen(seed); std::uniform_real_distribution dist_val(-10.0, 10.0); std::uniform_real_distribution dist_prob(0.0, 1.0); for (int j = 0; j < num_cols; ++j) { for (int i = 0; i < num_rows; ++i) { if (dist_prob(gen) < sparsity) { - mat.values.push_back({dist_val(gen), dist_val(gen)}); + mat.values.emplace_back(dist_val(gen), dist_val(gen)); mat.row_indices.push_back(i); } } - mat.col_ptrs[j + 1] = mat.values.size(); + mat.col_ptrs[j + 1] = static_cast(mat.values.size()); } return mat; } -SparseMatrix MultiplyDense(const SparseMatrix& A, const SparseMatrix& B) { - SparseMatrix C; - C.num_rows = A.num_rows; - C.num_cols = B.num_cols; - C.col_ptrs.assign(C.num_cols + 1, 0); - - std::vector>> dense_A(A.num_rows, std::vector>(A.num_cols, {0.0, 0.0})); - std::vector>> dense_B(B.num_rows, std::vector>(B.num_cols, {0.0, 0.0})); - std::vector>> dense_C(A.num_rows, std::vector>(B.num_cols, {0.0, 0.0})); - - for (int j = 0; j < A.num_cols; ++j) { - for (int idx = A.col_ptrs[j]; idx < A.col_ptrs[j + 1]; ++idx) { - dense_A[A.row_indices[idx]][j] = A.values[idx]; +DenseMatrix BuildDense(const SparseMatrix &mat) { + DenseMatrix dense(mat.num_rows, std::vector>(mat.num_cols, {0.0, 0.0})); + for (int j = 0; j < mat.num_cols; ++j) { + for (int idx = mat.col_ptrs[j]; idx < mat.col_ptrs[j + 1]; ++idx) { + dense[mat.row_indices[idx]][j] = mat.values[idx]; } } + return dense; +} - for (int j = 0; j < B.num_cols; ++j) { - for (int idx = B.col_ptrs[j]; idx < B.col_ptrs[j + 1]; ++idx) { - dense_B[B.row_indices[idx]][j] = B.values[idx]; - } - } +DenseMatrix MultiplyDenseMatrices(const DenseMatrix &left, const DenseMatrix &right) { + const int rows = static_cast(left.size()); + const int inner = rows == 0 ? 0 : static_cast(left[0].size()); + const int cols = right.empty() ? 0 : static_cast(right[0].size()); + DenseMatrix result(rows, std::vector>(cols, {0.0, 0.0})); - for (int i = 0; i < A.num_rows; ++i) { - for (int j = 0; j < B.num_cols; ++j) { - for (int k = 0; k < A.num_cols; ++k) { - dense_C[i][j] += dense_A[i][k] * dense_B[k][j]; + for (int i = 0; i < rows; ++i) { + for (int j = 0; j < cols; ++j) { + for (int k = 0; k < inner; ++k) { + result[i][j] += left[i][k] * right[k][j]; } } } - for (int j = 0; j < B.num_cols; ++j) { - for (int i = 0; i < A.num_rows; ++i) { - if (std::abs(dense_C[i][j]) > 1e-9) { - C.values.push_back(dense_C[i][j]); - C.row_indices.push_back(i); + return result; +} + +SparseMatrix BuildSparseFromDense(const DenseMatrix &dense) { + SparseMatrix c; + c.num_rows = static_cast(dense.size()); + c.num_cols = dense.empty() ? 0 : static_cast(dense[0].size()); + c.col_ptrs.assign(c.num_cols + 1, 0); + + for (int j = 0; j < c.num_cols; ++j) { + for (int i = 0; i < c.num_rows; ++i) { + if (std::abs(dense[i][j]) > 1e-9) { + c.values.push_back(dense[i][j]); + c.row_indices.push_back(i); } } - C.col_ptrs[j + 1] = C.values.size(); + c.col_ptrs[j + 1] = static_cast(c.values.size()); } - return C; + return c; } +SparseMatrix MultiplyDense(const SparseMatrix &a, const SparseMatrix &b) { + DenseMatrix dense_a = BuildDense(a); + DenseMatrix dense_b = BuildDense(b); + DenseMatrix dense_c = MultiplyDenseMatrices(dense_a, dense_b); + return BuildSparseFromDense(dense_c); +} + +} // namespace + class BorunovVRunFuncTestsThreads : 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)) + "_" + std::to_string(std::get<2>(test_param)); + return std::to_string(std::get<0>(test_param)) + "_" + std::to_string(std::get<1>(test_param)) + "_" + + std::to_string(std::get<2>(test_param)); } protected: @@ -91,25 +113,37 @@ class BorunovVRunFuncTestsThreads : public ppc::util::BaseRunFuncTests(params); int n = std::get<2>(params); - SparseMatrix A = GenerateRandomSparseMatrix(m, k, 0.2); - SparseMatrix B = GenerateRandomSparseMatrix(k, n, 0.2); + SparseMatrix a = GenerateRandomSparseMatrix(m, k, 0.2); + SparseMatrix b = GenerateRandomSparseMatrix(k, n, 0.2); - input_data_ = {A, B}; - expected_output_ = {MultiplyDense(A, B)}; + input_data_ = {a, b}; + expected_output_ = {MultiplyDense(a, b)}; } bool CheckTestOutputData(OutType &output_data) final { - if (expected_output_.size() != output_data.size()) return false; - const auto& expected = expected_output_[0]; - const auto& actual = output_data[0]; + if (expected_output_.size() != output_data.size()) { + return false; + } + const auto &expected = expected_output_[0]; + const auto &actual = output_data[0]; - if (expected.num_rows != actual.num_rows || expected.num_cols != actual.num_cols) return false; - if (expected.col_ptrs != actual.col_ptrs) return false; - if (expected.row_indices != actual.row_indices) return false; - if (expected.values.size() != actual.values.size()) return false; + if (expected.num_rows != actual.num_rows || expected.num_cols != actual.num_cols) { + return false; + } + if (expected.col_ptrs != actual.col_ptrs) { + return false; + } + if (expected.row_indices != actual.row_indices) { + return false; + } + if (expected.values.size() != actual.values.size()) { + return false; + } - for (size_t i = 0; i < expected.values.size(); ++i) { - if (std::abs(expected.values[i] - actual.values[i]) > 1e-6) return false; + for (std::size_t i = 0; i < expected.values.size(); ++i) { + if (std::abs(expected.values[i] - actual.values[i]) > 1e-6) { + return false; + } } return true; } @@ -129,10 +163,14 @@ TEST_P(BorunovVRunFuncTestsThreads, MatmulTests) { ExecuteTest(GetParam()); } -const std::array kTestParam = {std::make_tuple(10, 10, 10), std::make_tuple(20, 15, 25), std::make_tuple(5, 30, 5)}; +const std::array kTestParam = { + std::make_tuple(10, 10, 10), + std::make_tuple(20, 15, 25), + std::make_tuple(5, 30, 5), +}; -const auto kTestTasksList = - std::tuple_cat(ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_borunov_v_complex_ccs)); +const auto kTestTasksList = std::tuple_cat( + ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_borunov_v_complex_ccs)); const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList); diff --git a/tasks/borunov_v_complex_ccs/tests/performance/main.cpp b/tasks/borunov_v_complex_ccs/tests/performance/main.cpp index e55de1f5..375e0fd4 100644 --- a/tasks/borunov_v_complex_ccs/tests/performance/main.cpp +++ b/tasks/borunov_v_complex_ccs/tests/performance/main.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include "borunov_v_complex_ccs/common/include/common.hpp" @@ -10,6 +9,8 @@ namespace borunov_v_complex_ccs_seq { +namespace { + SparseMatrix GenerateSparseMatrixPerf(int num_rows, int num_cols, int non_zeros_per_col) { SparseMatrix mat; mat.num_rows = num_rows; @@ -20,26 +21,28 @@ SparseMatrix GenerateSparseMatrixPerf(int num_rows, int num_cols, int non_zeros_ for (int j = 0; j < num_cols; ++j) { for (int i = 0; i < num_rows; i += step) { - mat.values.push_back({static_cast(i + 1), static_cast(j + 1)}); + mat.values.emplace_back(static_cast(i + 1), static_cast(j + 1)); mat.row_indices.push_back(i); } - mat.col_ptrs[j + 1] = mat.values.size(); + mat.col_ptrs[j + 1] = static_cast(mat.values.size()); } return mat; } +} // namespace + class BorunovVRunPerfTestThreads : public ppc::util::BaseRunPerfTests { - InType input_data_{}; + InType input_data_; void SetUp() override { int m = 200000; int k = 200000; int n = 200000; - SparseMatrix A = GenerateSparseMatrixPerf(m, k, 20); - SparseMatrix B = GenerateSparseMatrixPerf(k, n, 20); + SparseMatrix a = GenerateSparseMatrixPerf(m, k, 20); + SparseMatrix b = GenerateSparseMatrixPerf(k, n, 20); - input_data_ = {A, B}; + input_data_ = {a, b}; } bool CheckTestOutputData(OutType &output_data) final { From 11e09adc79a426fd9941e0cadb9fc85039d82af2 Mon Sep 17 00:00:00 2001 From: vlad3005 Date: Tue, 24 Feb 2026 10:25:06 +0300 Subject: [PATCH 3/3] delet unused file --- tasks/borunov_v_complex_ccs/data/pic.ppm | Bin 23 -> 0 bytes tasks/borunov_v_complex_ccs/report.md | 0 tasks/borunov_v_complex_ccs/seq/report.md | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tasks/borunov_v_complex_ccs/data/pic.ppm delete mode 100644 tasks/borunov_v_complex_ccs/report.md delete mode 100644 tasks/borunov_v_complex_ccs/seq/report.md diff --git a/tasks/borunov_v_complex_ccs/data/pic.ppm b/tasks/borunov_v_complex_ccs/data/pic.ppm deleted file mode 100644 index 637624238c89d914613ed301968bffbf462bc110..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23 bcmWGA<1$h(;xaNd<@(RSzyQYo|NjR7KDY