GCC Code Coverage Report


Directory: ./
File: tasks/potashnik_m_matrix_mult_complex/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 32 32 100.0%
Functions: 5 5 100.0%
Branches: 13 16 81.2%

Line Branch Exec Source
1 // #include "potashnik_m_matrix_mult_complex/seq/include/ops_seq.hpp"
2 #include "potashnik_m_matrix_mult_complex/omp/include/ops_omp.hpp"
3
4 #include <omp.h>
5
6 #include <cstddef>
7 #include <map>
8 #include <utility>
9 #include <vector>
10
11 #include "potashnik_m_matrix_mult_complex/common/include/common.hpp"
12
13 namespace potashnik_m_matrix_mult_complex {
14
15
1/2
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
40 PotashnikMMatrixMultComplexOMP::PotashnikMMatrixMultComplexOMP(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17 GetInput() = in;
18 40 }
19
20 40 bool PotashnikMMatrixMultComplexOMP::ValidationImpl() {
21 const auto &matrix_left = std::get<0>(GetInput());
22 const auto &matrix_right = std::get<1>(GetInput());
23 40 return matrix_left.width == matrix_right.height;
24 }
25
26 40 bool PotashnikMMatrixMultComplexOMP::PreProcessingImpl() {
27 40 return true;
28 }
29
30 40 bool PotashnikMMatrixMultComplexOMP::RunImpl() {
31 const auto &matrix_left = std::get<0>(GetInput());
32 const auto &matrix_right = std::get<1>(GetInput());
33
34 40 const auto &val_left = matrix_left.val;
35 40 const auto &row_ind_left = matrix_left.row_ind;
36 40 const auto &col_ptr_left = matrix_left.col_ptr;
37 40 size_t height_left = matrix_left.height;
38
39 40 const auto &val_right = matrix_right.val;
40 40 const auto &row_ind_right = matrix_right.row_ind;
41 40 const auto &col_ptr_right = matrix_right.col_ptr;
42 40 size_t width_right = matrix_right.width;
43
44 40 int threads = omp_get_max_threads();
45 40 std::vector<std::map<std::pair<size_t, size_t>, Complex>> local_buffers(threads);
46
47 40 #pragma omp parallel num_threads(threads) default(none) \
48 shared(local_buffers, matrix_left, matrix_right, val_left, row_ind_left, col_ptr_left, val_right, row_ind_right, \
49 col_ptr_right, width_right, height_left, threads)
50 {
51 int tid = omp_get_thread_num();
52 auto &local_buffer = local_buffers[tid];
53 size_t left_count = matrix_left.Count();
54 #pragma omp for schedule(static)
55 for (size_t i = 0; i < left_count; i++) {
56 size_t row_left = row_ind_left[i];
57 size_t col_left = col_ptr_left[i];
58 Complex left_val = val_left[i];
59
60 for (size_t j = 0; j < matrix_right.Count(); j++) {
61 size_t row_right = row_ind_right[j];
62 size_t col_right = col_ptr_right[j];
63 Complex right_val = val_right[j];
64
65 if (col_left == row_right) {
66 local_buffer[{row_left, col_right}] += left_val * right_val;
67 }
68 }
69 }
70 }
71
72 std::map<std::pair<size_t, size_t>, Complex> buffer;
73
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 40 times.
140 for (const auto &local : local_buffers) {
74
2/2
✓ Branch 0 taken 4232 times.
✓ Branch 1 taken 100 times.
4332 for (const auto &[key, value] : local) {
75
1/2
✓ Branch 1 taken 4232 times.
✗ Branch 2 not taken.
4232 buffer[key] += value;
76 }
77 }
78
79 40 CCSMatrix matrix_res;
80 40 matrix_res.width = width_right;
81 40 matrix_res.height = height_left;
82
83
2/2
✓ Branch 0 taken 1716 times.
✓ Branch 1 taken 40 times.
1756 for (const auto &[key, value] : buffer) {
84 matrix_res.val.push_back(value);
85
2/2
✓ Branch 0 taken 1452 times.
✓ Branch 1 taken 264 times.
1716 matrix_res.row_ind.push_back(key.first);
86
2/2
✓ Branch 0 taken 1452 times.
✓ Branch 1 taken 264 times.
1716 matrix_res.col_ptr.push_back(key.second);
87 }
88
89
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 GetOutput() = matrix_res;
90 40 return true;
91 80 }
92
93 40 bool PotashnikMMatrixMultComplexOMP::PostProcessingImpl() {
94 40 return true;
95 }
96 } // namespace potashnik_m_matrix_mult_complex
97