| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "bortsova_a_integrals_rectangle/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | #include "bortsova_a_integrals_rectangle/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace bortsova_a_integrals_rectangle { | ||
| 9 | |||
| 10 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | BortsovaAIntegralsRectangleOMP::BortsovaAIntegralsRectangleOMP(const InType &in) { |
| 11 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 12 |
1/2✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
|
40 | GetInput() = in; |
| 13 | 40 | GetOutput() = 0.0; | |
| 14 | 40 | } | |
| 15 | |||
| 16 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | bool BortsovaAIntegralsRectangleOMP::ValidationImpl() { |
| 17 | const auto &input = GetInput(); | ||
| 18 |
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() && |
| 19 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | input.num_steps > 0; |
| 20 | } | ||
| 21 | |||
| 22 | 40 | bool BortsovaAIntegralsRectangleOMP::PreProcessingImpl() { | |
| 23 | const auto &input = GetInput(); | ||
| 24 | 40 | func_ = input.func; | |
| 25 | 40 | num_steps_ = input.num_steps; | |
| 26 | 40 | dims_ = static_cast<int>(input.lower_bounds.size()); | |
| 27 | |||
| 28 | 40 | midpoints_.resize(dims_); | |
| 29 | 40 | volume_ = 1.0; | |
| 30 | 40 | total_points_ = 1; | |
| 31 | |||
| 32 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 40 times.
|
108 | for (int di = 0; di < dims_; di++) { |
| 33 | 68 | double step = (input.upper_bounds[di] - input.lower_bounds[di]) / static_cast<double>(num_steps_); | |
| 34 | 68 | volume_ *= step; | |
| 35 | 68 | total_points_ *= num_steps_; | |
| 36 | |||
| 37 | 68 | midpoints_[di].resize(num_steps_); | |
| 38 |
2/2✓ Branch 0 taken 11684 times.
✓ Branch 1 taken 68 times.
|
11752 | for (int si = 0; si < num_steps_; si++) { |
| 39 | 11684 | midpoints_[di][si] = input.lower_bounds[di] + ((si + 0.5) * step); | |
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | 40 | return true; | |
| 44 | } | ||
| 45 | |||
| 46 | 40 | bool BortsovaAIntegralsRectangleOMP::RunImpl() { | |
| 47 | double sum = 0.0; | ||
| 48 | 40 | const int dims = dims_; | |
| 49 | 40 | const int num_steps = num_steps_; | |
| 50 | 40 | const int64_t total_points = total_points_; | |
| 51 | 40 | const auto &midpoints = midpoints_; | |
| 52 | 40 | const auto &func = func_; | |
| 53 | |||
| 54 | 40 | #pragma omp parallel default(none) shared(sum, dims, num_steps, total_points, midpoints, func) | |
| 55 | { | ||
| 56 | std::vector<int> indices(dims, 0); | ||
| 57 | std::vector<double> point(dims, 0.0); | ||
| 58 | |||
| 59 | #pragma omp for reduction(+ : sum) | ||
| 60 | for (int64_t pt = 0; pt < total_points; pt++) { | ||
| 61 | int64_t tmp = pt; | ||
| 62 | for (int di = dims - 1; di >= 0; di--) { | ||
| 63 | indices[di] = static_cast<int>(tmp % num_steps); | ||
| 64 | tmp /= num_steps; | ||
| 65 | } | ||
| 66 | |||
| 67 | for (int di = 0; di < dims; di++) { | ||
| 68 | point[di] = midpoints[di][indices[di]]; | ||
| 69 | } | ||
| 70 | sum += func(point); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | 40 | GetOutput() = sum * volume_; | |
| 75 | 40 | return true; | |
| 76 | } | ||
| 77 | |||
| 78 | 40 | bool BortsovaAIntegralsRectangleOMP::PostProcessingImpl() { | |
| 79 | 40 | return true; | |
| 80 | } | ||
| 81 | |||
| 82 | } // namespace bortsova_a_integrals_rectangle | ||
| 83 |