| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "tabalaev_a_elem_mat_min/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <climits> | ||
| 7 | #include <cstddef> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "tabalaev_a_elem_mat_min/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace tabalaev_a_elem_mat_min { | ||
| 14 | |||
| 15 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | TabalaevAElemMatMinMPI::TabalaevAElemMatMinMPI(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 | GetInput() = in; | ||
| 18 | 12 | GetOutput() = 0; | |
| 19 | 12 | } | |
| 20 | |||
| 21 | 12 | bool TabalaevAElemMatMinMPI::ValidationImpl() { | |
| 22 | 12 | int world_rank = 0; | |
| 23 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); | |
| 24 | |||
| 25 | 12 | int validation = 0; | |
| 26 | |||
| 27 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (world_rank == 0) { |
| 28 | auto &rows = std::get<0>(GetInput()); | ||
| 29 | auto &columns = std::get<1>(GetInput()); | ||
| 30 | auto &matrix = std::get<2>(GetInput()); | ||
| 31 | |||
| 32 |
4/8✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
6 | if ((rows != 0 && columns != 0) && (!matrix.empty()) && (matrix.size() == rows * columns)) { |
| 33 | 6 | validation = 1; | |
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | 12 | MPI_Bcast(&validation, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 38 | |||
| 39 | 12 | return validation != 0; | |
| 40 | } | ||
| 41 | |||
| 42 | 12 | bool TabalaevAElemMatMinMPI::PreProcessingImpl() { | |
| 43 | 12 | GetOutput() = 0; | |
| 44 | 12 | return true; | |
| 45 | } | ||
| 46 | |||
| 47 | 12 | bool TabalaevAElemMatMinMPI::RunImpl() { | |
| 48 | 12 | int world_size = 1; | |
| 49 | 12 | MPI_Comm_size(MPI_COMM_WORLD, &world_size); | |
| 50 | 12 | int world_rank = 0; | |
| 51 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); | |
| 52 | |||
| 53 | 12 | std::vector<int> matrix; | |
| 54 |
1/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | std::vector<int> sendcounts(world_size); |
| 55 |
1/4✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
12 | std::vector<int> displs(world_size); |
| 56 | 12 | std::vector<int> local_matrix; | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (world_rank == 0) { |
| 59 | auto &input = GetInput(); | ||
| 60 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | matrix = std::get<2>(input); |
| 61 | |||
| 62 | size_t matrix_size = matrix.size(); | ||
| 63 | 6 | size_t part_size = matrix_size / world_size; | |
| 64 | 6 | size_t remainder = matrix_size % world_size; | |
| 65 | |||
| 66 | int offset = 0; | ||
| 67 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | for (size_t i = 0; std::cmp_less(i, world_size); ++i) { |
| 68 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
21 | sendcounts[i] = static_cast<int>(part_size) + (i < remainder ? 1 : 0); |
| 69 | 12 | displs[i] = offset; | |
| 70 | 12 | offset += sendcounts[i]; | |
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Bcast(sendcounts.data(), world_size, MPI_INT, 0, MPI_COMM_WORLD); |
| 75 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | int local_size = sendcounts[world_rank]; |
| 76 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | local_matrix.resize(local_size); |
| 77 | |||
| 78 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
|
18 | MPI_Scatterv(world_rank == 0 ? matrix.data() : nullptr, sendcounts.data(), displs.data(), MPI_INT, |
| 79 | local_matrix.data(), local_size, MPI_INT, 0, MPI_COMM_WORLD); | ||
| 80 | |||
| 81 | 12 | int local_minik = INT_MAX; | |
| 82 |
2/2✓ Branch 0 taken 251 times.
✓ Branch 1 taken 12 times.
|
263 | for (int elem : local_matrix) { |
| 83 | 251 | local_minik = std::min(local_minik, elem); | |
| 84 | } | ||
| 85 | |||
| 86 | 12 | int global_minik = 0; | |
| 87 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MPI_Allreduce(&local_minik, &global_minik, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD); |
| 88 | |||
| 89 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
|
12 | GetOutput() = global_minik; |
| 90 | |||
| 91 | 12 | return true; | |
| 92 | } | ||
| 93 | |||
| 94 | 12 | bool TabalaevAElemMatMinMPI::PostProcessingImpl() { | |
| 95 | 12 | return true; | |
| 96 | } | ||
| 97 | |||
| 98 | } // namespace tabalaev_a_elem_mat_min | ||
| 99 |