GCC Code Coverage Report


Directory: ./
File: tasks/nazyrov_a_multidim_integral_rectangle/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 34 35 97.1%
Functions: 6 6 100.0%
Branches: 19 32 59.4%

Line Branch Exec Source
1 #include "nazyrov_a_multidim_integral_rectangle/tbb/include/ops_tbb.hpp"
2
3 #include <algorithm>
4 #include <cmath>
5 #include <cstddef>
6 #include <cstdint>
7 #include <functional>
8 #include <vector>
9
10 #include "nazyrov_a_multidim_integral_rectangle/common/include/common.hpp"
11 #include "oneapi/tbb/blocked_range.h"
12 #include "oneapi/tbb/parallel_reduce.h"
13
14 namespace nazyrov_a_multidim_integral_rectangle {
15
16
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 NazyrovAMultidimIntegralRectangleTbb::NazyrovAMultidimIntegralRectangleTbb(const InType &in) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 GetInput() = in;
19 40 GetOutput() = 0.0;
20 40 }
21
22 40 bool NazyrovAMultidimIntegralRectangleTbb::ValidationImpl() {
23 const auto &func = std::get<0>(GetInput());
24 const auto &bounds = std::get<1>(GetInput());
25
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 const int n = std::get<2>(GetInput());
26
3/6
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
40 return func && n > 0 && !bounds.empty() && std::ranges::all_of(bounds, [](const auto &bd) {
27
3/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 84 times.
✗ Branch 5 not taken.
84 return std::isfinite(bd.first) && std::isfinite(bd.second) && bd.first < bd.second;
28 40 });
29 }
30
31 40 bool NazyrovAMultidimIntegralRectangleTbb::PreProcessingImpl() {
32 40 return true;
33 }
34
35 40 bool NazyrovAMultidimIntegralRectangleTbb::RunImpl() {
36 const auto &func = std::get<0>(GetInput());
37 const auto &bounds = std::get<1>(GetInput());
38 40 const int n = std::get<2>(GetInput());
39
40 40 const int dim = static_cast<int>(bounds.size());
41
42 40 std::vector<double> h(static_cast<std::size_t>(dim));
43 double cell_vol = 1.0;
44
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 40 times.
124 for (int i = 0; i < dim; ++i) {
45 84 h[i] = (bounds[i].second - bounds[i].first) / n;
46 84 cell_vol *= h[i];
47 }
48
49 std::int64_t total = 1;
50
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 40 times.
124 for (int i = 0; i < dim; ++i) {
51 84 total *= n;
52 }
53
54 const double sum =
55 80 oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<std::int64_t>(0, total), 0.0,
56
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 [&](const oneapi::tbb::blocked_range<std::int64_t> &range, double partial) {
57 10939 std::vector<double> point(static_cast<std::size_t>(dim));
58
2/2
✓ Branch 0 taken 5741600 times.
✓ Branch 1 taken 10939 times.
5752539 for (std::int64_t cell = range.begin(); cell < range.end(); ++cell) {
59 std::int64_t tmp = cell;
60
2/2
✓ Branch 0 taken 16981600 times.
✓ Branch 1 taken 5741600 times.
22723200 for (int i = dim - 1; i >= 0; --i) {
61 16981600 const int ki = static_cast<int>(tmp % n);
62 16981600 tmp /= n;
63 16981600 const double coordinate = bounds[i].first + ((ki + 0.5) * h[i]);
64 16981600 point[i] = coordinate;
65 }
66
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5741600 times.
11483200 partial += func(point);
67 }
68 10939 return partial;
69 }, std::plus<double>{});
70
71
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 GetOutput() = sum * cell_vol;
72 40 return true;
73 }
74
75 40 bool NazyrovAMultidimIntegralRectangleTbb::PostProcessingImpl() {
76 40 return true;
77 }
78
79 } // namespace nazyrov_a_multidim_integral_rectangle
80