GCC Code Coverage Report


Directory: ./
File: tasks/sabirov_s_monte_carlo/tbb/include/ops_tbb.hpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 20 20 100.0%
Functions: 1 1 100.0%
Branches: 24 25 96.0%

Line Branch Exec Source
1 #pragma once
2
3 #include <cmath>
4 #include <vector>
5
6 #include "sabirov_s_monte_carlo/common/include/common.hpp"
7 #include "task/include/task.hpp"
8
9 namespace sabirov_s_monte_carlo {
10
11 namespace detail {
12
13 inline double EvalLinear(const std::vector<double> &point) {
14 double s = 0.0;
15
2/2
✓ Branch 0 taken 440000 times.
✓ Branch 1 taken 240000 times.
680000 for (double x : point) {
16 440000 s += x;
17 }
18 return s;
19 }
20
21 inline double EvalSumCubes(const std::vector<double> &point) {
22 double s = 0.0;
23
2/2
✓ Branch 0 taken 440000 times.
✓ Branch 1 taken 240000 times.
680000 for (double x : point) {
24 440000 s += x * x * x;
25 }
26 return s;
27 }
28
29 inline double EvalCosProduct(const std::vector<double> &point) {
30 double p = 1.0;
31
2/2
✓ Branch 0 taken 440000 times.
✓ Branch 1 taken 240000 times.
680000 for (double x : point) {
32 440000 p *= std::cos(x);
33 }
34 return p;
35 }
36
37 inline double EvalExpNeg(const std::vector<double> &point) {
38 double s = 0.0;
39
2/2
✓ Branch 0 taken 440000 times.
✓ Branch 1 taken 240000 times.
680000 for (double x : point) {
40 440000 s += x;
41 }
42 240000 return std::exp(-s);
43 }
44
45 inline double EvalMixedPoly(const std::vector<double> &point) {
46 double s = 0.0;
47
2/2
✓ Branch 0 taken 1240000 times.
✓ Branch 1 taken 440000 times.
1680000 for (double x : point) {
48 1240000 s += (x * x) + x;
49 }
50 return s;
51 }
52
53 inline double EvalSinSum(const std::vector<double> &point) {
54 double s = 0.0;
55
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 40000 times.
80000 for (double x : point) {
56 40000 s += std::sin(x);
57 }
58 return s;
59 }
60
61 inline double EvalSqrtSum(const std::vector<double> &point) {
62 double s = 0.0;
63
2/2
✓ Branch 0 taken 40000 times.
✓ Branch 1 taken 40000 times.
80000 for (double x : point) {
64 40000 s += std::sqrt(x);
65 }
66 return s;
67 }
68
69 inline double EvalQuarticSum(const std::vector<double> &point) {
70 double s = 0.0;
71
2/2
✓ Branch 0 taken 400000 times.
✓ Branch 1 taken 200000 times.
600000 for (double x : point) {
72 400000 s += x * x * x * x;
73 }
74 return s;
75 }
76
77 1680000 inline double EvaluateAt(FuncType func_type, const std::vector<double> &point) {
78
8/9
✓ Branch 0 taken 240000 times.
✓ Branch 1 taken 240000 times.
✓ Branch 2 taken 240000 times.
✓ Branch 3 taken 240000 times.
✓ Branch 4 taken 440000 times.
✓ Branch 5 taken 40000 times.
✓ Branch 6 taken 40000 times.
✓ Branch 7 taken 200000 times.
✗ Branch 8 not taken.
1680000 switch (func_type) {
79 case FuncType::kLinear:
80 return EvalLinear(point);
81 case FuncType::kSumCubes:
82 return EvalSumCubes(point);
83 case FuncType::kCosProduct:
84 return EvalCosProduct(point);
85 case FuncType::kExpNeg:
86 240000 return EvalExpNeg(point);
87 case FuncType::kMixedPoly:
88 return EvalMixedPoly(point);
89 case FuncType::kSinSum:
90 return EvalSinSum(point);
91 case FuncType::kSqrtSum:
92 return EvalSqrtSum(point);
93 case FuncType::kQuarticSum:
94 return EvalQuarticSum(point);
95 default:
96 return 0.0;
97 }
98 }
99
100 } // namespace detail
101
102 class SabirovSMonteCarloTBB : public BaseTask {
103 public:
104 static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
105 return ppc::task::TypeOfTask::kTBB;
106 }
107 explicit SabirovSMonteCarloTBB(const InType &in);
108
109 private:
110 bool ValidationImpl() override;
111 bool PreProcessingImpl() override;
112 bool RunImpl() override;
113 bool PostProcessingImpl() override;
114
115 std::vector<double> lower_;
116 std::vector<double> upper_;
117 int num_samples_{};
118 FuncType func_type_{};
119 };
120
121 } // namespace sabirov_s_monte_carlo
122