GCC Code Coverage Report


Directory: ./
File: tasks/zavyalov_a_complex_sparse_matrix_mult/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 28 29 96.6%
Functions: 6 6 100.0%
Branches: 15 20 75.0%

Line Branch Exec Source
1 #include "zavyalov_a_complex_sparse_matrix_mult/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cstddef>
6 #include <map>
7 #include <stdexcept>
8 #include <utility>
9 #include <vector>
10
11 #include "util/include/util.hpp"
12 #include "zavyalov_a_complex_sparse_matrix_mult/common/include/common.hpp"
13
14 namespace zavyalov_a_compl_sparse_matr_mult {
15
16 40 SparseMatrix ZavyalovAComplSparseMatrMultOMP::MultiplicateWithOmp(const SparseMatrix &matr_a,
17 const SparseMatrix &matr_b) {
18
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (matr_a.width != matr_b.height) {
19 throw std::invalid_argument("Incompatible matrix dimensions for multiplication");
20 }
21
22 40 int num_threads = ppc::util::GetNumThreads();
23
24 40 std::vector<std::map<std::pair<size_t, size_t>, Complex>> local_maps(num_threads);
25
26 40 #pragma omp parallel for num_threads(num_threads) schedule(static) default(none) shared(matr_a, matr_b, local_maps)
27 for (size_t i = 0; i < matr_a.Count(); ++i) {
28 int tid = omp_get_thread_num();
29 size_t row_a = matr_a.row_ind[i];
30 size_t col_a = matr_a.col_ind[i];
31 Complex val_a = matr_a.val[i];
32
33 for (size_t j = 0; j < matr_b.Count(); ++j) {
34 if (col_a == matr_b.row_ind[j]) {
35 local_maps[tid][{row_a, matr_b.col_ind[j]}] += val_a * matr_b.val[j];
36 }
37 }
38 }
39
40 std::map<std::pair<size_t, size_t>, Complex> mp;
41
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 40 times.
140 for (auto &lm : local_maps) {
42
2/2
✓ Branch 0 taken 1389 times.
✓ Branch 1 taken 100 times.
1489 for (auto &[key, value] : lm) {
43
1/2
✓ Branch 1 taken 1389 times.
✗ Branch 2 not taken.
1389 mp[key] += value;
44 }
45 }
46
47 40 SparseMatrix res;
48 40 res.width = matr_b.width;
49 40 res.height = matr_a.height;
50
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 40 times.
628 for (const auto &[key, value] : mp) {
51
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 188 times.
588 res.val.push_back(value);
52
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 188 times.
588 res.row_ind.push_back(key.first);
53
2/2
✓ Branch 0 taken 400 times.
✓ Branch 1 taken 188 times.
588 res.col_ind.push_back(key.second);
54 }
55
56 40 return res;
57 40 }
58
59
1/2
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 ZavyalovAComplSparseMatrMultOMP::ZavyalovAComplSparseMatrMultOMP(const InType &in) {
60 SetTypeOfTask(GetStaticTypeOfTask());
61 GetInput() = in;
62 40 }
63
64 40 bool ZavyalovAComplSparseMatrMultOMP::ValidationImpl() {
65 const auto &matr_a = std::get<0>(GetInput());
66 const auto &matr_b = std::get<1>(GetInput());
67 40 return matr_a.width == matr_b.height;
68 }
69
70 40 bool ZavyalovAComplSparseMatrMultOMP::PreProcessingImpl() {
71 40 return true;
72 }
73
74 40 bool ZavyalovAComplSparseMatrMultOMP::RunImpl() {
75 const auto &matr_a = std::get<0>(GetInput());
76 const auto &matr_b = std::get<1>(GetInput());
77
78 40 GetOutput() = MultiplicateWithOmp(matr_a, matr_b);
79
80 40 return true;
81 }
82
83 40 bool ZavyalovAComplSparseMatrMultOMP::PostProcessingImpl() {
84 40 return true;
85 }
86 } // namespace zavyalov_a_compl_sparse_matr_mult
87