| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "Nazarova_K_rad_sort_batcher_metod/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <cmath> | ||
| 4 | #include <cstddef> | ||
| 5 | #include <limits> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "Nazarova_K_rad_sort_batcher_metod/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace nazarova_k_calc_integ_rectangles { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
|
28 | NazarovaKCalcIntegRectanglesOMP::NazarovaKCalcIntegRectanglesOMP(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 |
1/2✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
|
28 | GetInput() = in; |
| 15 | 28 | GetOutput() = {}; | |
| 16 | 28 | } | |
| 17 | |||
| 18 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | bool NazarovaKCalcIntegRectanglesOMP::HasValidInput() { |
| 19 | const auto &input = GetInput(); | ||
| 20 | const std::size_t dimension = input.lower_bounds.size(); | ||
| 21 |
4/8✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
|
28 | if (!input.function || dimension == 0U || input.upper_bounds.size() != dimension || input.steps.size() != dimension) { |
| 22 | return false; | ||
| 23 | } | ||
| 24 | |||
| 25 | std::size_t total_cells = 1U; | ||
| 26 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 28 times.
|
84 | for (std::size_t i = 0; i < dimension; ++i) { |
| 27 |
4/8✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 56 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 56 times.
|
56 | if (input.steps[i] == 0U || !std::isfinite(input.lower_bounds[i]) || !std::isfinite(input.upper_bounds[i]) || |
| 28 | input.lower_bounds[i] > input.upper_bounds[i]) { | ||
| 29 | return false; | ||
| 30 | } | ||
| 31 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
|
56 | if (total_cells > (std::numeric_limits<std::size_t>::max() / input.steps[i])) { |
| 32 | return false; | ||
| 33 | } | ||
| 34 | 56 | total_cells *= input.steps[i]; | |
| 35 | } | ||
| 36 | |||
| 37 | return true; | ||
| 38 | } | ||
| 39 | |||
| 40 | 28 | bool NazarovaKCalcIntegRectanglesOMP::ValidationImpl() { | |
| 41 | 28 | return HasValidInput(); | |
| 42 | } | ||
| 43 | |||
| 44 | 28 | bool NazarovaKCalcIntegRectanglesOMP::PreProcessingImpl() { | |
| 45 | const auto &input = GetInput(); | ||
| 46 | 28 | dimension_ = input.lower_bounds.size(); | |
| 47 | 28 | step_sizes_.assign(dimension_, 0.0); | |
| 48 | 28 | cell_volume_ = 1.0; | |
| 49 | 28 | total_cells_ = 1U; | |
| 50 | 28 | result_ = 0.0; | |
| 51 | |||
| 52 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 28 times.
|
84 | for (std::size_t i = 0; i < dimension_; ++i) { |
| 53 | 56 | step_sizes_[i] = (input.upper_bounds[i] - input.lower_bounds[i]) / static_cast<double>(input.steps[i]); | |
| 54 | 56 | cell_volume_ *= step_sizes_[i]; | |
| 55 | 56 | total_cells_ *= input.steps[i]; | |
| 56 | } | ||
| 57 | |||
| 58 | 28 | GetOutput() = 0.0; | |
| 59 | 28 | return true; | |
| 60 | } | ||
| 61 | |||
| 62 | 28 | bool NazarovaKCalcIntegRectanglesOMP::RunImpl() { | |
| 63 | const auto &input = GetInput(); | ||
| 64 | 28 | const std::size_t dimension = dimension_; | |
| 65 | 28 | const std::size_t total_cells = total_cells_; | |
| 66 | 28 | const auto &step_sizes = step_sizes_; | |
| 67 | double sum = 0.0; | ||
| 68 | |||
| 69 | 28 | #pragma omp parallel default(none) shared(input, step_sizes) firstprivate(dimension, total_cells) reduction(+ : sum) | |
| 70 | { | ||
| 71 | std::vector<double> point(dimension, 0.0); | ||
| 72 | |||
| 73 | #pragma omp for schedule(static) | ||
| 74 | for (std::size_t linear_index = 0U; linear_index < total_cells; ++linear_index) { | ||
| 75 | std::size_t current_index = linear_index; | ||
| 76 | for (std::size_t axis = 0U; axis < dimension; ++axis) { | ||
| 77 | const std::size_t coordinate_index = current_index % input.steps[axis]; | ||
| 78 | current_index /= input.steps[axis]; | ||
| 79 | point[axis] = input.lower_bounds[axis] + ((static_cast<double>(coordinate_index) + 0.5) * step_sizes[axis]); | ||
| 80 | } | ||
| 81 | sum += input.function(point); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | 28 | result_ = sum * cell_volume_; | |
| 86 | 28 | GetOutput() = result_; | |
| 87 | 28 | return true; | |
| 88 | } | ||
| 89 | |||
| 90 | 28 | bool NazarovaKCalcIntegRectanglesOMP::PostProcessingImpl() { | |
| 91 | 28 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | } // namespace nazarova_k_calc_integ_rectangles | ||
| 95 |