GCC Code Coverage Report


Directory: ./
File: tasks/zagryadskov_m_complex_spmm_ccs/omp/src/ops_omp.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 61 61 100.0%
Functions: 9 9 100.0%
Branches: 34 40 85.0%

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::SpMMSymbolic(const CCS &a, const CCS &b, std::vector<int> &col_ptr, int jstart,
21 int jend) {
22 30 std::vector<int> marker(a.m, -1);
23
24
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 30 times.
58 for (int j = jstart; j < jend; ++j) {
25 int count = 0;
26
27
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) {
28 40 int b_row = b.row_ind[k];
29
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 40 times.
84 for (int zp = a.col_ptr[b_row]; zp < a.col_ptr[b_row + 1]; ++zp) {
30
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 int a_row = a.row_ind[zp];
31
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 if (marker[a_row] != j) {
32 36 marker[a_row] = j;
33 36 ++count;
34 }
35 }
36 }
37 28 col_ptr[j + 1] += count;
38 }
39 30 }
40
41
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 23 times.
28 void ZagryadskovMComplexSpMMCCSOMP::SpMMKernel(const CCS &a, const CCS &b, CCS &c, const std::complex<double> &zero,
42 std::vector<int> &rows, std::vector<std::complex<double>> &acc,
43 std::vector<int> &marker, int j) {
44 rows.clear();
45 28 int write_ptr = c.col_ptr[j];
46
47
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) {
48 40 std::complex<double> tmpval = b.values[k];
49 40 int b_row = b.row_ind[k];
50
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 40 times.
84 for (int zp = a.col_ptr[b_row]; zp < a.col_ptr[b_row + 1]; ++zp) {
51
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 int a_row = a.row_ind[zp];
52
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 acc[a_row] += tmpval * a.values[zp];
53
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 8 times.
44 if (marker[a_row] != j) {
54
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 30 times.
36 marker[a_row] = j;
55 rows.push_back(a_row);
56 }
57 }
58 }
59
60
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 28 times.
64 for (int r_idx : rows) {
61 36 c.row_ind[write_ptr] = r_idx;
62 36 c.values[write_ptr] = acc[r_idx];
63 36 ++write_ptr;
64 36 acc[r_idx] = zero;
65 }
66 28 }
67
68 30 void ZagryadskovMComplexSpMMCCSOMP::SpMMNumeric(const CCS &a, const CCS &b, CCS &c, const std::complex<double> &zero,
69 int jstart, int jend) {
70 30 std::vector<int> marker(a.m, -1);
71
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);
72 30 std::vector<int> rows;
73
74
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 30 times.
58 for (int j = jstart; j < jend; ++j) {
75
1/2
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
28 SpMMKernel(a, b, c, zero, rows, acc, marker, j);
76 }
77 30 }
78
79 12 void ZagryadskovMComplexSpMMCCSOMP::SpMM(const CCS &a, const CCS &b, CCS &c) {
80 12 c.m = a.m;
81 12 c.n = b.n;
82 12 const int num_threads = ppc::util::GetNumThreads();
83
84 12 std::complex<double> zero(0.0, 0.0);
85 12 c.col_ptr.assign(c.n + 1, 0);
86
87 12 #pragma omp parallel default(none) shared(num_threads, a, b, c) num_threads(ppc::util::GetNumThreads())
88 {
89 int tid = omp_get_thread_num();
90 int jstart = (tid * b.n) / num_threads;
91 int jend = ((tid + 1) * b.n) / num_threads;
92 SpMMSymbolic(a, b, c.col_ptr, jstart, jend);
93 }
94
95
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 12 times.
40 for (int j = 0; j < c.n; ++j) {
96 28 c.col_ptr[j + 1] += c.col_ptr[j];
97 }
98 12 int nnz = c.col_ptr[b.n];
99 12 c.row_ind.resize(nnz);
100 12 c.values.resize(nnz);
101 12 #pragma omp parallel default(none) shared(num_threads, a, b, c, zero) num_threads(ppc::util::GetNumThreads())
102 {
103 int tid = omp_get_thread_num();
104 int jstart = (tid * b.n) / num_threads;
105 int jend = ((tid + 1) * b.n) / num_threads;
106 SpMMNumeric(a, b, c, zero, jstart, jend);
107 }
108 12 }
109
110 12 bool ZagryadskovMComplexSpMMCCSOMP::ValidationImpl() {
111 const CCS &a = std::get<0>(GetInput());
112 const CCS &b = std::get<1>(GetInput());
113 12 return a.n == b.m;
114 }
115
116 12 bool ZagryadskovMComplexSpMMCCSOMP::PreProcessingImpl() {
117 12 return true;
118 }
119
120 12 bool ZagryadskovMComplexSpMMCCSOMP::RunImpl() {
121 const CCS &a = std::get<0>(GetInput());
122 const CCS &b = std::get<1>(GetInput());
123 CCS &c = GetOutput();
124
125 12 ZagryadskovMComplexSpMMCCSOMP::SpMM(a, b, c);
126
127 12 return true;
128 }
129
130 12 bool ZagryadskovMComplexSpMMCCSOMP::PostProcessingImpl() {
131 12 return true;
132 }
133
134 } // namespace zagryadskov_m_complex_spmm_ccs
135