| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "nikitina_v_trans_all_one_distrib/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <functional> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "nikitina_v_trans_all_one_distrib/common/include/common.hpp" | ||
| 11 | |||
| 12 | namespace nikitina_v_trans_all_one_distrib { | ||
| 13 | |||
| 14 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | TestTaskMPI::TestTaskMPI(const InType &in) { |
| 15 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 16 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | InType tmp = in; |
| 17 | GetInput().swap(tmp); | ||
| 18 | 12 | } | |
| 19 | |||
| 20 | 12 | bool TestTaskMPI::ValidationImpl() { | |
| 21 | 12 | return true; | |
| 22 | } | ||
| 23 | |||
| 24 | 12 | bool TestTaskMPI::PreProcessingImpl() { | |
| 25 | 12 | return true; | |
| 26 | } | ||
| 27 | |||
| 28 | 12 | bool TestTaskMPI::RunImpl() { | |
| 29 | 12 | int rank = 0; | |
| 30 | 12 | int size = 0; | |
| 31 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 32 | 12 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 33 | |||
| 34 | 12 | int input_size = static_cast<int>(GetInput().size()); | |
| 35 | 12 | int global_vec_size = input_size; | |
| 36 | 12 | MPI_Bcast(&global_vec_size, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 37 | |||
| 38 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (global_vec_size == 0) { |
| 39 | return true; | ||
| 40 | } | ||
| 41 | |||
| 42 | 12 | std::vector<int> current_values = GetInput(); | |
| 43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (current_values.size() != static_cast<size_t>(global_vec_size)) { |
| 44 | ✗ | current_values.resize(static_cast<size_t>(global_vec_size), 0); | |
| 45 | } | ||
| 46 | |||
| 47 | 12 | int left_child = (2 * rank) + 1; | |
| 48 | 12 | int right_child = (2 * rank) + 2; | |
| 49 | 12 | int parent = (rank - 1) / 2; | |
| 50 | |||
| 51 | MPI_Status status; | ||
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (left_child < size) { |
| 54 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | std::vector<int> recv_buf(static_cast<size_t>(global_vec_size)); |
| 55 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | MPI_Recv(recv_buf.data(), global_vec_size, MPI_INT, left_child, 0, MPI_COMM_WORLD, &status); |
| 56 | std::ranges::transform(current_values, recv_buf, current_values.begin(), std::plus<>()); | ||
| 57 | } | ||
| 58 | |||
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (right_child < size) { |
| 60 | ✗ | std::vector<int> recv_buf(static_cast<size_t>(global_vec_size)); | |
| 61 | ✗ | MPI_Recv(recv_buf.data(), global_vec_size, MPI_INT, right_child, 0, MPI_COMM_WORLD, &status); | |
| 62 | std::ranges::transform(current_values, recv_buf, current_values.begin(), std::plus<>()); | ||
| 63 | } | ||
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank != 0) { |
| 66 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | MPI_Send(current_values.data(), global_vec_size, MPI_INT, parent, 0, MPI_COMM_WORLD); |
| 67 | } | ||
| 68 | |||
| 69 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank != 0) { |
| 70 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | MPI_Recv(current_values.data(), global_vec_size, MPI_INT, parent, 1, MPI_COMM_WORLD, &status); |
| 71 | } | ||
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (left_child < size) { |
| 74 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | MPI_Send(current_values.data(), global_vec_size, MPI_INT, left_child, 1, MPI_COMM_WORLD); |
| 75 | } | ||
| 76 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (right_child < size) { |
| 77 | ✗ | MPI_Send(current_values.data(), global_vec_size, MPI_INT, right_child, 1, MPI_COMM_WORLD); | |
| 78 | } | ||
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 81 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | GetOutput().resize(static_cast<size_t>(global_vec_size)); |
| 82 | std::ranges::copy(current_values, GetOutput().begin()); | ||
| 83 | } | ||
| 84 | |||
| 85 | return true; | ||
| 86 | } | ||
| 87 | |||
| 88 | 12 | bool TestTaskMPI::PostProcessingImpl() { | |
| 89 | 12 | return true; | |
| 90 | } | ||
| 91 | |||
| 92 | } // namespace nikitina_v_trans_all_one_distrib | ||
| 93 |