GCC Code Coverage Report


Directory: ./
File: tasks/chaschin_v_broadcast/mpi/src/ops_mpi.cpp
Date: 2026-01-10 02:40:41
Exec Total Coverage
Lines: 29 29 100.0%
Functions: 4 12 33.3%
Branches: 11 18 61.1%

Line Branch Exec Source
1 #include "chaschin_v_broadcast/mpi/include/ops_mpi.hpp"
2
3 #include <mpi.h>
4
5 namespace chaschin_v_broadcast {
6
7 template <typename T>
8
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 ChaschinVBroadcastMPI<T>::ChaschinVBroadcastMPI(const InType &in) {
9 this->SetTypeOfTask(GetStaticTypeOfTask());
10
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 this->GetInput() = in;
11
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
40 this->GetOutput().resize(0);
12 40 }
13
14 template <typename T>
15
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
40 bool ChaschinVBroadcastMPI<T>::ValidationImpl() {
16
2/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
40 return (!this->GetInput().empty()) && (this->GetOutput().empty());
17 }
18
19 template <typename T>
20 40 bool ChaschinVBroadcastMPI<T>::PreProcessingImpl() {
21 40 return true;
22 }
23
24 template <typename T>
25 40 bool ChaschinVBroadcastMPI<T>::RunImpl() {
26 40 int rank = 0;
27 40 int size = 0;
28 40 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29 40 MPI_Comm_size(MPI_COMM_WORLD, &size);
30
31 MPI_Datatype mpi_type = MPI_DATATYPE_NULL;
32 if constexpr (std::is_same_v<T, int>) {
33 mpi_type = MPI_INT;
34 } else if constexpr (std::is_same_v<T, float>) {
35 mpi_type = MPI_FLOAT;
36 } else if constexpr (std::is_same_v<T, double>) {
37 mpi_type = MPI_DOUBLE;
38 }
39
40 auto &input = this->GetInput();
41 40 int count = static_cast<int>(input.size());
42 void *data_ptr = input.data();
43
44 const int root = 0;
45 40 int virtual_rank = (rank + size - root) % size;
46
47 int mask = 1;
48
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
80 while (mask < size) {
49
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
40 if ((virtual_rank & mask) == 0) {
50 20 int dest = virtual_rank | mask;
51
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
20 if (dest < size) {
52 20 int real_dest = (dest + root) % size;
53 20 MPI_Send(data_ptr, count, mpi_type, real_dest, 0, MPI_COMM_WORLD);
54 }
55 } else {
56 20 int src = virtual_rank & (~mask);
57 20 int real_src = (src + root) % size;
58 20 MPI_Recv(data_ptr, count, mpi_type, real_src, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
59 }
60 40 mask <<= 1;
61 }
62
63 40 this->GetOutput() = input;
64 40 return true;
65 }
66
67 template <typename T>
68 20 bool ChaschinVBroadcastMPI<T>::PostProcessingImpl() {
69 20 return true;
70 }
71
72 template class chaschin_v_broadcast::ChaschinVBroadcastMPI<int>;
73 template class chaschin_v_broadcast::ChaschinVBroadcastMPI<float>;
74 template class chaschin_v_broadcast::ChaschinVBroadcastMPI<double>;
75
76 } // namespace chaschin_v_broadcast
77