| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "maslova_u_fast_sort_simple/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <iterator> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "maslova_u_fast_sort_simple/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace maslova_u_fast_sort_simple { | ||
| 14 | |||
| 15 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | MaslovaUFastSortSimpleMPI::MaslovaUFastSortSimpleMPI(const InType &in) { |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
12 | GetInput() = in; |
| 18 | 12 | } | |
| 19 | |||
| 20 | 12 | bool MaslovaUFastSortSimpleMPI::ValidationImpl() { | |
| 21 | 12 | int rank = 0; | |
| 22 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 23 | 12 | int flag = 0; | |
| 24 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (GetInput().size() > static_cast<size_t>(2147483647)) { |
| 26 | ✗ | flag = 1; | |
| 27 | } | ||
| 28 | } | ||
| 29 | 12 | MPI_Bcast(&flag, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 30 | 12 | return flag == 0; | |
| 31 | } | ||
| 32 | |||
| 33 | 12 | bool MaslovaUFastSortSimpleMPI::PreProcessingImpl() { | |
| 34 | 12 | return true; | |
| 35 | } | ||
| 36 | |||
| 37 | 10 | void MaslovaUFastSortSimpleMPI::TreeMerge(std::vector<int> &local_vec, int rank, int size) { | |
| 38 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 5 times.
|
15 | for (int step = 1; step < size; step *= 2) { |
| 39 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | if ((rank % (2 * step)) == 0) { |
| 40 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if ((rank + step) < size) { |
| 41 | 5 | int recv_size = 0; | |
| 42 | MPI_Status status; | ||
| 43 | 5 | MPI_Probe(rank + step, 0, MPI_COMM_WORLD, &status); | |
| 44 | 5 | MPI_Get_count(&status, MPI_INT, &recv_size); | |
| 45 | 5 | std::vector<int> received(recv_size); | |
| 46 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | MPI_Recv(received.data(), recv_size, MPI_INT, rank + step, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); |
| 47 | |||
| 48 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | std::vector<int> merged; |
| 49 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | merged.reserve(local_vec.size() + received.size()); |
| 50 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | std::ranges::merge(local_vec, received, std::back_inserter(merged)); |
| 51 | local_vec = std::move(merged); | ||
| 52 | } | ||
| 53 | } else { | ||
| 54 | 5 | int target = rank - step; | |
| 55 | 5 | MPI_Send(local_vec.data(), static_cast<int>(local_vec.size()), MPI_INT, target, 0, MPI_COMM_WORLD); | |
| 56 | 5 | break; | |
| 57 | } | ||
| 58 | } | ||
| 59 | 10 | } | |
| 60 | |||
| 61 | 12 | bool MaslovaUFastSortSimpleMPI::RunImpl() { | |
| 62 | 12 | int rank = 0; | |
| 63 | 12 | int size = 0; | |
| 64 | 12 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 65 | 12 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 66 | |||
| 67 | 12 | int total_size = 0; | |
| 68 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | if (rank == 0) { |
| 69 | 6 | total_size = static_cast<int>(GetInput().size()); | |
| 70 | } | ||
| 71 | 12 | MPI_Bcast(&total_size, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (total_size == 0) { |
| 74 | return true; | ||
| 75 | } | ||
| 76 | |||
| 77 | 10 | std::vector<int> send_counts(size); | |
| 78 |
1/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
10 | std::vector<int> displs(size); |
| 79 | 10 | int part = total_size / size; | |
| 80 | 10 | int rem = total_size % size; | |
| 81 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
|
30 | for (int i = 0; i < size; ++i) { |
| 82 |
4/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 10 times.
|
32 | send_counts[i] = part + (i < rem ? 1 : 0); |
| 83 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | displs[i] = (i == 0) ? 0 : displs[i - 1] + send_counts[i - 1]; |
| 84 | } | ||
| 85 | |||
| 86 |
1/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
10 | std::vector<int> local_vec(send_counts[rank]); |
| 87 |
3/4✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 3 taken 10 times.
✗ Branch 4 not taken.
|
15 | MPI_Scatterv(rank == 0 ? GetInput().data() : nullptr, send_counts.data(), displs.data(), MPI_INT, local_vec.data(), |
| 88 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | send_counts[rank], MPI_INT, 0, MPI_COMM_WORLD); |
| 89 | |||
| 90 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
|
10 | if (!local_vec.empty()) { |
| 91 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | QuickSort(local_vec.data(), 0, static_cast<int>(local_vec.size()) - 1); |
| 92 | } | ||
| 93 | |||
| 94 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | TreeMerge(local_vec, rank, size); |
| 95 | |||
| 96 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
|
10 | if (rank == 0) { |
| 97 | GetOutput() = std::move(local_vec); | ||
| 98 | } | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | 12 | bool MaslovaUFastSortSimpleMPI::PostProcessingImpl() { | |
| 103 | 12 | return true; | |
| 104 | } | ||
| 105 | |||
| 106 | } // namespace maslova_u_fast_sort_simple | ||
| 107 |