| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "kutergin_a_multidim_trapezoid/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <tbb/tbb.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cmath> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <functional> | ||
| 9 | #include <utility> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | #include "kutergin_a_multidim_trapezoid/common/include/common.hpp" | ||
| 13 | |||
| 14 | namespace kutergin_a_multidim_trapezoid { | ||
| 15 | namespace { | ||
| 16 | |||
| 17 | bool ValidateBorders(const std::vector<std::pair<double, double>> &borders) { | ||
| 18 | return std::ranges::all_of( | ||
| 19 |
3/6✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
|
80 | borders, [](const auto &p) { return std::isfinite(p.first) && std::isfinite(p.second) && (p.first < p.second); }); |
| 20 | } | ||
| 21 | |||
| 22 | } // namespace | ||
| 23 | |||
| 24 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | KuterginAMultidimTrapezoidTBB::KuterginAMultidimTrapezoidTBB(const InType &in) { |
| 25 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 26 | GetInput() = in; | ||
| 27 | 48 | GetOutput() = 0.0; | |
| 28 | 48 | } | |
| 29 | |||
| 30 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 | bool KuterginAMultidimTrapezoidTBB::ValidationImpl() { |
| 31 | const auto &[func, borders, n] = GetInput(); | ||
| 32 |
3/6✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
|
48 | return func && n > 0 && !borders.empty() && ValidateBorders(borders); |
| 33 | } | ||
| 34 | |||
| 35 | 48 | bool KuterginAMultidimTrapezoidTBB::PreProcessingImpl() { | |
| 36 | local_input_ = GetInput(); | ||
| 37 | 48 | res_ = 0.0; | |
| 38 | 48 | return true; | |
| 39 | } | ||
| 40 | |||
| 41 | 48 | bool KuterginAMultidimTrapezoidTBB::RunImpl() { | |
| 42 | const auto &[func, borders, n] = local_input_; | ||
| 43 | 48 | const int dim = static_cast<int>(borders.size()); | |
| 44 | |||
| 45 | 48 | std::vector<double> h(dim); | |
| 46 | double cell_volume = 1.0; | ||
| 47 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 48 times.
|
128 | for (int i = 0; i < dim; ++i) { |
| 48 | 80 | h[i] = (borders[i].second - borders[i].first) / n; | |
| 49 | 80 | cell_volume *= h[i]; | |
| 50 | } | ||
| 51 | |||
| 52 | size_t total_points = 1; | ||
| 53 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 48 times.
|
128 | for (int i = 0; i < dim; ++i) { |
| 54 | 80 | total_points *= (static_cast<size_t>(n) + 1); | |
| 55 | } | ||
| 56 | |||
| 57 |
1/2✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
|
48 | res_ = tbb::parallel_reduce(tbb::blocked_range<size_t>(0, total_points), 0.0, |
| 58 |
3/8✓ Branch 1 taken 48 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 48 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
48 | [=](const tbb::blocked_range<size_t> &r, double local_sum) { |
| 59 | 13123 | std::vector<double> point(dim); | |
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 1436048 times.
✓ Branch 1 taken 13123 times.
|
1449171 | for (size_t i = r.begin(); i < r.end(); ++i) { |
| 62 | double weight = 1.0; | ||
| 63 | size_t temp_idx = i; | ||
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 3775920 times.
✓ Branch 1 taken 1436048 times.
|
5211968 | for (int dim_idx = 0; dim_idx < dim; ++dim_idx) { |
| 66 | 3775920 | int coord_idx = static_cast<int>(temp_idx % (n + 1)); | |
| 67 | 3775920 | temp_idx /= (n + 1); | |
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 103040 times.
✓ Branch 1 taken 3672880 times.
|
3775920 | point[dim_idx] = borders[dim_idx].first + (coord_idx * h[dim_idx]); |
| 70 | |||
| 71 |
2/2✓ Branch 0 taken 103040 times.
✓ Branch 1 taken 3672880 times.
|
3775920 | if (coord_idx == 0 || coord_idx == n) { |
| 72 | 103040 | weight *= 0.5; | |
| 73 | } | ||
| 74 | } | ||
| 75 | 1436048 | local_sum += weight * func(point); | |
| 76 | } | ||
| 77 | 13123 | return local_sum; | |
| 78 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
48 | }, std::plus<>()) * |
| 79 | cell_volume; | ||
| 80 | |||
| 81 |
1/2✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
96 | return std::isfinite(res_); |
| 82 | } | ||
| 83 | |||
| 84 | 48 | bool KuterginAMultidimTrapezoidTBB::PostProcessingImpl() { | |
| 85 | 48 | GetOutput() = res_; | |
| 86 | 48 | return true; | |
| 87 | } | ||
| 88 | |||
| 89 | } // namespace kutergin_a_multidim_trapezoid | ||
| 90 |