GCC Code Coverage Report


Directory: ./
File: tasks/telnov_a_integral_rectangle/tbb/src/ops_tbb.cpp
Date: 2026-05-11 08:26:31
Exec Total Coverage
Lines: 26 26 100.0%
Functions: 5 5 100.0%
Branches: 6 8 75.0%

Line Branch Exec Source
1 #include "telnov_a_integral_rectangle/tbb/include/ops_tbb.hpp"
2
3 #include <cmath>
4 #include <cstdint>
5
6 #include "oneapi/tbb/blocked_range.h"
7 #include "oneapi/tbb/parallel_reduce.h"
8 #include "telnov_a_integral_rectangle/common/include/common.hpp"
9
10 namespace telnov_a_integral_rectangle {
11
12 32 TelnovAIntegralRectangleTBB::TelnovAIntegralRectangleTBB(const InType &in) {
13 SetTypeOfTask(GetStaticTypeOfTask());
14 GetInput() = in;
15 GetOutput() = 0;
16 32 }
17
18 32 bool TelnovAIntegralRectangleTBB::ValidationImpl() {
19
2/4
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32 times.
32 return GetInput().first > 0 && GetInput().second > 0;
20 }
21
22 32 bool TelnovAIntegralRectangleTBB::PreProcessingImpl() {
23 32 GetOutput() = 0.0;
24 32 return true;
25 }
26
27 32 bool TelnovAIntegralRectangleTBB::RunImpl() {
28 32 const int n = GetInput().first;
29 32 const int d = GetInput().second;
30
31 const double a = 0.0;
32 const double b = 1.0;
33 32 const double h = (b - a) / static_cast<double>(n);
34
35 32 const auto total_points = static_cast<int64_t>(std::pow(n, d));
36
37 const double result =
38 64 oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<int64_t>(0, total_points), 0.0,
39 32 [n, d, a, h](const oneapi::tbb::blocked_range<int64_t> &range, double local_sum) {
40
2/2
✓ Branch 0 taken 150676 times.
✓ Branch 1 taken 5395 times.
156071 for (int64_t idx = range.begin(); idx != range.end(); ++idx) {
41 int64_t tmp = idx;
42 double f_value = 0.0;
43
44
2/2
✓ Branch 0 taken 711964 times.
✓ Branch 1 taken 150676 times.
862640 for (int dim = 0; dim < d; ++dim) {
45 711964 const int coord_index = static_cast<int>(tmp % n);
46 711964 tmp /= n;
47
48 711964 const double x = a + ((static_cast<double>(coord_index) + 0.5) * h);
49 711964 f_value += x;
50 }
51
52 150676 local_sum += f_value;
53 }
54 return local_sum;
55 102 }, [](double lhs, double rhs) { return lhs + rhs; });
56
57 32 GetOutput() = result * std::pow(h, d);
58 32 return true;
59 }
60
61 32 bool TelnovAIntegralRectangleTBB::PostProcessingImpl() {
62 32 return true;
63 }
64
65 } // namespace telnov_a_integral_rectangle
66