GCC Code Coverage Report


Directory: ./
File: tasks/sabirov_s_hypercube/seq/src/ops_seq.cpp
Date: 2026-01-27 01:59:34
Exec Total Coverage
Lines: 0 37 0.0%
Functions: 0 6 0.0%
Branches: 0 32 0.0%

Line Branch Exec Source
1 #include "sabirov_s_hypercube/seq/include/ops_seq.hpp"
2
3 #include <cmath>
4 #include <cstddef>
5 #include <vector>
6
7 #include "sabirov_s_hypercube/common/include/common.hpp"
8
9 namespace sabirov_s_hypercube {
10
11 SabirovSHypercubeSEQ::SabirovSHypercubeSEQ(const InType &in) {
12 SetTypeOfTask(GetStaticTypeOfTask());
13 GetInput() = in;
14 GetOutput() = HypercubeOutput{.received_data = {}, .route = {}, .success = false};
15 }
16
17 bool SabirovSHypercubeSEQ::ValidationImpl() {
18 const auto &input = GetInput();
19
20 // Проверка размерности
21 if (input.dimension < 0) {
22 return false;
23 }
24
25 int num_nodes = 1 << input.dimension; // 2^dimension
26
27 // Проверка корректности рангов источника и получателя
28 if (input.source_rank < 0 || input.source_rank >= num_nodes) {
29 return false;
30 }
31
32 if (input.dest_rank < 0 || input.dest_rank >= num_nodes) {
33 return false;
34 }
35
36 return true;
37 }
38
39 bool SabirovSHypercubeSEQ::PreProcessingImpl() {
40 dimension_ = GetInput().dimension;
41 num_nodes_ = 1 << dimension_;
42
43 // Инициализация выходных данных
44 GetOutput().success = false;
45 GetOutput().received_data.clear();
46 GetOutput().route.clear();
47
48 return true;
49 }
50
51 std::vector<int> SabirovSHypercubeSEQ::EmulateHypercubeTransfer(int source, int dest, const std::vector<int> &data) {
52 // Вычисляем маршрут от источника к получателю
53 std::vector<int> route = BuildRoute(source, dest);
54
55 // Сохраняем маршрут
56 if (!route.empty()) {
57 GetOutput().route.assign(route.begin(), route.end());
58 } else {
59 GetOutput().route.clear();
60 }
61
62 // В последовательной версии эмулируем передачу
63 // Данные просто копируются, так как нет реальной передачи между процессами
64 std::vector<int> result;
65 if (!data.empty()) {
66 result.assign(data.begin(), data.end());
67 }
68
69 // Эмуляция пересылки через промежуточные узлы
70 // В реальной системе данные проходили бы через каждый узел маршрута
71 // Здесь мы просто проверяем корректность маршрута
72
73 // Проверяем, что каждый шаг маршрута - это переход к соседу в гиперкубе
74 for (size_t i = 1; i < route.size(); ++i) {
75 int prev = route[i - 1];
76 int curr = route[i];
77
78 // Расстояние Хэмминга между соседями должно быть равно 1
79 if (HammingDistance(prev, curr) != 1) {
80 // Некорректный маршрут
81 return {};
82 }
83 }
84
85 return result;
86 }
87
88 bool SabirovSHypercubeSEQ::RunImpl() {
89 const auto &input = GetInput();
90
91 int source = input.source_rank;
92 int dest = input.dest_rank;
93 const auto &data = input.data;
94
95 // Эмуляция передачи данных через гиперкуб
96 std::vector<int> received = EmulateHypercubeTransfer(source, dest, data);
97
98 // Сохраняем результат
99 if (!received.empty()) {
100 GetOutput().received_data.assign(received.begin(), received.end());
101 } else {
102 GetOutput().received_data.clear();
103 }
104 GetOutput().success = true;
105
106 return true;
107 }
108
109 bool SabirovSHypercubeSEQ::PostProcessingImpl() {
110 return GetOutput().success;
111 }
112
113 } // namespace sabirov_s_hypercube
114