GCC Code Coverage Report


Directory: ./
File: tasks/savva_d_monte_carlo/tbb/src/ops_tbb.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 34 34 100.0%
Functions: 6 6 100.0%
Branches: 21 36 58.3%

Line Branch Exec Source
1 #include "savva_d_monte_carlo/tbb/include/ops_tbb.hpp"
2
3 #include <tbb/blocked_range.h>
4 #include <tbb/parallel_reduce.h>
5
6 #include <cstddef>
7 #include <cstdint>
8 #include <random>
9 #include <vector>
10
11 #include "savva_d_monte_carlo/common/include/common.hpp"
12
13 namespace savva_d_monte_carlo {
14
15
1/2
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
68 SavvaDMonteCarloTBB::SavvaDMonteCarloTBB(const InType &in) {
16 SetTypeOfTask(GetStaticTypeOfTask());
17
1/2
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
68 GetInput() = in;
18 68 GetOutput() = 0.0;
19 68 }
20
21 68 bool SavvaDMonteCarloTBB::ValidationImpl() {
22 const auto &input = GetInput();
23
24 // Проверка количества точек
25
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if (input.count_points == 0) {
26 return false;
27 }
28
29 // Проверка наличия функции
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if (!input.f) {
31 return false;
32 }
33
34 // Проверка размерности
35
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if (input.Dimension() == 0) {
36 return false;
37 }
38
39 // Проверка корректности границ
40
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 68 times.
236 for (size_t i = 0; i < input.Dimension(); ++i) {
41
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if (input.lower_bounds[i] > input.upper_bounds[i]) {
42 return false;
43 }
44 }
45
46 return true;
47 }
48
49 68 bool SavvaDMonteCarloTBB::PreProcessingImpl() {
50 68 return true;
51 }
52
53
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 bool SavvaDMonteCarloTBB::RunImpl() {
54 const auto &input = GetInput();
55 auto &result = GetOutput();
56
57
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 const size_t dim = input.Dimension();
58 const double vol = input.Volume();
59 68 const auto n = static_cast<int64_t>(input.count_points);
60 68 const auto &func = input.f;
61
62 const auto &lb = input.lower_bounds;
63 const auto &ub = input.upper_bounds;
64
65 68 std::vector<std::uniform_real_distribution<double>> dists;
66
1/2
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
68 dists.reserve(dim);
67
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 68 times.
236 for (size_t i = 0; i < dim; ++i) {
68
1/2
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
168 dists.emplace_back(lb[i], ub[i]);
69 }
70
71 136 double sum = tbb::parallel_reduce(tbb::blocked_range<int64_t>(0, n), 0.0,
72
73
1/2
✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
22465 [&](const tbb::blocked_range<int64_t> &r, double local_sum) {
74 22397 std::minstd_rand gen(static_cast<uint32_t>(r.begin()) ^ 0x9e3779b9U);
75
76 22397 std::vector<double> point(dim);
77
78
2/2
✓ Branch 0 taken 60404000 times.
✓ Branch 1 taken 22397 times.
60426397 for (int64_t i = r.begin(); i < r.end(); ++i) {
79 // генерация точки
80
2/2
✓ Branch 0 taken 152808000 times.
✓ Branch 1 taken 60404000 times.
213212000 for (size_t j = 0; j < dim; ++j) {
81 305616000 point[j] = dists[j](gen);
82 }
83
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60404000 times.
120808000 local_sum += func(point);
85 }
86
87 22397 return local_sum;
88 },
89
90
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
774 [](double a, double b) { return a + b; });
91
92
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 result = vol * sum / static_cast<double>(n);
93 68 return true;
94 }
95
96 68 bool SavvaDMonteCarloTBB::PostProcessingImpl() {
97 68 return true;
98 }
99
100 } // namespace savva_d_monte_carlo
101