| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "golovanov_d_matrix_max_elem//mpi/include/ops_mpi.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "golovanov_d_matrix_max_elem//common/include/common.hpp" | ||
| 9 | |||
| 10 | namespace golovanov_d_matrix_max_elem { | ||
| 11 | |||
| 12 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | GolovanovDMatrixMaxElemMPI::GolovanovDMatrixMaxElemMPI(const InType &in) { |
| 13 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 14 | GetInput() = in; | ||
| 15 | 8 | GetOutput() = 1234; | |
| 16 | 8 | } | |
| 17 | |||
| 18 | 8 | bool GolovanovDMatrixMaxElemMPI::ValidationImpl() { | |
| 19 | 8 | int columns = std::get<0>(GetInput()); | |
| 20 | 8 | int strokes = std::get<1>(GetInput()); | |
| 21 |
2/4✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
8 | return (columns > 0) && (strokes > 0) && (static_cast<int>(std::get<2>(GetInput()).size()) == (strokes * columns)) && |
| 22 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | (GetOutput() == 1234); |
| 23 | } | ||
| 24 | |||
| 25 | 8 | bool GolovanovDMatrixMaxElemMPI::PreProcessingImpl() { | |
| 26 | 8 | return true; | |
| 27 | } | ||
| 28 | |||
| 29 | 8 | bool GolovanovDMatrixMaxElemMPI::RunImpl() { | |
| 30 | 8 | int rank = 0; | |
| 31 | 8 | int processes = 0; | |
| 32 | 8 | int n = 0; | |
| 33 | 8 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 34 | 8 | MPI_Comm_size(MPI_COMM_WORLD, &processes); | |
| 35 | 8 | std::vector<double> elems; | |
| 36 | 8 | double answer = 0; | |
| 37 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | if (rank == 0) { |
| 38 | 4 | auto columns = std::get<0>(GetInput()); | |
| 39 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | auto strokes = std::get<1>(GetInput()); |
| 40 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | elems = std::get<2>(GetInput()); |
| 41 | 4 | auto count = columns * strokes; | |
| 42 | |||
| 43 | 4 | n = count / processes; | |
| 44 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (count % processes != 0) { |
| 45 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
|
8 | for (int i = 0; i < processes - (count % processes); i++) { |
| 46 | elems.push_back(elems[0]); | ||
| 47 | } | ||
| 48 | 4 | n++; | |
| 49 | } | ||
| 50 | } | ||
| 51 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); |
| 52 |
1/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
8 | std::vector<double> work_vector(n); |
| 53 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Scatter(elems.data(), n, MPI_DOUBLE, work_vector.data(), n, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
| 54 | 8 | double max = *std::ranges::max_element(work_vector); | |
| 55 |
1/2✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
|
8 | MPI_Allreduce(&max, &answer, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD); |
| 56 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | GetOutput() = answer; |
| 57 | 8 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | 8 | bool GolovanovDMatrixMaxElemMPI::PostProcessingImpl() { | |
| 61 | 8 | return true; | |
| 62 | } | ||
| 63 | |||
| 64 | } // namespace golovanov_d_matrix_max_elem | ||
| 65 |