| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ovsyannikov_n_shell_batcher/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "ovsyannikov_n_shell_batcher/common/include/add_functs.hpp" | ||
| 9 | |||
| 10 | namespace ovsyannikov_n_shell_batcher { | ||
| 11 | |||
| 12 | 6 | bool OvsyannikovNShellBatcherMPI::ValidationImpl() { | |
| 13 | 6 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank_); | |
| 14 | 6 | MPI_Comm_size(MPI_COMM_WORLD, &world_size_); | |
| 15 | 6 | return true; | |
| 16 | } | ||
| 17 | |||
| 18 | 6 | bool OvsyannikovNShellBatcherMPI::PreProcessingImpl() { | |
| 19 | 6 | MPI_Comm_rank(MPI_COMM_WORLD, &world_rank_); | |
| 20 | 6 | MPI_Comm_size(MPI_COMM_WORLD, &world_size_); | |
| 21 | |||
| 22 | 6 | int global_size = 0; | |
| 23 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (world_rank_ == 0) { |
| 24 | 3 | global_size = static_cast<int>(GetInput().size()); | |
| 25 | } | ||
| 26 | 6 | MPI_Bcast(&global_size, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 27 | |||
| 28 | 6 | counts_.assign(world_size_, 0); | |
| 29 | 6 | displs_.assign(world_size_, 0); | |
| 30 | |||
| 31 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | const int base = (world_size_ > 0) ? (global_size / world_size_) : 0; |
| 32 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | const int rem = (world_size_ > 0) ? (global_size % world_size_) : 0; |
| 33 | |||
| 34 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
|
18 | for (int rank_index = 0; rank_index < world_size_; ++rank_index) { |
| 35 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
24 | counts_[rank_index] = base + ((rank_index < rem) ? 1 : 0); |
| 36 | } | ||
| 37 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 | for (int rank_index = 1; rank_index < world_size_; ++rank_index) { |
| 38 | 6 | displs_[rank_index] = displs_[rank_index - 1] + counts_[rank_index - 1]; | |
| 39 | } | ||
| 40 | |||
| 41 | 6 | local_.assign(static_cast<std::size_t>(counts_[world_rank_]), 0); | |
| 42 | |||
| 43 | int *send_buf = nullptr; | ||
| 44 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 | if (world_rank_ == 0 && global_size > 0) { |
| 45 | send_buf = GetInput().data(); | ||
| 46 | } | ||
| 47 | |||
| 48 | 6 | MPI_Scatterv(send_buf, counts_.data(), displs_.data(), MPI_INT, local_.data(), counts_[world_rank_], MPI_INT, 0, | |
| 49 | MPI_COMM_WORLD); | ||
| 50 | |||
| 51 | GetOutput().clear(); | ||
| 52 | 6 | return true; | |
| 53 | } | ||
| 54 | |||
| 55 | 6 | bool OvsyannikovNShellBatcherMPI::RunImpl() { | |
| 56 | 6 | ShellSort(&local_); | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | for (int step = 1; step < world_size_; step <<= 1) { |
| 59 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if ((world_rank_ % (2 * step)) == 0) { |
| 60 | 3 | const int partner = world_rank_ + step; | |
| 61 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (partner < world_size_) { |
| 62 | 3 | std::vector<int> other = RecvVector(partner, 1000 + step, MPI_COMM_WORLD); | |
| 63 |
2/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
6 | local_ = BatcherOddEvenMerge(local_, other); |
| 64 | } | ||
| 65 | } else { | ||
| 66 | 3 | const int partner = world_rank_ - step; | |
| 67 | 3 | SendVector(partner, 1000 + step, local_, MPI_COMM_WORLD); | |
| 68 | 3 | break; | |
| 69 | } | ||
| 70 | } | ||
| 71 | 6 | return true; | |
| 72 | } | ||
| 73 | |||
| 74 | 6 | bool OvsyannikovNShellBatcherMPI::PostProcessingImpl() { | |
| 75 | 6 | int out_size = 0; | |
| 76 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (world_rank_ == 0) { |
| 77 | 3 | GetOutput() = local_; | |
| 78 | 3 | out_size = static_cast<int>(GetOutput().size()); | |
| 79 | } | ||
| 80 | |||
| 81 | 6 | MPI_Bcast(&out_size, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 82 | |||
| 83 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (world_rank_ != 0) { |
| 84 | 3 | GetOutput().assign(static_cast<std::size_t>(out_size), 0); | |
| 85 | } | ||
| 86 | |||
| 87 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (out_size > 0) { |
| 88 | 6 | MPI_Bcast(GetOutput().data(), out_size, MPI_INT, 0, MPI_COMM_WORLD); | |
| 89 | } | ||
| 90 | 6 | return true; | |
| 91 | } | ||
| 92 | |||
| 93 | } // namespace ovsyannikov_n_shell_batcher | ||
| 94 |