GCC Code Coverage Report


Directory: ./
File: tasks/guseva_crs/omp/include/multiplier_omp.hpp
Date: 2026-04-02 17:12:27
Exec Total Coverage
Lines: 22 22 100.0%
Functions: 1 1 100.0%
Branches: 11 18 61.1%

Line Branch Exec Source
1 #pragma once
2 #include <omp.h>
3
4 #include <cmath>
5 #include <cstddef>
6 #include <vector>
7
8 #include "guseva_crs/common/include/common.hpp"
9 #include "guseva_crs/common/include/multiplier.hpp"
10
11 namespace guseva_crs {
12
13 24 class MultiplierOmp : public Multiplier {
14 static void PerformCalculation(std::size_t k, std::size_t ind3, std::size_t ind4, const CRS &a, const CRS &bt,
15 double &sum, std::vector<int> &temp) {
16 for (k = ind3; k < ind4; k++) {
17 std::size_t bcol = bt.cols[k];
18 int aind = temp[bcol];
19 if (aind != -1) {
20 sum += a.values[aind] * bt.values[k];
21 }
22 }
23 }
24
25 public:
26 24 [[nodiscard]] CRS Multiply(const CRS &a, const CRS &b) const override {
27 24 std::size_t n = a.nrows;
28 std::size_t i = 0;
29
30 24 auto bt = this->Transpose(b);
31
32
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<std::vector<std::size_t>> columns(n);
33
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<std::vector<double>> values(n);
34
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 std::vector<std::size_t> row_index(n + 1, 0);
35
36 24 #pragma omp parallel shared(n, a, bt, columns, values, row_index) private(i) default(none)
37 {
38 std::size_t j = 0;
39 std::size_t k = 0;
40 std::vector<int> temp(n);
41 #pragma omp for private(j, k)
42 for (i = 0; i < n; i++) {
43 for (int &l : temp) {
44 l = -1;
45 }
46 std::size_t ind1 = a.row_ptrs[i];
47 std::size_t ind2 = a.row_ptrs[i + 1];
48 for (j = ind1; j < ind2; j++) {
49 std::size_t col = a.cols[j];
50 temp[col] = static_cast<int>(j);
51 }
52 for (j = 0; j < n; j++) {
53 double sum = 0;
54 std::size_t ind3 = bt.row_ptrs[j];
55 std::size_t ind4 = bt.row_ptrs[j + 1];
56 k = 0;
57 PerformCalculation(k, ind3, ind4, a, bt, sum, temp);
58 if (std::fabs(sum) > kZERO) {
59 columns[i].push_back(j);
60 values[i].push_back(sum);
61 row_index[i]++;
62 }
63 }
64 }
65 temp.clear();
66 }
67
68 std::size_t nz = 0;
69
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 24 times.
412 for (i = 0; i < n; i++) {
70 388 std::size_t tmp = row_index[i];
71 388 row_index[i] = nz;
72 388 nz += tmp;
73 }
74
75 24 CRS result;
76
2/2
✓ Branch 0 taken 388 times.
✓ Branch 1 taken 24 times.
412 for (i = 0; i < n; i++) {
77
1/2
✓ Branch 1 taken 388 times.
✗ Branch 2 not taken.
388 result.cols.insert(result.cols.end(), columns[i].begin(), columns[i].end());
78
1/2
✓ Branch 1 taken 388 times.
✗ Branch 2 not taken.
388 result.values.insert(result.values.end(), values[i].begin(), values[i].end());
79 }
80
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
24 result.row_ptrs = row_index;
81 24 result.nz = result.values.size();
82 24 result.ncols = n;
83
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 result.nrows = n;
84
85 24 return result;
86 24 }
87 };
88 } // namespace guseva_crs
89