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