| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "liulin_y_integ_mnog_func_monte_carlo/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <random> | ||
| 5 | |||
| 6 | #include "liulin_y_integ_mnog_func_monte_carlo/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace liulin_y_integ_mnog_func_monte_carlo { | ||
| 9 | |||
| 10 | // Remove the thread_local static std::mt19937 gen declaration since it's not used | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 80 times.
✗ Branch 2 not taken.
|
80 | LiulinYIntegMnogFuncMonteCarloSEQ::LiulinYIntegMnogFuncMonteCarloSEQ(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | 80 | GetOutput() = 0.0; | |
| 16 | 80 | } | |
| 17 | |||
| 18 | 80 | bool LiulinYIntegMnogFuncMonteCarloSEQ::ValidationImpl() { | |
| 19 | const auto &input = GetInput(); | ||
| 20 |
3/6✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 80 times.
|
80 | return input.num_points > 0 && input.x_min <= input.x_max && input.y_min <= input.y_max; |
| 21 | } | ||
| 22 | |||
| 23 | 80 | bool LiulinYIntegMnogFuncMonteCarloSEQ::PreProcessingImpl() { | |
| 24 | 80 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | 80 | bool LiulinYIntegMnogFuncMonteCarloSEQ::RunImpl() { | |
| 28 | const auto &input = GetInput(); | ||
| 29 | auto &result = GetOutput(); | ||
| 30 | |||
| 31 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
|
80 | if (input.num_points <= 0) { |
| 32 | ✗ | result = 0.0; | |
| 33 | ✗ | return true; | |
| 34 | } | ||
| 35 | |||
| 36 | 80 | const double area = (input.x_max - input.x_min) * (input.y_max - input.y_min); | |
| 37 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 72 times.
|
80 | if (area <= 0.0) { |
| 38 | 8 | result = 0.0; | |
| 39 | 8 | return true; | |
| 40 | } | ||
| 41 | |||
| 42 | const double x_min = input.x_min; | ||
| 43 | const double x_range = input.x_max - x_min; | ||
| 44 | const double y_min = input.y_min; | ||
| 45 | const double y_range = input.y_max - y_min; | ||
| 46 | const auto &func = input.f; | ||
| 47 | const int64_t n = input.num_points; | ||
| 48 | |||
| 49 |
3/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 64 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
|
88 | static thread_local std::minstd_rand fast_gen(std::random_device{}()); |
| 50 | |||
| 51 | std::uniform_real_distribution<double> dist_x(0.0, x_range); | ||
| 52 | std::uniform_real_distribution<double> dist_y(0.0, y_range); | ||
| 53 | |||
| 54 | double sum = 0.0; | ||
| 55 | int64_t i = 0; | ||
| 56 | |||
| 57 | // Пришлось развернуть цикл вручную для оптимизации производительности | ||
| 58 |
2/2✓ Branch 0 taken 8202000 times.
✓ Branch 1 taken 72 times.
|
8202072 | for (; i + 3 < n; i += 4) { |
| 59 | 8202000 | const double x1 = x_min + dist_x(fast_gen); | |
| 60 | 8202000 | const double y1 = y_min + dist_y(fast_gen); | |
| 61 | 8202000 | const double x2 = x_min + dist_x(fast_gen); | |
| 62 | 8202000 | const double y2 = y_min + dist_y(fast_gen); | |
| 63 | 8202000 | const double x3 = x_min + dist_x(fast_gen); | |
| 64 | 8202000 | const double y3 = y_min + dist_y(fast_gen); | |
| 65 | 8202000 | const double x4 = x_min + dist_x(fast_gen); | |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8202000 times.
|
8202000 | const double y4 = y_min + dist_y(fast_gen); |
| 67 | |||
| 68 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 8202000 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8202000 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8202000 times.
|
32808000 | sum += func(x1, y1) + func(x2, y2) + func(x3, y3) + func(x4, y4); |
| 69 | } | ||
| 70 | |||
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | for (; i < n; ++i) { |
| 72 | ✗ | const double x = x_min + dist_x(fast_gen); | |
| 73 | ✗ | const double y = y_min + dist_y(fast_gen); | |
| 74 | ✗ | sum += func(x, y); | |
| 75 | } | ||
| 76 | |||
| 77 | 72 | result = (sum * area) / static_cast<double>(n); | |
| 78 | |||
| 79 | 72 | return true; | |
| 80 | } | ||
| 81 | |||
| 82 | 80 | bool LiulinYIntegMnogFuncMonteCarloSEQ::PostProcessingImpl() { | |
| 83 | 80 | return true; | |
| 84 | } | ||
| 85 | |||
| 86 | } // namespace liulin_y_integ_mnog_func_monte_carlo | ||
| 87 |