| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "bortsova_a_integrals_rectangle/tbb/include/ops_tbb.hpp" | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <functional> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "bortsova_a_integrals_rectangle/common/include/common.hpp" | ||
| 8 | #include "oneapi/tbb/blocked_range.h" | ||
| 9 | #include "oneapi/tbb/parallel_reduce.h" | ||
| 10 | |||
| 11 | namespace bortsova_a_integrals_rectangle { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | BortsovaAIntegralsRectangleTBB::BortsovaAIntegralsRectangleTBB(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 16 | 40 | GetOutput() = 0.0; | |
| 17 | 40 | } | |
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool BortsovaAIntegralsRectangleTBB::ValidationImpl() { |
| 20 | const auto &input = GetInput(); | ||
| 21 |
3/6✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
|
40 | return input.func && !input.lower_bounds.empty() && input.lower_bounds.size() == input.upper_bounds.size() && |
| 22 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | input.num_steps > 0; |
| 23 | } | ||
| 24 | |||
| 25 | 40 | bool BortsovaAIntegralsRectangleTBB::PreProcessingImpl() { | |
| 26 | const auto &input = GetInput(); | ||
| 27 | 40 | func_ = input.func; | |
| 28 | 40 | num_steps_ = input.num_steps; | |
| 29 | 40 | dims_ = static_cast<int>(input.lower_bounds.size()); | |
| 30 | |||
| 31 | 40 | midpoints_.resize(dims_); | |
| 32 | 40 | volume_ = 1.0; | |
| 33 | 40 | total_points_ = 1; | |
| 34 | |||
| 35 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 40 times.
|
108 | for (int di = 0; di < dims_; di++) { |
| 36 | 68 | double step = (input.upper_bounds[di] - input.lower_bounds[di]) / static_cast<double>(num_steps_); | |
| 37 | 68 | volume_ *= step; | |
| 38 | 68 | total_points_ *= num_steps_; | |
| 39 | |||
| 40 | 68 | midpoints_[di].resize(num_steps_); | |
| 41 |
2/2✓ Branch 0 taken 11684 times.
✓ Branch 1 taken 68 times.
|
11752 | for (int si = 0; si < num_steps_; si++) { |
| 42 | 11684 | midpoints_[di][si] = input.lower_bounds[di] + ((si + 0.5) * step); | |
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | 40 | return true; | |
| 47 | } | ||
| 48 | |||
| 49 | 40 | bool BortsovaAIntegralsRectangleTBB::RunImpl() { | |
| 50 | 40 | int dims = dims_; | |
| 51 | 40 | int num_steps = num_steps_; | |
| 52 | 40 | const auto &midpoints = midpoints_; | |
| 53 | 40 | const auto &func = func_; | |
| 54 | |||
| 55 | 80 | double sum = tbb::parallel_reduce(tbb::blocked_range<int64_t>(0, total_points_), 0.0, | |
| 56 | 40 | [&](const tbb::blocked_range<int64_t> &range, double local_sum) { | |
| 57 | 9682 | std::vector<int> indices(dims, 0); | |
| 58 |
1/4✓ Branch 1 taken 9682 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
9682 | std::vector<double> point(dims); |
| 59 | |||
| 60 | int64_t temp = range.begin(); | ||
| 61 |
2/2✓ Branch 0 taken 18930 times.
✓ Branch 1 taken 9682 times.
|
28612 | for (int di = dims - 1; di >= 0; di--) { |
| 62 | 18930 | indices[di] = static_cast<int>(temp % num_steps); | |
| 63 | 18930 | temp /= num_steps; | |
| 64 | } | ||
| 65 | |||
| 66 |
2/2✓ Branch 0 taken 192804 times.
✓ Branch 1 taken 9682 times.
|
202486 | for (int64_t pt = range.begin(); pt < range.end(); pt++) { |
| 67 |
2/2✓ Branch 0 taken 440804 times.
✓ Branch 1 taken 192804 times.
|
633608 | for (int di = 0; di < dims; di++) { |
| 68 | 440804 | point[di] = midpoints[di][indices[di]]; | |
| 69 | } | ||
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 192804 times.
|
192804 | local_sum += func(point); |
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 197364 times.
✓ Branch 1 taken 40 times.
|
197404 | for (int di = dims - 1; di >= 0; di--) { |
| 73 |
2/2✓ Branch 0 taken 4600 times.
✓ Branch 1 taken 192764 times.
|
197364 | indices[di]++; |
| 74 |
2/2✓ Branch 0 taken 4600 times.
✓ Branch 1 taken 192764 times.
|
197364 | if (indices[di] < num_steps) { |
| 75 | break; | ||
| 76 | } | ||
| 77 | 4600 | indices[di] = 0; | |
| 78 | } | ||
| 79 | } | ||
| 80 | 9682 | return local_sum; | |
| 81 | 40 | }, std::plus<>()); | |
| 82 | |||
| 83 | 40 | GetOutput() = sum * volume_; | |
| 84 | 40 | return true; | |
| 85 | } | ||
| 86 | |||
| 87 | 40 | bool BortsovaAIntegralsRectangleTBB::PostProcessingImpl() { | |
| 88 | 40 | return true; | |
| 89 | } | ||
| 90 | |||
| 91 | } // namespace bortsova_a_integrals_rectangle | ||
| 92 |