GCC Code Coverage Report


Directory: ./
File: tasks/goriacheva_k_mult_sparse_complex_matrix_ccs/stl/src/ops_stl.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 57 58 98.3%
Functions: 7 7 100.0%
Branches: 40 60 66.7%

Line Branch Exec Source
1 #include "goriacheva_k_mult_sparse_complex_matrix_ccs/stl/include/ops_stl.hpp"
2
3 #include <algorithm>
4 #include <ranges>
5 #include <thread>
6 #include <vector>
7
8 #include "goriacheva_k_mult_sparse_complex_matrix_ccs/common/include/common.hpp"
9
10 namespace goriacheva_k_mult_sparse_complex_matrix_ccs {
11
12
1/2
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
112 GoriachevaKMultSparseComplexMatrixCcsSTL::GoriachevaKMultSparseComplexMatrixCcsSTL(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 112 }
16
17 112 bool GoriachevaKMultSparseComplexMatrixCcsSTL::ValidationImpl() {
18 auto &[a, b] = GetInput();
19
20
1/2
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
112 if (a.cols != b.rows) {
21 return false;
22 }
23
24
2/4
✓ Branch 0 taken 112 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 112 times.
112 if (a.col_ptr.empty() || b.col_ptr.empty()) {
25 return false;
26 }
27
28 return true;
29 }
30
31 112 bool GoriachevaKMultSparseComplexMatrixCcsSTL::PreProcessingImpl() {
32 112 GetOutput() = {};
33 112 return true;
34 }
35
36 namespace {
37 328 void ProcessColumn(int j, const SparseMatrixCCS &a, const SparseMatrixCCS &b, std::vector<Complex> &values,
38 std::vector<int> &rows) {
39 328 std::vector<Complex> accumulator(a.rows);
40
1/4
✓ Branch 1 taken 328 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
328 std::vector<int> marker(a.rows, -1);
41 328 std::vector<int> used_rows;
42
43
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 328 times.
552 for (int bi = b.col_ptr[j]; bi < b.col_ptr[j + 1]; bi++) {
44 224 int k = b.row_ind[bi];
45 224 Complex b_val = b.values[bi];
46
47
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 224 times.
440 for (int ai = a.col_ptr[k]; ai < a.col_ptr[k + 1]; ai++) {
48
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 int i = a.row_ind[ai];
49
50
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 if (marker[i] != j) {
51
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 marker[i] = j;
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 accumulator[i] = Complex(0.0, 0.0);
53 used_rows.push_back(i);
54 }
55
56 accumulator[i] += a.values[ai] * b_val;
57 }
58 }
59
60 std::ranges::sort(used_rows);
61
62
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 328 times.
544 for (int r : used_rows) {
63
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 192 times.
216 if (accumulator[r] != Complex(0.0, 0.0)) {
64 rows.push_back(r);
65 values.push_back(accumulator[r]);
66 }
67 }
68 328 }
69 } // namespace
70
71 112 bool GoriachevaKMultSparseComplexMatrixCcsSTL::RunImpl() {
72 auto &a = std::get<0>(GetInput());
73 auto &b = std::get<1>(GetInput());
74 auto &c = GetOutput();
75
76 112 c.rows = a.rows;
77 112 c.cols = b.cols;
78 112 c.col_ptr.resize(c.cols + 1);
79
80 112 std::vector<std::vector<Complex>> local_values(c.cols);
81
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 std::vector<std::vector<int>> local_rows(c.cols);
82
83 112 int num_threads = static_cast<int>(std::thread::hardware_concurrency());
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
112 if (num_threads == 0) {
85 num_threads = 1;
86 }
87
88 112 std::vector<std::thread> threads;
89
90 328 auto worker = [&](int start, int end) {
91
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 328 times.
656 for (int j = start; j < end; j++) {
92 328 ProcessColumn(j, a, b, local_values[j], local_rows[j]);
93 }
94 440 };
95
96 112 int cols_per_thread = (b.cols + num_threads - 1) / num_threads;
97
98
2/2
✓ Branch 0 taken 408 times.
✓ Branch 1 taken 32 times.
440 for (int thread_idx = 0; thread_idx < num_threads; thread_idx++) {
99 408 int start = thread_idx * cols_per_thread;
100
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 80 times.
408 int end = std::min(start + cols_per_thread, b.cols);
101
102
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 80 times.
408 if (start >= end) {
103 break;
104 }
105
106
1/2
✓ Branch 1 taken 328 times.
✗ Branch 2 not taken.
328 threads.emplace_back(worker, start, end);
107 }
108
109
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 112 times.
440 for (auto &th : threads) {
110
1/2
✓ Branch 1 taken 328 times.
✗ Branch 2 not taken.
328 th.join();
111 }
112
113 int nnz = 0;
114
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 112 times.
440 for (int j = 0; j < c.cols; j++) {
115 328 c.col_ptr[j] = nnz;
116 328 nnz += static_cast<int>(local_values[j].size());
117 }
118
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 c.col_ptr[c.cols] = nnz;
119
120
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 c.values.reserve(nnz);
121
1/2
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 c.row_ind.reserve(nnz);
122
123
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 112 times.
440 for (int j = 0; j < c.cols; j++) {
124
2/4
✓ Branch 1 taken 328 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 328 times.
✗ Branch 5 not taken.
328 c.values.insert(c.values.end(), local_values[j].begin(), local_values[j].end());
125 328 c.row_ind.insert(c.row_ind.end(), local_rows[j].begin(), local_rows[j].end());
126 }
127
128 112 return true;
129 112 }
130
131 112 bool GoriachevaKMultSparseComplexMatrixCcsSTL::PostProcessingImpl() {
132 112 return true;
133 }
134
135 } // namespace goriacheva_k_mult_sparse_complex_matrix_ccs
136