| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "timofeev_n_lexicographic_ordering/mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cstddef> | ||
| 6 | #include <utility> | ||
| 7 | |||
| 8 | #include "timofeev_n_lexicographic_ordering/common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace timofeev_n_lexicographic_ordering { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
|
14 | TimofeevNLexicographicOrderingMPI::TimofeevNLexicographicOrderingMPI(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | GetOutput() = std::pair<int, int>(1, 1); | ||
| 16 | 14 | } | |
| 17 | |||
| 18 | 14 | bool TimofeevNLexicographicOrderingMPI::ValidationImpl() { | |
| 19 | 14 | return true; | |
| 20 | } | ||
| 21 | |||
| 22 | 14 | bool TimofeevNLexicographicOrderingMPI::PreProcessingImpl() { | |
| 23 | 14 | return true; | |
| 24 | } | ||
| 25 | |||
| 26 | 14 | bool TimofeevNLexicographicOrderingMPI::RunImpl() { | |
| 27 | 14 | int rank = 0; | |
| 28 | 14 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 29 | 14 | int size = 0; | |
| 30 | 14 | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 31 | GetOutput() = std::pair<int, int>(1, 1); | ||
| 32 | |||
| 33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (size <= 1) { |
| 34 | ✗ | auto input = GetInput(); | |
| 35 | ✗ | for (size_t i = 0; !input.first.empty() && i < input.first.length() - 1; i++) { | |
| 36 | ✗ | GetOutput().first &= static_cast<int>(input.first[i] <= input.first[i + 1]); | |
| 37 | } | ||
| 38 | ✗ | for (size_t i = 0; !input.second.empty() && i < input.second.length() - 1; i++) { | |
| 39 | ✗ | GetOutput().second &= static_cast<int>(input.second[i] <= input.second[i + 1]); | |
| 40 | } | ||
| 41 | return true; | ||
| 42 | } | ||
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | if (rank == 0) { |
| 45 | 7 | auto input = GetInput(); | |
| 46 | 7 | size_t second_length = input.second.length(); | |
| 47 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | MPI_Send(&second_length, 1, MPI_UNSIGNED_LONG, 1, 0, MPI_COMM_WORLD); |
| 48 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
7 | MPI_Send(input.second.c_str(), static_cast<int>(second_length), MPI_CHAR, 1, 1, MPI_COMM_WORLD); |
| 49 | // only true if comparison is true on every step | ||
| 50 |
4/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 15 times.
|
22 | for (size_t i = 0; !input.first.empty() && i < input.first.length() - 1; i++) { |
| 51 | 15 | GetOutput().first &= static_cast<int>(input.first[i] <= input.first[i + 1]); | |
| 52 | } | ||
| 53 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | } else if (rank == 1) { |
| 54 | 7 | size_t llength = 0; | |
| 55 | // если упадёт на каких-то мудрёных тестах - может быть, дело в size_t | ||
| 56 | 7 | MPI_Recv(&llength, 1, MPI_UNSIGNED_LONG, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 57 | 7 | char *inpput = new char[(llength + 1) * sizeof(char)]; | |
| 58 | 7 | inpput[llength] = '\0'; | |
| 59 | 7 | MPI_Recv(inpput, static_cast<int>(llength), MPI_CHAR, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
| 60 |
4/4✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 5 times.
|
22 | for (size_t i = 0; llength != 0 && i < llength - 1; i++) { |
| 61 | 15 | GetOutput().second &= static_cast<int>(inpput[i] <= inpput[i + 1]); | |
| 62 | } | ||
| 63 | 7 | delete[] inpput; | |
| 64 | } | ||
| 65 | |||
| 66 | 14 | MPI_Bcast(&GetOutput().first, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
| 67 | 14 | MPI_Bcast(&GetOutput().second, 1, MPI_INT, 1, MPI_COMM_WORLD); | |
| 68 | |||
| 69 | 14 | MPI_Barrier(MPI_COMM_WORLD); | |
| 70 | |||
| 71 | return true; | ||
| 72 | } | ||
| 73 | |||
| 74 | 14 | bool TimofeevNLexicographicOrderingMPI::PostProcessingImpl() { | |
| 75 | // idk what else to put there | ||
| 76 | 14 | return true; | |
| 77 | } | ||
| 78 | |||
| 79 | } // namespace timofeev_n_lexicographic_ordering | ||
| 80 |