| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "vlasova_a_simpson_method/omp/include/ops_omp.hpp" | ||
| 2 | |||
| 3 | #include <omp.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <utility> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "vlasova_a_simpson_method/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace vlasova_a_simpson_method { | ||
| 13 | |||
| 14 | 88 | VlasovaASimpsonMethodOMP::VlasovaASimpsonMethodOMP(InType in) : task_data_(std::move(in)) { | |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 | 88 | GetOutput() = 0.0; | |
| 17 | 88 | } | |
| 18 | |||
| 19 |
1/2✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 | bool VlasovaASimpsonMethodOMP::ValidationImpl() { |
| 20 | size_t dim = task_data_.a.size(); | ||
| 21 | |||
| 22 |
3/6✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 88 times.
|
88 | if (dim == 0 || dim != task_data_.b.size() || dim != task_data_.n.size()) { |
| 23 | return false; | ||
| 24 | } | ||
| 25 | |||
| 26 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
|
256 | for (size_t i = 0; i < dim; ++i) { |
| 27 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
|
168 | if (task_data_.a[i] >= task_data_.b[i]) { |
| 28 | return false; | ||
| 29 | } | ||
| 30 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 168 times.
|
168 | if (task_data_.n[i] <= 0 || task_data_.n[i] % 2 != 0) { |
| 31 | return false; | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
|
88 | if (!task_data_.func) { |
| 36 | return false; | ||
| 37 | } | ||
| 38 | |||
| 39 | 88 | return GetOutput() == 0.0; | |
| 40 | } | ||
| 41 | |||
| 42 | 88 | bool VlasovaASimpsonMethodOMP::PreProcessingImpl() { | |
| 43 | 88 | result_ = 0.0; | |
| 44 | 88 | GetOutput() = 0.0; | |
| 45 | |||
| 46 | size_t dim = task_data_.a.size(); | ||
| 47 | 88 | h_.resize(dim); | |
| 48 | 88 | dimensions_.resize(dim); | |
| 49 | |||
| 50 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
|
256 | for (size_t i = 0; i < dim; ++i) { |
| 51 | 168 | h_[i] = (task_data_.b[i] - task_data_.a[i]) / task_data_.n[i]; | |
| 52 | 168 | dimensions_[i] = task_data_.n[i] + 1; | |
| 53 | } | ||
| 54 | |||
| 55 | 88 | return true; | |
| 56 | } | ||
| 57 | |||
| 58 | 620984 | void VlasovaASimpsonMethodOMP::ComputeWeight(const std::vector<int> &index, double &weight) const { | |
| 59 | 620984 | weight = 1.0; | |
| 60 | size_t dim = index.size(); | ||
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 1857080 times.
✓ Branch 1 taken 620984 times.
|
2478064 | for (size_t i = 0; i < dim; ++i) { |
| 63 | 1857080 | int idx = index[i]; | |
| 64 | 1857080 | int steps = task_data_.n[i]; | |
| 65 | |||
| 66 |
2/2✓ Branch 0 taken 1765192 times.
✓ Branch 1 taken 91888 times.
|
1857080 | if (idx == 0 || idx == steps) { |
| 67 | weight *= 1.0; | ||
| 68 |
2/2✓ Branch 0 taken 859624 times.
✓ Branch 1 taken 905568 times.
|
1765192 | } else if (idx % 2 == 0) { |
| 69 | 859624 | weight *= 2.0; | |
| 70 | } else { | ||
| 71 | 905568 | weight *= 4.0; | |
| 72 | } | ||
| 73 | } | ||
| 74 | 620984 | } | |
| 75 | |||
| 76 | 620984 | void VlasovaASimpsonMethodOMP::ComputePoint(const std::vector<int> &index, std::vector<double> &point) const { | |
| 77 | size_t dim = index.size(); | ||
| 78 | 620984 | point.resize(dim); | |
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 1857080 times.
✓ Branch 1 taken 620984 times.
|
2478064 | for (size_t i = 0; i < dim; ++i) { |
| 81 | 1857080 | point[i] = task_data_.a[i] + (index[i] * h_[i]); | |
| 82 | } | ||
| 83 | 620984 | } | |
| 84 | |||
| 85 | 88 | bool VlasovaASimpsonMethodOMP::RunImpl() { | |
| 86 | size_t dim = task_data_.a.size(); | ||
| 87 | |||
| 88 | size_t total_points = 1; | ||
| 89 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
|
256 | for (size_t i = 0; i < dim; ++i) { |
| 90 | 168 | total_points *= static_cast<size_t>(dimensions_[i]); | |
| 91 | } | ||
| 92 | |||
| 93 | double sum = 0.0; | ||
| 94 | |||
| 95 | 88 | #pragma omp parallel default(none) shared(dim, total_points) reduction(+ : sum) | |
| 96 | { | ||
| 97 | std::vector<int> cur_index(dim, 0); | ||
| 98 | std::vector<double> cur_point; | ||
| 99 | double local_weight = 0.0; | ||
| 100 | |||
| 101 | #pragma omp for schedule(static) | ||
| 102 | for (size_t idx = 0; idx < total_points; ++idx) { | ||
| 103 | size_t temp_idx = idx; | ||
| 104 | for (size_t i = 0; i < dim; ++i) { | ||
| 105 | cur_index[i] = static_cast<int>(temp_idx % static_cast<int>(dimensions_[i])); | ||
| 106 | temp_idx /= static_cast<int>(dimensions_[i]); | ||
| 107 | } | ||
| 108 | |||
| 109 | ComputeWeight(cur_index, local_weight); | ||
| 110 | ComputePoint(cur_index, cur_point); | ||
| 111 | sum += local_weight * task_data_.func(cur_point); | ||
| 112 | } | ||
| 113 | } | ||
| 114 | |||
| 115 | double factor = 1.0; | ||
| 116 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 88 times.
|
256 | for (size_t i = 0; i < dim; ++i) { |
| 117 | 168 | factor *= h_[i] / 3.0; | |
| 118 | } | ||
| 119 | |||
| 120 | 88 | result_ = sum * factor; | |
| 121 | 88 | GetOutput() = result_; | |
| 122 | |||
| 123 | 88 | return true; | |
| 124 | } | ||
| 125 | |||
| 126 | 88 | bool VlasovaASimpsonMethodOMP::PostProcessingImpl() { | |
| 127 | 88 | return std::isfinite(GetOutput()); | |
| 128 | } | ||
| 129 | |||
| 130 | } // namespace vlasova_a_simpson_method | ||
| 131 |