| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "redkina_a_min_elem_vec/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <climits> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "redkina_a_min_elem_vec/common/include/common.hpp" | ||
| 10 | |||
| 11 | namespace redkina_a_min_elem_vec { | ||
| 12 | |||
| 13 |
1/2✓ Branch 1 taken 132 times.
✗ Branch 2 not taken.
|
132 | RedkinaAMinElemVecMPI::RedkinaAMinElemVecMPI(const InType &in) { |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 |
1/2✓ Branch 1 taken 132 times.
✗ Branch 2 not taken.
|
132 | GetInput() = in; |
| 16 | 132 | GetOutput() = 0; | |
| 17 | 132 | } | |
| 18 | |||
| 19 | 132 | bool RedkinaAMinElemVecMPI::ValidationImpl() { | |
| 20 | 132 | return !GetInput().empty(); | |
| 21 | } | ||
| 22 | |||
| 23 | 132 | bool RedkinaAMinElemVecMPI::PreProcessingImpl() { | |
| 24 | 132 | return true; | |
| 25 | } | ||
| 26 | |||
| 27 | 132 | bool RedkinaAMinElemVecMPI::RunImpl() { | |
| 28 | 132 | int rank = 0; | |
| 29 | 132 | int size = 0; | |
| 30 | 132 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 31 | 132 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 32 | |||
| 33 | 132 | int n = 0; | |
| 34 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
|
132 | if (rank == 0) { |
| 35 | 66 | n = static_cast<int>(GetInput().size()); | |
| 36 | } | ||
| 37 | |||
| 38 | 132 | MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 39 | |||
| 40 | 132 | const int base = n / size; | |
| 41 | 132 | const int rem = n % size; | |
| 42 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 94 times.
|
132 | const int size_l = (rank < rem) ? base + 1 : base; |
| 43 | |||
| 44 | 132 | std::vector<int> vec_l(size_l); | |
| 45 | |||
| 46 |
1/4✓ Branch 1 taken 132 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
132 | std::vector<int> counts(size, 0); |
| 47 |
1/4✓ Branch 1 taken 132 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
132 | std::vector<int> displs(size, 0); |
| 48 | |||
| 49 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
|
132 | if (rank == 0) { |
| 50 |
2/2✓ Branch 0 taken 132 times.
✓ Branch 1 taken 66 times.
|
198 | for (int i = 0; i < size; ++i) { |
| 51 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 94 times.
|
132 | counts[i] = (i < rem) ? base + 1 : base; |
| 52 | } | ||
| 53 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
|
132 | for (int i = 1; i < size; ++i) { |
| 54 | 66 | displs[i] = displs[i - 1] + counts[i - 1]; | |
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 |
7/8✓ Branch 0 taken 128 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 66 times.
✓ Branch 5 taken 66 times.
✓ Branch 7 taken 132 times.
✗ Branch 8 not taken.
|
396 | MPI_Scatterv(rank == 0 ? GetInput().data() : nullptr, rank == 0 ? counts.data() : nullptr, |
| 59 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 66 times.
|
132 | rank == 0 ? displs.data() : nullptr, MPI_INT, size_l > 0 ? vec_l.data() : nullptr, size_l, MPI_INT, 0, |
| 60 | MPI_COMM_WORLD); | ||
| 61 | |||
| 62 | 132 | int min_l = INT_MAX; | |
| 63 |
2/2✓ Branch 0 taken 2494 times.
✓ Branch 1 taken 132 times.
|
2626 | for (const int v : vec_l) { |
| 64 | 2494 | min_l = std::min(min_l, v); | |
| 65 | } | ||
| 66 | |||
| 67 | 132 | int min_g = 0; | |
| 68 |
1/2✓ Branch 1 taken 132 times.
✗ Branch 2 not taken.
|
132 | MPI_Allreduce(&min_l, &min_g, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD); |
| 69 | |||
| 70 |
1/2✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
|
132 | GetOutput() = min_g; |
| 71 | 132 | return true; | |
| 72 | } | ||
| 73 | |||
| 74 | 132 | bool RedkinaAMinElemVecMPI::PostProcessingImpl() { | |
| 75 | 132 | return true; | |
| 76 | } | ||
| 77 | |||
| 78 | } // namespace redkina_a_min_elem_vec | ||
| 79 |