GCC Code Coverage Report


Directory: ./
File: tasks/vlasova_a_simpson_method/all/src/ops_all.cpp
Date: 2026-06-04 20:25:32
Exec Total Coverage
Lines: 73 73 100.0%
Functions: 8 8 100.0%
Branches: 32 42 76.2%

Line Branch Exec Source
1 #include "vlasova_a_simpson_method/all/include/ops_all.hpp"
2
3 #include <mpi.h>
4 #include <tbb/blocked_range.h>
5 #include <tbb/parallel_reduce.h>
6
7 #include <cmath>
8 #include <cstddef>
9 #include <utility>
10 #include <vector>
11
12 #include "vlasova_a_simpson_method/common/include/common.hpp"
13
14 namespace vlasova_a_simpson_method {
15
16 44 VlasovaASimpsonMethodALL::VlasovaASimpsonMethodALL(InType in) : task_data_(std::move(in)) {
17 SetTypeOfTask(GetStaticTypeOfTask());
18 44 GetOutput() = 0.0;
19 44 }
20
21
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
44 bool VlasovaASimpsonMethodALL::ValidationImpl() {
22 size_t dim = task_data_.a.size();
23
24
3/6
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 44 times.
44 if (dim == 0 || dim != task_data_.b.size() || dim != task_data_.n.size()) {
25 return false;
26 }
27
28
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 44 times.
128 for (size_t i = 0; i < dim; ++i) {
29
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 if (task_data_.a[i] >= task_data_.b[i]) {
30 return false;
31 }
32
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
84 if (task_data_.n[i] <= 0 || task_data_.n[i] % 2 != 0) {
33 return false;
34 }
35 }
36
37
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
44 if (!task_data_.func) {
38 return false;
39 }
40
41 44 return GetOutput() == 0.0;
42 }
43
44 44 bool VlasovaASimpsonMethodALL::PreProcessingImpl() {
45 44 result_ = 0.0;
46 44 GetOutput() = 0.0;
47
48 size_t dim = task_data_.a.size();
49 44 h_.resize(dim);
50 44 dimensions_.resize(dim);
51
52
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 44 times.
128 for (size_t i = 0; i < dim; ++i) {
53 84 h_[i] = (task_data_.b[i] - task_data_.a[i]) / task_data_.n[i];
54 84 dimensions_[i] = task_data_.n[i] + 1;
55 }
56
57 44 return true;
58 }
59
60 155246 void VlasovaASimpsonMethodALL::ComputeWeight(const std::vector<int> &index, double &weight) const {
61 155246 weight = 1.0;
62 size_t dim = index.size();
63
64
2/2
✓ Branch 0 taken 464270 times.
✓ Branch 1 taken 155246 times.
619516 for (size_t i = 0; i < dim; ++i) {
65 464270 int idx = index[i];
66 464270 int steps = task_data_.n[i];
67
68
2/2
✓ Branch 0 taken 441298 times.
✓ Branch 1 taken 22972 times.
464270 if (idx == 0 || idx == steps) {
69 weight *= 1.0;
70
2/2
✓ Branch 0 taken 214906 times.
✓ Branch 1 taken 226392 times.
441298 } else if (idx % 2 == 0) {
71 214906 weight *= 2.0;
72 } else {
73 226392 weight *= 4.0;
74 }
75 }
76 155246 }
77
78 155246 void VlasovaASimpsonMethodALL::ComputePoint(const std::vector<int> &index, std::vector<double> &point) const {
79 size_t dim = index.size();
80 155246 point.resize(dim);
81
82
2/2
✓ Branch 0 taken 464270 times.
✓ Branch 1 taken 155246 times.
619516 for (size_t i = 0; i < dim; ++i) {
83 464270 point[i] = task_data_.a[i] + (index[i] * h_[i]);
84 }
85 155246 }
86
87 44 bool VlasovaASimpsonMethodALL::RunImpl() {
88 44 int rank = 0;
89 44 int size = 1;
90 44 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
91 44 MPI_Comm_size(MPI_COMM_WORLD, &size);
92
93 size_t dim = task_data_.a.size();
94
95 size_t total_points = 1;
96
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 44 times.
128 for (size_t i = 0; i < dim; ++i) {
97 84 total_points *= static_cast<size_t>(dimensions_[i]);
98 }
99
100 44 const auto urank = static_cast<size_t>(rank);
101 44 const auto usize = static_cast<size_t>(size);
102 44 const size_t chunk = total_points / usize;
103 44 const size_t rem = total_points % usize;
104
105 size_t begin = 0;
106 size_t end = 0;
107
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 22 times.
44 if (urank < rem) {
108 22 begin = urank * (chunk + 1);
109 22 end = begin + (chunk + 1);
110 } else {
111 22 begin = (rem * (chunk + 1)) + ((urank - rem) * chunk);
112 22 end = begin + chunk;
113 }
114
115 88 double local_sum = tbb::parallel_reduce(tbb::blocked_range<size_t>(begin, end), 0.0,
116 44 [this, dim](const tbb::blocked_range<size_t> &range, double acc) {
117 2666 std::vector<int> cur_index(dim, 0);
118 2666 std::vector<double> cur_point;
119 2666 double local_weight = 0.0;
120
121
2/2
✓ Branch 0 taken 155246 times.
✓ Branch 1 taken 2666 times.
157912 for (size_t idx = range.begin(); idx != range.end(); ++idx) {
122 size_t temp = idx;
123
2/2
✓ Branch 0 taken 464270 times.
✓ Branch 1 taken 155246 times.
619516 for (size_t i = 0; i < dim; ++i) {
124 464270 cur_index[i] = static_cast<int>(temp % static_cast<size_t>(dimensions_[i]));
125 464270 temp /= static_cast<size_t>(dimensions_[i]);
126 }
127 155246 ComputeWeight(cur_index, local_weight);
128
1/2
✓ Branch 1 taken 155246 times.
✗ Branch 2 not taken.
155246 ComputePoint(cur_index, cur_point);
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 155246 times.
310492 acc += local_weight * task_data_.func(cur_point);
130 }
131 2666 return acc;
132 10 }, [](double x, double y) { return x + y; });
133
134 44 double global_sum = 0.0;
135 44 MPI_Allreduce(&local_sum, &global_sum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
136
137 double factor = 1.0;
138
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 44 times.
128 for (size_t i = 0; i < dim; ++i) {
139 84 factor *= h_[i] / 3.0;
140 }
141 44 result_ = global_sum * factor;
142 44 GetOutput() = result_;
143
144 44 return true;
145 }
146
147 44 bool VlasovaASimpsonMethodALL::PostProcessingImpl() {
148 44 return std::isfinite(GetOutput());
149 }
150
151 } // namespace vlasova_a_simpson_method
152