| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "chernykh_s_trapezoidal_integration/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <cstdint> | ||
| 9 | #include <functional> | ||
| 10 | #include <utility> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | #include "chernykh_s_trapezoidal_integration/common/include/common.hpp" | ||
| 14 | |||
| 15 | namespace chernykh_s_trapezoidal_integration { | ||
| 16 | |||
| 17 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | ChernykhSTrapezoidalIntegrationTBB::ChernykhSTrapezoidalIntegrationTBB(const InType &in) { |
| 18 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 19 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | GetInput() = in; |
| 20 | 24 | GetOutput() = 0.0; | |
| 21 | 24 | } | |
| 22 | |||
| 23 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | bool ChernykhSTrapezoidalIntegrationTBB::ValidationImpl() { |
| 24 | const auto &input = this->GetInput(); | ||
| 25 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | if (input.limits.empty() || input.limits.size() != input.steps.size()) { |
| 26 | return false; | ||
| 27 | } | ||
| 28 | return std::ranges::all_of(input.steps, [](int s) { return s > 0; }); | ||
| 29 | } | ||
| 30 | |||
| 31 | 24 | bool ChernykhSTrapezoidalIntegrationTBB::PreProcessingImpl() { | |
| 32 | 24 | return true; | |
| 33 | } | ||
| 34 | |||
| 35 | 58544 | double ChernykhSTrapezoidalIntegrationTBB::CalculatePointAndWeight(const IntegrationInType &input, | |
| 36 | const std::vector<std::size_t> &counters, | ||
| 37 | std::vector<double> &point) { | ||
| 38 | double weight = 1.0; | ||
| 39 |
2/2✓ Branch 0 taken 109996 times.
✓ Branch 1 taken 58544 times.
|
168540 | for (std::size_t i = 0; i < input.limits.size(); ++i) { // проходим по границам каждого из измерений |
| 40 | 109996 | const double h = (input.limits[i].second - input.limits[i].first) / | |
| 41 | 109996 | static_cast<double>(input.steps[i]); // велечина шага в текущем измерении | |
| 42 | 109996 | point[i] = input.limits[i].first + | |
| 43 |
2/2✓ Branch 0 taken 107720 times.
✓ Branch 1 taken 2276 times.
|
109996 | (static_cast<double>(counters[i]) * h); // дискретная точка: начало_измерения + шаг*номер_шага |
| 44 | if (std::cmp_equal(counters[i], 0) || | ||
| 45 | std::cmp_equal(counters[i], input.steps[i])) { // если шаг граничный, то его вес уменьшается | ||
| 46 | 4552 | weight *= 0.5; | |
| 47 | } | ||
| 48 | } | ||
| 49 | 58544 | return weight; | |
| 50 | } | ||
| 51 | |||
| 52 | 24 | bool ChernykhSTrapezoidalIntegrationTBB::RunImpl() { | |
| 53 | const auto &input = this->GetInput(); | ||
| 54 | 24 | const std::size_t dims = input.limits.size(); | |
| 55 | double total_sum = 0.0; | ||
| 56 | int64_t total_points = 1; | ||
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
|
60 | for (int steps_on_this_spase : input.steps) { |
| 59 | 36 | total_points *= steps_on_this_spase + 1; | |
| 60 | } | ||
| 61 | |||
| 62 | 6546 | auto body = [&](const tbb::blocked_range<int64_t> &r, double local_sum) -> double { | |
| 63 | 6546 | std::vector<double> local_point(dims); | |
| 64 |
1/4✓ Branch 1 taken 6546 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
6546 | std::vector<size_t> local_counters(dims); |
| 65 | |||
| 66 |
2/2✓ Branch 0 taken 58544 times.
✓ Branch 1 taken 6546 times.
|
65090 | for (int64_t j = r.begin(); j < r.end(); j++) { |
| 67 | int64_t temp_j = j; | ||
| 68 |
2/2✓ Branch 0 taken 109996 times.
✓ Branch 1 taken 58544 times.
|
168540 | for (size_t i = 0; i < input.steps.size(); i++) { |
| 69 | 109996 | local_counters[i] = temp_j % (input.steps[i] + 1); | |
| 70 | 109996 | temp_j /= input.steps[i] + 1; | |
| 71 | } | ||
| 72 | 58544 | double weight = CalculatePointAndWeight(input, local_counters, local_point); | |
| 73 | 58544 | local_sum += input.func(local_point) * weight; | |
| 74 | } | ||
| 75 | |||
| 76 | 6546 | return local_sum; | |
| 77 | 24 | }; | |
| 78 | |||
| 79 | 24 | total_sum = tbb::parallel_reduce(tbb::blocked_range<int64_t>(0, total_points), 0.0, body, std::plus<>()); | |
| 80 | |||
| 81 | double h_prod = 1.0; | ||
| 82 |
2/2✓ Branch 0 taken 36 times.
✓ Branch 1 taken 24 times.
|
60 | for (std::size_t i = 0; i < dims; ++i) { |
| 83 | 36 | h_prod *= (input.limits[i].second - input.limits[i].first) / static_cast<double>(input.steps[i]); | |
| 84 | } | ||
| 85 | |||
| 86 | 24 | GetOutput() = total_sum * h_prod; | |
| 87 | 24 | return true; | |
| 88 | } | ||
| 89 | |||
| 90 | 24 | bool ChernykhSTrapezoidalIntegrationTBB::PostProcessingImpl() { | |
| 91 | 24 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | } // namespace chernykh_s_trapezoidal_integration | ||
| 95 |