| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ovsyannikov_n_star/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "ovsyannikov_n_star/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace ovsyannikov_n_star { | ||
| 10 | |||
| 11 | constexpr int kTerm = -1; | ||
| 12 | |||
| 13 | 6 | OvsyannikovNStarMPI::OvsyannikovNStarMPI(const InType &in) { | |
| 14 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 15 | 6 | GetInput() = in; | |
| 16 | GetOutput() = 0; | ||
| 17 | 6 | } | |
| 18 | |||
| 19 | 6 | bool OvsyannikovNStarMPI::ValidationImpl() { | |
| 20 | 6 | return true; | |
| 21 | } | ||
| 22 | |||
| 23 | 6 | bool OvsyannikovNStarMPI::PreProcessingImpl() { | |
| 24 | 6 | int rank = 0; | |
| 25 | 6 | int size = 0; | |
| 26 | 6 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 27 | 6 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 28 | |||
| 29 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (rank != 0) { |
| 30 | 3 | int data_size = GetInput(); | |
| 31 | 3 | dest_ = 1 + (rank % (size - 1)); | |
| 32 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (dest_ == rank) { |
| 33 | 3 | dest_ = (dest_ + 1) % size; | |
| 34 | } | ||
| 35 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (dest_ == 0) { |
| 36 | 3 | dest_ = 1; | |
| 37 | } | ||
| 38 | |||
| 39 | 3 | data_.resize(data_size); | |
| 40 | 3 | output_.resize(data_size); | |
| 41 | |||
| 42 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | for (int i = 0; i < data_size; ++i) { |
| 43 | 6 | data_[i] = i; | |
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | 6 | return true; | |
| 48 | } | ||
| 49 | |||
| 50 | 6 | bool OvsyannikovNStarMPI::RunImpl() { | |
| 51 | 6 | int rank = 0; | |
| 52 | 6 | int size = 0; | |
| 53 | 6 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 54 | 6 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 55 | |||
| 56 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (rank == 0) { |
| 57 | 3 | int nodes = size - 1; | |
| 58 | 3 | std::vector<int> buf; | |
| 59 | MPI_Status status; | ||
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | for (int i = 0; i < nodes; ++i) { |
| 62 | 3 | int dst = 0; | |
| 63 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Recv(&dst, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status); |
| 64 | 3 | int src = status.MPI_SOURCE; | |
| 65 | |||
| 66 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Probe(src, 0, MPI_COMM_WORLD, &status); |
| 67 | 3 | int buf_size = 0; | |
| 68 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Get_count(&status, MPI_INT, &buf_size); |
| 69 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | buf.resize(buf_size); |
| 70 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Recv(buf.data(), buf_size, MPI_INT, src, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); |
| 71 | |||
| 72 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Send(&src, 1, MPI_INT, dst, 0, MPI_COMM_WORLD); |
| 73 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Send(buf.data(), buf_size, MPI_INT, dst, 0, MPI_COMM_WORLD); |
| 74 | } | ||
| 75 | |||
| 76 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | for (int i = 0; i < nodes; ++i) { |
| 77 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | MPI_Send(&kTerm, 1, MPI_INT, i + 1, 0, MPI_COMM_WORLD); |
| 78 | } | ||
| 79 | |||
| 80 | } else { | ||
| 81 | 3 | MPI_Send(&dest_, 1, MPI_INT, 0, 0, MPI_COMM_WORLD); | |
| 82 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | int send_size = data_.empty() ? 0 : static_cast<int>(data_.size()); |
| 83 | 3 | MPI_Send(data_.data(), send_size, MPI_INT, 0, 0, MPI_COMM_WORLD); | |
| 84 | |||
| 85 | while (true) { | ||
| 86 | 6 | int src = 0; | |
| 87 | 6 | MPI_Recv(&src, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 88 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (src == kTerm) { |
| 89 | break; | ||
| 90 | } | ||
| 91 | |||
| 92 | MPI_Status status; | ||
| 93 | 3 | MPI_Probe(0, 0, MPI_COMM_WORLD, &status); | |
| 94 | 3 | int buf_size = 0; | |
| 95 | 3 | MPI_Get_count(&status, MPI_INT, &buf_size); | |
| 96 | 3 | output_.resize(buf_size); | |
| 97 | 3 | MPI_Recv(output_.data(), buf_size, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 98 | 3 | } | |
| 99 | } | ||
| 100 | |||
| 101 | 6 | return true; | |
| 102 | } | ||
| 103 | |||
| 104 | 6 | bool OvsyannikovNStarMPI::PostProcessingImpl() { | |
| 105 | 6 | int rank = 0; | |
| 106 | 6 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 107 | |||
| 108 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | if (rank != 0) { |
| 109 | 3 | GetOutput() = static_cast<OutType>(output_.size()); | |
| 110 | } else { | ||
| 111 | 3 | GetOutput() = 0; | |
| 112 | } | ||
| 113 | |||
| 114 | 6 | return true; | |
| 115 | } | ||
| 116 | |||
| 117 | } // namespace ovsyannikov_n_star | ||
| 118 |