| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "trofimov_n_linear_topology/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | |||
| 7 | #include "trofimov_n_linear_topology/common/include/common.hpp" | ||
| 8 | |||
| 9 | namespace trofimov_n_linear_topology { | ||
| 10 | |||
| 11 | 20 | TrofimovNLinearTopologyMPI::TrofimovNLinearTopologyMPI(const InType &in) { | |
| 12 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 13 | 20 | GetInput() = in; | |
| 14 | GetOutput() = 0; | ||
| 15 | 20 | } | |
| 16 | |||
| 17 | 20 | bool TrofimovNLinearTopologyMPI::ValidationImpl() { | |
| 18 | const auto &in = GetInput(); | ||
| 19 |
3/6✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
|
20 | return in.source >= 0 && in.target >= 0 && in.value >= 0; |
| 20 | } | ||
| 21 | |||
| 22 | 20 | bool TrofimovNLinearTopologyMPI::PreProcessingImpl() { | |
| 23 | 20 | MPI_Comm_rank(MPI_COMM_WORLD, &rank_); | |
| 24 | 20 | MPI_Comm_size(MPI_COMM_WORLD, &size_); | |
| 25 | 20 | GetOutput() = 0; | |
| 26 | 20 | return true; | |
| 27 | } | ||
| 28 | |||
| 29 | 20 | bool TrofimovNLinearTopologyMPI::RunImpl() { | |
| 30 | const auto &in = GetInput(); | ||
| 31 | |||
| 32 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (size_ == 1) { |
| 33 | ✗ | Work(in.value); | |
| 34 | ✗ | GetOutput() = in.value; | |
| 35 | ✗ | return true; | |
| 36 | } | ||
| 37 | |||
| 38 | 20 | Work((in.value / size_) + 1); | |
| 39 | |||
| 40 | 20 | int result = 0; | |
| 41 | |||
| 42 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (in.source == in.target) { |
| 43 | ✗ | if (rank_ == in.source) { | |
| 44 | ✗ | result = in.value; | |
| 45 | } | ||
| 46 | ✗ | MPI_Bcast(&result, 1, MPI_INT, in.source, MPI_COMM_WORLD); | |
| 47 | ✗ | GetOutput() = result; | |
| 48 | ✗ | return true; | |
| 49 | } | ||
| 50 | |||
| 51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | const int step = (in.target > in.source) ? 1 : -1; |
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (rank_ == in.source) { |
| 54 | 10 | result = in.value; | |
| 55 | 10 | MPI_Send(&result, 1, MPI_INT, rank_ + step, 0, MPI_COMM_WORLD); | |
| 56 | } | ||
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
|
40 | for (int curr_rank = in.source + step; curr_rank != in.target + step; curr_rank += step) { |
| 59 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
|
20 | if (rank_ == curr_rank) { |
| 60 | 10 | MPI_Recv(&result, 1, MPI_INT, rank_ - step, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 61 | 10 | Work(result); | |
| 62 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (curr_rank != in.target) { |
| 63 | ✗ | MPI_Send(&result, 1, MPI_INT, rank_ + step, 0, MPI_COMM_WORLD); | |
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | 20 | MPI_Bcast(&result, 1, MPI_INT, in.target, MPI_COMM_WORLD); | |
| 69 | 20 | GetOutput() = result; | |
| 70 | |||
| 71 | 20 | return true; | |
| 72 | } | ||
| 73 | |||
| 74 | 20 | bool TrofimovNLinearTopologyMPI::PostProcessingImpl() { | |
| 75 | 20 | return true; | |
| 76 | } | ||
| 77 | |||
| 78 | } // namespace trofimov_n_linear_topology | ||
| 79 |