GCC Code Coverage Report


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

Line Branch Exec Source
1 #include "afanasyev_a_integ_rect_method/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range.h>
4 #include <tbb/parallel_reduce.h>
5
6 #include <array>
7 #include <cmath>
8 #include <cstdint>
9 #include <functional>
10
11 #include "afanasyev_a_integ_rect_method/common/include/common.hpp"
12
13 namespace afanasyev_a_integ_rect_method {
14 namespace {
15
16 double ExampleIntegrand(const std::array<double, 3> &x) {
17 double s = 0.0;
18
2/2
✓ Branch 0 taken 6480000 times.
✓ Branch 1 taken 2160000 times.
8640000 for (double xi : x) {
19 6480000 s += xi * xi;
20 }
21 2160000 return std::exp(-s);
22 }
23
24 } // namespace
25
26 12 AfanasyevAIntegRectMethodTBB::AfanasyevAIntegRectMethodTBB(const InType &in) {
27 SetTypeOfTask(GetStaticTypeOfTask());
28 12 GetInput() = in;
29 GetOutput() = 0.0;
30 12 }
31
32 12 bool AfanasyevAIntegRectMethodTBB::ValidationImpl() {
33 12 return (GetInput() > 0);
34 }
35
36 12 bool AfanasyevAIntegRectMethodTBB::PreProcessingImpl() {
37 12 return true;
38 }
39
40 12 bool AfanasyevAIntegRectMethodTBB::RunImpl() {
41 12 const int n = GetInput();
42
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (n <= 0) {
43 return false;
44 }
45
46 const int k_dim = 3;
47 12 const double h = 1.0 / static_cast<double>(n);
48 12 const int64_t total_points = static_cast<int64_t>(n) * n * n;
49
50 24 const double sum = tbb::parallel_reduce(tbb::blocked_range<int64_t>(0, total_points), 0.0,
51 12 [&](const tbb::blocked_range<int64_t> &range, double local_sum) {
52 std::array<double, 3> x{};
53 4015 const int64_t plane = static_cast<int64_t>(n) * n;
54
2/2
✓ Branch 0 taken 2160000 times.
✓ Branch 1 taken 4015 times.
2164015 for (int64_t index = range.begin(); index != range.end(); ++index) {
55 2160000 const int i = static_cast<int>(index / plane);
56 2160000 const int j = static_cast<int>((index / n) % n);
57 2160000 const int k = static_cast<int>(index % n);
58
59 2160000 x[0] = (static_cast<double>(i) + 0.5) * h;
60 2160000 x[1] = (static_cast<double>(j) + 0.5) * h;
61 2160000 x[2] = (static_cast<double>(k) + 0.5) * h;
62
63 2160000 local_sum += ExampleIntegrand(x);
64 }
65 4015 return local_sum;
66 12 }, std::plus<>());
67
68 12 const double volume = std::pow(h, k_dim);
69 12 GetOutput() = sum * volume;
70
71 12 return true;
72 }
73
74 12 bool AfanasyevAIntegRectMethodTBB::PostProcessingImpl() {
75 12 return true;
76 }
77
78 } // namespace afanasyev_a_integ_rect_method
79