GCC Code Coverage Report


Directory: ./
File: tasks/zagryadskov_m_complex_spmm_ccs/omp/src/ops_omp.cpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 53 53 100.0%
Functions: 7 7 100.0%
Branches: 29 44 65.9%

Line Branch Exec Source
1 #include "zagryadskov_m_complex_spmm_ccs/omp/include/ops_omp.hpp"
2
3 #include <omp.h>
4
5 #include <cmath>
6 #include <complex>
7 #include <vector>
8
9 #include "util/include/util.hpp"
10 #include "zagryadskov_m_complex_spmm_ccs/common/include/common.hpp"
11
12 namespace zagryadskov_m_complex_spmm_ccs {
13
14
1/2
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 ZagryadskovMComplexSpMMCCSOMP::ZagryadskovMComplexSpMMCCSOMP(const InType &in) {
15 SetTypeOfTask(GetStaticTypeOfTask());
16 GetInput() = in;
17
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 GetOutput() = CCS();
18 12 }
19
20 30 void ZagryadskovMComplexSpMMCCSOMP::SpMMkernel(const CCS &a, const CCS &b, const std::complex<double> &zero, double eps,
21 int num_threads, std::vector<std::vector<int>> &t_row_ind,
22 std::vector<std::vector<std::complex<double>>> &t_values,
23 std::vector<std::vector<int>> &t_col_ptr) {
24 30 int tid = omp_get_thread_num();
25 30 int jstart = (tid * b.n) / num_threads;
26 30 int jend = ((tid + 1) * b.n) / num_threads;
27
28 30 t_col_ptr[tid].assign(jend - jstart + 1, 0);
29
30 30 std::vector<int> rows;
31
1/4
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
30 std::vector<int> marker(a.m, -1);
32
1/4
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
30 std::vector<std::complex<double>> acc(a.m, zero);
33
34
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 30 times.
58 for (int j = jstart; j < jend; ++j) {
35 rows.clear();
36
37
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 28 times.
68 for (int k = b.col_ptr[j]; k < b.col_ptr[j + 1]; ++k) {
38 40 std::complex<double> tmpval = b.values[k];
39 40 int btmpind = b.row_ind[k];
40
41
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 40 times.
84 for (int zp = a.col_ptr[btmpind]; zp < a.col_ptr[btmpind + 1]; ++zp) {
42
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 int atmpind = a.row_ind[zp];
43
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 acc[atmpind] += tmpval * a.values[zp];
44
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 if (marker[atmpind] != j) {
45 rows.push_back(atmpind);
46 36 marker[atmpind] = j;
47 }
48 }
49 }
50
51
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 28 times.
64 for (int tmpind : rows) {
52
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if (std::abs(acc[tmpind]) > eps) {
53 t_values[tid].push_back(acc[tmpind]);
54 t_row_ind[tid].push_back(tmpind);
55 36 ++t_col_ptr[tid][j - jstart + 1];
56 }
57 36 acc[tmpind] = zero;
58 }
59 }
60 30 }
61
62 12 void ZagryadskovMComplexSpMMCCSOMP::SpMM(const CCS &a, const CCS &b, CCS &c) {
63 12 c.m = a.m;
64 12 c.n = b.n;
65
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 c.col_ptr.assign(b.n + 1, 0);
66 c.row_ind.clear();
67 c.values.clear();
68 12 std::complex<double> zero(0.0, 0.0);
69 const double eps = 1e-14;
70 12 const int num_threads = ppc::util::GetNumThreads();
71
72 12 std::vector<std::vector<int>> t_row_ind(num_threads);
73
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 std::vector<std::vector<std::complex<double>>> t_values(num_threads);
74
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 std::vector<std::vector<int>> t_col_ptr(num_threads);
75
76 12 #pragma omp parallel default(none) shared(zero, eps, num_threads, t_row_ind, t_values, t_col_ptr, a, b) \
77
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 num_threads(ppc::util::GetNumThreads())
78 {
79 SpMMkernel(a, b, zero, eps, num_threads, t_row_ind, t_values, t_col_ptr);
80 }
81
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 12 times.
42 for (int tid = 0; tid < num_threads; ++tid) {
82 30 int jstart = (tid * b.n) / num_threads;
83 30 int jend = ((tid + 1) * b.n) / num_threads;
84
85
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 30 times.
58 for (int j = jstart; j < jend; ++j) {
86 28 c.col_ptr[j + 1] = c.col_ptr[j] + t_col_ptr[tid][j - jstart + 1];
87 }
88
89
1/2
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
30 c.row_ind.insert(c.row_ind.end(), t_row_ind[tid].begin(), t_row_ind[tid].end());
90
1/2
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
30 c.values.insert(c.values.end(), t_values[tid].begin(), t_values[tid].end());
91 }
92 12 }
93
94 12 bool ZagryadskovMComplexSpMMCCSOMP::ValidationImpl() {
95 const CCS &a = std::get<0>(GetInput());
96 const CCS &b = std::get<1>(GetInput());
97 12 return a.n == b.m;
98 }
99
100 12 bool ZagryadskovMComplexSpMMCCSOMP::PreProcessingImpl() {
101 12 return true;
102 }
103
104 12 bool ZagryadskovMComplexSpMMCCSOMP::RunImpl() {
105 const CCS &a = std::get<0>(GetInput());
106 const CCS &b = std::get<1>(GetInput());
107 CCS &c = GetOutput();
108
109 12 ZagryadskovMComplexSpMMCCSOMP::SpMM(a, b, c);
110
111 12 return true;
112 }
113
114 12 bool ZagryadskovMComplexSpMMCCSOMP::PostProcessingImpl() {
115 12 return true;
116 }
117
118 } // namespace zagryadskov_m_complex_spmm_ccs
119