GCC Code Coverage Report


Directory: ./
File: tasks/potashnik_m_short_ways_bellford/mpi/include/ops_mpi.hpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 24 24 100.0%
Functions: 2 2 100.0%
Branches: 10 12 83.3%

Line Branch Exec Source
1 #pragma once
2
3 #include <mpi.h>
4
5 #include <vector>
6
7 #include "potashnik_m_short_ways_bellford/common/include/common.hpp"
8 #include "task/include/task.hpp"
9
10 namespace potashnik_m_short_ways_bellford {
11
12 class PotashnikMShortWaysBellfordMPI : public BaseTask {
13 public:
14 static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
15 return ppc::task::TypeOfTask::kMPI;
16 }
17 explicit PotashnikMShortWaysBellfordMPI(const InType &in);
18
19 private:
20 bool ValidationImpl() override;
21 bool PreProcessingImpl() override;
22 bool RunImpl() override;
23 bool PostProcessingImpl() override;
24 };
25
26 104 inline void BellmanFordAlgoIterationMpi(const Graph &g, const std::vector<int> &dist, std::vector<int> &dist_next,
27 int start, int end) {
28 104 dist_next = dist;
29
2/2
✓ Branch 0 taken 742 times.
✓ Branch 1 taken 104 times.
846 for (int uidx = start; uidx < end; uidx++) {
30
2/2
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 498 times.
742 if (dist[uidx] == 1e9) {
31 244 continue;
32 }
33 498 IterateThroughVertex(g, uidx, dist, dist_next);
34 }
35 104 }
36
37 10 inline void BellmanFordAlgoMpi(const Graph &g, int source, std::vector<int> &dist) {
38 10 int rank = 0;
39 10 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
40 10 int size = 0;
41 10 MPI_Comm_size(MPI_COMM_WORLD, &size);
42
43 10 int n = g.n;
44
45 10 dist.assign(n, 1e9);
46
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (rank == 0) {
47 5 dist[source] = 0;
48 }
49
50 10 MPI_Bcast(dist.data(), n, MPI_INT, 0, MPI_COMM_WORLD);
51
52 10 std::vector<int> dist_next(n);
53
54 10 int start = rank * n / size;
55 10 int end = (rank + 1) * n / size;
56
57
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 10 times.
114 for (int i = 0; i < n - 1; i++) {
58
1/2
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
104 BellmanFordAlgoIterationMpi(g, dist, dist_next, start, end);
59
1/2
✓ Branch 1 taken 104 times.
✗ Branch 2 not taken.
104 MPI_Allreduce(dist_next.data(), dist.data(), n, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
60 }
61 10 }
62
63 } // namespace potashnik_m_short_ways_bellford
64